1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | |
3 | #include <linux/module.h> |
4 | #include <linux/platform_device.h> |
5 | #include <linux/of.h> |
6 | #include "pinctrl-mtmips.h" |
7 | |
8 | #define MT7620_GPIO_MODE_UART0_SHIFT 2 |
9 | #define MT7620_GPIO_MODE_UART0_MASK 0x7 |
10 | #define MT7620_GPIO_MODE_UART0(x) ((x) << MT7620_GPIO_MODE_UART0_SHIFT) |
11 | #define MT7620_GPIO_MODE_UARTF 0x0 |
12 | #define MT7620_GPIO_MODE_PCM_UARTF 0x1 |
13 | #define MT7620_GPIO_MODE_PCM_I2S 0x2 |
14 | #define MT7620_GPIO_MODE_I2S_UARTF 0x3 |
15 | #define MT7620_GPIO_MODE_PCM_GPIO 0x4 |
16 | #define MT7620_GPIO_MODE_GPIO_UARTF 0x5 |
17 | #define MT7620_GPIO_MODE_GPIO_I2S 0x6 |
18 | #define MT7620_GPIO_MODE_GPIO 0x7 |
19 | |
20 | #define MT7620_GPIO_MODE_NAND 0 |
21 | #define MT7620_GPIO_MODE_SD 1 |
22 | #define MT7620_GPIO_MODE_ND_SD_GPIO 2 |
23 | #define MT7620_GPIO_MODE_ND_SD_MASK 0x3 |
24 | #define MT7620_GPIO_MODE_ND_SD_SHIFT 18 |
25 | |
26 | #define MT7620_GPIO_MODE_PCIE_RST 0 |
27 | #define MT7620_GPIO_MODE_PCIE_REF 1 |
28 | #define MT7620_GPIO_MODE_PCIE_GPIO 2 |
29 | #define MT7620_GPIO_MODE_PCIE_MASK 0x3 |
30 | #define MT7620_GPIO_MODE_PCIE_SHIFT 16 |
31 | |
32 | #define MT7620_GPIO_MODE_WDT_RST 0 |
33 | #define MT7620_GPIO_MODE_WDT_REF 1 |
34 | #define MT7620_GPIO_MODE_WDT_GPIO 2 |
35 | #define MT7620_GPIO_MODE_WDT_MASK 0x3 |
36 | #define MT7620_GPIO_MODE_WDT_SHIFT 21 |
37 | |
38 | #define MT7620_GPIO_MODE_MDIO 0 |
39 | #define MT7620_GPIO_MODE_MDIO_REFCLK 1 |
40 | #define MT7620_GPIO_MODE_MDIO_GPIO 2 |
41 | #define MT7620_GPIO_MODE_MDIO_MASK 0x3 |
42 | #define MT7620_GPIO_MODE_MDIO_SHIFT 7 |
43 | |
44 | #define MT7620_GPIO_MODE_I2C 0 |
45 | #define MT7620_GPIO_MODE_UART1 5 |
46 | #define MT7620_GPIO_MODE_RGMII1 9 |
47 | #define MT7620_GPIO_MODE_RGMII2 10 |
48 | #define MT7620_GPIO_MODE_SPI 11 |
49 | #define MT7620_GPIO_MODE_SPI_REF_CLK 12 |
50 | #define MT7620_GPIO_MODE_WLED 13 |
51 | #define MT7620_GPIO_MODE_JTAG 15 |
52 | #define MT7620_GPIO_MODE_EPHY 15 |
53 | #define MT7620_GPIO_MODE_PA 20 |
54 | |
55 | static struct mtmips_pmx_func i2c_grp[] = { FUNC("i2c" , 0, 1, 2) }; |
56 | static struct mtmips_pmx_func spi_grp[] = { FUNC("spi" , 0, 3, 4) }; |
57 | static struct mtmips_pmx_func uartlite_grp[] = { FUNC("uartlite" , 0, 15, 2) }; |
58 | static struct mtmips_pmx_func mdio_grp[] = { |
59 | FUNC("mdio" , MT7620_GPIO_MODE_MDIO, 22, 2), |
60 | FUNC("refclk" , MT7620_GPIO_MODE_MDIO_REFCLK, 22, 2), |
61 | }; |
62 | static struct mtmips_pmx_func rgmii1_grp[] = { FUNC("rgmii1" , 0, 24, 12) }; |
63 | static struct mtmips_pmx_func refclk_grp[] = { FUNC("spi refclk" , 0, 37, 3) }; |
64 | static struct mtmips_pmx_func ephy_grp[] = { FUNC("ephy" , 0, 40, 5) }; |
65 | static struct mtmips_pmx_func rgmii2_grp[] = { FUNC("rgmii2" , 0, 60, 12) }; |
66 | static struct mtmips_pmx_func wled_grp[] = { FUNC("wled" , 0, 72, 1) }; |
67 | static struct mtmips_pmx_func pa_grp[] = { FUNC("pa" , 0, 18, 4) }; |
68 | static struct mtmips_pmx_func uartf_grp[] = { |
69 | FUNC("uartf" , MT7620_GPIO_MODE_UARTF, 7, 8), |
70 | FUNC("pcm uartf" , MT7620_GPIO_MODE_PCM_UARTF, 7, 8), |
71 | FUNC("pcm i2s" , MT7620_GPIO_MODE_PCM_I2S, 7, 8), |
72 | FUNC("i2s uartf" , MT7620_GPIO_MODE_I2S_UARTF, 7, 8), |
73 | FUNC("pcm gpio" , MT7620_GPIO_MODE_PCM_GPIO, 11, 4), |
74 | FUNC("gpio uartf" , MT7620_GPIO_MODE_GPIO_UARTF, 7, 4), |
75 | FUNC("gpio i2s" , MT7620_GPIO_MODE_GPIO_I2S, 7, 4), |
76 | }; |
77 | static struct mtmips_pmx_func wdt_grp[] = { |
78 | FUNC("wdt rst" , 0, 17, 1), |
79 | FUNC("wdt refclk" , 0, 17, 1), |
80 | }; |
81 | static struct mtmips_pmx_func pcie_rst_grp[] = { |
82 | FUNC("pcie rst" , MT7620_GPIO_MODE_PCIE_RST, 36, 1), |
83 | FUNC("pcie refclk" , MT7620_GPIO_MODE_PCIE_REF, 36, 1) |
84 | }; |
85 | static struct mtmips_pmx_func nd_sd_grp[] = { |
86 | FUNC("nand" , MT7620_GPIO_MODE_NAND, 45, 15), |
87 | FUNC("sd" , MT7620_GPIO_MODE_SD, 47, 13) |
88 | }; |
89 | |
90 | static struct mtmips_pmx_group mt7620a_pinmux_data[] = { |
91 | GRP("i2c" , i2c_grp, 1, MT7620_GPIO_MODE_I2C), |
92 | GRP("uartf" , uartf_grp, MT7620_GPIO_MODE_UART0_MASK, |
93 | MT7620_GPIO_MODE_UART0_SHIFT), |
94 | GRP("spi" , spi_grp, 1, MT7620_GPIO_MODE_SPI), |
95 | GRP("uartlite" , uartlite_grp, 1, MT7620_GPIO_MODE_UART1), |
96 | GRP_G("wdt" , wdt_grp, MT7620_GPIO_MODE_WDT_MASK, |
97 | MT7620_GPIO_MODE_WDT_GPIO, MT7620_GPIO_MODE_WDT_SHIFT), |
98 | GRP_G("mdio" , mdio_grp, MT7620_GPIO_MODE_MDIO_MASK, |
99 | MT7620_GPIO_MODE_MDIO_GPIO, MT7620_GPIO_MODE_MDIO_SHIFT), |
100 | GRP("rgmii1" , rgmii1_grp, 1, MT7620_GPIO_MODE_RGMII1), |
101 | GRP("spi refclk" , refclk_grp, 1, MT7620_GPIO_MODE_SPI_REF_CLK), |
102 | GRP_G("pcie" , pcie_rst_grp, MT7620_GPIO_MODE_PCIE_MASK, |
103 | MT7620_GPIO_MODE_PCIE_GPIO, MT7620_GPIO_MODE_PCIE_SHIFT), |
104 | GRP_G("nd_sd" , nd_sd_grp, MT7620_GPIO_MODE_ND_SD_MASK, |
105 | MT7620_GPIO_MODE_ND_SD_GPIO, MT7620_GPIO_MODE_ND_SD_SHIFT), |
106 | GRP("rgmii2" , rgmii2_grp, 1, MT7620_GPIO_MODE_RGMII2), |
107 | GRP("wled" , wled_grp, 1, MT7620_GPIO_MODE_WLED), |
108 | GRP("ephy" , ephy_grp, 1, MT7620_GPIO_MODE_EPHY), |
109 | GRP("pa" , pa_grp, 1, MT7620_GPIO_MODE_PA), |
110 | { 0 } |
111 | }; |
112 | |
113 | static int mt7620_pinctrl_probe(struct platform_device *pdev) |
114 | { |
115 | return mtmips_pinctrl_init(pdev, data: mt7620a_pinmux_data); |
116 | } |
117 | |
118 | static const struct of_device_id mt7620_pinctrl_match[] = { |
119 | { .compatible = "ralink,mt7620-pinctrl" }, |
120 | { .compatible = "ralink,rt2880-pinmux" }, |
121 | {} |
122 | }; |
123 | MODULE_DEVICE_TABLE(of, mt7620_pinctrl_match); |
124 | |
125 | static struct platform_driver mt7620_pinctrl_driver = { |
126 | .probe = mt7620_pinctrl_probe, |
127 | .driver = { |
128 | .name = "mt7620-pinctrl" , |
129 | .of_match_table = mt7620_pinctrl_match, |
130 | }, |
131 | }; |
132 | |
133 | static int __init mt7620_pinctrl_init(void) |
134 | { |
135 | return platform_driver_register(&mt7620_pinctrl_driver); |
136 | } |
137 | core_initcall_sync(mt7620_pinctrl_init); |
138 | |