ma5d4evk.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. * Copyright (C) 2015 Marek Vasut <marex@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/at91_common.h>
  9. #include <asm/arch/at91_pmc.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 <spi.h>
  24. #include <version.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. #ifdef CONFIG_ATMEL_SPI
  27. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  28. {
  29. return bus == 0 && cs == 0;
  30. }
  31. void spi_cs_activate(struct spi_slave *slave)
  32. {
  33. at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
  34. }
  35. void spi_cs_deactivate(struct spi_slave *slave)
  36. {
  37. at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
  38. }
  39. static void ma5d4evk_spi0_hw_init(void)
  40. {
  41. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
  42. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
  43. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
  44. at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
  45. /* Enable clock */
  46. at91_periph_clk_enable(ATMEL_ID_SPI0);
  47. }
  48. #endif /* CONFIG_ATMEL_SPI */
  49. #ifdef CONFIG_CMD_USB
  50. static void ma5d4evk_usb_hw_init(void)
  51. {
  52. at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
  53. at91_set_pio_output(AT91_PIO_PORTE, 14, 0);
  54. }
  55. #endif
  56. #ifdef CONFIG_LCD
  57. vidinfo_t panel_info = {
  58. .vl_col = 800,
  59. .vl_row = 480,
  60. .vl_clk = 33500000,
  61. .vl_bpix = LCD_BPP,
  62. .vl_tft = 1,
  63. .vl_hsync_len = 10,
  64. .vl_left_margin = 89,
  65. .vl_right_margin = 164,
  66. .vl_vsync_len = 10,
  67. .vl_upper_margin = 23,
  68. .vl_lower_margin = 10,
  69. .mmio = ATMEL_BASE_LCDC,
  70. };
  71. /* No power up/down pin for the LCD pannel */
  72. void lcd_enable(void) { /* Empty! */ }
  73. void lcd_disable(void) { /* Empty! */ }
  74. unsigned int has_lcdc(void)
  75. {
  76. return 1;
  77. }
  78. static void ma5d4evk_lcd_hw_init(void)
  79. {
  80. at91_set_a_periph(AT91_PIO_PORTA, 24, 1); /* LCDPWM */
  81. at91_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
  82. at91_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
  83. at91_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
  84. at91_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
  85. at91_set_a_periph(AT91_PIO_PORTA, 29, 1); /* LCDDEN */
  86. at91_set_a_periph(AT91_PIO_PORTA, 0, 0); /* LCDD0 */
  87. at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* LCDD1 */
  88. at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
  89. at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
  90. at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
  91. at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
  92. at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
  93. at91_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
  94. at91_set_a_periph(AT91_PIO_PORTA, 8, 0); /* LCDD9 */
  95. at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* LCDD8 */
  96. at91_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
  97. at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
  98. at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
  99. at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
  100. at91_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
  101. at91_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
  102. at91_set_a_periph(AT91_PIO_PORTA, 16, 0); /* LCDD16 */
  103. at91_set_a_periph(AT91_PIO_PORTA, 17, 0); /* LCDD17 */
  104. at91_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */
  105. at91_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */
  106. at91_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */
  107. at91_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */
  108. at91_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */
  109. at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */
  110. /* Enable clock */
  111. at91_periph_clk_enable(ATMEL_ID_LCDC);
  112. }
  113. #endif /* CONFIG_LCD */
  114. #ifdef CONFIG_GENERIC_ATMEL_MCI
  115. /* On-SoM eMMC */
  116. void ma5d4evk_mci0_hw_init(void)
  117. {
  118. at91_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI1 CDA */
  119. at91_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI1 DA0 */
  120. at91_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI1 DA1 */
  121. at91_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI1 DA2 */
  122. at91_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI1 DA3 */
  123. at91_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI1 DA4 */
  124. at91_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI1 DA5 */
  125. at91_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI1 DA6 */
  126. at91_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI1 DA7 */
  127. at91_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI1 CLK */
  128. /*
  129. * As the mci io internal pull down is too strong, so if the io needs
  130. * external pull up, the pull up resistor will be very small, if so
  131. * the power consumption will increase, so disable the internal pull
  132. * down to save the power.
  133. */
  134. at91_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
  135. at91_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
  136. at91_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
  137. at91_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
  138. at91_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
  139. at91_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
  140. at91_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
  141. at91_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
  142. at91_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
  143. at91_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
  144. /* Enable clock */
  145. at91_periph_clk_enable(ATMEL_ID_MCI0);
  146. }
  147. /* On-board MicroSD slot */
  148. void ma5d4evk_mci1_hw_init(void)
  149. {
  150. at91_set_c_periph(AT91_PIO_PORTE, 19, 1); /* MCI1 CDA */
  151. at91_set_c_periph(AT91_PIO_PORTE, 20, 1); /* MCI1 DA0 */
  152. at91_set_c_periph(AT91_PIO_PORTE, 21, 1); /* MCI1 DA1 */
  153. at91_set_c_periph(AT91_PIO_PORTE, 22, 1); /* MCI1 DA2 */
  154. at91_set_c_periph(AT91_PIO_PORTE, 23, 1); /* MCI1 DA3 */
  155. at91_set_c_periph(AT91_PIO_PORTE, 18, 0); /* MCI1 CLK */
  156. /*
  157. * As the mci io internal pull down is too strong, so if the io needs
  158. * external pull up, the pull up resistor will be very small, if so
  159. * the power consumption will increase, so disable the internal pull
  160. * down to save the power.
  161. */
  162. at91_set_pio_pulldown(AT91_PIO_PORTE, 18, 0);
  163. at91_set_pio_pulldown(AT91_PIO_PORTE, 19, 0);
  164. at91_set_pio_pulldown(AT91_PIO_PORTE, 20, 0);
  165. at91_set_pio_pulldown(AT91_PIO_PORTE, 21, 0);
  166. at91_set_pio_pulldown(AT91_PIO_PORTE, 22, 0);
  167. at91_set_pio_pulldown(AT91_PIO_PORTE, 23, 0);
  168. /* Deal with WP pin on the microSD slot. */
  169. at91_set_pio_output(AT91_PIO_PORTE, 16, 0);
  170. at91_set_pio_pulldown(AT91_PIO_PORTE, 16, 1);
  171. /* Enable clock */
  172. at91_periph_clk_enable(ATMEL_ID_MCI1);
  173. }
  174. int board_mmc_init(bd_t *bis)
  175. {
  176. int ret;
  177. /* De-assert reset on On-SoM eMMC */
  178. at91_set_pio_output(AT91_PIO_PORTE, 15, 1);
  179. at91_set_pio_pulldown(AT91_PIO_PORTE, 15, 0);
  180. ret = atmel_mci_init((void *)ATMEL_BASE_MCI0);
  181. if (ret) /* eMMC init failed, skip it. */
  182. at91_set_pio_output(AT91_PIO_PORTE, 15, 0);
  183. /* Enable the power supply to On-board MicroSD */
  184. at91_set_pio_output(AT91_PIO_PORTE, 17, 0);
  185. ret = atmel_mci_init((void *)ATMEL_BASE_MCI1);
  186. if (ret) /* uSD init failed, power it down. */
  187. at91_set_pio_output(AT91_PIO_PORTE, 17, 1);
  188. return 0;
  189. }
  190. #endif /* CONFIG_GENERIC_ATMEL_MCI */
  191. #ifdef CONFIG_MACB
  192. void ma5d4evk_macb0_hw_init(void)
  193. {
  194. at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
  195. at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
  196. at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
  197. at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
  198. at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
  199. at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
  200. at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
  201. at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
  202. at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
  203. at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
  204. /* Enable clock */
  205. at91_periph_clk_enable(ATMEL_ID_GMAC0);
  206. }
  207. #endif
  208. static void ma5d4evk_serial_hw_init(void)
  209. {
  210. /* USART0 */
  211. at91_set_a_periph(AT91_PIO_PORTD, 13, 1); /* TXD */
  212. at91_set_a_periph(AT91_PIO_PORTD, 12, 0); /* RXD */
  213. at91_set_a_periph(AT91_PIO_PORTD, 11, 0); /* RTS */
  214. at91_set_a_periph(AT91_PIO_PORTD, 10, 0); /* CTS */
  215. at91_periph_clk_enable(ATMEL_ID_USART0);
  216. /* USART1 */
  217. at91_set_a_periph(AT91_PIO_PORTD, 17, 1); /* TXD */
  218. at91_set_a_periph(AT91_PIO_PORTD, 16, 0); /* RXD */
  219. at91_set_a_periph(AT91_PIO_PORTD, 15, 0); /* RTS */
  220. at91_set_a_periph(AT91_PIO_PORTD, 14, 0); /* CTS */
  221. at91_periph_clk_enable(ATMEL_ID_USART1);
  222. }
  223. int board_early_init_f(void)
  224. {
  225. at91_periph_clk_enable(ATMEL_ID_PIOA);
  226. at91_periph_clk_enable(ATMEL_ID_PIOB);
  227. at91_periph_clk_enable(ATMEL_ID_PIOC);
  228. at91_periph_clk_enable(ATMEL_ID_PIOD);
  229. at91_periph_clk_enable(ATMEL_ID_PIOE);
  230. /* Configure LEDs as OFF */
  231. at91_set_pio_output(AT91_PIO_PORTD, 28, 0);
  232. at91_set_pio_output(AT91_PIO_PORTD, 29, 0);
  233. at91_set_pio_output(AT91_PIO_PORTD, 30, 0);
  234. /* Reset CAN controllers */
  235. at91_set_pio_output(AT91_PIO_PORTB, 21, 0);
  236. udelay(100);
  237. at91_set_pio_output(AT91_PIO_PORTB, 21, 1);
  238. at91_set_pio_pulldown(AT91_PIO_PORTB, 21, 0);
  239. ma5d4evk_serial_hw_init();
  240. return 0;
  241. }
  242. int board_init(void)
  243. {
  244. /* adress of boot parameters */
  245. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  246. #ifdef CONFIG_ATMEL_SPI
  247. ma5d4evk_spi0_hw_init();
  248. #endif
  249. #ifdef CONFIG_GENERIC_ATMEL_MCI
  250. ma5d4evk_mci0_hw_init();
  251. ma5d4evk_mci1_hw_init();
  252. #endif
  253. #ifdef CONFIG_MACB
  254. ma5d4evk_macb0_hw_init();
  255. #endif
  256. #ifdef CONFIG_LCD
  257. ma5d4evk_lcd_hw_init();
  258. #endif
  259. #ifdef CONFIG_CMD_USB
  260. ma5d4evk_usb_hw_init();
  261. #endif
  262. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  263. at91_udp_hw_init();
  264. #endif
  265. return 0;
  266. }
  267. int dram_init(void)
  268. {
  269. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  270. CONFIG_SYS_SDRAM_SIZE);
  271. return 0;
  272. }
  273. int board_eth_init(bd_t *bis)
  274. {
  275. int rc = 0;
  276. #ifdef CONFIG_MACB
  277. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
  278. #endif
  279. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  280. usba_udc_probe(&pdata);
  281. #ifdef CONFIG_USB_ETH_RNDIS
  282. usb_eth_initialize(bis);
  283. #endif
  284. #endif
  285. return rc;
  286. }
  287. /* SPL */
  288. #ifdef CONFIG_SPL_BUILD
  289. void spl_board_init(void)
  290. {
  291. ma5d4evk_spi0_hw_init();
  292. }
  293. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  294. {
  295. ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  296. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  297. ATMEL_MPDDRC_CR_NR_ROW_13 |
  298. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  299. ATMEL_MPDDRC_CR_NB_8BANKS |
  300. ATMEL_MPDDRC_CR_NDQS_DISABLED |
  301. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
  302. ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
  303. ddr2->rtr = 0x2b0;
  304. ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  305. 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  306. 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  307. 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  308. 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  309. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  310. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  311. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  312. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  313. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  314. 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  315. 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  316. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  317. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  318. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  319. 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  320. 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  321. }
  322. void mem_init(void)
  323. {
  324. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  325. struct atmel_mpddrc_config ddr2;
  326. ddr2_conf(&ddr2);
  327. /* enable MPDDR clock */
  328. at91_periph_clk_enable(ATMEL_ID_MPDDRC);
  329. writel(AT91_PMC_DDR, &pmc->scer);
  330. /* DDRAM2 Controller initialize */
  331. ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
  332. }
  333. void at91_pmc_init(void)
  334. {
  335. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  336. u32 tmp;
  337. tmp = AT91_PMC_PLLAR_29 |
  338. AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
  339. AT91_PMC_PLLXR_MUL(87) |
  340. AT91_PMC_PLLXR_DIV(1);
  341. at91_plla_init(tmp);
  342. writel(0x0 << 8, &pmc->pllicpr);
  343. tmp = AT91_PMC_MCKR_H32MXDIV |
  344. AT91_PMC_MCKR_PLLADIV_2 |
  345. AT91_PMC_MCKR_MDIV_3 |
  346. AT91_PMC_MCKR_CSS_PLLA;
  347. at91_mck_init(tmp);
  348. }
  349. #endif