Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 
0003 #include <linux/module.h>
0004 #include <linux/platform_device.h>
0005 #include <linux/of.h>
0006 #include "pinctrl-ralink.h"
0007 
0008 #define MT7621_GPIO_MODE_UART1      1
0009 #define MT7621_GPIO_MODE_I2C        2
0010 #define MT7621_GPIO_MODE_UART3_MASK 0x3
0011 #define MT7621_GPIO_MODE_UART3_SHIFT    3
0012 #define MT7621_GPIO_MODE_UART3_GPIO 1
0013 #define MT7621_GPIO_MODE_UART2_MASK 0x3
0014 #define MT7621_GPIO_MODE_UART2_SHIFT    5
0015 #define MT7621_GPIO_MODE_UART2_GPIO 1
0016 #define MT7621_GPIO_MODE_JTAG       7
0017 #define MT7621_GPIO_MODE_WDT_MASK   0x3
0018 #define MT7621_GPIO_MODE_WDT_SHIFT  8
0019 #define MT7621_GPIO_MODE_WDT_GPIO   1
0020 #define MT7621_GPIO_MODE_PCIE_RST   0
0021 #define MT7621_GPIO_MODE_PCIE_REF   2
0022 #define MT7621_GPIO_MODE_PCIE_MASK  0x3
0023 #define MT7621_GPIO_MODE_PCIE_SHIFT 10
0024 #define MT7621_GPIO_MODE_PCIE_GPIO  1
0025 #define MT7621_GPIO_MODE_MDIO_MASK  0x3
0026 #define MT7621_GPIO_MODE_MDIO_SHIFT 12
0027 #define MT7621_GPIO_MODE_MDIO_GPIO  1
0028 #define MT7621_GPIO_MODE_RGMII1     14
0029 #define MT7621_GPIO_MODE_RGMII2     15
0030 #define MT7621_GPIO_MODE_SPI_MASK   0x3
0031 #define MT7621_GPIO_MODE_SPI_SHIFT  16
0032 #define MT7621_GPIO_MODE_SPI_GPIO   1
0033 #define MT7621_GPIO_MODE_SDHCI_MASK 0x3
0034 #define MT7621_GPIO_MODE_SDHCI_SHIFT    18
0035 #define MT7621_GPIO_MODE_SDHCI_GPIO 1
0036 
0037 static struct ralink_pmx_func uart1_func[] =  { FUNC("uart1", 0, 1, 2) };
0038 static struct ralink_pmx_func i2c_func[] =  { FUNC("i2c", 0, 3, 2) };
0039 static struct ralink_pmx_func uart3_func[] = {
0040     FUNC("uart3", 0, 5, 4),
0041     FUNC("i2s", 2, 5, 4),
0042     FUNC("spdif3", 3, 5, 4),
0043 };
0044 static struct ralink_pmx_func uart2_func[] = {
0045     FUNC("uart2", 0, 9, 4),
0046     FUNC("pcm", 2, 9, 4),
0047     FUNC("spdif2", 3, 9, 4),
0048 };
0049 static struct ralink_pmx_func jtag_func[] = { FUNC("jtag", 0, 13, 5) };
0050 static struct ralink_pmx_func wdt_func[] = {
0051     FUNC("wdt rst", 0, 18, 1),
0052     FUNC("wdt refclk", 2, 18, 1),
0053 };
0054 static struct ralink_pmx_func pcie_rst_func[] = {
0055     FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
0056     FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
0057 };
0058 static struct ralink_pmx_func mdio_func[] = { FUNC("mdio", 0, 20, 2) };
0059 static struct ralink_pmx_func rgmii2_func[] = { FUNC("rgmii2", 0, 22, 12) };
0060 static struct ralink_pmx_func spi_func[] = {
0061     FUNC("spi", 0, 34, 7),
0062     FUNC("nand1", 2, 34, 7),
0063 };
0064 static struct ralink_pmx_func sdhci_func[] = {
0065     FUNC("sdhci", 0, 41, 8),
0066     FUNC("nand2", 2, 41, 8),
0067 };
0068 static struct ralink_pmx_func rgmii1_func[] = { FUNC("rgmii1", 0, 49, 12) };
0069 
0070 static struct ralink_pmx_group mt7621_pinmux_data[] = {
0071     GRP("uart1", uart1_func, 1, MT7621_GPIO_MODE_UART1),
0072     GRP("i2c", i2c_func, 1, MT7621_GPIO_MODE_I2C),
0073     GRP_G("uart3", uart3_func, MT7621_GPIO_MODE_UART3_MASK,
0074         MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT),
0075     GRP_G("uart2", uart2_func, MT7621_GPIO_MODE_UART2_MASK,
0076         MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT),
0077     GRP("jtag", jtag_func, 1, MT7621_GPIO_MODE_JTAG),
0078     GRP_G("wdt", wdt_func, MT7621_GPIO_MODE_WDT_MASK,
0079         MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
0080     GRP_G("pcie", pcie_rst_func, MT7621_GPIO_MODE_PCIE_MASK,
0081         MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
0082     GRP_G("mdio", mdio_func, MT7621_GPIO_MODE_MDIO_MASK,
0083         MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT),
0084     GRP("rgmii2", rgmii2_func, 1, MT7621_GPIO_MODE_RGMII2),
0085     GRP_G("spi", spi_func, MT7621_GPIO_MODE_SPI_MASK,
0086         MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
0087     GRP_G("sdhci", sdhci_func, MT7621_GPIO_MODE_SDHCI_MASK,
0088         MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
0089     GRP("rgmii1", rgmii1_func, 1, MT7621_GPIO_MODE_RGMII1),
0090     { 0 }
0091 };
0092 
0093 static int mt7621_pinctrl_probe(struct platform_device *pdev)
0094 {
0095     return ralink_pinctrl_init(pdev, mt7621_pinmux_data);
0096 }
0097 
0098 static const struct of_device_id mt7621_pinctrl_match[] = {
0099     { .compatible = "ralink,mt7621-pinctrl" },
0100     {}
0101 };
0102 MODULE_DEVICE_TABLE(of, mt7621_pinctrl_match);
0103 
0104 static struct platform_driver mt7621_pinctrl_driver = {
0105     .probe = mt7621_pinctrl_probe,
0106     .driver = {
0107         .name = "mt7621-pinctrl",
0108         .of_match_table = mt7621_pinctrl_match,
0109     },
0110 };
0111 
0112 static int __init mt7621_pinctrl_init(void)
0113 {
0114     return platform_driver_register(&mt7621_pinctrl_driver);
0115 }
0116 core_initcall_sync(mt7621_pinctrl_init);