vinco.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board file for the VInCo platform
  4. * Based on the the SAMA5-EK board file
  5. * Configuration settings for the VInCo platform.
  6. * Copyright (C) 2014 Atmel
  7. * Bo Shen <voice.shen@atmel.com>
  8. * Copyright (C) 2015 Free Electrons
  9. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  10. */
  11. #include <common.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/at91_pmc.h>
  15. #include <asm/arch/at91_rstc.h>
  16. #include <asm/arch/atmel_mpddrc.h>
  17. #include <asm/arch/atmel_usba_udc.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/arch/clk.h>
  20. #include <asm/arch/sama5d3_smc.h>
  21. #include <asm/arch/sama5d4.h>
  22. #include <atmel_hlcdc.h>
  23. #include <atmel_mci.h>
  24. #include <lcd.h>
  25. #include <mmc.h>
  26. #include <net.h>
  27. #include <netdev.h>
  28. #include <nand.h>
  29. #include <spi.h>
  30. #include <version.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* FIXME gpio code here need to handle through DM_GPIO */
  33. #ifndef CONFIG_DM_SPI
  34. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  35. {
  36. return bus == 0 && cs == 0;
  37. }
  38. void spi_cs_activate(struct spi_slave *slave)
  39. {
  40. at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
  41. }
  42. void spi_cs_deactivate(struct spi_slave *slave)
  43. {
  44. at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
  45. }
  46. static void vinco_spi0_hw_init(void)
  47. {
  48. at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
  49. at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
  50. at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
  51. at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
  52. /* Enable clock */
  53. at91_periph_clk_enable(ATMEL_ID_SPI0);
  54. }
  55. #endif /* CONFIG_ATMEL_SPI */
  56. #ifdef CONFIG_CMD_USB
  57. static void vinco_usb_hw_init(void)
  58. {
  59. at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
  60. at91_set_pio_output(AT91_PIO_PORTE, 12, 0);
  61. at91_set_pio_output(AT91_PIO_PORTE, 10, 0);
  62. }
  63. #endif
  64. #ifdef CONFIG_GENERIC_ATMEL_MCI
  65. void vinco_mci0_hw_init(void)
  66. {
  67. at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI0 CDA */
  68. at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI0 DA0 */
  69. at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI0 DA1 */
  70. at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI0 DA2 */
  71. at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI0 DA3 */
  72. at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI0 DA4 */
  73. at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI0 DA5 */
  74. at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI0 DA6 */
  75. at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI0 DA7 */
  76. at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI0 CLK */
  77. /*
  78. * As the mci io internal pull down is too strong, so if the io needs
  79. * external pull up, the pull up resistor will be very small, if so
  80. * the power consumption will increase, so disable the interanl pull
  81. * down to save the power.
  82. */
  83. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
  84. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
  85. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
  86. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
  87. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
  88. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
  89. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
  90. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
  91. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
  92. at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
  93. /* Enable clock */
  94. at91_periph_clk_enable(ATMEL_ID_MCI0);
  95. }
  96. int board_mmc_init(bd_t *bis)
  97. {
  98. /* Enable power for MCI0 interface */
  99. at91_set_pio_output(AT91_PIO_PORTE, 7, 1);
  100. return atmel_mci_init((void *)ATMEL_BASE_MCI0);
  101. }
  102. #endif /* CONFIG_GENERIC_ATMEL_MCI */
  103. #ifdef CONFIG_MACB
  104. void vinco_macb0_hw_init(void)
  105. {
  106. at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
  107. at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
  108. at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
  109. at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
  110. at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
  111. at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
  112. at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
  113. at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
  114. at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
  115. at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
  116. /* Enable clock */
  117. at91_periph_clk_enable(ATMEL_ID_GMAC0);
  118. /* Enable Phy*/
  119. at91_set_pio_output(AT91_PIO_PORTE, 8, 1);
  120. }
  121. #endif
  122. static void vinco_serial3_hw_init(void)
  123. {
  124. at91_pio3_set_b_periph(AT91_PIO_PORTE, 17, 1); /* TXD3 */
  125. at91_pio3_set_b_periph(AT91_PIO_PORTE, 16, 0); /* RXD3 */
  126. /* Enable clock */
  127. at91_periph_clk_enable(ATMEL_ID_USART3);
  128. }
  129. int board_early_init_f(void)
  130. {
  131. at91_periph_clk_enable(ATMEL_ID_PIOA);
  132. at91_periph_clk_enable(ATMEL_ID_PIOB);
  133. at91_periph_clk_enable(ATMEL_ID_PIOC);
  134. at91_periph_clk_enable(ATMEL_ID_PIOD);
  135. at91_periph_clk_enable(ATMEL_ID_PIOE);
  136. vinco_serial3_hw_init();
  137. return 0;
  138. }
  139. int board_init(void)
  140. {
  141. /* adress of boot parameters */
  142. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  143. #ifndef CONFIG_DM_SPI
  144. vinco_spi0_hw_init();
  145. #endif
  146. #ifdef CONFIG_GENERIC_ATMEL_MCI
  147. vinco_mci0_hw_init();
  148. #endif
  149. #ifdef CONFIG_MACB
  150. vinco_macb0_hw_init();
  151. #endif
  152. #ifdef CONFIG_CMD_USB
  153. vinco_usb_hw_init();
  154. #endif
  155. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  156. at91_udp_hw_init();
  157. #endif
  158. return 0;
  159. }
  160. int dram_init(void)
  161. {
  162. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  163. CONFIG_SYS_SDRAM_SIZE);
  164. return 0;
  165. }
  166. int board_eth_init(bd_t *bis)
  167. {
  168. int rc = 0;
  169. #ifdef CONFIG_MACB
  170. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
  171. #endif
  172. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  173. usba_udc_probe(&pdata);
  174. #ifdef CONFIG_USB_ETH_RNDIS
  175. usb_eth_initialize(bis);
  176. #endif
  177. #endif
  178. return rc;
  179. }