pinctrl-mt7621.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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-ralink.h"
  6. #define MT7621_GPIO_MODE_UART1 1
  7. #define MT7621_GPIO_MODE_I2C 2
  8. #define MT7621_GPIO_MODE_UART3_MASK 0x3
  9. #define MT7621_GPIO_MODE_UART3_SHIFT 3
  10. #define MT7621_GPIO_MODE_UART3_GPIO 1
  11. #define MT7621_GPIO_MODE_UART2_MASK 0x3
  12. #define MT7621_GPIO_MODE_UART2_SHIFT 5
  13. #define MT7621_GPIO_MODE_UART2_GPIO 1
  14. #define MT7621_GPIO_MODE_JTAG 7
  15. #define MT7621_GPIO_MODE_WDT_MASK 0x3
  16. #define MT7621_GPIO_MODE_WDT_SHIFT 8
  17. #define MT7621_GPIO_MODE_WDT_GPIO 1
  18. #define MT7621_GPIO_MODE_PCIE_RST 0
  19. #define MT7621_GPIO_MODE_PCIE_REF 2
  20. #define MT7621_GPIO_MODE_PCIE_MASK 0x3
  21. #define MT7621_GPIO_MODE_PCIE_SHIFT 10
  22. #define MT7621_GPIO_MODE_PCIE_GPIO 1
  23. #define MT7621_GPIO_MODE_MDIO_MASK 0x3
  24. #define MT7621_GPIO_MODE_MDIO_SHIFT 12
  25. #define MT7621_GPIO_MODE_MDIO_GPIO 1
  26. #define MT7621_GPIO_MODE_RGMII1 14
  27. #define MT7621_GPIO_MODE_RGMII2 15
  28. #define MT7621_GPIO_MODE_SPI_MASK 0x3
  29. #define MT7621_GPIO_MODE_SPI_SHIFT 16
  30. #define MT7621_GPIO_MODE_SPI_GPIO 1
  31. #define MT7621_GPIO_MODE_SDHCI_MASK 0x3
  32. #define MT7621_GPIO_MODE_SDHCI_SHIFT 18
  33. #define MT7621_GPIO_MODE_SDHCI_GPIO 1
  34. static struct ralink_pmx_func uart1_func[] = { FUNC("uart1", 0, 1, 2) };
  35. static struct ralink_pmx_func i2c_func[] = { FUNC("i2c", 0, 3, 2) };
  36. static struct ralink_pmx_func uart3_func[] = {
  37. FUNC("uart3", 0, 5, 4),
  38. FUNC("i2s", 2, 5, 4),
  39. FUNC("spdif3", 3, 5, 4),
  40. };
  41. static struct ralink_pmx_func uart2_func[] = {
  42. FUNC("uart2", 0, 9, 4),
  43. FUNC("pcm", 2, 9, 4),
  44. FUNC("spdif2", 3, 9, 4),
  45. };
  46. static struct ralink_pmx_func jtag_func[] = { FUNC("jtag", 0, 13, 5) };
  47. static struct ralink_pmx_func wdt_func[] = {
  48. FUNC("wdt rst", 0, 18, 1),
  49. FUNC("wdt refclk", 2, 18, 1),
  50. };
  51. static struct ralink_pmx_func pcie_rst_func[] = {
  52. FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
  53. FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
  54. };
  55. static struct ralink_pmx_func mdio_func[] = { FUNC("mdio", 0, 20, 2) };
  56. static struct ralink_pmx_func rgmii2_func[] = { FUNC("rgmii2", 0, 22, 12) };
  57. static struct ralink_pmx_func spi_func[] = {
  58. FUNC("spi", 0, 34, 7),
  59. FUNC("nand1", 2, 34, 7),
  60. };
  61. static struct ralink_pmx_func sdhci_func[] = {
  62. FUNC("sdhci", 0, 41, 8),
  63. FUNC("nand2", 2, 41, 8),
  64. };
  65. static struct ralink_pmx_func rgmii1_func[] = { FUNC("rgmii1", 0, 49, 12) };
  66. static struct ralink_pmx_group mt7621_pinmux_data[] = {
  67. GRP("uart1", uart1_func, 1, MT7621_GPIO_MODE_UART1),
  68. GRP("i2c", i2c_func, 1, MT7621_GPIO_MODE_I2C),
  69. GRP_G("uart3", uart3_func, MT7621_GPIO_MODE_UART3_MASK,
  70. MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT),
  71. GRP_G("uart2", uart2_func, MT7621_GPIO_MODE_UART2_MASK,
  72. MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT),
  73. GRP("jtag", jtag_func, 1, MT7621_GPIO_MODE_JTAG),
  74. GRP_G("wdt", wdt_func, MT7621_GPIO_MODE_WDT_MASK,
  75. MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
  76. GRP_G("pcie", pcie_rst_func, MT7621_GPIO_MODE_PCIE_MASK,
  77. MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
  78. GRP_G("mdio", mdio_func, MT7621_GPIO_MODE_MDIO_MASK,
  79. MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT),
  80. GRP("rgmii2", rgmii2_func, 1, MT7621_GPIO_MODE_RGMII2),
  81. GRP_G("spi", spi_func, MT7621_GPIO_MODE_SPI_MASK,
  82. MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
  83. GRP_G("sdhci", sdhci_func, MT7621_GPIO_MODE_SDHCI_MASK,
  84. MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
  85. GRP("rgmii1", rgmii1_func, 1, MT7621_GPIO_MODE_RGMII1),
  86. { 0 }
  87. };
  88. static int mt7621_pinctrl_probe(struct platform_device *pdev)
  89. {
  90. return ralink_pinctrl_init(pdev, mt7621_pinmux_data);
  91. }
  92. static const struct of_device_id mt7621_pinctrl_match[] = {
  93. { .compatible = "ralink,mt7621-pinctrl" },
  94. { .compatible = "ralink,rt2880-pinmux" },
  95. {}
  96. };
  97. MODULE_DEVICE_TABLE(of, mt7621_pinctrl_match);
  98. static struct platform_driver mt7621_pinctrl_driver = {
  99. .probe = mt7621_pinctrl_probe,
  100. .driver = {
  101. .name = "mt7621-pinctrl",
  102. .of_match_table = mt7621_pinctrl_match,
  103. },
  104. };
  105. static int __init mt7621_pinctrl_init(void)
  106. {
  107. return platform_driver_register(&mt7621_pinctrl_driver);
  108. }
  109. core_initcall_sync(mt7621_pinctrl_init);