162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#include <linux/module.h>
462306a36Sopenharmony_ci#include <linux/platform_device.h>
562306a36Sopenharmony_ci#include <linux/of.h>
662306a36Sopenharmony_ci#include "pinctrl-mtmips.h"
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART1		1
962306a36Sopenharmony_ci#define MT7621_GPIO_MODE_I2C		2
1062306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART3_MASK	0x3
1162306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART3_SHIFT	3
1262306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART3_GPIO	1
1362306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART2_MASK	0x3
1462306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART2_SHIFT	5
1562306a36Sopenharmony_ci#define MT7621_GPIO_MODE_UART2_GPIO	1
1662306a36Sopenharmony_ci#define MT7621_GPIO_MODE_JTAG		7
1762306a36Sopenharmony_ci#define MT7621_GPIO_MODE_WDT_MASK	0x3
1862306a36Sopenharmony_ci#define MT7621_GPIO_MODE_WDT_SHIFT	8
1962306a36Sopenharmony_ci#define MT7621_GPIO_MODE_WDT_GPIO	1
2062306a36Sopenharmony_ci#define MT7621_GPIO_MODE_PCIE_RST	0
2162306a36Sopenharmony_ci#define MT7621_GPIO_MODE_PCIE_REF	2
2262306a36Sopenharmony_ci#define MT7621_GPIO_MODE_PCIE_MASK	0x3
2362306a36Sopenharmony_ci#define MT7621_GPIO_MODE_PCIE_SHIFT	10
2462306a36Sopenharmony_ci#define MT7621_GPIO_MODE_PCIE_GPIO	1
2562306a36Sopenharmony_ci#define MT7621_GPIO_MODE_MDIO_MASK	0x3
2662306a36Sopenharmony_ci#define MT7621_GPIO_MODE_MDIO_SHIFT	12
2762306a36Sopenharmony_ci#define MT7621_GPIO_MODE_MDIO_GPIO	1
2862306a36Sopenharmony_ci#define MT7621_GPIO_MODE_RGMII1		14
2962306a36Sopenharmony_ci#define MT7621_GPIO_MODE_RGMII2		15
3062306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SPI_MASK	0x3
3162306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SPI_SHIFT	16
3262306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SPI_GPIO	1
3362306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SDHCI_MASK	0x3
3462306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SDHCI_SHIFT	18
3562306a36Sopenharmony_ci#define MT7621_GPIO_MODE_SDHCI_GPIO	1
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistatic struct mtmips_pmx_func uart1_grp[] =  { FUNC("uart1", 0, 1, 2) };
3862306a36Sopenharmony_cistatic struct mtmips_pmx_func i2c_grp[] =  { FUNC("i2c", 0, 3, 2) };
3962306a36Sopenharmony_cistatic struct mtmips_pmx_func uart3_grp[] = {
4062306a36Sopenharmony_ci	FUNC("uart3", 0, 5, 4),
4162306a36Sopenharmony_ci	FUNC("i2s", 2, 5, 4),
4262306a36Sopenharmony_ci	FUNC("spdif3", 3, 5, 4),
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_cistatic struct mtmips_pmx_func uart2_grp[] = {
4562306a36Sopenharmony_ci	FUNC("uart2", 0, 9, 4),
4662306a36Sopenharmony_ci	FUNC("pcm", 2, 9, 4),
4762306a36Sopenharmony_ci	FUNC("spdif2", 3, 9, 4),
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_cistatic struct mtmips_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) };
5062306a36Sopenharmony_cistatic struct mtmips_pmx_func wdt_grp[] = {
5162306a36Sopenharmony_ci	FUNC("wdt rst", 0, 18, 1),
5262306a36Sopenharmony_ci	FUNC("wdt refclk", 2, 18, 1),
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_cistatic struct mtmips_pmx_func pcie_rst_grp[] = {
5562306a36Sopenharmony_ci	FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
5662306a36Sopenharmony_ci	FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_cistatic struct mtmips_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) };
5962306a36Sopenharmony_cistatic struct mtmips_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 22, 12) };
6062306a36Sopenharmony_cistatic struct mtmips_pmx_func spi_grp[] = {
6162306a36Sopenharmony_ci	FUNC("spi", 0, 34, 7),
6262306a36Sopenharmony_ci	FUNC("nand1", 2, 34, 7),
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_cistatic struct mtmips_pmx_func sdhci_grp[] = {
6562306a36Sopenharmony_ci	FUNC("sdhci", 0, 41, 8),
6662306a36Sopenharmony_ci	FUNC("nand2", 2, 41, 8),
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_cistatic struct mtmips_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 49, 12) };
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic struct mtmips_pmx_group mt7621_pinmux_data[] = {
7162306a36Sopenharmony_ci	GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1),
7262306a36Sopenharmony_ci	GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C),
7362306a36Sopenharmony_ci	GRP_G("uart3", uart3_grp, MT7621_GPIO_MODE_UART3_MASK,
7462306a36Sopenharmony_ci		MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT),
7562306a36Sopenharmony_ci	GRP_G("uart2", uart2_grp, MT7621_GPIO_MODE_UART2_MASK,
7662306a36Sopenharmony_ci		MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT),
7762306a36Sopenharmony_ci	GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG),
7862306a36Sopenharmony_ci	GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK,
7962306a36Sopenharmony_ci		MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
8062306a36Sopenharmony_ci	GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK,
8162306a36Sopenharmony_ci		MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
8262306a36Sopenharmony_ci	GRP_G("mdio", mdio_grp, MT7621_GPIO_MODE_MDIO_MASK,
8362306a36Sopenharmony_ci		MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT),
8462306a36Sopenharmony_ci	GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2),
8562306a36Sopenharmony_ci	GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK,
8662306a36Sopenharmony_ci		MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
8762306a36Sopenharmony_ci	GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK,
8862306a36Sopenharmony_ci		MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
8962306a36Sopenharmony_ci	GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1),
9062306a36Sopenharmony_ci	{ 0 }
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistatic int mt7621_pinctrl_probe(struct platform_device *pdev)
9462306a36Sopenharmony_ci{
9562306a36Sopenharmony_ci	return mtmips_pinctrl_init(pdev, mt7621_pinmux_data);
9662306a36Sopenharmony_ci}
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_cistatic const struct of_device_id mt7621_pinctrl_match[] = {
9962306a36Sopenharmony_ci	{ .compatible = "ralink,mt7621-pinctrl" },
10062306a36Sopenharmony_ci	{ .compatible = "ralink,rt2880-pinmux" },
10162306a36Sopenharmony_ci	{}
10262306a36Sopenharmony_ci};
10362306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, mt7621_pinctrl_match);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistatic struct platform_driver mt7621_pinctrl_driver = {
10662306a36Sopenharmony_ci	.probe = mt7621_pinctrl_probe,
10762306a36Sopenharmony_ci	.driver = {
10862306a36Sopenharmony_ci		.name = "mt7621-pinctrl",
10962306a36Sopenharmony_ci		.of_match_table = mt7621_pinctrl_match,
11062306a36Sopenharmony_ci	},
11162306a36Sopenharmony_ci};
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_cistatic int __init mt7621_pinctrl_init(void)
11462306a36Sopenharmony_ci{
11562306a36Sopenharmony_ci	return platform_driver_register(&mt7621_pinctrl_driver);
11662306a36Sopenharmony_ci}
11762306a36Sopenharmony_cicore_initcall_sync(mt7621_pinctrl_init);
118