board.c 6.9 KB

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