at91sam9x5_devices.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Atmel Corporation
  4. */
  5. #include <common.h>
  6. #include <asm/arch/at91_common.h>
  7. #include <asm/arch/clk.h>
  8. #include <asm/arch/gpio.h>
  9. #include <asm/io.h>
  10. unsigned int get_chip_id(void)
  11. {
  12. /* The 0x40 is the offset of cidr in DBGU */
  13. return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
  14. }
  15. unsigned int get_extension_chip_id(void)
  16. {
  17. /* The 0x44 is the offset of exid in DBGU */
  18. return readl(ATMEL_BASE_DBGU + 0x44);
  19. }
  20. unsigned int has_emac1()
  21. {
  22. return cpu_is_at91sam9x25();
  23. }
  24. unsigned int has_emac0()
  25. {
  26. return !(cpu_is_at91sam9g15());
  27. }
  28. unsigned int has_lcdc()
  29. {
  30. return cpu_is_at91sam9g15() || cpu_is_at91sam9g35()
  31. || cpu_is_at91sam9x35();
  32. }
  33. char *get_cpu_name()
  34. {
  35. unsigned int extension_id = get_extension_chip_id();
  36. if (cpu_is_at91sam9x5()) {
  37. switch (extension_id) {
  38. case ARCH_EXID_AT91SAM9G15:
  39. return "AT91SAM9G15";
  40. case ARCH_EXID_AT91SAM9G25:
  41. return "AT91SAM9G25";
  42. case ARCH_EXID_AT91SAM9G35:
  43. return "AT91SAM9G35";
  44. case ARCH_EXID_AT91SAM9X25:
  45. return "AT91SAM9X25";
  46. case ARCH_EXID_AT91SAM9X35:
  47. return "AT91SAM9X35";
  48. default:
  49. return "Unknown CPU type";
  50. }
  51. } else {
  52. return "Unknown CPU type";
  53. }
  54. }
  55. void at91_seriald_hw_init(void)
  56. {
  57. at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
  58. at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
  59. at91_periph_clk_enable(ATMEL_ID_SYS);
  60. }
  61. void at91_serial0_hw_init(void)
  62. {
  63. at91_pio3_set_a_periph(AT91_PIO_PORTA, 0, 1); /* TXD */
  64. at91_pio3_set_a_periph(AT91_PIO_PORTA, 1, 0); /* RXD */
  65. at91_periph_clk_enable(ATMEL_ID_USART0);
  66. }
  67. void at91_serial1_hw_init(void)
  68. {
  69. at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 1); /* TXD */
  70. at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* RXD */
  71. at91_periph_clk_enable(ATMEL_ID_USART1);
  72. }
  73. void at91_serial2_hw_init(void)
  74. {
  75. at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 1); /* TXD */
  76. at91_pio3_set_a_periph(AT91_PIO_PORTA, 8, 0); /* RXD */
  77. at91_periph_clk_enable(ATMEL_ID_USART2);
  78. }
  79. void at91_mci_hw_init(void)
  80. {
  81. /* Initialize the MCI0 */
  82. at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 1); /* MCCK */
  83. at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 1); /* MCCDA */
  84. at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 1); /* MCDA0 */
  85. at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 1); /* MCDA1 */
  86. at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 1); /* MCDA2 */
  87. at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 1); /* MCDA3 */
  88. at91_periph_clk_enable(ATMEL_ID_HSMCI0);
  89. }
  90. #ifdef CONFIG_ATMEL_SPI
  91. void at91_spi0_hw_init(unsigned long cs_mask)
  92. {
  93. at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SPI0_MISO */
  94. at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* SPI0_MOSI */
  95. at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* SPI0_SPCK */
  96. at91_periph_clk_enable(ATMEL_ID_SPI0);
  97. if (cs_mask & (1 << 0))
  98. at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0);
  99. if (cs_mask & (1 << 1))
  100. at91_pio3_set_b_periph(AT91_PIO_PORTA, 7, 0);
  101. if (cs_mask & (1 << 2))
  102. at91_pio3_set_b_periph(AT91_PIO_PORTA, 1, 0);
  103. if (cs_mask & (1 << 3))
  104. at91_pio3_set_b_periph(AT91_PIO_PORTB, 3, 0);
  105. if (cs_mask & (1 << 4))
  106. at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
  107. if (cs_mask & (1 << 5))
  108. at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
  109. if (cs_mask & (1 << 6))
  110. at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
  111. if (cs_mask & (1 << 7))
  112. at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
  113. }
  114. void at91_spi1_hw_init(unsigned long cs_mask)
  115. {
  116. at91_pio3_set_b_periph(AT91_PIO_PORTA, 21, 0); /* SPI1_MISO */
  117. at91_pio3_set_b_periph(AT91_PIO_PORTA, 22, 0); /* SPI1_MOSI */
  118. at91_pio3_set_b_periph(AT91_PIO_PORTA, 23, 0); /* SPI1_SPCK */
  119. at91_periph_clk_enable(ATMEL_ID_SPI1);
  120. if (cs_mask & (1 << 0))
  121. at91_pio3_set_b_periph(AT91_PIO_PORTA, 8, 0);
  122. if (cs_mask & (1 << 1))
  123. at91_pio3_set_b_periph(AT91_PIO_PORTA, 0, 0);
  124. if (cs_mask & (1 << 2))
  125. at91_pio3_set_b_periph(AT91_PIO_PORTA, 31, 0);
  126. if (cs_mask & (1 << 3))
  127. at91_pio3_set_b_periph(AT91_PIO_PORTA, 30, 0);
  128. if (cs_mask & (1 << 4))
  129. at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
  130. if (cs_mask & (1 << 5))
  131. at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
  132. if (cs_mask & (1 << 6))
  133. at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
  134. if (cs_mask & (1 << 7))
  135. at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
  136. }
  137. #endif
  138. #if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD)
  139. void at91_uhp_hw_init(void)
  140. {
  141. /* Enable VBus on UHP ports */
  142. at91_set_pio_output(AT91_PIO_PORTD, 18, 0); /* port A */
  143. at91_set_pio_output(AT91_PIO_PORTD, 19, 0); /* port B */
  144. #if defined(CONFIG_USB_OHCI_NEW)
  145. /* port C is OHCI only */
  146. at91_set_pio_output(AT91_PIO_PORTD, 20, 0); /* port C */
  147. #endif
  148. }
  149. #endif
  150. #ifdef CONFIG_MACB
  151. void at91_macb_hw_init(void)
  152. {
  153. if (has_emac0()) {
  154. /* Enable EMAC0 clock */
  155. at91_periph_clk_enable(ATMEL_ID_EMAC0);
  156. /* EMAC0 pins setup */
  157. at91_pio3_set_a_periph(AT91_PIO_PORTB, 4, 0); /* ETXCK */
  158. at91_pio3_set_a_periph(AT91_PIO_PORTB, 3, 0); /* ERXDV */
  159. at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ERX0 */
  160. at91_pio3_set_a_periph(AT91_PIO_PORTB, 1, 0); /* ERX1 */
  161. at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ERXER */
  162. at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ETXEN */
  163. at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ETX0 */
  164. at91_pio3_set_a_periph(AT91_PIO_PORTB, 10, 0); /* ETX1 */
  165. at91_pio3_set_a_periph(AT91_PIO_PORTB, 5, 0); /* EMDIO */
  166. at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* EMDC */
  167. }
  168. if (has_emac1()) {
  169. /* Enable EMAC1 clock */
  170. at91_periph_clk_enable(ATMEL_ID_EMAC1);
  171. /* EMAC1 pins setup */
  172. at91_pio3_set_b_periph(AT91_PIO_PORTC, 29, 0); /* ETXCK */
  173. at91_pio3_set_b_periph(AT91_PIO_PORTC, 28, 0); /* ECRSDV */
  174. at91_pio3_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ERXO */
  175. at91_pio3_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ERX1 */
  176. at91_pio3_set_b_periph(AT91_PIO_PORTC, 16, 0); /* ERXER */
  177. at91_pio3_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ETXEN */
  178. at91_pio3_set_b_periph(AT91_PIO_PORTC, 18, 0); /* ETX0 */
  179. at91_pio3_set_b_periph(AT91_PIO_PORTC, 19, 0); /* ETX1 */
  180. at91_pio3_set_b_periph(AT91_PIO_PORTC, 31, 0); /* EMDIO */
  181. at91_pio3_set_b_periph(AT91_PIO_PORTC, 30, 0); /* EMDC */
  182. }
  183. #ifndef CONFIG_RMII
  184. /* Only emac0 support MII */
  185. if (has_emac0()) {
  186. at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* ECRS */
  187. at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* ECOL */
  188. at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ERX2 */
  189. at91_pio3_set_a_periph(AT91_PIO_PORTB, 14, 0); /* ERX3 */
  190. at91_pio3_set_a_periph(AT91_PIO_PORTB, 15, 0); /* ERXCK */
  191. at91_pio3_set_a_periph(AT91_PIO_PORTB, 11, 0); /* ETX2 */
  192. at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX3 */
  193. at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ETXER */
  194. }
  195. #endif
  196. }
  197. #endif