portmux.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2006, 2008 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/chip-features.h>
  9. #include <asm/arch/hardware.h>
  10. #include <asm/arch/portmux.h>
  11. /*
  12. * Lots of small functions here. We depend on --gc-sections getting
  13. * rid of the ones we don't need.
  14. */
  15. void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width,
  16. unsigned long flags, unsigned long drive_strength)
  17. {
  18. unsigned long porte_mask = 0;
  19. if (bus_width > 16)
  20. portmux_select_peripheral(PORTMUX_PORT_E, 0xffff,
  21. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  22. if (addr_width > 23)
  23. porte_mask |= (((1 << (addr_width - 23)) - 1) & 7) << 16;
  24. if (flags & PORTMUX_EBI_CS(2))
  25. porte_mask |= 1 << 25;
  26. if (flags & PORTMUX_EBI_CS(4))
  27. porte_mask |= 1 << 21;
  28. if (flags & PORTMUX_EBI_CS(5))
  29. porte_mask |= 1 << 22;
  30. if (flags & (PORTMUX_EBI_CF(0) | PORTMUX_EBI_CF(1)))
  31. porte_mask |= (1 << 19) | (1 << 20) | (1 << 23);
  32. portmux_select_peripheral(PORTMUX_PORT_E, porte_mask,
  33. PORTMUX_FUNC_A, 0);
  34. if (flags & PORTMUX_EBI_NWAIT)
  35. portmux_select_peripheral(PORTMUX_PORT_E, 1 << 24,
  36. PORTMUX_FUNC_A, PORTMUX_PULL_UP);
  37. }
  38. #ifdef AT32AP700x_CHIP_HAS_MACB
  39. void portmux_enable_macb0(unsigned long flags, unsigned long drive_strength)
  40. {
  41. unsigned long portc_mask;
  42. portc_mask = (1 << 3) /* TXD0 */
  43. | (1 << 4) /* TXD1 */
  44. | (1 << 7) /* TXEN */
  45. | (1 << 8) /* TXCK */
  46. | (1 << 9) /* RXD0 */
  47. | (1 << 10) /* RXD1 */
  48. | (1 << 13) /* RXER */
  49. | (1 << 15) /* RXDV */
  50. | (1 << 16) /* MDC */
  51. | (1 << 17); /* MDIO */
  52. if (flags & PORTMUX_MACB_MII)
  53. portc_mask |= (1 << 0) /* COL */
  54. | (1 << 1) /* CRS */
  55. | (1 << 2) /* TXER */
  56. | (1 << 5) /* TXD2 */
  57. | (1 << 6) /* TXD3 */
  58. | (1 << 11) /* RXD2 */
  59. | (1 << 12) /* RXD3 */
  60. | (1 << 14); /* RXCK */
  61. if (flags & PORTMUX_MACB_SPEED)
  62. portc_mask |= (1 << 18);/* SPD */
  63. /* REVISIT: Some pins are probably pure outputs */
  64. portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
  65. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  66. }
  67. void portmux_enable_macb1(unsigned long flags, unsigned long drive_strength)
  68. {
  69. unsigned long portc_mask = 0;
  70. unsigned long portd_mask;
  71. portd_mask = (1 << 13) /* TXD0 */
  72. | (1 << 14) /* TXD1 */
  73. | (1 << 11) /* TXEN */
  74. | (1 << 12) /* TXCK */
  75. | (1 << 10) /* RXD0 */
  76. | (1 << 6) /* RXD1 */
  77. | (1 << 5) /* RXER */
  78. | (1 << 4) /* RXDV */
  79. | (1 << 3) /* MDC */
  80. | (1 << 2); /* MDIO */
  81. if (flags & PORTMUX_MACB_MII)
  82. portc_mask = (1 << 19) /* COL */
  83. | (1 << 23) /* CRS */
  84. | (1 << 26) /* TXER */
  85. | (1 << 27) /* TXD2 */
  86. | (1 << 28) /* TXD3 */
  87. | (1 << 29) /* RXD2 */
  88. | (1 << 30) /* RXD3 */
  89. | (1 << 24); /* RXCK */
  90. if (flags & PORTMUX_MACB_SPEED)
  91. portd_mask |= (1 << 15);/* SPD */
  92. /* REVISIT: Some pins are probably pure outputs */
  93. portmux_select_peripheral(PORTMUX_PORT_D, portd_mask,
  94. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  95. portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
  96. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  97. }
  98. #endif
  99. #ifdef AT32AP700x_CHIP_HAS_MMCI
  100. void portmux_enable_mmci(unsigned int slot, unsigned long flags,
  101. unsigned long drive_strength)
  102. {
  103. unsigned long mask;
  104. unsigned long portmux_flags = PORTMUX_PULL_UP;
  105. /* First, the common CLK signal. It doesn't need a pull-up */
  106. portmux_select_peripheral(PORTMUX_PORT_A, 1 << 10,
  107. PORTMUX_FUNC_A, 0);
  108. if (flags & PORTMUX_MMCI_EXT_PULLUP)
  109. portmux_flags = 0;
  110. /* Then, the per-slot signals */
  111. switch (slot) {
  112. case 0:
  113. mask = (1 << 11) | (1 << 12); /* CMD and DATA0 */
  114. if (flags & PORTMUX_MMCI_4BIT)
  115. /* DATA1..DATA3 */
  116. mask |= (1 << 13) | (1 << 14) | (1 << 15);
  117. portmux_select_peripheral(PORTMUX_PORT_A, mask,
  118. PORTMUX_FUNC_A, portmux_flags);
  119. break;
  120. case 1:
  121. mask = (1 << 6) | (1 << 7); /* CMD and DATA0 */
  122. if (flags & PORTMUX_MMCI_4BIT)
  123. /* DATA1..DATA3 */
  124. mask |= (1 << 8) | (1 << 9) | (1 << 10);
  125. portmux_select_peripheral(PORTMUX_PORT_B, mask,
  126. PORTMUX_FUNC_B, portmux_flags);
  127. break;
  128. }
  129. }
  130. #endif
  131. #ifdef AT32AP700x_CHIP_HAS_SPI
  132. void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength)
  133. {
  134. unsigned long pin_mask;
  135. /* MOSI and SCK */
  136. portmux_select_peripheral(PORTMUX_PORT_A, (1 << 1) | (1 << 2),
  137. PORTMUX_FUNC_A, 0);
  138. /* MISO may float */
  139. portmux_select_peripheral(PORTMUX_PORT_A, 1 << 0,
  140. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  141. /* Set up NPCSx as GPIO outputs, initially high */
  142. pin_mask = (cs_mask & 7) << 3;
  143. if (cs_mask & (1 << 3))
  144. pin_mask |= 1 << 20;
  145. portmux_select_gpio(PORTMUX_PORT_A, pin_mask,
  146. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  147. }
  148. void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength)
  149. {
  150. /* MOSI and SCK */
  151. portmux_select_peripheral(PORTMUX_PORT_B, (1 << 1) | (1 << 5),
  152. PORTMUX_FUNC_B, 0);
  153. /* MISO may float */
  154. portmux_select_peripheral(PORTMUX_PORT_B, 1 << 0,
  155. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  156. /* Set up NPCSx as GPIO outputs, initially high */
  157. portmux_select_gpio(PORTMUX_PORT_B, (cs_mask & 7) << 2,
  158. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  159. portmux_select_gpio(PORTMUX_PORT_A, (cs_mask & 8) << (27 - 3),
  160. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
  161. }
  162. #endif
  163. #ifdef AT32AP700x_CHIP_HAS_LCDC
  164. void portmux_enable_lcdc(int pin_config)
  165. {
  166. unsigned long portc_mask = 0;
  167. unsigned long portd_mask = 0;
  168. unsigned long porte_mask = 0;
  169. switch (pin_config) {
  170. case 0:
  171. portc_mask = (1 << 19) /* CC */
  172. | (1 << 20) /* HSYNC */
  173. | (1 << 21) /* PCLK */
  174. | (1 << 22) /* VSYNC */
  175. | (1 << 23) /* DVAL */
  176. | (1 << 24) /* MODE */
  177. | (1 << 25) /* PWR */
  178. | (1 << 26) /* DATA0 */
  179. | (1 << 27) /* DATA1 */
  180. | (1 << 28) /* DATA2 */
  181. | (1 << 29) /* DATA3 */
  182. | (1 << 30) /* DATA4 */
  183. | (1 << 31); /* DATA5 */
  184. portd_mask = (1 << 0) /* DATA6 */
  185. | (1 << 1) /* DATA7 */
  186. | (1 << 2) /* DATA8 */
  187. | (1 << 3) /* DATA9 */
  188. | (1 << 4) /* DATA10 */
  189. | (1 << 5) /* DATA11 */
  190. | (1 << 6) /* DATA12 */
  191. | (1 << 7) /* DATA13 */
  192. | (1 << 8) /* DATA14 */
  193. | (1 << 9) /* DATA15 */
  194. | (1 << 10) /* DATA16 */
  195. | (1 << 11) /* DATA17 */
  196. | (1 << 12) /* DATA18 */
  197. | (1 << 13) /* DATA19 */
  198. | (1 << 14) /* DATA20 */
  199. | (1 << 15) /* DATA21 */
  200. | (1 << 16) /* DATA22 */
  201. | (1 << 17); /* DATA23 */
  202. break;
  203. case 1:
  204. portc_mask = (1 << 20) /* HSYNC */
  205. | (1 << 21) /* PCLK */
  206. | (1 << 22) /* VSYNC */
  207. | (1 << 25) /* PWR */
  208. | (1 << 31); /* DATA5 */
  209. portd_mask = (1 << 0) /* DATA6 */
  210. | (1 << 1) /* DATA7 */
  211. | (1 << 7) /* DATA13 */
  212. | (1 << 8) /* DATA14 */
  213. | (1 << 9) /* DATA15 */
  214. | (1 << 16) /* DATA22 */
  215. | (1 << 17); /* DATA23 */
  216. porte_mask = (1 << 0) /* CC */
  217. | (1 << 1) /* DVAL */
  218. | (1 << 2) /* MODE */
  219. | (1 << 3) /* DATA0 */
  220. | (1 << 4) /* DATA1 */
  221. | (1 << 5) /* DATA2 */
  222. | (1 << 6) /* DATA3 */
  223. | (1 << 7) /* DATA4 */
  224. | (1 << 8) /* DATA8 */
  225. | (1 << 9) /* DATA9 */
  226. | (1 << 10) /* DATA10 */
  227. | (1 << 11) /* DATA11 */
  228. | (1 << 12) /* DATA12 */
  229. | (1 << 13) /* DATA16 */
  230. | (1 << 14) /* DATA17 */
  231. | (1 << 15) /* DATA18 */
  232. | (1 << 16) /* DATA19 */
  233. | (1 << 17) /* DATA20 */
  234. | (1 << 18); /* DATA21 */
  235. break;
  236. }
  237. /* REVISIT: Some pins are probably pure outputs */
  238. portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
  239. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  240. portmux_select_peripheral(PORTMUX_PORT_D, portd_mask,
  241. PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
  242. portmux_select_peripheral(PORTMUX_PORT_E, porte_mask,
  243. PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
  244. }
  245. #endif