1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/module.h>
4 #include <linux/platform_device.h>
6 #include "pinctrl-mtmips.h"
8 #define MT7621_GPIO_MODE_UART1 1
9 #define MT7621_GPIO_MODE_I2C 2
10 #define MT7621_GPIO_MODE_UART3_MASK 0x3
11 #define MT7621_GPIO_MODE_UART3_SHIFT 3
12 #define MT7621_GPIO_MODE_UART3_GPIO 1
13 #define MT7621_GPIO_MODE_UART2_MASK 0x3
14 #define MT7621_GPIO_MODE_UART2_SHIFT 5
15 #define MT7621_GPIO_MODE_UART2_GPIO 1
16 #define MT7621_GPIO_MODE_JTAG 7
17 #define MT7621_GPIO_MODE_WDT_MASK 0x3
18 #define MT7621_GPIO_MODE_WDT_SHIFT 8
19 #define MT7621_GPIO_MODE_WDT_GPIO 1
20 #define MT7621_GPIO_MODE_PCIE_RST 0
21 #define MT7621_GPIO_MODE_PCIE_REF 2
22 #define MT7621_GPIO_MODE_PCIE_MASK 0x3
23 #define MT7621_GPIO_MODE_PCIE_SHIFT 10
24 #define MT7621_GPIO_MODE_PCIE_GPIO 1
25 #define MT7621_GPIO_MODE_MDIO_MASK 0x3
26 #define MT7621_GPIO_MODE_MDIO_SHIFT 12
27 #define MT7621_GPIO_MODE_MDIO_GPIO 1
28 #define MT7621_GPIO_MODE_RGMII1 14
29 #define MT7621_GPIO_MODE_RGMII2 15
30 #define MT7621_GPIO_MODE_SPI_MASK 0x3
31 #define MT7621_GPIO_MODE_SPI_SHIFT 16
32 #define MT7621_GPIO_MODE_SPI_GPIO 1
33 #define MT7621_GPIO_MODE_SDHCI_MASK 0x3
34 #define MT7621_GPIO_MODE_SDHCI_SHIFT 18
35 #define MT7621_GPIO_MODE_SDHCI_GPIO 1
37 static struct mtmips_pmx_func uart1_grp
[] = { FUNC("uart1", 0, 1, 2) };
38 static struct mtmips_pmx_func i2c_grp
[] = { FUNC("i2c", 0, 3, 2) };
39 static struct mtmips_pmx_func uart3_grp
[] = {
40 FUNC("uart3", 0, 5, 4),
42 FUNC("spdif3", 3, 5, 4),
44 static struct mtmips_pmx_func uart2_grp
[] = {
45 FUNC("uart2", 0, 9, 4),
47 FUNC("spdif2", 3, 9, 4),
49 static struct mtmips_pmx_func jtag_grp
[] = { FUNC("jtag", 0, 13, 5) };
50 static struct mtmips_pmx_func wdt_grp
[] = {
51 FUNC("wdt rst", 0, 18, 1),
52 FUNC("wdt refclk", 2, 18, 1),
54 static struct mtmips_pmx_func pcie_rst_grp
[] = {
55 FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST
, 19, 1),
56 FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF
, 19, 1)
58 static struct mtmips_pmx_func mdio_grp
[] = { FUNC("mdio", 0, 20, 2) };
59 static struct mtmips_pmx_func rgmii2_grp
[] = { FUNC("rgmii2", 0, 22, 12) };
60 static struct mtmips_pmx_func spi_grp
[] = {
61 FUNC("spi", 0, 34, 7),
62 FUNC("nand1", 2, 34, 7),
64 static struct mtmips_pmx_func sdhci_grp
[] = {
65 FUNC("sdhci", 0, 41, 8),
66 FUNC("nand2", 2, 41, 8),
68 static struct mtmips_pmx_func rgmii1_grp
[] = { FUNC("rgmii1", 0, 49, 12) };
70 static struct mtmips_pmx_group mt7621_pinmux_data
[] = {
71 GRP("uart1", uart1_grp
, 1, MT7621_GPIO_MODE_UART1
),
72 GRP("i2c", i2c_grp
, 1, MT7621_GPIO_MODE_I2C
),
73 GRP_G("uart3", uart3_grp
, MT7621_GPIO_MODE_UART3_MASK
,
74 MT7621_GPIO_MODE_UART3_GPIO
, MT7621_GPIO_MODE_UART3_SHIFT
),
75 GRP_G("uart2", uart2_grp
, MT7621_GPIO_MODE_UART2_MASK
,
76 MT7621_GPIO_MODE_UART2_GPIO
, MT7621_GPIO_MODE_UART2_SHIFT
),
77 GRP("jtag", jtag_grp
, 1, MT7621_GPIO_MODE_JTAG
),
78 GRP_G("wdt", wdt_grp
, MT7621_GPIO_MODE_WDT_MASK
,
79 MT7621_GPIO_MODE_WDT_GPIO
, MT7621_GPIO_MODE_WDT_SHIFT
),
80 GRP_G("pcie", pcie_rst_grp
, MT7621_GPIO_MODE_PCIE_MASK
,
81 MT7621_GPIO_MODE_PCIE_GPIO
, MT7621_GPIO_MODE_PCIE_SHIFT
),
82 GRP_G("mdio", mdio_grp
, MT7621_GPIO_MODE_MDIO_MASK
,
83 MT7621_GPIO_MODE_MDIO_GPIO
, MT7621_GPIO_MODE_MDIO_SHIFT
),
84 GRP("rgmii2", rgmii2_grp
, 1, MT7621_GPIO_MODE_RGMII2
),
85 GRP_G("spi", spi_grp
, MT7621_GPIO_MODE_SPI_MASK
,
86 MT7621_GPIO_MODE_SPI_GPIO
, MT7621_GPIO_MODE_SPI_SHIFT
),
87 GRP_G("sdhci", sdhci_grp
, MT7621_GPIO_MODE_SDHCI_MASK
,
88 MT7621_GPIO_MODE_SDHCI_GPIO
, MT7621_GPIO_MODE_SDHCI_SHIFT
),
89 GRP("rgmii1", rgmii1_grp
, 1, MT7621_GPIO_MODE_RGMII1
),
93 static int mt7621_pinctrl_probe(struct platform_device
*pdev
)
95 return mtmips_pinctrl_init(pdev
, mt7621_pinmux_data
);
98 static const struct of_device_id mt7621_pinctrl_match
[] = {
99 { .compatible
= "ralink,mt7621-pinctrl" },
100 { .compatible
= "ralink,rt2880-pinmux" },
103 MODULE_DEVICE_TABLE(of
, mt7621_pinctrl_match
);
105 static struct platform_driver mt7621_pinctrl_driver
= {
106 .probe
= mt7621_pinctrl_probe
,
108 .name
= "mt7621-pinctrl",
109 .of_match_table
= mt7621_pinctrl_match
,
113 static int __init
mt7621_pinctrl_init(void)
115 return platform_driver_register(&mt7621_pinctrl_driver
);
117 core_initcall_sync(mt7621_pinctrl_init
);