sama5d4ek.c 11 KB

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