pinctrl-rt305x.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <asm/mach-ralink/ralink_regs.h>
  3. #include <asm/mach-ralink/rt305x.h>
  4. #include <linux/module.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/of.h>
  7. #include "pinctrl-ralink.h"
  8. #define RT305X_GPIO_MODE_UART0_SHIFT 2
  9. #define RT305X_GPIO_MODE_UART0_MASK 0x7
  10. #define RT305X_GPIO_MODE_UART0(x) ((x) << RT305X_GPIO_MODE_UART0_SHIFT)
  11. #define RT305X_GPIO_MODE_UARTF 0
  12. #define RT305X_GPIO_MODE_PCM_UARTF 1
  13. #define RT305X_GPIO_MODE_PCM_I2S 2
  14. #define RT305X_GPIO_MODE_I2S_UARTF 3
  15. #define RT305X_GPIO_MODE_PCM_GPIO 4
  16. #define RT305X_GPIO_MODE_GPIO_UARTF 5
  17. #define RT305X_GPIO_MODE_GPIO_I2S 6
  18. #define RT305X_GPIO_MODE_GPIO 7
  19. #define RT305X_GPIO_MODE_I2C 0
  20. #define RT305X_GPIO_MODE_SPI 1
  21. #define RT305X_GPIO_MODE_UART1 5
  22. #define RT305X_GPIO_MODE_JTAG 6
  23. #define RT305X_GPIO_MODE_MDIO 7
  24. #define RT305X_GPIO_MODE_SDRAM 8
  25. #define RT305X_GPIO_MODE_RGMII 9
  26. #define RT5350_GPIO_MODE_PHY_LED 14
  27. #define RT5350_GPIO_MODE_SPI_CS1 21
  28. #define RT3352_GPIO_MODE_LNA 18
  29. #define RT3352_GPIO_MODE_PA 20
  30. static struct ralink_pmx_func i2c_func[] = { FUNC("i2c", 0, 1, 2) };
  31. static struct ralink_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
  32. static struct ralink_pmx_func uartf_func[] = {
  33. FUNC("uartf", RT305X_GPIO_MODE_UARTF, 7, 8),
  34. FUNC("pcm uartf", RT305X_GPIO_MODE_PCM_UARTF, 7, 8),
  35. FUNC("pcm i2s", RT305X_GPIO_MODE_PCM_I2S, 7, 8),
  36. FUNC("i2s uartf", RT305X_GPIO_MODE_I2S_UARTF, 7, 8),
  37. FUNC("pcm gpio", RT305X_GPIO_MODE_PCM_GPIO, 11, 4),
  38. FUNC("gpio uartf", RT305X_GPIO_MODE_GPIO_UARTF, 7, 4),
  39. FUNC("gpio i2s", RT305X_GPIO_MODE_GPIO_I2S, 7, 4),
  40. };
  41. static struct ralink_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 15, 2) };
  42. static struct ralink_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) };
  43. static struct ralink_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) };
  44. static struct ralink_pmx_func rt5350_led_func[] = { FUNC("led", 0, 22, 5) };
  45. static struct ralink_pmx_func rt5350_cs1_func[] = {
  46. FUNC("spi_cs1", 0, 27, 1),
  47. FUNC("wdg_cs1", 1, 27, 1),
  48. };
  49. static struct ralink_pmx_func sdram_func[] = { FUNC("sdram", 0, 24, 16) };
  50. static struct ralink_pmx_func rt3352_rgmii_func[] = {
  51. FUNC("rgmii", 0, 24, 12)
  52. };
  53. static struct ralink_pmx_func rgmii_func[] = { FUNC("rgmii", 0, 40, 12) };
  54. static struct ralink_pmx_func rt3352_lna_func[] = { FUNC("lna", 0, 36, 2) };
  55. static struct ralink_pmx_func rt3352_pa_func[] = { FUNC("pa", 0, 38, 2) };
  56. static struct ralink_pmx_func rt3352_led_func[] = { FUNC("led", 0, 40, 5) };
  57. static struct ralink_pmx_func rt3352_cs1_func[] = {
  58. FUNC("spi_cs1", 0, 45, 1),
  59. FUNC("wdg_cs1", 1, 45, 1),
  60. };
  61. static struct ralink_pmx_group rt3050_pinmux_data[] = {
  62. GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
  63. GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
  64. GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
  65. RT305X_GPIO_MODE_UART0_SHIFT),
  66. GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
  67. GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
  68. GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO),
  69. GRP("rgmii", rgmii_func, 1, RT305X_GPIO_MODE_RGMII),
  70. GRP("sdram", sdram_func, 1, RT305X_GPIO_MODE_SDRAM),
  71. { 0 }
  72. };
  73. static struct ralink_pmx_group rt3352_pinmux_data[] = {
  74. GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
  75. GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
  76. GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
  77. RT305X_GPIO_MODE_UART0_SHIFT),
  78. GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
  79. GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
  80. GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO),
  81. GRP("rgmii", rt3352_rgmii_func, 1, RT305X_GPIO_MODE_RGMII),
  82. GRP("lna", rt3352_lna_func, 1, RT3352_GPIO_MODE_LNA),
  83. GRP("pa", rt3352_pa_func, 1, RT3352_GPIO_MODE_PA),
  84. GRP("led", rt3352_led_func, 1, RT5350_GPIO_MODE_PHY_LED),
  85. GRP("spi_cs1", rt3352_cs1_func, 2, RT5350_GPIO_MODE_SPI_CS1),
  86. { 0 }
  87. };
  88. static struct ralink_pmx_group rt5350_pinmux_data[] = {
  89. GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C),
  90. GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI),
  91. GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK,
  92. RT305X_GPIO_MODE_UART0_SHIFT),
  93. GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1),
  94. GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG),
  95. GRP("led", rt5350_led_func, 1, RT5350_GPIO_MODE_PHY_LED),
  96. GRP("spi_cs1", rt5350_cs1_func, 2, RT5350_GPIO_MODE_SPI_CS1),
  97. { 0 }
  98. };
  99. static int rt305x_pinctrl_probe(struct platform_device *pdev)
  100. {
  101. if (soc_is_rt5350())
  102. return ralink_pinctrl_init(pdev, rt5350_pinmux_data);
  103. else if (soc_is_rt305x() || soc_is_rt3350())
  104. return ralink_pinctrl_init(pdev, rt3050_pinmux_data);
  105. else if (soc_is_rt3352())
  106. return ralink_pinctrl_init(pdev, rt3352_pinmux_data);
  107. else
  108. return -EINVAL;
  109. }
  110. static const struct of_device_id rt305x_pinctrl_match[] = {
  111. { .compatible = "ralink,rt305x-pinctrl" },
  112. { .compatible = "ralink,rt2880-pinmux" },
  113. {}
  114. };
  115. MODULE_DEVICE_TABLE(of, rt305x_pinctrl_match);
  116. static struct platform_driver rt305x_pinctrl_driver = {
  117. .probe = rt305x_pinctrl_probe,
  118. .driver = {
  119. .name = "rt305x-pinctrl",
  120. .of_match_table = rt305x_pinctrl_match,
  121. },
  122. };
  123. static int __init rt305x_pinctrl_init(void)
  124. {
  125. return platform_driver_register(&rt305x_pinctrl_driver);
  126. }
  127. core_initcall_sync(rt305x_pinctrl_init);