board.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board functions for Siemens CORVUS (AT91SAM9G45) based board
  4. * (C) Copyright 2013 Siemens AG
  5. *
  6. * Based on:
  7. * U-Boot file: board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
  8. * (C) Copyright 2007-2008
  9. * Stelian Pop <stelian@popies.net>
  10. * Lead Tech Design <www.leadtechdesign.com>
  11. */
  12. #include <common.h>
  13. #include <dm.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/at91sam9g45_matrix.h>
  16. #include <asm/arch/at91sam9_smc.h>
  17. #include <asm/arch/at91_common.h>
  18. #include <asm/arch/at91_rstc.h>
  19. #include <asm/arch/atmel_serial.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/gpio.h>
  22. #include <asm/arch/clk.h>
  23. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  24. #include <net.h>
  25. #endif
  26. #ifndef CONFIG_DM_ETH
  27. #include <netdev.h>
  28. #endif
  29. #include <spi.h>
  30. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  31. #include <asm/arch/atmel_usba_udc.h>
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. static void corvus_request_gpio(void)
  35. {
  36. gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand ena");
  37. gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand rdy");
  38. gpio_request(AT91_PIN_PD7, "d0");
  39. gpio_request(AT91_PIN_PD8, "d1");
  40. gpio_request(AT91_PIN_PA12, "d2");
  41. gpio_request(AT91_PIN_PA13, "d3");
  42. gpio_request(AT91_PIN_PA15, "d4");
  43. gpio_request(AT91_PIN_PB7, "recovery button");
  44. gpio_request(AT91_PIN_PD1, "USB0");
  45. gpio_request(AT91_PIN_PD3, "USB1");
  46. gpio_request(AT91_PIN_PB18, "SPICS1");
  47. gpio_request(AT91_PIN_PB3, "SPICS0");
  48. gpio_request(CONFIG_RED_LED, "red led");
  49. gpio_request(CONFIG_GREEN_LED, "green led");
  50. }
  51. static void corvus_nand_hw_init(void)
  52. {
  53. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  54. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  55. unsigned long csa;
  56. /* Enable CS3 */
  57. csa = readl(&matrix->ebicsa);
  58. csa |= AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA;
  59. writel(csa, &matrix->ebicsa);
  60. /* Configure SMC CS3 for NAND/SmartMedia */
  61. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  62. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  63. &smc->cs[3].setup);
  64. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
  65. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
  66. &smc->cs[3].pulse);
  67. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
  68. &smc->cs[3].cycle);
  69. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  70. AT91_SMC_MODE_EXNW_DISABLE |
  71. #ifdef CONFIG_SYS_NAND_DBW_16
  72. AT91_SMC_MODE_DBW_16 |
  73. #else /* CONFIG_SYS_NAND_DBW_8 */
  74. AT91_SMC_MODE_DBW_8 |
  75. #endif
  76. AT91_SMC_MODE_TDF_CYCLE(3),
  77. &smc->cs[3].mode);
  78. at91_periph_clk_enable(ATMEL_ID_PIOC);
  79. at91_periph_clk_enable(ATMEL_ID_PIOA);
  80. /* Enable NandFlash */
  81. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  82. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  83. }
  84. #if defined(CONFIG_SPL_BUILD)
  85. #include <spl.h>
  86. #include <nand.h>
  87. void spl_board_init(void)
  88. {
  89. corvus_request_gpio();
  90. /*
  91. * For on the sam9m10g45ek board, the chip wm9711 stay in the test
  92. * mode, so it need do some action to exit mode.
  93. */
  94. at91_set_gpio_output(AT91_PIN_PD7, 0);
  95. at91_set_gpio_output(AT91_PIN_PD8, 0);
  96. at91_set_pio_pullup(AT91_PIO_PORTD, 7, 1);
  97. at91_set_pio_pullup(AT91_PIO_PORTD, 8, 1);
  98. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
  99. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
  100. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
  101. corvus_nand_hw_init();
  102. /* Configure recovery button PINs */
  103. at91_set_gpio_input(AT91_PIN_PB7, 1);
  104. /* check if button is pressed */
  105. if (at91_get_gpio_value(AT91_PIN_PB7) == 0) {
  106. u32 boot_device;
  107. debug("Recovery button pressed\n");
  108. boot_device = spl_boot_device();
  109. switch (boot_device) {
  110. #ifdef CONFIG_SPL_NAND_SUPPORT
  111. case BOOT_DEVICE_NAND:
  112. nand_init();
  113. spl_nand_erase_one(0, 0);
  114. break;
  115. #endif
  116. }
  117. }
  118. }
  119. #include <asm/arch/atmel_mpddrc.h>
  120. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  121. {
  122. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  123. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  124. ATMEL_MPDDRC_CR_NR_ROW_14 |
  125. ATMEL_MPDDRC_CR_DIC_DS |
  126. ATMEL_MPDDRC_CR_DQMS_SHARED |
  127. ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
  128. ddr2->rtr = 0x24b;
  129. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
  130. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
  131. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
  132. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 75 ns */
  133. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
  134. 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
  135. 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
  136. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
  137. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
  138. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  139. 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  140. 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  141. ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  142. 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  143. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  144. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  145. }
  146. void mem_init(void)
  147. {
  148. struct atmel_mpddrc_config ddr2;
  149. ddr2_conf(&ddr2);
  150. at91_system_clk_enable(AT91_PMC_DDR);
  151. /* DDRAM2 Controller initialize */
  152. ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
  153. }
  154. #endif
  155. #ifdef CONFIG_CMD_USB
  156. static void taurus_usb_hw_init(void)
  157. {
  158. at91_periph_clk_enable(ATMEL_ID_PIODE);
  159. at91_set_gpio_output(AT91_PIN_PD1, 0);
  160. at91_set_gpio_output(AT91_PIN_PD3, 0);
  161. }
  162. #endif
  163. #ifdef CONFIG_MACB
  164. static void corvus_macb_hw_init(void)
  165. {
  166. /* Enable clock */
  167. at91_periph_clk_enable(ATMEL_ID_EMAC);
  168. /*
  169. * Disable pull-up on:
  170. * RXDV (PA15) => PHY normal mode (not Test mode)
  171. * ERX0 (PA12) => PHY ADDR0
  172. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  173. *
  174. * PHY has internal pull-down
  175. */
  176. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
  177. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
  178. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
  179. at91_phy_reset();
  180. /* Re-enable pull-up */
  181. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
  182. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
  183. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
  184. /* And the pins. */
  185. at91_macb_hw_init();
  186. }
  187. #endif
  188. int board_early_init_f(void)
  189. {
  190. at91_seriald_hw_init();
  191. corvus_request_gpio();
  192. return 0;
  193. }
  194. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  195. /* from ./arch/arm/mach-at91/armv7/sama5d3_devices.c */
  196. void at91_udp_hw_init(void)
  197. {
  198. /* Enable UPLL clock */
  199. at91_upll_clk_enable();
  200. /* Enable UDPHS clock */
  201. at91_periph_clk_enable(ATMEL_ID_UDPHS);
  202. }
  203. #endif
  204. int board_init(void)
  205. {
  206. /* address of boot parameters */
  207. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  208. /* we have to request the gpios again after relocation */
  209. corvus_request_gpio();
  210. #ifdef CONFIG_CMD_NAND
  211. corvus_nand_hw_init();
  212. #endif
  213. #ifdef CONFIG_ATMEL_SPI
  214. at91_spi0_hw_init(1 << 4);
  215. #endif
  216. #ifdef CONFIG_MACB
  217. corvus_macb_hw_init();
  218. #endif
  219. #ifdef CONFIG_CMD_USB
  220. taurus_usb_hw_init();
  221. #endif
  222. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  223. at91_udp_hw_init();
  224. usba_udc_probe(&pdata);
  225. #endif
  226. return 0;
  227. }
  228. int dram_init(void)
  229. {
  230. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  231. CONFIG_SYS_SDRAM_SIZE);
  232. return 0;
  233. }
  234. #ifndef CONFIG_DM_ETH
  235. int board_eth_init(bd_t *bis)
  236. {
  237. int rc = 0;
  238. #ifdef CONFIG_MACB
  239. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  240. #endif
  241. return rc;
  242. }
  243. #endif
  244. /* SPI chip select control */
  245. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  246. {
  247. return bus == 0 && cs < 2;
  248. }
  249. void spi_cs_activate(struct spi_slave *slave)
  250. {
  251. switch (slave->cs) {
  252. case 1:
  253. at91_set_gpio_output(AT91_PIN_PB18, 0);
  254. break;
  255. case 0:
  256. default:
  257. at91_set_gpio_output(AT91_PIN_PB3, 0);
  258. break;
  259. }
  260. }
  261. void spi_cs_deactivate(struct spi_slave *slave)
  262. {
  263. switch (slave->cs) {
  264. case 1:
  265. at91_set_gpio_output(AT91_PIN_PB18, 1);
  266. break;
  267. case 0:
  268. default:
  269. at91_set_gpio_output(AT91_PIN_PB3, 1);
  270. break;
  271. }
  272. }
  273. static struct atmel_serial_platdata at91sam9260_serial_plat = {
  274. .base_addr = ATMEL_BASE_DBGU,
  275. };
  276. U_BOOT_DEVICE(at91sam9260_serial) = {
  277. .name = "serial_atmel",
  278. .platdata = &at91sam9260_serial_plat,
  279. };