at91sam9x5_devices.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (C) 2012 Atmel Corporation
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/arch/at91_common.h>
  24. #include <asm/arch/at91_pmc.h>
  25. #include <asm/arch/gpio.h>
  26. #include <asm/io.h>
  27. unsigned int get_chip_id(void)
  28. {
  29. /* The 0x40 is the offset of cidr in DBGU */
  30. return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
  31. }
  32. unsigned int get_extension_chip_id(void)
  33. {
  34. /* The 0x44 is the offset of exid in DBGU */
  35. return readl(ATMEL_BASE_DBGU + 0x44);
  36. }
  37. unsigned int has_emac1()
  38. {
  39. return cpu_is_at91sam9x25();
  40. }
  41. unsigned int has_emac0()
  42. {
  43. return !(cpu_is_at91sam9g15());
  44. }
  45. unsigned int has_lcdc()
  46. {
  47. return cpu_is_at91sam9g15() || cpu_is_at91sam9g35()
  48. || cpu_is_at91sam9x35();
  49. }
  50. char *get_cpu_name()
  51. {
  52. unsigned int extension_id = get_extension_chip_id();
  53. if (cpu_is_at91sam9x5()) {
  54. switch (extension_id) {
  55. case ARCH_EXID_AT91SAM9G15:
  56. return CONFIG_SYS_AT91_G15_CPU_NAME;
  57. case ARCH_EXID_AT91SAM9G25:
  58. return CONFIG_SYS_AT91_G25_CPU_NAME;
  59. case ARCH_EXID_AT91SAM9G35:
  60. return CONFIG_SYS_AT91_G35_CPU_NAME;
  61. case ARCH_EXID_AT91SAM9X25:
  62. return CONFIG_SYS_AT91_X25_CPU_NAME;
  63. case ARCH_EXID_AT91SAM9X35:
  64. return CONFIG_SYS_AT91_X35_CPU_NAME;
  65. default:
  66. return CONFIG_SYS_AT91_UNKNOWN_CPU;
  67. }
  68. } else {
  69. return CONFIG_SYS_AT91_UNKNOWN_CPU;
  70. }
  71. }
  72. void at91_seriald_hw_init(void)
  73. {
  74. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  75. at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
  76. at91_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
  77. writel(1 << ATMEL_ID_SYS, &pmc->pcer);
  78. }
  79. void at91_serial0_hw_init(void)
  80. {
  81. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  82. at91_set_a_periph(AT91_PIO_PORTA, 0, 1); /* TXD */
  83. at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* RXD */
  84. writel(1 << ATMEL_ID_USART0, &pmc->pcer);
  85. }
  86. void at91_serial1_hw_init(void)
  87. {
  88. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  89. at91_set_a_periph(AT91_PIO_PORTA, 5, 1); /* TXD */
  90. at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* RXD */
  91. writel(1 << ATMEL_ID_USART1, &pmc->pcer);
  92. }
  93. void at91_serial2_hw_init(void)
  94. {
  95. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  96. at91_set_a_periph(AT91_PIO_PORTA, 7, 1); /* TXD */
  97. at91_set_a_periph(AT91_PIO_PORTA, 8, 0); /* RXD */
  98. writel(1 << ATMEL_ID_USART2, &pmc->pcer);
  99. }
  100. #ifdef CONFIG_ATMEL_SPI
  101. void at91_spi0_hw_init(unsigned long cs_mask)
  102. {
  103. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_PMC_BASE;
  104. at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SPI0_MISO */
  105. at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* SPI0_MOSI */
  106. at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* SPI0_SPCK */
  107. /* Enable clock */
  108. writel(1 << ATMEL_ID_SPI0, &pmc->pcer);
  109. if (cs_mask & (1 << 0))
  110. at91_set_a_periph(AT91_PIO_PORTA, 14, 0);
  111. if (cs_mask & (1 << 1))
  112. at91_set_b_periph(AT91_PIO_PORTA, 7, 0);
  113. if (cs_mask & (1 << 2))
  114. at91_set_b_periph(AT91_PIO_PORTA, 1, 0);
  115. if (cs_mask & (1 << 3))
  116. at91_set_b_periph(AT91_PIO_PORTB, 3, 0);
  117. if (cs_mask & (1 << 4))
  118. at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
  119. if (cs_mask & (1 << 5))
  120. at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
  121. if (cs_mask & (1 << 6))
  122. at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
  123. if (cs_mask & (1 << 7))
  124. at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
  125. }
  126. void at91_spi1_hw_init(unsigned long cs_mask)
  127. {
  128. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_PMC_BASE;
  129. at91_set_b_periph(AT91_PIO_PORTA, 21, 0); /* SPI1_MISO */
  130. at91_set_b_periph(AT91_PIO_PORTA, 22, 0); /* SPI1_MOSI */
  131. at91_set_b_periph(AT91_PIO_PORTA, 23, 0); /* SPI1_SPCK */
  132. /* Enable clock */
  133. writel(1 << ATMEL_ID_SPI1, &pmc->pcer);
  134. if (cs_mask & (1 << 0))
  135. at91_set_b_periph(AT91_PIO_PORTA, 8, 0);
  136. if (cs_mask & (1 << 1))
  137. at91_set_b_periph(AT91_PIO_PORTA, 0, 0);
  138. if (cs_mask & (1 << 2))
  139. at91_set_b_periph(AT91_PIO_PORTA, 31, 0);
  140. if (cs_mask & (1 << 3))
  141. at91_set_b_periph(AT91_PIO_PORTA, 30, 0);
  142. if (cs_mask & (1 << 4))
  143. at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
  144. if (cs_mask & (1 << 5))
  145. at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
  146. if (cs_mask & (1 << 6))
  147. at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
  148. if (cs_mask & (1 << 7))
  149. at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
  150. }
  151. #endif
  152. #ifdef CONFIG_MACB
  153. void at91_macb_hw_init(void)
  154. {
  155. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  156. if (has_emac0()) {
  157. /* Enable EMAC0 clock */
  158. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  159. /* EMAC0 pins setup */
  160. at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* ETXCK */
  161. at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* ERXDV */
  162. at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ERX0 */
  163. at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* ERX1 */
  164. at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ERXER */
  165. at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ETXEN */
  166. at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ETX0 */
  167. at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* ETX1 */
  168. at91_set_a_periph(AT91_PIO_PORTB, 5, 0); /* EMDIO */
  169. at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* EMDC */
  170. }
  171. if (has_emac1()) {
  172. /* Enable EMAC1 clock */
  173. writel(1 << ATMEL_ID_EMAC1, &pmc->pcer);
  174. /* EMAC1 pins setup */
  175. at91_set_b_periph(AT91_PIO_PORTC, 29, 0); /* ETXCK */
  176. at91_set_b_periph(AT91_PIO_PORTC, 28, 0); /* ECRSDV */
  177. at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ERXO */
  178. at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ERX1 */
  179. at91_set_b_periph(AT91_PIO_PORTC, 16, 0); /* ERXER */
  180. at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ETXEN */
  181. at91_set_b_periph(AT91_PIO_PORTC, 18, 0); /* ETX0 */
  182. at91_set_b_periph(AT91_PIO_PORTC, 19, 0); /* ETX1 */
  183. at91_set_b_periph(AT91_PIO_PORTC, 31, 0); /* EMDIO */
  184. at91_set_b_periph(AT91_PIO_PORTC, 30, 0); /* EMDC */
  185. }
  186. #ifndef CONFIG_RMII
  187. /* Only emac0 support MII */
  188. if (has_emac0()) {
  189. at91_set_b_periph(AT91_PIO_PORTB, 16, 0); /* ECRS */
  190. at91_set_b_periph(AT91_PIO_PORTB, 17, 0); /* ECOL */
  191. at91_set_b_periph(AT91_PIO_PORTB, 13, 0); /* ERX2 */
  192. at91_set_b_periph(AT91_PIO_PORTB, 14, 0); /* ERX3 */
  193. at91_set_b_periph(AT91_PIO_PORTB, 15, 0); /* ERXCK */
  194. at91_set_b_periph(AT91_PIO_PORTB, 11, 0); /* ETX2 */
  195. at91_set_b_periph(AT91_PIO_PORTB, 12, 0); /* ETX3 */
  196. at91_set_b_periph(AT91_PIO_PORTB, 8, 0); /* ETXER */
  197. }
  198. #endif
  199. }
  200. #endif