at91cap9_devices.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * (C) Copyright 2009
  7. * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
  8. * esd electronic system design gmbh <www.esd.eu>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <asm/arch/at91_common.h>
  14. #include <asm/arch/at91_pmc.h>
  15. #include <asm/arch/gpio.h>
  16. #include <asm/arch/io.h>
  17. void at91_serial0_hw_init(void)
  18. {
  19. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  20. at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */
  21. at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */
  22. writel(1 << AT91CAP9_ID_US0, &pmc->pcer);
  23. }
  24. void at91_serial1_hw_init(void)
  25. {
  26. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  27. at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
  28. at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */
  29. writel(1 << AT91CAP9_ID_US1, &pmc->pcer);
  30. }
  31. void at91_serial2_hw_init(void)
  32. {
  33. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  34. at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
  35. at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */
  36. writel(1 << AT91CAP9_ID_US2, &pmc->pcer);
  37. }
  38. void at91_serial3_hw_init(void)
  39. {
  40. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  41. at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */
  42. at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
  43. writel(1 << AT91_ID_SYS, &pmc->pcer);
  44. }
  45. void at91_serial_hw_init(void)
  46. {
  47. #ifdef CONFIG_USART0
  48. at91_serial0_hw_init();
  49. #endif
  50. #ifdef CONFIG_USART1
  51. at91_serial1_hw_init();
  52. #endif
  53. #ifdef CONFIG_USART2
  54. at91_serial2_hw_init();
  55. #endif
  56. #ifdef CONFIG_USART3 /* DBGU */
  57. at91_serial3_hw_init();
  58. #endif
  59. }
  60. #ifdef CONFIG_HAS_DATAFLASH
  61. void at91_spi0_hw_init(unsigned long cs_mask)
  62. {
  63. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  64. at91_set_b_periph(AT91_PIO_PORTA, 0, 0); /* SPI0_MISO */
  65. at91_set_b_periph(AT91_PIO_PORTA, 1, 0); /* SPI0_MOSI */
  66. at91_set_b_periph(AT91_PIO_PORTA, 2, 0); /* SPI0_SPCK */
  67. /* Enable clock */
  68. writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer);
  69. if (cs_mask & (1 << 0)) {
  70. at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
  71. }
  72. if (cs_mask & (1 << 1)) {
  73. at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
  74. }
  75. if (cs_mask & (1 << 2)) {
  76. at91_set_b_periph(AT91_PIO_PORTD, 0, 1);
  77. }
  78. if (cs_mask & (1 << 3)) {
  79. at91_set_b_periph(AT91_PIO_PORTD, 1, 1);
  80. }
  81. if (cs_mask & (1 << 4)) {
  82. at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
  83. }
  84. if (cs_mask & (1 << 5)) {
  85. at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
  86. }
  87. if (cs_mask & (1 << 6)) {
  88. at91_set_pio_output(AT91_PIO_PORTD, 0, 1);
  89. }
  90. if (cs_mask & (1 << 7)) {
  91. at91_set_pio_output(AT91_PIO_PORTD, 1, 1);
  92. }
  93. }
  94. void at91_spi1_hw_init(unsigned long cs_mask)
  95. {
  96. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  97. at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* SPI1_MISO */
  98. at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* SPI1_MOSI */
  99. at91_set_a_periph(AT91_PIO_PORTB, 14, 0); /* SPI1_SPCK */
  100. /* Enable clock */
  101. writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer);
  102. if (cs_mask & (1 << 0)) {
  103. at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
  104. }
  105. if (cs_mask & (1 << 1)) {
  106. at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
  107. }
  108. if (cs_mask & (1 << 2)) {
  109. at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
  110. }
  111. if (cs_mask & (1 << 3)) {
  112. at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
  113. }
  114. if (cs_mask & (1 << 4)) {
  115. at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
  116. }
  117. if (cs_mask & (1 << 5)) {
  118. at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
  119. }
  120. if (cs_mask & (1 << 6)) {
  121. at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
  122. }
  123. if (cs_mask & (1 << 7)) {
  124. at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
  125. }
  126. }
  127. #endif
  128. #ifdef CONFIG_MACB
  129. void at91_macb_hw_init(void)
  130. {
  131. at91_set_a_periph(AT91_PIO_PORTB, 21, 0); /* ETXCK_EREFCK */
  132. at91_set_a_periph(AT91_PIO_PORTB, 22, 0); /* ERXDV */
  133. at91_set_a_periph(AT91_PIO_PORTB, 25, 0); /* ERX0 */
  134. at91_set_a_periph(AT91_PIO_PORTB, 26, 0); /* ERX1 */
  135. at91_set_a_periph(AT91_PIO_PORTB, 27, 0); /* ERXER */
  136. at91_set_a_periph(AT91_PIO_PORTB, 28, 0); /* ETXEN */
  137. at91_set_a_periph(AT91_PIO_PORTB, 23, 0); /* ETX0 */
  138. at91_set_a_periph(AT91_PIO_PORTB, 24, 0); /* ETX1 */
  139. at91_set_a_periph(AT91_PIO_PORTB, 30, 0); /* EMDIO */
  140. at91_set_a_periph(AT91_PIO_PORTB, 29, 0); /* EMDC */
  141. #ifndef CONFIG_RMII
  142. at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ECRS */
  143. at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
  144. at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
  145. at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
  146. at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
  147. at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
  148. at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
  149. at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
  150. #endif
  151. }
  152. #endif
  153. #ifdef CONFIG_AT91_CAN
  154. void at91_can_hw_init(void)
  155. {
  156. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  157. at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */
  158. at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */
  159. /* Enable clock */
  160. writel(1 << AT91CAP9_ID_CAN, &pmc->pcer);
  161. }
  162. #endif