vinco.c 5.5 KB

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