at91sam9m10g45ek.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007-2008
  4. * Stelian Pop <stelian@popies.net>
  5. * Lead Tech Design <www.leadtechdesign.com>
  6. */
  7. #include <common.h>
  8. #include <debug_uart.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/clk.h>
  11. #include <asm/arch/at91sam9g45_matrix.h>
  12. #include <asm/arch/at91sam9_smc.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/gpio.h>
  15. #include <asm/arch/clk.h>
  16. #include <lcd.h>
  17. #include <linux/mtd/rawnand.h>
  18. #include <atmel_lcdc.h>
  19. #include <asm/mach-types.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /* ------------------------------------------------------------------------- */
  22. /*
  23. * Miscelaneous platform dependent initialisations
  24. */
  25. #ifdef CONFIG_CMD_NAND
  26. void at91sam9m10g45ek_nand_hw_init(void)
  27. {
  28. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  29. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  30. unsigned long csa;
  31. /* Enable CS3 */
  32. csa = readl(&matrix->ebicsa);
  33. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  34. writel(csa, &matrix->ebicsa);
  35. /* Configure SMC CS3 for NAND/SmartMedia */
  36. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  37. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  38. &smc->cs[3].setup);
  39. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  40. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  41. &smc->cs[3].pulse);
  42. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  43. &smc->cs[3].cycle);
  44. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  45. AT91_SMC_MODE_EXNW_DISABLE |
  46. #ifdef CONFIG_SYS_NAND_DBW_16
  47. AT91_SMC_MODE_DBW_16 |
  48. #else /* CONFIG_SYS_NAND_DBW_8 */
  49. AT91_SMC_MODE_DBW_8 |
  50. #endif
  51. AT91_SMC_MODE_TDF_CYCLE(3),
  52. &smc->cs[3].mode);
  53. at91_periph_clk_enable(ATMEL_ID_PIOC);
  54. /* Configure RDY/BSY */
  55. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  56. /* Enable NandFlash */
  57. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  58. }
  59. #endif
  60. #if defined(CONFIG_SPL_BUILD)
  61. #include <spl.h>
  62. #include <nand.h>
  63. void at91_spl_board_init(void)
  64. {
  65. /*
  66. * On the at91sam9m10g45ek board, the chip wm9711 stays in the
  67. * test mode, so it needs do some action to exit test mode.
  68. */
  69. at91_periph_clk_enable(ATMEL_ID_PIODE);
  70. at91_set_gpio_output(AT91_PIN_PD7, 0);
  71. at91_set_gpio_output(AT91_PIN_PD8, 0);
  72. at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
  73. at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
  74. #ifdef CONFIG_SD_BOOT
  75. at91_mci_hw_init();
  76. #elif CONFIG_NAND_BOOT
  77. at91sam9m10g45ek_nand_hw_init();
  78. #endif
  79. }
  80. #include <asm/arch/atmel_mpddrc.h>
  81. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  82. {
  83. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  84. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  85. ATMEL_MPDDRC_CR_NR_ROW_14 |
  86. ATMEL_MPDDRC_CR_DQMS_SHARED |
  87. ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
  88. ddr2->rtr = 0x24b;
  89. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
  90. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
  91. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
  92. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
  93. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
  94. 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
  95. 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
  96. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
  97. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
  98. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  99. 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  100. 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  101. ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  102. 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  103. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  104. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  105. }
  106. void mem_init(void)
  107. {
  108. struct atmel_mpddrc_config ddr2;
  109. ddr2_conf(&ddr2);
  110. at91_system_clk_enable(AT91_PMC_DDR);
  111. /* DDRAM2 Controller initialize */
  112. ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
  113. }
  114. #endif
  115. #ifdef CONFIG_CMD_USB
  116. static void at91sam9m10g45ek_usb_hw_init(void)
  117. {
  118. at91_periph_clk_enable(ATMEL_ID_PIODE);
  119. at91_set_gpio_output(AT91_PIN_PD1, 0);
  120. at91_set_gpio_output(AT91_PIN_PD3, 0);
  121. }
  122. #endif
  123. #ifdef CONFIG_LCD
  124. vidinfo_t panel_info = {
  125. .vl_col = 480,
  126. .vl_row = 272,
  127. .vl_clk = 9000000,
  128. .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
  129. ATMEL_LCDC_INVFRAME_NORMAL,
  130. .vl_bpix = 3,
  131. .vl_tft = 1,
  132. .vl_hsync_len = 45,
  133. .vl_left_margin = 1,
  134. .vl_right_margin = 1,
  135. .vl_vsync_len = 1,
  136. .vl_upper_margin = 40,
  137. .vl_lower_margin = 1,
  138. .mmio = ATMEL_BASE_LCDC,
  139. };
  140. void lcd_enable(void)
  141. {
  142. at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
  143. }
  144. void lcd_disable(void)
  145. {
  146. at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
  147. }
  148. static void at91sam9m10g45ek_lcd_hw_init(void)
  149. {
  150. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  151. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  152. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  153. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  154. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  155. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  156. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  157. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  158. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  159. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  160. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  161. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  162. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  163. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  164. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  165. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  166. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  167. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  168. at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  169. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  170. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  171. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  172. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  173. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  174. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  175. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  176. at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  177. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  178. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  179. at91_periph_clk_enable(ATMEL_ID_LCDC);
  180. gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
  181. }
  182. #ifdef CONFIG_LCD_INFO
  183. #include <nand.h>
  184. #include <version.h>
  185. void lcd_show_board_info(void)
  186. {
  187. ulong dram_size, nand_size;
  188. int i;
  189. char temp[32];
  190. lcd_printf ("%s\n", U_BOOT_VERSION);
  191. lcd_printf ("(C) 2008 ATMEL Corp\n");
  192. lcd_printf ("at91support@atmel.com\n");
  193. lcd_printf ("%s CPU at %s MHz\n",
  194. ATMEL_CPU_NAME,
  195. strmhz(temp, get_cpu_clk_rate()));
  196. dram_size = 0;
  197. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  198. dram_size += gd->bd->bi_dram[i].size;
  199. nand_size = 0;
  200. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  201. nand_size += get_nand_dev_by_index(i)->size;
  202. lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
  203. dram_size >> 20,
  204. nand_size >> 20 );
  205. }
  206. #endif /* CONFIG_LCD_INFO */
  207. #endif
  208. #ifdef CONFIG_DEBUG_UART_BOARD_INIT
  209. void board_debug_uart_init(void)
  210. {
  211. at91_seriald_hw_init();
  212. }
  213. #endif
  214. #ifdef CONFIG_BOARD_EARLY_INIT_F
  215. int board_early_init_f(void)
  216. {
  217. #ifdef CONFIG_DEBUG_UART
  218. debug_uart_init();
  219. #endif
  220. return 0;
  221. }
  222. #endif
  223. int board_init(void)
  224. {
  225. /* arch number of AT91SAM9M10G45EK-Board */
  226. #ifdef CONFIG_AT91SAM9M10G45EK
  227. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
  228. #elif defined CONFIG_AT91SAM9G45EKES
  229. gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
  230. #endif
  231. /* adress of boot parameters */
  232. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  233. #ifdef CONFIG_CMD_NAND
  234. at91sam9m10g45ek_nand_hw_init();
  235. #endif
  236. #ifdef CONFIG_CMD_USB
  237. at91sam9m10g45ek_usb_hw_init();
  238. #endif
  239. #ifdef CONFIG_LCD
  240. at91sam9m10g45ek_lcd_hw_init();
  241. #endif
  242. return 0;
  243. }
  244. int dram_init(void)
  245. {
  246. gd->ram_size = get_ram_size((void *) CONFIG_SYS_SDRAM_BASE,
  247. CONFIG_SYS_SDRAM_SIZE);
  248. return 0;
  249. }
  250. #ifdef CONFIG_RESET_PHY_R
  251. void reset_phy(void)
  252. {
  253. }
  254. #endif