at91cap9_devices.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  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. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <asm/arch/at91_common.h>
  30. #include <asm/arch/at91_pmc.h>
  31. #include <asm/arch/gpio.h>
  32. #include <asm/arch/io.h>
  33. void at91_serial0_hw_init(void)
  34. {
  35. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  36. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  37. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US0);
  38. }
  39. void at91_serial1_hw_init(void)
  40. {
  41. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  42. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  43. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US1);
  44. }
  45. void at91_serial2_hw_init(void)
  46. {
  47. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  48. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  49. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_US2);
  50. }
  51. void at91_serial3_hw_init(void)
  52. {
  53. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  54. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  55. at91_sys_write(AT91_PMC_PCER, 1 << AT91_ID_SYS);
  56. }
  57. void at91_serial_hw_init(void)
  58. {
  59. #ifdef CONFIG_USART0
  60. at91_serial0_hw_init();
  61. #endif
  62. #ifdef CONFIG_USART1
  63. at91_serial1_hw_init();
  64. #endif
  65. #ifdef CONFIG_USART2
  66. at91_serial2_hw_init();
  67. #endif
  68. #ifdef CONFIG_USART3 /* DBGU */
  69. at91_serial3_hw_init();
  70. #endif
  71. }
  72. #ifdef CONFIG_HAS_DATAFLASH
  73. void at91_spi0_hw_init(unsigned long cs_mask)
  74. {
  75. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  76. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  77. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  78. /* Enable clock */
  79. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI0);
  80. if (cs_mask & (1 << 0)) {
  81. at91_set_B_periph(AT91_PIN_PA5, 1);
  82. }
  83. if (cs_mask & (1 << 1)) {
  84. at91_set_B_periph(AT91_PIN_PA3, 1);
  85. }
  86. if (cs_mask & (1 << 2)) {
  87. at91_set_B_periph(AT91_PIN_PD0, 1);
  88. }
  89. if (cs_mask & (1 << 3)) {
  90. at91_set_B_periph(AT91_PIN_PD1, 1);
  91. }
  92. if (cs_mask & (1 << 4)) {
  93. at91_set_gpio_output(AT91_PIN_PA5, 1);
  94. }
  95. if (cs_mask & (1 << 5)) {
  96. at91_set_gpio_output(AT91_PIN_PA3, 1);
  97. }
  98. if (cs_mask & (1 << 6)) {
  99. at91_set_gpio_output(AT91_PIN_PD0, 1);
  100. }
  101. if (cs_mask & (1 << 7)) {
  102. at91_set_gpio_output(AT91_PIN_PD1, 1);
  103. }
  104. }
  105. void at91_spi1_hw_init(unsigned long cs_mask)
  106. {
  107. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  108. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  109. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  110. /* Enable clock */
  111. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_SPI1);
  112. if (cs_mask & (1 << 0)) {
  113. at91_set_A_periph(AT91_PIN_PB15, 1);
  114. }
  115. if (cs_mask & (1 << 1)) {
  116. at91_set_A_periph(AT91_PIN_PB16, 1);
  117. }
  118. if (cs_mask & (1 << 2)) {
  119. at91_set_A_periph(AT91_PIN_PB17, 1);
  120. }
  121. if (cs_mask & (1 << 3)) {
  122. at91_set_A_periph(AT91_PIN_PB18, 1);
  123. }
  124. if (cs_mask & (1 << 4)) {
  125. at91_set_gpio_output(AT91_PIN_PB15, 1);
  126. }
  127. if (cs_mask & (1 << 5)) {
  128. at91_set_gpio_output(AT91_PIN_PB16, 1);
  129. }
  130. if (cs_mask & (1 << 6)) {
  131. at91_set_gpio_output(AT91_PIN_PB17, 1);
  132. }
  133. if (cs_mask & (1 << 7)) {
  134. at91_set_gpio_output(AT91_PIN_PB18, 1);
  135. }
  136. }
  137. #endif
  138. #ifdef CONFIG_MACB
  139. void at91_macb_hw_init(void)
  140. {
  141. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  142. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  143. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  144. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  145. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  146. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  147. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  148. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  149. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  150. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  151. #ifndef CONFIG_RMII
  152. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  153. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  154. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  155. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  156. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  157. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  158. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  159. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  160. #endif
  161. }
  162. #endif
  163. #ifdef CONFIG_AT91_CAN
  164. void at91_can_hw_init(void)
  165. {
  166. at91_set_A_periph(AT91_PIN_PA12, 0); /* CAN_TX */
  167. at91_set_A_periph(AT91_PIN_PA13, 1); /* CAN_RX */
  168. /* Enable clock */
  169. at91_sys_write(AT91_PMC_PCER, 1 << AT91CAP9_ID_CAN);
  170. }
  171. #endif