portmux.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2006, 2008 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/memory-map.h>
  26. #include <asm/arch/portmux.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 portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width,
  32. unsigned long flags, unsigned long drive_strength)
  33. {
  34. unsigned long porte_mask = 0;
  35. if (bus_width > 16)
  36. portmux_select_peripheral(PORTMUX_PORT_E, 0xffff,
  37. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  38. if (addr_width > 23)
  39. porte_mask |= (((1 << (addr_width - 23)) - 1) & 7) << 16;
  40. if (flags & PORTMUX_EBI_CS(2))
  41. porte_mask |= 1 << 25;
  42. if (flags & PORTMUX_EBI_CS(4))
  43. porte_mask |= 1 << 21;
  44. if (flags & PORTMUX_EBI_CS(5))
  45. porte_mask |= 1 << 22;
  46. if (flags & (PORTMUX_EBI_CF(0) | PORTMUX_EBI_CF(1)))
  47. porte_mask |= (1 << 19) | (1 << 20) | (1 << 23);
  48. portmux_select_peripheral(PORTMUX_PORT_E, porte_mask,
  49. PORTMUX_FUNC_A, 0);
  50. if (flags & PORTMUX_EBI_NWAIT)
  51. portmux_select_peripheral(PORTMUX_PORT_E, 1 << 24,
  52. PORTMUX_FUNC_A, PORTMUX_PULL_UP);
  53. }
  54. #ifdef AT32AP700x_CHIP_HAS_MACB
  55. void portmux_enable_macb0(unsigned long flags, unsigned long drive_strength)
  56. {
  57. unsigned long portc_mask;
  58. portc_mask = (1 << 3) /* TXD0 */
  59. | (1 << 4) /* TXD1 */
  60. | (1 << 7) /* TXEN */
  61. | (1 << 8) /* TXCK */
  62. | (1 << 9) /* RXD0 */
  63. | (1 << 10) /* RXD1 */
  64. | (1 << 13) /* RXER */
  65. | (1 << 15) /* RXDV */
  66. | (1 << 16) /* MDC */
  67. | (1 << 17); /* MDIO */
  68. if (flags & PORTMUX_MACB_MII)
  69. portc_mask |= (1 << 0) /* COL */
  70. | (1 << 1) /* CRS */
  71. | (1 << 2) /* TXER */
  72. | (1 << 5) /* TXD2 */
  73. | (1 << 6) /* TXD3 */
  74. | (1 << 11) /* RXD2 */
  75. | (1 << 12) /* RXD3 */
  76. | (1 << 14); /* RXCK */
  77. if (flags & PORTMUX_MACB_SPEED)
  78. portc_mask |= (1 << 18);/* SPD */
  79. /* REVISIT: Some pins are probably pure outputs */
  80. portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
  81. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  82. }
  83. void portmux_enable_macb1(unsigned long flags, unsigned long drive_strength)
  84. {
  85. unsigned long portc_mask = 0;
  86. unsigned long portd_mask;
  87. portd_mask = (1 << 13) /* TXD0 */
  88. | (1 << 14) /* TXD1 */
  89. | (1 << 11) /* TXEN */
  90. | (1 << 12) /* TXCK */
  91. | (1 << 10) /* RXD0 */
  92. | (1 << 6) /* RXD1 */
  93. | (1 << 5) /* RXER */
  94. | (1 << 4) /* RXDV */
  95. | (1 << 3) /* MDC */
  96. | (1 << 2); /* MDIO */
  97. if (flags & PORTMUX_MACB_MII)
  98. portc_mask = (1 << 19) /* COL */
  99. | (1 << 23) /* CRS */
  100. | (1 << 26) /* TXER */
  101. | (1 << 27) /* TXD2 */
  102. | (1 << 28) /* TXD3 */
  103. | (1 << 29) /* RXD2 */
  104. | (1 << 30) /* RXD3 */
  105. | (1 << 24); /* RXCK */
  106. if (flags & PORTMUX_MACB_SPEED)
  107. portd_mask |= (1 << 15);/* SPD */
  108. /* REVISIT: Some pins are probably pure outputs */
  109. portmux_select_peripheral(PORTMUX_PORT_D, portc_mask,
  110. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  111. portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
  112. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  113. }
  114. #endif
  115. #ifdef AT32AP700x_CHIP_HAS_MMCI
  116. void portmux_enable_mmci(unsigned int slot, unsigned long flags,
  117. unsigned long drive_strength)
  118. {
  119. unsigned long mask;
  120. unsigned long portmux_flags = PORTMUX_PULL_UP;
  121. /* First, the common CLK signal. It doesn't need a pull-up */
  122. portmux_select_peripheral(PORTMUX_PORT_A, 1 << 10,
  123. PORTMUX_FUNC_A, 0);
  124. if (flags & PORTMUX_MMCI_EXT_PULLUP)
  125. portmux_flags = 0;
  126. /* Then, the per-slot signals */
  127. switch (slot) {
  128. case 0:
  129. mask = (1 << 11) | (1 << 12); /* CMD and DATA0 */
  130. if (flags & PORTMUX_MMCI_4BIT)
  131. /* DATA1..DATA3 */
  132. mask |= (1 << 13) | (1 << 14) | (1 << 15);
  133. portmux_select_peripheral(PORTMUX_PORT_A, mask,
  134. PORTMUX_FUNC_A, portmux_flags);
  135. break;
  136. case 1:
  137. mask = (1 << 6) | (1 << 7); /* CMD and DATA0 */
  138. if (flags & PORTMUX_MMCI_4BIT)
  139. /* DATA1..DATA3 */
  140. mask |= (1 << 8) | (1 << 9) | (1 << 10);
  141. portmux_select_peripheral(PORTMUX_PORT_B, mask,
  142. PORTMUX_FUNC_B, portmux_flags);
  143. break;
  144. }
  145. }
  146. #endif
  147. #ifdef AT32AP700x_CHIP_HAS_SPI
  148. void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength)
  149. {
  150. unsigned long pin_mask;
  151. /* MOSI and SCK */
  152. portmux_select_peripheral(PORTMUX_PORT_A, (1 << 1) | (1 << 2),
  153. PORTMUX_FUNC_A, 0);
  154. /* MISO may float */
  155. portmux_select_peripheral(PORTMUX_PORT_A, 1 << 0,
  156. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  157. /* Set up NPCSx as GPIO outputs, initially high */
  158. pin_mask = (cs_mask & 7) << 3;
  159. if (cs_mask & (1 << 3))
  160. pin_mask |= 1 << 20;
  161. portmux_select_gpio(PORTMUX_PORT_A, pin_mask,
  162. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  163. }
  164. void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength)
  165. {
  166. /* MOSI and SCK */
  167. portmux_select_peripheral(PORTMUX_PORT_B, (1 << 1) | (1 << 5),
  168. PORTMUX_FUNC_B, 0);
  169. /* MISO may float */
  170. portmux_select_peripheral(PORTMUX_PORT_B, 1 << 0,
  171. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  172. /* Set up NPCSx as GPIO outputs, initially high */
  173. portmux_select_gpio(PORTMUX_PORT_B, (cs_mask & 7) << 2,
  174. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  175. portmux_select_gpio(PORTMUX_PORT_A, (cs_mask & 8) << (27 - 3),
  176. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  177. }
  178. #endif