pinctrl-mt76x8.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/module.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/of.h>
  5. #include "pinctrl-mtmips.h"
  6. #define MT76X8_GPIO_MODE_MASK 0x3
  7. #define MT76X8_GPIO_MODE_P4LED_KN 58
  8. #define MT76X8_GPIO_MODE_P3LED_KN 56
  9. #define MT76X8_GPIO_MODE_P2LED_KN 54
  10. #define MT76X8_GPIO_MODE_P1LED_KN 52
  11. #define MT76X8_GPIO_MODE_P0LED_KN 50
  12. #define MT76X8_GPIO_MODE_WLED_KN 48
  13. #define MT76X8_GPIO_MODE_P4LED_AN 42
  14. #define MT76X8_GPIO_MODE_P3LED_AN 40
  15. #define MT76X8_GPIO_MODE_P2LED_AN 38
  16. #define MT76X8_GPIO_MODE_P1LED_AN 36
  17. #define MT76X8_GPIO_MODE_P0LED_AN 34
  18. #define MT76X8_GPIO_MODE_WLED_AN 32
  19. #define MT76X8_GPIO_MODE_PWM1 30
  20. #define MT76X8_GPIO_MODE_PWM0 28
  21. #define MT76X8_GPIO_MODE_UART2 26
  22. #define MT76X8_GPIO_MODE_UART1 24
  23. #define MT76X8_GPIO_MODE_I2C 20
  24. #define MT76X8_GPIO_MODE_REFCLK 18
  25. #define MT76X8_GPIO_MODE_PERST 16
  26. #define MT76X8_GPIO_MODE_WDT 14
  27. #define MT76X8_GPIO_MODE_SPI 12
  28. #define MT76X8_GPIO_MODE_SDMODE 10
  29. #define MT76X8_GPIO_MODE_UART0 8
  30. #define MT76X8_GPIO_MODE_I2S 6
  31. #define MT76X8_GPIO_MODE_CS1 4
  32. #define MT76X8_GPIO_MODE_SPIS 2
  33. #define MT76X8_GPIO_MODE_GPIO 0
  34. static struct mtmips_pmx_func pwm1_grp[] = {
  35. FUNC("sdxc d6", 3, 19, 1),
  36. FUNC("pwm1 utif", 2, 19, 1),
  37. FUNC("pwm1", 0, 19, 1),
  38. };
  39. static struct mtmips_pmx_func pwm0_grp[] = {
  40. FUNC("sdxc d7", 3, 18, 1),
  41. FUNC("pwm0 utif", 2, 18, 1),
  42. FUNC("pwm0", 0, 18, 1),
  43. };
  44. static struct mtmips_pmx_func uart2_grp[] = {
  45. FUNC("sdxc d5 d4", 3, 20, 2),
  46. FUNC("uart2 pwm", 2, 20, 2),
  47. FUNC("uart2", 0, 20, 2),
  48. };
  49. static struct mtmips_pmx_func uart1_grp[] = {
  50. FUNC("sw_r", 3, 45, 2),
  51. FUNC("uart1 pwm", 2, 45, 2),
  52. FUNC("uart1", 0, 45, 2),
  53. };
  54. static struct mtmips_pmx_func i2c_grp[] = {
  55. FUNC("debug", 2, 4, 2),
  56. FUNC("i2c", 0, 4, 2),
  57. };
  58. static struct mtmips_pmx_func refclk_grp[] = { FUNC("refclk", 0, 37, 1) };
  59. static struct mtmips_pmx_func perst_grp[] = { FUNC("perst", 0, 36, 1) };
  60. static struct mtmips_pmx_func wdt_grp[] = { FUNC("wdt", 0, 38, 1) };
  61. static struct mtmips_pmx_func spi_grp[] = { FUNC("spi", 0, 7, 4) };
  62. static struct mtmips_pmx_func sd_mode_grp[] = {
  63. FUNC("sdxc jtag", 3, 22, 8),
  64. FUNC("sdxc utif", 2, 22, 8),
  65. FUNC("sdxc", 0, 22, 8),
  66. };
  67. static struct mtmips_pmx_func uart0_grp[] = {
  68. FUNC("uart0", 0, 12, 2),
  69. };
  70. static struct mtmips_pmx_func i2s_grp[] = {
  71. FUNC("antenna", 3, 0, 4),
  72. FUNC("pcm", 2, 0, 4),
  73. FUNC("i2s", 0, 0, 4),
  74. };
  75. static struct mtmips_pmx_func spi_cs1_grp[] = {
  76. FUNC("spi refclk", 2, 6, 1),
  77. FUNC("spi cs1", 0, 6, 1),
  78. };
  79. static struct mtmips_pmx_func spis_grp[] = {
  80. FUNC("pwm_uart2", 3, 14, 4),
  81. FUNC("spis utif", 2, 14, 4),
  82. FUNC("spis", 0, 14, 4),
  83. };
  84. static struct mtmips_pmx_func gpio_grp[] = {
  85. FUNC("pcie", 3, 11, 1),
  86. FUNC("gpio refclk", 2, 11, 1),
  87. };
  88. static struct mtmips_pmx_func p4led_kn_grp[] = {
  89. FUNC("p4led_kn jtag", 3, 30, 1),
  90. FUNC("p4led_kn utif", 2, 30, 1),
  91. FUNC("p4led_kn", 0, 30, 1),
  92. };
  93. static struct mtmips_pmx_func p3led_kn_grp[] = {
  94. FUNC("p3led_kn jtag", 3, 31, 1),
  95. FUNC("p3led_kn utif", 2, 31, 1),
  96. FUNC("p3led_kn", 0, 31, 1),
  97. };
  98. static struct mtmips_pmx_func p2led_kn_grp[] = {
  99. FUNC("p2led_kn jtag", 3, 32, 1),
  100. FUNC("p2led_kn utif", 2, 32, 1),
  101. FUNC("p2led_kn", 0, 32, 1),
  102. };
  103. static struct mtmips_pmx_func p1led_kn_grp[] = {
  104. FUNC("p1led_kn jtag", 3, 33, 1),
  105. FUNC("p1led_kn utif", 2, 33, 1),
  106. FUNC("p1led_kn", 0, 33, 1),
  107. };
  108. static struct mtmips_pmx_func p0led_kn_grp[] = {
  109. FUNC("p0led_kn jtag", 3, 34, 1),
  110. FUNC("p0led_kn", 0, 34, 1),
  111. };
  112. static struct mtmips_pmx_func wled_kn_grp[] = {
  113. FUNC("wled_kn", 0, 35, 1),
  114. };
  115. static struct mtmips_pmx_func p4led_an_grp[] = {
  116. FUNC("p4led_an jtag", 3, 39, 1),
  117. FUNC("p4led_an utif", 2, 39, 1),
  118. FUNC("p4led_an", 0, 39, 1),
  119. };
  120. static struct mtmips_pmx_func p3led_an_grp[] = {
  121. FUNC("p3led_an jtag", 3, 40, 1),
  122. FUNC("p3led_an utif", 2, 40, 1),
  123. FUNC("p3led_an", 0, 40, 1),
  124. };
  125. static struct mtmips_pmx_func p2led_an_grp[] = {
  126. FUNC("p2led_an jtag", 3, 41, 1),
  127. FUNC("p2led_an utif", 2, 41, 1),
  128. FUNC("p2led_an", 0, 41, 1),
  129. };
  130. static struct mtmips_pmx_func p1led_an_grp[] = {
  131. FUNC("p1led_an jtag", 3, 42, 1),
  132. FUNC("p1led_an utif", 2, 42, 1),
  133. FUNC("p1led_an", 0, 42, 1),
  134. };
  135. static struct mtmips_pmx_func p0led_an_grp[] = {
  136. FUNC("p0led_an jtag", 3, 43, 1),
  137. FUNC("p0led_an", 0, 43, 1),
  138. };
  139. static struct mtmips_pmx_func wled_an_grp[] = {
  140. FUNC("wled_an", 0, 44, 1),
  141. };
  142. static struct mtmips_pmx_group mt76x8_pinmux_data[] = {
  143. GRP_G("pwm1", pwm1_grp, MT76X8_GPIO_MODE_MASK,
  144. 1, MT76X8_GPIO_MODE_PWM1),
  145. GRP_G("pwm0", pwm0_grp, MT76X8_GPIO_MODE_MASK,
  146. 1, MT76X8_GPIO_MODE_PWM0),
  147. GRP_G("uart2", uart2_grp, MT76X8_GPIO_MODE_MASK,
  148. 1, MT76X8_GPIO_MODE_UART2),
  149. GRP_G("uart1", uart1_grp, MT76X8_GPIO_MODE_MASK,
  150. 1, MT76X8_GPIO_MODE_UART1),
  151. GRP_G("i2c", i2c_grp, MT76X8_GPIO_MODE_MASK,
  152. 1, MT76X8_GPIO_MODE_I2C),
  153. GRP("refclk", refclk_grp, 1, MT76X8_GPIO_MODE_REFCLK),
  154. GRP("perst", perst_grp, 1, MT76X8_GPIO_MODE_PERST),
  155. GRP("wdt", wdt_grp, 1, MT76X8_GPIO_MODE_WDT),
  156. GRP("spi", spi_grp, 1, MT76X8_GPIO_MODE_SPI),
  157. GRP_G("sdmode", sd_mode_grp, MT76X8_GPIO_MODE_MASK,
  158. 1, MT76X8_GPIO_MODE_SDMODE),
  159. GRP_G("uart0", uart0_grp, MT76X8_GPIO_MODE_MASK,
  160. 1, MT76X8_GPIO_MODE_UART0),
  161. GRP_G("i2s", i2s_grp, MT76X8_GPIO_MODE_MASK,
  162. 1, MT76X8_GPIO_MODE_I2S),
  163. GRP_G("spi cs1", spi_cs1_grp, MT76X8_GPIO_MODE_MASK,
  164. 1, MT76X8_GPIO_MODE_CS1),
  165. GRP_G("spis", spis_grp, MT76X8_GPIO_MODE_MASK,
  166. 1, MT76X8_GPIO_MODE_SPIS),
  167. GRP_G("gpio", gpio_grp, MT76X8_GPIO_MODE_MASK,
  168. 1, MT76X8_GPIO_MODE_GPIO),
  169. GRP_G("wled_an", wled_an_grp, MT76X8_GPIO_MODE_MASK,
  170. 1, MT76X8_GPIO_MODE_WLED_AN),
  171. GRP_G("p0led_an", p0led_an_grp, MT76X8_GPIO_MODE_MASK,
  172. 1, MT76X8_GPIO_MODE_P0LED_AN),
  173. GRP_G("p1led_an", p1led_an_grp, MT76X8_GPIO_MODE_MASK,
  174. 1, MT76X8_GPIO_MODE_P1LED_AN),
  175. GRP_G("p2led_an", p2led_an_grp, MT76X8_GPIO_MODE_MASK,
  176. 1, MT76X8_GPIO_MODE_P2LED_AN),
  177. GRP_G("p3led_an", p3led_an_grp, MT76X8_GPIO_MODE_MASK,
  178. 1, MT76X8_GPIO_MODE_P3LED_AN),
  179. GRP_G("p4led_an", p4led_an_grp, MT76X8_GPIO_MODE_MASK,
  180. 1, MT76X8_GPIO_MODE_P4LED_AN),
  181. GRP_G("wled_kn", wled_kn_grp, MT76X8_GPIO_MODE_MASK,
  182. 1, MT76X8_GPIO_MODE_WLED_KN),
  183. GRP_G("p0led_kn", p0led_kn_grp, MT76X8_GPIO_MODE_MASK,
  184. 1, MT76X8_GPIO_MODE_P0LED_KN),
  185. GRP_G("p1led_kn", p1led_kn_grp, MT76X8_GPIO_MODE_MASK,
  186. 1, MT76X8_GPIO_MODE_P1LED_KN),
  187. GRP_G("p2led_kn", p2led_kn_grp, MT76X8_GPIO_MODE_MASK,
  188. 1, MT76X8_GPIO_MODE_P2LED_KN),
  189. GRP_G("p3led_kn", p3led_kn_grp, MT76X8_GPIO_MODE_MASK,
  190. 1, MT76X8_GPIO_MODE_P3LED_KN),
  191. GRP_G("p4led_kn", p4led_kn_grp, MT76X8_GPIO_MODE_MASK,
  192. 1, MT76X8_GPIO_MODE_P4LED_KN),
  193. { 0 }
  194. };
  195. static int mt76x8_pinctrl_probe(struct platform_device *pdev)
  196. {
  197. return mtmips_pinctrl_init(pdev, mt76x8_pinmux_data);
  198. }
  199. static const struct of_device_id mt76x8_pinctrl_match[] = {
  200. { .compatible = "ralink,mt76x8-pinctrl" },
  201. { .compatible = "ralink,mt7620-pinctrl" },
  202. { .compatible = "ralink,rt2880-pinmux" },
  203. {}
  204. };
  205. MODULE_DEVICE_TABLE(of, mt76x8_pinctrl_match);
  206. static struct platform_driver mt76x8_pinctrl_driver = {
  207. .probe = mt76x8_pinctrl_probe,
  208. .driver = {
  209. .name = "mt76x8-pinctrl",
  210. .of_match_table = mt76x8_pinctrl_match,
  211. },
  212. };
  213. static int __init mt76x8_pinctrl_init(void)
  214. {
  215. return platform_driver_register(&mt76x8_pinctrl_driver);
  216. }
  217. core_initcall_sync(mt76x8_pinctrl_init);