sama5d3_devices.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (C) 2012-2013 Atmel Corporation
  3. * Bo Shen <voice.shen@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/arch/sama5d3.h>
  9. #include <asm/arch/at91_common.h>
  10. #include <asm/arch/at91_pmc.h>
  11. #include <asm/arch/clk.h>
  12. #include <asm/arch/gpio.h>
  13. #include <asm/io.h>
  14. unsigned int has_emac()
  15. {
  16. return cpu_is_sama5d31() || cpu_is_sama5d35() || cpu_is_sama5d36();
  17. }
  18. unsigned int has_gmac()
  19. {
  20. return !cpu_is_sama5d31();
  21. }
  22. unsigned int has_lcdc()
  23. {
  24. return !cpu_is_sama5d35();
  25. }
  26. char *get_cpu_name()
  27. {
  28. unsigned int extension_id = get_extension_chip_id();
  29. if (cpu_is_sama5d3())
  30. switch (extension_id) {
  31. case ARCH_EXID_SAMA5D31:
  32. return "SAMA5D31";
  33. case ARCH_EXID_SAMA5D33:
  34. return "SAMA5D33";
  35. case ARCH_EXID_SAMA5D34:
  36. return "SAMA5D34";
  37. case ARCH_EXID_SAMA5D35:
  38. return "SAMA5D35";
  39. case ARCH_EXID_SAMA5D36:
  40. return "SAMA5D36";
  41. default:
  42. return "Unknown CPU type";
  43. }
  44. else
  45. return "Unknown CPU type";
  46. }
  47. void at91_serial0_hw_init(void)
  48. {
  49. at91_set_a_periph(AT91_PIO_PORTD, 18, 1); /* TXD0 */
  50. at91_set_a_periph(AT91_PIO_PORTD, 17, 0); /* RXD0 */
  51. /* Enable clock */
  52. at91_periph_clk_enable(ATMEL_ID_USART0);
  53. }
  54. void at91_serial1_hw_init(void)
  55. {
  56. at91_set_a_periph(AT91_PIO_PORTB, 29, 1); /* TXD1 */
  57. at91_set_a_periph(AT91_PIO_PORTB, 28, 0); /* RXD1 */
  58. /* Enable clock */
  59. at91_periph_clk_enable(ATMEL_ID_USART1);
  60. }
  61. void at91_serial2_hw_init(void)
  62. {
  63. at91_set_b_periph(AT91_PIO_PORTE, 26, 1); /* TXD2 */
  64. at91_set_b_periph(AT91_PIO_PORTE, 25, 0); /* RXD2 */
  65. /* Enable clock */
  66. at91_periph_clk_enable(ATMEL_ID_USART2);
  67. }
  68. void at91_seriald_hw_init(void)
  69. {
  70. at91_set_a_periph(AT91_PIO_PORTB, 31, 1); /* DTXD */
  71. at91_set_a_periph(AT91_PIO_PORTB, 30, 0); /* DRXD */
  72. /* Enable clock */
  73. at91_periph_clk_enable(ATMEL_ID_DBGU);
  74. }
  75. #if defined(CONFIG_ATMEL_SPI)
  76. void at91_spi0_hw_init(unsigned long cs_mask)
  77. {
  78. at91_set_a_periph(AT91_PIO_PORTD, 10, 0); /* SPI0_MISO */
  79. at91_set_a_periph(AT91_PIO_PORTD, 11, 0); /* SPI0_MOSI */
  80. at91_set_a_periph(AT91_PIO_PORTD, 12, 0); /* SPI0_SPCK */
  81. if (cs_mask & (1 << 0))
  82. at91_set_pio_output(AT91_PIO_PORTD, 13, 1);
  83. if (cs_mask & (1 << 1))
  84. at91_set_pio_output(AT91_PIO_PORTD, 14, 1);
  85. if (cs_mask & (1 << 2))
  86. at91_set_pio_output(AT91_PIO_PORTD, 15, 1);
  87. if (cs_mask & (1 << 3))
  88. at91_set_pio_output(AT91_PIO_PORTD, 16, 1);
  89. /* Enable clock */
  90. at91_periph_clk_enable(ATMEL_ID_SPI0);
  91. }
  92. #endif
  93. #ifdef CONFIG_GENERIC_ATMEL_MCI
  94. void at91_mci_hw_init(void)
  95. {
  96. at91_set_a_periph(AT91_PIO_PORTD, 0, 0); /* MCI0 CMD */
  97. at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* MCI0 DA0 */
  98. at91_set_a_periph(AT91_PIO_PORTD, 2, 0); /* MCI0 DA1 */
  99. at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* MCI0 DA2 */
  100. at91_set_a_periph(AT91_PIO_PORTD, 4, 0); /* MCI0 DA3 */
  101. #ifdef CONFIG_ATMEL_MCI_8BIT
  102. at91_set_a_periph(AT91_PIO_PORTD, 5, 0); /* MCI0 DA4 */
  103. at91_set_a_periph(AT91_PIO_PORTD, 6, 0); /* MCI0 DA5 */
  104. at91_set_a_periph(AT91_PIO_PORTD, 7, 0); /* MCI0 DA6 */
  105. at91_set_a_periph(AT91_PIO_PORTD, 8, 0); /* MCI0 DA7 */
  106. #endif
  107. at91_set_a_periph(AT91_PIO_PORTD, 9, 0); /* MCI0 CLK */
  108. /* Enable clock */
  109. at91_periph_clk_enable(ATMEL_ID_MCI0);
  110. }
  111. #endif
  112. #ifdef CONFIG_MACB
  113. void at91_macb_hw_init(void)
  114. {
  115. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* ETXCK_EREFCK */
  116. at91_set_a_periph(AT91_PIO_PORTC, 5, 0); /* ERXDV */
  117. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* ERX0 */
  118. at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* ERX1 */
  119. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* ERXER */
  120. at91_set_a_periph(AT91_PIO_PORTC, 4, 0); /* ETXEN */
  121. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* ETX0 */
  122. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* ETX1 */
  123. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* EMDIO */
  124. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* EMDC */
  125. /* Enable clock */
  126. at91_periph_clk_enable(ATMEL_ID_EMAC);
  127. }
  128. void at91_gmac_hw_init(void)
  129. {
  130. at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* GTX0 */
  131. at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* GTX1 */
  132. at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* GTX2 */
  133. at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* GTX3 */
  134. at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* GRX0 */
  135. at91_set_a_periph(AT91_PIO_PORTB, 5, 0); /* GRX1 */
  136. at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* GRX2 */
  137. at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* GRX3 */
  138. at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* GTXCK */
  139. at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* GTXEN */
  140. at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* GRXCK */
  141. at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* GRXER */
  142. at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* GMDC */
  143. at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* GMDIO */
  144. at91_set_a_periph(AT91_PIO_PORTB, 18, 0); /* G125CK */
  145. /* Enable clock */
  146. at91_periph_clk_enable(ATMEL_ID_GMAC);
  147. }
  148. #endif
  149. #ifdef CONFIG_LCD
  150. void at91_lcd_hw_init(void)
  151. {
  152. at91_set_a_periph(AT91_PIO_PORTA, 24, 0); /* LCDPWM */
  153. at91_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
  154. at91_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
  155. at91_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
  156. at91_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
  157. at91_set_a_periph(AT91_PIO_PORTA, 29, 0); /* LCDDEN */
  158. /* The lower 16-bit of LCD only available on Port A */
  159. at91_set_a_periph(AT91_PIO_PORTA, 0, 0); /* LCDD0 */
  160. at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* LCDD1 */
  161. at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
  162. at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
  163. at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
  164. at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
  165. at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
  166. at91_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
  167. at91_set_a_periph(AT91_PIO_PORTA, 8, 0); /* LCDD8 */
  168. at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* LCDD9 */
  169. at91_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
  170. at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
  171. at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
  172. at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
  173. at91_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
  174. at91_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
  175. /* Enable clock */
  176. at91_periph_clk_enable(ATMEL_ID_LCDC);
  177. }
  178. #endif
  179. #ifdef CONFIG_USB_GADGET_ATMEL_USBA
  180. void at91_udp_hw_init(void)
  181. {
  182. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  183. /* Enable UPLL clock */
  184. writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
  185. /* Enable UDPHS clock */
  186. at91_periph_clk_enable(ATMEL_ID_UDPHS);
  187. }
  188. #endif