Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 
0003 #include <asm/mach-ralink/ralink_regs.h>
0004 #include <asm/mach-ralink/mt7620.h>
0005 #include <linux/module.h>
0006 #include <linux/platform_device.h>
0007 #include <linux/of.h>
0008 #include "pinctrl-ralink.h"
0009 
0010 #define MT7620_GPIO_MODE_UART0_SHIFT    2
0011 #define MT7620_GPIO_MODE_UART0_MASK 0x7
0012 #define MT7620_GPIO_MODE_UART0(x)   ((x) << MT7620_GPIO_MODE_UART0_SHIFT)
0013 #define MT7620_GPIO_MODE_UARTF      0x0
0014 #define MT7620_GPIO_MODE_PCM_UARTF  0x1
0015 #define MT7620_GPIO_MODE_PCM_I2S    0x2
0016 #define MT7620_GPIO_MODE_I2S_UARTF  0x3
0017 #define MT7620_GPIO_MODE_PCM_GPIO   0x4
0018 #define MT7620_GPIO_MODE_GPIO_UARTF 0x5
0019 #define MT7620_GPIO_MODE_GPIO_I2S   0x6
0020 #define MT7620_GPIO_MODE_GPIO       0x7
0021 
0022 #define MT7620_GPIO_MODE_NAND       0
0023 #define MT7620_GPIO_MODE_SD     1
0024 #define MT7620_GPIO_MODE_ND_SD_GPIO 2
0025 #define MT7620_GPIO_MODE_ND_SD_MASK 0x3
0026 #define MT7620_GPIO_MODE_ND_SD_SHIFT    18
0027 
0028 #define MT7620_GPIO_MODE_PCIE_RST   0
0029 #define MT7620_GPIO_MODE_PCIE_REF   1
0030 #define MT7620_GPIO_MODE_PCIE_GPIO  2
0031 #define MT7620_GPIO_MODE_PCIE_MASK  0x3
0032 #define MT7620_GPIO_MODE_PCIE_SHIFT 16
0033 
0034 #define MT7620_GPIO_MODE_WDT_RST    0
0035 #define MT7620_GPIO_MODE_WDT_REF    1
0036 #define MT7620_GPIO_MODE_WDT_GPIO   2
0037 #define MT7620_GPIO_MODE_WDT_MASK   0x3
0038 #define MT7620_GPIO_MODE_WDT_SHIFT  21
0039 
0040 #define MT7620_GPIO_MODE_MDIO       0
0041 #define MT7620_GPIO_MODE_MDIO_REFCLK    1
0042 #define MT7620_GPIO_MODE_MDIO_GPIO  2
0043 #define MT7620_GPIO_MODE_MDIO_MASK  0x3
0044 #define MT7620_GPIO_MODE_MDIO_SHIFT 7
0045 
0046 #define MT7620_GPIO_MODE_I2C        0
0047 #define MT7620_GPIO_MODE_UART1      5
0048 #define MT7620_GPIO_MODE_RGMII1     9
0049 #define MT7620_GPIO_MODE_RGMII2     10
0050 #define MT7620_GPIO_MODE_SPI        11
0051 #define MT7620_GPIO_MODE_SPI_REF_CLK    12
0052 #define MT7620_GPIO_MODE_WLED       13
0053 #define MT7620_GPIO_MODE_JTAG       15
0054 #define MT7620_GPIO_MODE_EPHY       15
0055 #define MT7620_GPIO_MODE_PA     20
0056 
0057 static struct ralink_pmx_func i2c_func[] =  { FUNC("i2c", 0, 1, 2) };
0058 static struct ralink_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
0059 static struct ralink_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 15, 2) };
0060 static struct ralink_pmx_func mdio_func[] = {
0061     FUNC("mdio", MT7620_GPIO_MODE_MDIO, 22, 2),
0062     FUNC("refclk", MT7620_GPIO_MODE_MDIO_REFCLK, 22, 2),
0063 };
0064 static struct ralink_pmx_func rgmii1_func[] = { FUNC("rgmii1", 0, 24, 12) };
0065 static struct ralink_pmx_func refclk_func[] = { FUNC("spi refclk", 0, 37, 3) };
0066 static struct ralink_pmx_func ephy_func[] = { FUNC("ephy", 0, 40, 5) };
0067 static struct ralink_pmx_func rgmii2_func[] = { FUNC("rgmii2", 0, 60, 12) };
0068 static struct ralink_pmx_func wled_func[] = { FUNC("wled", 0, 72, 1) };
0069 static struct ralink_pmx_func pa_func[] = { FUNC("pa", 0, 18, 4) };
0070 static struct ralink_pmx_func uartf_func[] = {
0071     FUNC("uartf", MT7620_GPIO_MODE_UARTF, 7, 8),
0072     FUNC("pcm uartf", MT7620_GPIO_MODE_PCM_UARTF, 7, 8),
0073     FUNC("pcm i2s", MT7620_GPIO_MODE_PCM_I2S, 7, 8),
0074     FUNC("i2s uartf", MT7620_GPIO_MODE_I2S_UARTF, 7, 8),
0075     FUNC("pcm gpio", MT7620_GPIO_MODE_PCM_GPIO, 11, 4),
0076     FUNC("gpio uartf", MT7620_GPIO_MODE_GPIO_UARTF, 7, 4),
0077     FUNC("gpio i2s", MT7620_GPIO_MODE_GPIO_I2S, 7, 4),
0078 };
0079 static struct ralink_pmx_func wdt_func[] = {
0080     FUNC("wdt rst", 0, 17, 1),
0081     FUNC("wdt refclk", 0, 17, 1),
0082     };
0083 static struct ralink_pmx_func pcie_rst_func[] = {
0084     FUNC("pcie rst", MT7620_GPIO_MODE_PCIE_RST, 36, 1),
0085     FUNC("pcie refclk", MT7620_GPIO_MODE_PCIE_REF, 36, 1)
0086 };
0087 static struct ralink_pmx_func nd_sd_func[] = {
0088     FUNC("nand", MT7620_GPIO_MODE_NAND, 45, 15),
0089     FUNC("sd", MT7620_GPIO_MODE_SD, 47, 13)
0090 };
0091 
0092 static struct ralink_pmx_group mt7620a_pinmux_data[] = {
0093     GRP("i2c", i2c_func, 1, MT7620_GPIO_MODE_I2C),
0094     GRP("uartf", uartf_func, MT7620_GPIO_MODE_UART0_MASK,
0095         MT7620_GPIO_MODE_UART0_SHIFT),
0096     GRP("spi", spi_func, 1, MT7620_GPIO_MODE_SPI),
0097     GRP("uartlite", uartlite_func, 1, MT7620_GPIO_MODE_UART1),
0098     GRP_G("wdt", wdt_func, MT7620_GPIO_MODE_WDT_MASK,
0099         MT7620_GPIO_MODE_WDT_GPIO, MT7620_GPIO_MODE_WDT_SHIFT),
0100     GRP_G("mdio", mdio_func, MT7620_GPIO_MODE_MDIO_MASK,
0101         MT7620_GPIO_MODE_MDIO_GPIO, MT7620_GPIO_MODE_MDIO_SHIFT),
0102     GRP("rgmii1", rgmii1_func, 1, MT7620_GPIO_MODE_RGMII1),
0103     GRP("spi refclk", refclk_func, 1, MT7620_GPIO_MODE_SPI_REF_CLK),
0104     GRP_G("pcie", pcie_rst_func, MT7620_GPIO_MODE_PCIE_MASK,
0105         MT7620_GPIO_MODE_PCIE_GPIO, MT7620_GPIO_MODE_PCIE_SHIFT),
0106     GRP_G("nd_sd", nd_sd_func, MT7620_GPIO_MODE_ND_SD_MASK,
0107         MT7620_GPIO_MODE_ND_SD_GPIO, MT7620_GPIO_MODE_ND_SD_SHIFT),
0108     GRP("rgmii2", rgmii2_func, 1, MT7620_GPIO_MODE_RGMII2),
0109     GRP("wled", wled_func, 1, MT7620_GPIO_MODE_WLED),
0110     GRP("ephy", ephy_func, 1, MT7620_GPIO_MODE_EPHY),
0111     GRP("pa", pa_func, 1, MT7620_GPIO_MODE_PA),
0112     { 0 }
0113 };
0114 
0115 static struct ralink_pmx_func pwm1_func_mt76x8[] = {
0116     FUNC("sdxc d6", 3, 19, 1),
0117     FUNC("utif", 2, 19, 1),
0118     FUNC("gpio", 1, 19, 1),
0119     FUNC("pwm1", 0, 19, 1),
0120 };
0121 
0122 static struct ralink_pmx_func pwm0_func_mt76x8[] = {
0123     FUNC("sdxc d7", 3, 18, 1),
0124     FUNC("utif", 2, 18, 1),
0125     FUNC("gpio", 1, 18, 1),
0126     FUNC("pwm0", 0, 18, 1),
0127 };
0128 
0129 static struct ralink_pmx_func uart2_func_mt76x8[] = {
0130     FUNC("sdxc d5 d4", 3, 20, 2),
0131     FUNC("pwm", 2, 20, 2),
0132     FUNC("gpio", 1, 20, 2),
0133     FUNC("uart2", 0, 20, 2),
0134 };
0135 
0136 static struct ralink_pmx_func uart1_func_mt76x8[] = {
0137     FUNC("sw_r", 3, 45, 2),
0138     FUNC("pwm", 2, 45, 2),
0139     FUNC("gpio", 1, 45, 2),
0140     FUNC("uart1", 0, 45, 2),
0141 };
0142 
0143 static struct ralink_pmx_func i2c_func_mt76x8[] = {
0144     FUNC("-", 3, 4, 2),
0145     FUNC("debug", 2, 4, 2),
0146     FUNC("gpio", 1, 4, 2),
0147     FUNC("i2c", 0, 4, 2),
0148 };
0149 
0150 static struct ralink_pmx_func refclk_func_mt76x8[] = { FUNC("refclk", 0, 37, 1) };
0151 static struct ralink_pmx_func perst_func_mt76x8[] = { FUNC("perst", 0, 36, 1) };
0152 static struct ralink_pmx_func wdt_func_mt76x8[] = { FUNC("wdt", 0, 38, 1) };
0153 static struct ralink_pmx_func spi_func_mt76x8[] = { FUNC("spi", 0, 7, 4) };
0154 
0155 static struct ralink_pmx_func sd_mode_func_mt76x8[] = {
0156     FUNC("jtag", 3, 22, 8),
0157     FUNC("utif", 2, 22, 8),
0158     FUNC("gpio", 1, 22, 8),
0159     FUNC("sdxc", 0, 22, 8),
0160 };
0161 
0162 static struct ralink_pmx_func uart0_func_mt76x8[] = {
0163     FUNC("-", 3, 12, 2),
0164     FUNC("-", 2, 12, 2),
0165     FUNC("gpio", 1, 12, 2),
0166     FUNC("uart0", 0, 12, 2),
0167 };
0168 
0169 static struct ralink_pmx_func i2s_func_mt76x8[] = {
0170     FUNC("antenna", 3, 0, 4),
0171     FUNC("pcm", 2, 0, 4),
0172     FUNC("gpio", 1, 0, 4),
0173     FUNC("i2s", 0, 0, 4),
0174 };
0175 
0176 static struct ralink_pmx_func spi_cs1_func_mt76x8[] = {
0177     FUNC("-", 3, 6, 1),
0178     FUNC("refclk", 2, 6, 1),
0179     FUNC("gpio", 1, 6, 1),
0180     FUNC("spi cs1", 0, 6, 1),
0181 };
0182 
0183 static struct ralink_pmx_func spis_func_mt76x8[] = {
0184     FUNC("pwm_uart2", 3, 14, 4),
0185     FUNC("utif", 2, 14, 4),
0186     FUNC("gpio", 1, 14, 4),
0187     FUNC("spis", 0, 14, 4),
0188 };
0189 
0190 static struct ralink_pmx_func gpio_func_mt76x8[] = {
0191     FUNC("pcie", 3, 11, 1),
0192     FUNC("refclk", 2, 11, 1),
0193     FUNC("gpio", 1, 11, 1),
0194     FUNC("gpio", 0, 11, 1),
0195 };
0196 
0197 static struct ralink_pmx_func p4led_kn_func_mt76x8[] = {
0198     FUNC("jtag", 3, 30, 1),
0199     FUNC("utif", 2, 30, 1),
0200     FUNC("gpio", 1, 30, 1),
0201     FUNC("p4led_kn", 0, 30, 1),
0202 };
0203 
0204 static struct ralink_pmx_func p3led_kn_func_mt76x8[] = {
0205     FUNC("jtag", 3, 31, 1),
0206     FUNC("utif", 2, 31, 1),
0207     FUNC("gpio", 1, 31, 1),
0208     FUNC("p3led_kn", 0, 31, 1),
0209 };
0210 
0211 static struct ralink_pmx_func p2led_kn_func_mt76x8[] = {
0212     FUNC("jtag", 3, 32, 1),
0213     FUNC("utif", 2, 32, 1),
0214     FUNC("gpio", 1, 32, 1),
0215     FUNC("p2led_kn", 0, 32, 1),
0216 };
0217 
0218 static struct ralink_pmx_func p1led_kn_func_mt76x8[] = {
0219     FUNC("jtag", 3, 33, 1),
0220     FUNC("utif", 2, 33, 1),
0221     FUNC("gpio", 1, 33, 1),
0222     FUNC("p1led_kn", 0, 33, 1),
0223 };
0224 
0225 static struct ralink_pmx_func p0led_kn_func_mt76x8[] = {
0226     FUNC("jtag", 3, 34, 1),
0227     FUNC("rsvd", 2, 34, 1),
0228     FUNC("gpio", 1, 34, 1),
0229     FUNC("p0led_kn", 0, 34, 1),
0230 };
0231 
0232 static struct ralink_pmx_func wled_kn_func_mt76x8[] = {
0233     FUNC("rsvd", 3, 35, 1),
0234     FUNC("rsvd", 2, 35, 1),
0235     FUNC("gpio", 1, 35, 1),
0236     FUNC("wled_kn", 0, 35, 1),
0237 };
0238 
0239 static struct ralink_pmx_func p4led_an_func_mt76x8[] = {
0240     FUNC("jtag", 3, 39, 1),
0241     FUNC("utif", 2, 39, 1),
0242     FUNC("gpio", 1, 39, 1),
0243     FUNC("p4led_an", 0, 39, 1),
0244 };
0245 
0246 static struct ralink_pmx_func p3led_an_func_mt76x8[] = {
0247     FUNC("jtag", 3, 40, 1),
0248     FUNC("utif", 2, 40, 1),
0249     FUNC("gpio", 1, 40, 1),
0250     FUNC("p3led_an", 0, 40, 1),
0251 };
0252 
0253 static struct ralink_pmx_func p2led_an_func_mt76x8[] = {
0254     FUNC("jtag", 3, 41, 1),
0255     FUNC("utif", 2, 41, 1),
0256     FUNC("gpio", 1, 41, 1),
0257     FUNC("p2led_an", 0, 41, 1),
0258 };
0259 
0260 static struct ralink_pmx_func p1led_an_func_mt76x8[] = {
0261     FUNC("jtag", 3, 42, 1),
0262     FUNC("utif", 2, 42, 1),
0263     FUNC("gpio", 1, 42, 1),
0264     FUNC("p1led_an", 0, 42, 1),
0265 };
0266 
0267 static struct ralink_pmx_func p0led_an_func_mt76x8[] = {
0268     FUNC("jtag", 3, 43, 1),
0269     FUNC("rsvd", 2, 43, 1),
0270     FUNC("gpio", 1, 43, 1),
0271     FUNC("p0led_an", 0, 43, 1),
0272 };
0273 
0274 static struct ralink_pmx_func wled_an_func_mt76x8[] = {
0275     FUNC("rsvd", 3, 44, 1),
0276     FUNC("rsvd", 2, 44, 1),
0277     FUNC("gpio", 1, 44, 1),
0278     FUNC("wled_an", 0, 44, 1),
0279 };
0280 
0281 #define MT76X8_GPIO_MODE_MASK       0x3
0282 
0283 #define MT76X8_GPIO_MODE_P4LED_KN   58
0284 #define MT76X8_GPIO_MODE_P3LED_KN   56
0285 #define MT76X8_GPIO_MODE_P2LED_KN   54
0286 #define MT76X8_GPIO_MODE_P1LED_KN   52
0287 #define MT76X8_GPIO_MODE_P0LED_KN   50
0288 #define MT76X8_GPIO_MODE_WLED_KN    48
0289 #define MT76X8_GPIO_MODE_P4LED_AN   42
0290 #define MT76X8_GPIO_MODE_P3LED_AN   40
0291 #define MT76X8_GPIO_MODE_P2LED_AN   38
0292 #define MT76X8_GPIO_MODE_P1LED_AN   36
0293 #define MT76X8_GPIO_MODE_P0LED_AN   34
0294 #define MT76X8_GPIO_MODE_WLED_AN    32
0295 #define MT76X8_GPIO_MODE_PWM1       30
0296 #define MT76X8_GPIO_MODE_PWM0       28
0297 #define MT76X8_GPIO_MODE_UART2      26
0298 #define MT76X8_GPIO_MODE_UART1      24
0299 #define MT76X8_GPIO_MODE_I2C        20
0300 #define MT76X8_GPIO_MODE_REFCLK     18
0301 #define MT76X8_GPIO_MODE_PERST      16
0302 #define MT76X8_GPIO_MODE_WDT        14
0303 #define MT76X8_GPIO_MODE_SPI        12
0304 #define MT76X8_GPIO_MODE_SDMODE     10
0305 #define MT76X8_GPIO_MODE_UART0      8
0306 #define MT76X8_GPIO_MODE_I2S        6
0307 #define MT76X8_GPIO_MODE_CS1        4
0308 #define MT76X8_GPIO_MODE_SPIS       2
0309 #define MT76X8_GPIO_MODE_GPIO       0
0310 
0311 static struct ralink_pmx_group mt76x8_pinmux_data[] = {
0312     GRP_G("pwm1", pwm1_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0313                 1, MT76X8_GPIO_MODE_PWM1),
0314     GRP_G("pwm0", pwm0_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0315                 1, MT76X8_GPIO_MODE_PWM0),
0316     GRP_G("uart2", uart2_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0317                 1, MT76X8_GPIO_MODE_UART2),
0318     GRP_G("uart1", uart1_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0319                 1, MT76X8_GPIO_MODE_UART1),
0320     GRP_G("i2c", i2c_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0321                 1, MT76X8_GPIO_MODE_I2C),
0322     GRP("refclk", refclk_func_mt76x8, 1, MT76X8_GPIO_MODE_REFCLK),
0323     GRP("perst", perst_func_mt76x8, 1, MT76X8_GPIO_MODE_PERST),
0324     GRP("wdt", wdt_func_mt76x8, 1, MT76X8_GPIO_MODE_WDT),
0325     GRP("spi", spi_func_mt76x8, 1, MT76X8_GPIO_MODE_SPI),
0326     GRP_G("sdmode", sd_mode_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0327                 1, MT76X8_GPIO_MODE_SDMODE),
0328     GRP_G("uart0", uart0_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0329                 1, MT76X8_GPIO_MODE_UART0),
0330     GRP_G("i2s", i2s_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0331                 1, MT76X8_GPIO_MODE_I2S),
0332     GRP_G("spi cs1", spi_cs1_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0333                 1, MT76X8_GPIO_MODE_CS1),
0334     GRP_G("spis", spis_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0335                 1, MT76X8_GPIO_MODE_SPIS),
0336     GRP_G("gpio", gpio_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0337                 1, MT76X8_GPIO_MODE_GPIO),
0338     GRP_G("wled_an", wled_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0339                 1, MT76X8_GPIO_MODE_WLED_AN),
0340     GRP_G("p0led_an", p0led_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0341                 1, MT76X8_GPIO_MODE_P0LED_AN),
0342     GRP_G("p1led_an", p1led_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0343                 1, MT76X8_GPIO_MODE_P1LED_AN),
0344     GRP_G("p2led_an", p2led_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0345                 1, MT76X8_GPIO_MODE_P2LED_AN),
0346     GRP_G("p3led_an", p3led_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0347                 1, MT76X8_GPIO_MODE_P3LED_AN),
0348     GRP_G("p4led_an", p4led_an_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0349                 1, MT76X8_GPIO_MODE_P4LED_AN),
0350     GRP_G("wled_kn", wled_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0351                 1, MT76X8_GPIO_MODE_WLED_KN),
0352     GRP_G("p0led_kn", p0led_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0353                 1, MT76X8_GPIO_MODE_P0LED_KN),
0354     GRP_G("p1led_kn", p1led_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0355                 1, MT76X8_GPIO_MODE_P1LED_KN),
0356     GRP_G("p2led_kn", p2led_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0357                 1, MT76X8_GPIO_MODE_P2LED_KN),
0358     GRP_G("p3led_kn", p3led_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0359                 1, MT76X8_GPIO_MODE_P3LED_KN),
0360     GRP_G("p4led_kn", p4led_kn_func_mt76x8, MT76X8_GPIO_MODE_MASK,
0361                 1, MT76X8_GPIO_MODE_P4LED_KN),
0362     { 0 }
0363 };
0364 
0365 static int mt7620_pinctrl_probe(struct platform_device *pdev)
0366 {
0367     if (is_mt76x8())
0368         return ralink_pinctrl_init(pdev, mt76x8_pinmux_data);
0369     else
0370         return ralink_pinctrl_init(pdev, mt7620a_pinmux_data);
0371 }
0372 
0373 static const struct of_device_id mt7620_pinctrl_match[] = {
0374     { .compatible = "ralink,mt7620-pinctrl" },
0375     {}
0376 };
0377 MODULE_DEVICE_TABLE(of, mt7620_pinctrl_match);
0378 
0379 static struct platform_driver mt7620_pinctrl_driver = {
0380     .probe = mt7620_pinctrl_probe,
0381     .driver = {
0382         .name = "mt7620-pinctrl",
0383         .of_match_table = mt7620_pinctrl_match,
0384     },
0385 };
0386 
0387 static int __init mt7620_pinctrl_init(void)
0388 {
0389     return platform_driver_register(&mt7620_pinctrl_driver);
0390 }
0391 core_initcall_sync(mt7620_pinctrl_init);