sama5d4ek.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * Copyright (C) 2014 Atmel
  3. * Bo Shen <voice.shen@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/at91_pmc.h>
  11. #include <asm/arch/at91_rstc.h>
  12. #include <asm/arch/atmel_mpddrc.h>
  13. #include <asm/arch/atmel_usba_udc.h>
  14. #include <asm/arch/gpio.h>
  15. #include <asm/arch/clk.h>
  16. #include <asm/arch/sama5d3_smc.h>
  17. #include <asm/arch/sama5d4.h>
  18. #include <atmel_hlcdc.h>
  19. #include <atmel_mci.h>
  20. #include <lcd.h>
  21. #include <mmc.h>
  22. #include <net.h>
  23. #include <netdev.h>
  24. #include <nand.h>
  25. #include <spi.h>
  26. #include <version.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #ifdef CONFIG_ATMEL_SPI
  29. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  30. {
  31. return bus == 0 && cs == 0;
  32. }
  33. void spi_cs_activate(struct spi_slave *slave)
  34. {
  35. at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
  36. }
  37. void spi_cs_deactivate(struct spi_slave *slave)
  38. {
  39. at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
  40. }
  41. static void sama5d4ek_spi0_hw_init(void)
  42. {
  43. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
  44. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
  45. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
  46. at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
  47. /* Enable clock */
  48. at91_periph_clk_enable(ATMEL_ID_SPI0);
  49. }
  50. #endif /* CONFIG_ATMEL_SPI */
  51. #ifdef CONFIG_NAND_ATMEL
  52. static void sama5d4ek_nand_hw_init(void)
  53. {
  54. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  55. at91_periph_clk_enable(ATMEL_ID_SMC);
  56. /* Configure SMC CS3 for NAND */
  57. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  58. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(1),
  59. &smc->cs[3].setup);
  60. writel(AT91_SMC_PULSE_NWE(2) | AT91_SMC_PULSE_NCS_WR(3) |
  61. AT91_SMC_PULSE_NRD(2) | AT91_SMC_PULSE_NCS_RD(3),
  62. &smc->cs[3].pulse);
  63. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  64. &smc->cs[3].cycle);
  65. writel(AT91_SMC_TIMINGS_TCLR(2) | AT91_SMC_TIMINGS_TADL(7) |
  66. AT91_SMC_TIMINGS_TAR(2) | AT91_SMC_TIMINGS_TRR(3) |
  67. AT91_SMC_TIMINGS_TWB(7) | AT91_SMC_TIMINGS_RBNSEL(3)|
  68. AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
  69. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  70. AT91_SMC_MODE_EXNW_DISABLE |
  71. AT91_SMC_MODE_DBW_8 |
  72. AT91_SMC_MODE_TDF_CYCLE(3),
  73. &smc->cs[3].mode);
  74. at91_set_a_periph(AT91_PIO_PORTC, 5, 0); /* D0 */
  75. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* D1 */
  76. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* D2 */
  77. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* D3 */
  78. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* D4 */
  79. at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* D5 */
  80. at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* D6 */
  81. at91_set_a_periph(AT91_PIO_PORTC, 12, 0); /* D7 */
  82. at91_set_a_periph(AT91_PIO_PORTC, 13, 0); /* RE */
  83. at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* WE */
  84. at91_set_a_periph(AT91_PIO_PORTC, 15, 1); /* NCS */
  85. at91_set_a_periph(AT91_PIO_PORTC, 16, 1); /* RDY */
  86. at91_set_a_periph(AT91_PIO_PORTC, 17, 1); /* ALE */
  87. at91_set_a_periph(AT91_PIO_PORTC, 18, 1); /* CLE */
  88. }
  89. #endif
  90. #ifdef CONFIG_CMD_USB
  91. static void sama5d4ek_usb_hw_init(void)
  92. {
  93. at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
  94. at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
  95. at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
  96. }
  97. #endif
  98. #ifdef CONFIG_LCD
  99. vidinfo_t panel_info = {
  100. .vl_col = 800,
  101. .vl_row = 480,
  102. .vl_clk = 33260000,
  103. .vl_bpix = LCD_BPP,
  104. .vl_tft = 1,
  105. .vl_hsync_len = 5,
  106. .vl_left_margin = 128,
  107. .vl_right_margin = 0,
  108. .vl_vsync_len = 5,
  109. .vl_upper_margin = 23,
  110. .vl_lower_margin = 22,
  111. .mmio = ATMEL_BASE_LCDC,
  112. };
  113. /* No power up/down pin for the LCD pannel */
  114. void lcd_enable(void) { /* Empty! */ }
  115. void lcd_disable(void) { /* Empty! */ }
  116. unsigned int has_lcdc(void)
  117. {
  118. return 1;
  119. }
  120. static void sama5d4ek_lcd_hw_init(void)
  121. {
  122. at91_set_a_periph(AT91_PIO_PORTA, 24, 0); /* LCDPWM */
  123. at91_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
  124. at91_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
  125. at91_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
  126. at91_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
  127. at91_set_a_periph(AT91_PIO_PORTA, 29, 0); /* LCDDEN */
  128. at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
  129. at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
  130. at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
  131. at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
  132. at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
  133. at91_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
  134. at91_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
  135. at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
  136. at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
  137. at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
  138. at91_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
  139. at91_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
  140. at91_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */
  141. at91_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */
  142. at91_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */
  143. at91_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */
  144. at91_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */
  145. at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */
  146. /* Enable clock */
  147. at91_periph_clk_enable(ATMEL_ID_LCDC);
  148. }
  149. #ifdef CONFIG_LCD_INFO
  150. void lcd_show_board_info(void)
  151. {
  152. ulong dram_size, nand_size;
  153. int i;
  154. char temp[32];
  155. lcd_printf("%s\n", U_BOOT_VERSION);
  156. lcd_printf("2014 ATMEL Corp\n");
  157. lcd_printf("at91@atmel.com\n");
  158. lcd_printf("%s CPU at %s MHz\n", get_cpu_name(),
  159. strmhz(temp, get_cpu_clk_rate()));
  160. dram_size = 0;
  161. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  162. dram_size += gd->bd->bi_dram[i].size;
  163. nand_size = 0;
  164. #ifdef CONFIG_NAND_ATMEL
  165. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  166. nand_size += nand_info[i].size;
  167. #endif
  168. lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
  169. dram_size >> 20, nand_size >> 20);
  170. }
  171. #endif /* CONFIG_LCD_INFO */
  172. #endif /* CONFIG_LCD */
  173. #ifdef CONFIG_GENERIC_ATMEL_MCI
  174. void sama5d4ek_mci1_hw_init(void)
  175. {
  176. at91_set_c_periph(AT91_PIO_PORTE, 19, 1); /* MCI1 CDA */
  177. at91_set_c_periph(AT91_PIO_PORTE, 20, 1); /* MCI1 DA0 */
  178. at91_set_c_periph(AT91_PIO_PORTE, 21, 1); /* MCI1 DA1 */
  179. at91_set_c_periph(AT91_PIO_PORTE, 22, 1); /* MCI1 DA2 */
  180. at91_set_c_periph(AT91_PIO_PORTE, 23, 1); /* MCI1 DA3 */
  181. at91_set_c_periph(AT91_PIO_PORTE, 18, 0); /* MCI1 CLK */
  182. /*
  183. * As the mci io internal pull down is too strong, so if the io needs
  184. * external pull up, the pull up resistor will be very small, if so
  185. * the power consumption will increase, so disable the interanl pull
  186. * down to save the power.
  187. */
  188. at91_set_pio_pulldown(AT91_PIO_PORTE, 18, 0);
  189. at91_set_pio_pulldown(AT91_PIO_PORTE, 19, 0);
  190. at91_set_pio_pulldown(AT91_PIO_PORTE, 20, 0);
  191. at91_set_pio_pulldown(AT91_PIO_PORTE, 21, 0);
  192. at91_set_pio_pulldown(AT91_PIO_PORTE, 22, 0);
  193. at91_set_pio_pulldown(AT91_PIO_PORTE, 23, 0);
  194. /* Enable clock */
  195. at91_periph_clk_enable(ATMEL_ID_MCI1);
  196. }
  197. int board_mmc_init(bd_t *bis)
  198. {
  199. /* Enable power for MCI1 interface */
  200. at91_set_pio_output(AT91_PIO_PORTE, 15, 0);
  201. return atmel_mci_init((void *)ATMEL_BASE_MCI1);
  202. }
  203. #endif /* CONFIG_GENERIC_ATMEL_MCI */
  204. #ifdef CONFIG_MACB
  205. void sama5d4ek_macb0_hw_init(void)
  206. {
  207. at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
  208. at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
  209. at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
  210. at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
  211. at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
  212. at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
  213. at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
  214. at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
  215. at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
  216. at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
  217. /* Enable clock */
  218. at91_periph_clk_enable(ATMEL_ID_GMAC0);
  219. }
  220. #endif
  221. static void sama5d4ek_serial3_hw_init(void)
  222. {
  223. at91_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
  224. at91_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
  225. /* Enable clock */
  226. at91_periph_clk_enable(ATMEL_ID_USART3);
  227. }
  228. int board_early_init_f(void)
  229. {
  230. at91_periph_clk_enable(ATMEL_ID_PIOA);
  231. at91_periph_clk_enable(ATMEL_ID_PIOB);
  232. at91_periph_clk_enable(ATMEL_ID_PIOC);
  233. at91_periph_clk_enable(ATMEL_ID_PIOD);
  234. at91_periph_clk_enable(ATMEL_ID_PIOE);
  235. sama5d4ek_serial3_hw_init();
  236. return 0;
  237. }
  238. int board_init(void)
  239. {
  240. /* adress of boot parameters */
  241. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  242. #ifdef CONFIG_ATMEL_SPI
  243. sama5d4ek_spi0_hw_init();
  244. #endif
  245. #ifdef CONFIG_NAND_ATMEL
  246. sama5d4ek_nand_hw_init();
  247. #endif
  248. #ifdef CONFIG_GENERIC_ATMEL_MCI
  249. sama5d4ek_mci1_hw_init();
  250. #endif
  251. #ifdef CONFIG_MACB
  252. sama5d4ek_macb0_hw_init();
  253. #endif
  254. #ifdef CONFIG_LCD
  255. sama5d4ek_lcd_hw_init();
  256. #endif
  257. #ifdef CONFIG_CMD_USB
  258. sama5d4ek_usb_hw_init();
  259. #endif
  260. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  261. at91_udp_hw_init();
  262. #endif
  263. return 0;
  264. }
  265. int dram_init(void)
  266. {
  267. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  268. CONFIG_SYS_SDRAM_SIZE);
  269. return 0;
  270. }
  271. int board_eth_init(bd_t *bis)
  272. {
  273. int rc = 0;
  274. #ifdef CONFIG_MACB
  275. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
  276. #endif
  277. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  278. usba_udc_probe(&pdata);
  279. #ifdef CONFIG_USB_ETH_RNDIS
  280. usb_eth_initialize(bis);
  281. #endif
  282. #endif
  283. return rc;
  284. }
  285. /* SPL */
  286. #ifdef CONFIG_SPL_BUILD
  287. void spl_board_init(void)
  288. {
  289. #ifdef CONFIG_SYS_USE_MMC
  290. sama5d4ek_mci1_hw_init();
  291. #elif CONFIG_SYS_USE_NANDFLASH
  292. sama5d4ek_nand_hw_init();
  293. #elif CONFIG_SYS_USE_SERIALFLASH
  294. sama5d4ek_spi0_hw_init();
  295. #endif
  296. }
  297. static void ddr2_conf(struct atmel_mpddr *ddr2)
  298. {
  299. ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  300. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  301. ATMEL_MPDDRC_CR_NR_ROW_14 |
  302. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  303. ATMEL_MPDDRC_CR_NB_8BANKS |
  304. ATMEL_MPDDRC_CR_NDQS_DISABLED |
  305. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
  306. ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
  307. ddr2->rtr = 0x2b0;
  308. ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  309. 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  310. 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  311. 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  312. 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  313. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  314. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  315. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  316. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  317. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  318. 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  319. 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  320. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  321. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  322. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  323. 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  324. 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  325. }
  326. void mem_init(void)
  327. {
  328. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  329. struct atmel_mpddr ddr2;
  330. ddr2_conf(&ddr2);
  331. /* enable MPDDR clock */
  332. at91_periph_clk_enable(ATMEL_ID_MPDDRC);
  333. writel(AT91_PMC_DDR, &pmc->scer);
  334. /* DDRAM2 Controller initialize */
  335. ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
  336. }
  337. void at91_pmc_init(void)
  338. {
  339. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  340. u32 tmp;
  341. tmp = AT91_PMC_PLLAR_29 |
  342. AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
  343. AT91_PMC_PLLXR_MUL(87) |
  344. AT91_PMC_PLLXR_DIV(1);
  345. at91_plla_init(tmp);
  346. writel(0x0 << 8, &pmc->pllicpr);
  347. tmp = AT91_PMC_MCKR_H32MXDIV |
  348. AT91_PMC_MCKR_PLLADIV_2 |
  349. AT91_PMC_MCKR_MDIV_3 |
  350. AT91_PMC_MCKR_CSS_PLLA;
  351. at91_mck_init(tmp);
  352. }
  353. #endif