board.c 7.9 KB

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