gpio.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (C) 2006 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/io.h>
  24. #include <asm/arch/chip-features.h>
  25. #include <asm/arch/gpio.h>
  26. #include <asm/arch/memory-map.h>
  27. /*
  28. * Lots of small functions here. We depend on --gc-sections getting
  29. * rid of the ones we don't need.
  30. */
  31. void gpio_enable_ebi(void)
  32. {
  33. #ifdef CONFIG_SYS_HSDRAMC
  34. #ifndef CONFIG_SYS_SDRAM_16BIT
  35. gpio_select_periph_A(GPIO_PIN_PE0, 0);
  36. gpio_select_periph_A(GPIO_PIN_PE1, 0);
  37. gpio_select_periph_A(GPIO_PIN_PE2, 0);
  38. gpio_select_periph_A(GPIO_PIN_PE3, 0);
  39. gpio_select_periph_A(GPIO_PIN_PE4, 0);
  40. gpio_select_periph_A(GPIO_PIN_PE5, 0);
  41. gpio_select_periph_A(GPIO_PIN_PE6, 0);
  42. gpio_select_periph_A(GPIO_PIN_PE7, 0);
  43. gpio_select_periph_A(GPIO_PIN_PE8, 0);
  44. gpio_select_periph_A(GPIO_PIN_PE9, 0);
  45. gpio_select_periph_A(GPIO_PIN_PE10, 0);
  46. gpio_select_periph_A(GPIO_PIN_PE11, 0);
  47. gpio_select_periph_A(GPIO_PIN_PE12, 0);
  48. gpio_select_periph_A(GPIO_PIN_PE13, 0);
  49. gpio_select_periph_A(GPIO_PIN_PE14, 0);
  50. gpio_select_periph_A(GPIO_PIN_PE15, 0);
  51. #endif
  52. gpio_select_periph_A(GPIO_PIN_PE26, 0);
  53. #endif
  54. }
  55. #ifdef AT32AP700x_CHIP_HAS_USART
  56. void gpio_enable_usart0(void)
  57. {
  58. gpio_select_periph_B(GPIO_PIN_PA8, 0);
  59. gpio_select_periph_B(GPIO_PIN_PA9, 0);
  60. }
  61. void gpio_enable_usart1(void)
  62. {
  63. gpio_select_periph_A(GPIO_PIN_PA17, 0);
  64. gpio_select_periph_A(GPIO_PIN_PA18, 0);
  65. }
  66. void gpio_enable_usart2(void)
  67. {
  68. gpio_select_periph_B(GPIO_PIN_PB26, 0);
  69. gpio_select_periph_B(GPIO_PIN_PB27, 0);
  70. }
  71. void gpio_enable_usart3(void)
  72. {
  73. gpio_select_periph_B(GPIO_PIN_PB17, 0);
  74. gpio_select_periph_B(GPIO_PIN_PB18, 0);
  75. }
  76. #endif
  77. #ifdef AT32AP700x_CHIP_HAS_MACB
  78. void gpio_enable_macb0(void)
  79. {
  80. gpio_select_periph_A(GPIO_PIN_PC3, 0); /* TXD0 */
  81. gpio_select_periph_A(GPIO_PIN_PC4, 0); /* TXD1 */
  82. gpio_select_periph_A(GPIO_PIN_PC7, 0); /* TXEN */
  83. gpio_select_periph_A(GPIO_PIN_PC8, 0); /* TXCK */
  84. gpio_select_periph_A(GPIO_PIN_PC9, 0); /* RXD0 */
  85. gpio_select_periph_A(GPIO_PIN_PC10, 0); /* RXD1 */
  86. gpio_select_periph_A(GPIO_PIN_PC13, 0); /* RXER */
  87. gpio_select_periph_A(GPIO_PIN_PC15, 0); /* RXDV */
  88. gpio_select_periph_A(GPIO_PIN_PC16, 0); /* MDC */
  89. gpio_select_periph_A(GPIO_PIN_PC17, 0); /* MDIO */
  90. #if !defined(CONFIG_RMII)
  91. gpio_select_periph_A(GPIO_PIN_PC0, 0); /* COL */
  92. gpio_select_periph_A(GPIO_PIN_PC1, 0); /* CRS */
  93. gpio_select_periph_A(GPIO_PIN_PC2, 0); /* TXER */
  94. gpio_select_periph_A(GPIO_PIN_PC5, 0); /* TXD2 */
  95. gpio_select_periph_A(GPIO_PIN_PC6, 0); /* TXD3 */
  96. gpio_select_periph_A(GPIO_PIN_PC11, 0); /* RXD2 */
  97. gpio_select_periph_A(GPIO_PIN_PC12, 0); /* RXD3 */
  98. gpio_select_periph_A(GPIO_PIN_PC14, 0); /* RXCK */
  99. gpio_select_periph_A(GPIO_PIN_PC18, 0); /* SPD */
  100. #endif
  101. }
  102. void gpio_enable_macb1(void)
  103. {
  104. gpio_select_periph_B(GPIO_PIN_PD13, 0); /* TXD0 */
  105. gpio_select_periph_B(GPIO_PIN_PD14, 0); /* TXD1 */
  106. gpio_select_periph_B(GPIO_PIN_PD11, 0); /* TXEN */
  107. gpio_select_periph_B(GPIO_PIN_PD12, 0); /* TXCK */
  108. gpio_select_periph_B(GPIO_PIN_PD10, 0); /* RXD0 */
  109. gpio_select_periph_B(GPIO_PIN_PD6, 0); /* RXD1 */
  110. gpio_select_periph_B(GPIO_PIN_PD5, 0); /* RXER */
  111. gpio_select_periph_B(GPIO_PIN_PD4, 0); /* RXDV */
  112. gpio_select_periph_B(GPIO_PIN_PD3, 0); /* MDC */
  113. gpio_select_periph_B(GPIO_PIN_PD2, 0); /* MDIO */
  114. #if !defined(CONFIG_RMII)
  115. gpio_select_periph_B(GPIO_PIN_PC19, 0); /* COL */
  116. gpio_select_periph_B(GPIO_PIN_PC23, 0); /* CRS */
  117. gpio_select_periph_B(GPIO_PIN_PC26, 0); /* TXER */
  118. gpio_select_periph_B(GPIO_PIN_PC27, 0); /* TXD2 */
  119. gpio_select_periph_B(GPIO_PIN_PC28, 0); /* TXD3 */
  120. gpio_select_periph_B(GPIO_PIN_PC29, 0); /* RXD2 */
  121. gpio_select_periph_B(GPIO_PIN_PC30, 0); /* RXD3 */
  122. gpio_select_periph_B(GPIO_PIN_PC24, 0); /* RXCK */
  123. gpio_select_periph_B(GPIO_PIN_PD15, 0); /* SPD */
  124. #endif
  125. }
  126. #endif
  127. #ifdef AT32AP700x_CHIP_HAS_MMCI
  128. void gpio_enable_mmci(void)
  129. {
  130. gpio_select_periph_A(GPIO_PIN_PA10, 0); /* CLK */
  131. gpio_select_periph_A(GPIO_PIN_PA11, 0); /* CMD */
  132. gpio_select_periph_A(GPIO_PIN_PA12, 0); /* DATA0 */
  133. gpio_select_periph_A(GPIO_PIN_PA13, 0); /* DATA1 */
  134. gpio_select_periph_A(GPIO_PIN_PA14, 0); /* DATA2 */
  135. gpio_select_periph_A(GPIO_PIN_PA15, 0); /* DATA3 */
  136. }
  137. #endif
  138. #ifdef AT32AP700x_CHIP_HAS_SPI
  139. void gpio_enable_spi0(unsigned long cs_mask)
  140. {
  141. gpio_select_periph_A(GPIO_PIN_PA0, 0); /* MISO */
  142. gpio_select_periph_A(GPIO_PIN_PA1, 0); /* MOSI */
  143. gpio_select_periph_A(GPIO_PIN_PA2, 0); /* SCK */
  144. /* Set up NPCSx as GPIO outputs, initially high */
  145. if (cs_mask & (1 << 0)) {
  146. gpio_set_value(GPIO_PIN_PA3, 1);
  147. gpio_select_pio(GPIO_PIN_PA3, GPIOF_OUTPUT);
  148. }
  149. if (cs_mask & (1 << 1)) {
  150. gpio_set_value(GPIO_PIN_PA4, 1);
  151. gpio_select_pio(GPIO_PIN_PA4, GPIOF_OUTPUT);
  152. }
  153. if (cs_mask & (1 << 2)) {
  154. gpio_set_value(GPIO_PIN_PA5, 1);
  155. gpio_select_pio(GPIO_PIN_PA5, GPIOF_OUTPUT);
  156. }
  157. if (cs_mask & (1 << 3)) {
  158. gpio_set_value(GPIO_PIN_PA20, 1);
  159. gpio_select_pio(GPIO_PIN_PA20, GPIOF_OUTPUT);
  160. }
  161. }
  162. void gpio_enable_spi1(unsigned long cs_mask)
  163. {
  164. gpio_select_periph_B(GPIO_PIN_PA0, 0); /* MISO */
  165. gpio_select_periph_B(GPIO_PIN_PB1, 0); /* MOSI */
  166. gpio_select_periph_B(GPIO_PIN_PB5, 0); /* SCK */
  167. /* Set up NPCSx as GPIO outputs, initially high */
  168. if (cs_mask & (1 << 0)) {
  169. gpio_set_value(GPIO_PIN_PB2, 1);
  170. gpio_select_pio(GPIO_PIN_PB2, GPIOF_OUTPUT);
  171. }
  172. if (cs_mask & (1 << 1)) {
  173. gpio_set_value(GPIO_PIN_PB3, 1);
  174. gpio_select_pio(GPIO_PIN_PB3, GPIOF_OUTPUT);
  175. }
  176. if (cs_mask & (1 << 2)) {
  177. gpio_set_value(GPIO_PIN_PB4, 1);
  178. gpio_select_pio(GPIO_PIN_PB4, GPIOF_OUTPUT);
  179. }
  180. if (cs_mask & (1 << 3)) {
  181. gpio_set_value(GPIO_PIN_PA27, 1);
  182. gpio_select_pio(GPIO_PIN_PA27, GPIOF_OUTPUT);
  183. }
  184. }
  185. #endif