|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | + |
| 3 | +#include <asm/mach-ralink/rt305x.h> |
| 4 | +#include <linux/module.h> |
| 5 | +#include <linux/platform_device.h> |
| 6 | +#include <linux/of.h> |
| 7 | +#include "pinmux.h" |
| 8 | + |
| 9 | +#define RT305X_GPIO_MODE_UART0_SHIFT 2 |
| 10 | +#define RT305X_GPIO_MODE_UART0_MASK 0x7 |
| 11 | +#define RT305X_GPIO_MODE_UART0(x) ((x) << RT305X_GPIO_MODE_UART0_SHIFT) |
| 12 | +#define RT305X_GPIO_MODE_UARTF 0 |
| 13 | +#define RT305X_GPIO_MODE_PCM_UARTF 1 |
| 14 | +#define RT305X_GPIO_MODE_PCM_I2S 2 |
| 15 | +#define RT305X_GPIO_MODE_I2S_UARTF 3 |
| 16 | +#define RT305X_GPIO_MODE_PCM_GPIO 4 |
| 17 | +#define RT305X_GPIO_MODE_GPIO_UARTF 5 |
| 18 | +#define RT305X_GPIO_MODE_GPIO_I2S 6 |
| 19 | +#define RT305X_GPIO_MODE_GPIO 7 |
| 20 | + |
| 21 | +#define RT305X_GPIO_MODE_I2C 0 |
| 22 | +#define RT305X_GPIO_MODE_SPI 1 |
| 23 | +#define RT305X_GPIO_MODE_UART1 5 |
| 24 | +#define RT305X_GPIO_MODE_JTAG 6 |
| 25 | +#define RT305X_GPIO_MODE_MDIO 7 |
| 26 | +#define RT305X_GPIO_MODE_SDRAM 8 |
| 27 | +#define RT305X_GPIO_MODE_RGMII 9 |
| 28 | +#define RT5350_GPIO_MODE_PHY_LED 14 |
| 29 | +#define RT5350_GPIO_MODE_SPI_CS1 21 |
| 30 | +#define RT3352_GPIO_MODE_LNA 18 |
| 31 | +#define RT3352_GPIO_MODE_PA 20 |
| 32 | + |
| 33 | +static struct rt2880_pmx_func i2c_func[] = { FUNC("i2c", 0, 1, 2) }; |
| 34 | +static struct rt2880_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) }; |
| 35 | +static struct rt2880_pmx_func uartf_func[] = { |
| 36 | + FUNC("uartf", RT305X_GPIO_MODE_UARTF, 7, 8), |
| 37 | + FUNC("pcm uartf", RT305X_GPIO_MODE_PCM_UARTF, 7, 8), |
| 38 | + FUNC("pcm i2s", RT305X_GPIO_MODE_PCM_I2S, 7, 8), |
| 39 | + FUNC("i2s uartf", RT305X_GPIO_MODE_I2S_UARTF, 7, 8), |
| 40 | + FUNC("pcm gpio", RT305X_GPIO_MODE_PCM_GPIO, 11, 4), |
| 41 | + FUNC("gpio uartf", RT305X_GPIO_MODE_GPIO_UARTF, 7, 4), |
| 42 | + FUNC("gpio i2s", RT305X_GPIO_MODE_GPIO_I2S, 7, 4), |
| 43 | +}; |
| 44 | +static struct rt2880_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 15, 2) }; |
| 45 | +static struct rt2880_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) }; |
| 46 | +static struct rt2880_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) }; |
| 47 | +static struct rt2880_pmx_func rt5350_led_func[] = { FUNC("led", 0, 22, 5) }; |
| 48 | +static struct rt2880_pmx_func rt5350_cs1_func[] = { |
| 49 | + FUNC("spi_cs1", 0, 27, 1), |
| 50 | + FUNC("wdg_cs1", 1, 27, 1), |
| 51 | +}; |
| 52 | +static struct rt2880_pmx_func sdram_func[] = { FUNC("sdram", 0, 24, 16) }; |
| 53 | +static struct rt2880_pmx_func rt3352_rgmii_func[] = { |
| 54 | + FUNC("rgmii", 0, 24, 12) |
| 55 | +}; |
| 56 | +static struct rt2880_pmx_func rgmii_func[] = { FUNC("rgmii", 0, 40, 12) }; |
| 57 | +static struct rt2880_pmx_func rt3352_lna_func[] = { FUNC("lna", 0, 36, 2) }; |
| 58 | +static struct rt2880_pmx_func rt3352_pa_func[] = { FUNC("pa", 0, 38, 2) }; |
| 59 | +static struct rt2880_pmx_func rt3352_led_func[] = { FUNC("led", 0, 40, 5) }; |
| 60 | +static struct rt2880_pmx_func rt3352_cs1_func[] = { |
| 61 | + FUNC("spi_cs1", 0, 45, 1), |
| 62 | + FUNC("wdg_cs1", 1, 45, 1), |
| 63 | +}; |
| 64 | + |
| 65 | +static struct rt2880_pmx_group rt3050_pinmux_data[] = { |
| 66 | + GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), |
| 67 | + GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), |
| 68 | + GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, |
| 69 | + RT305X_GPIO_MODE_UART0_SHIFT), |
| 70 | + GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1), |
| 71 | + GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG), |
| 72 | + GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO), |
| 73 | + GRP("rgmii", rgmii_func, 1, RT305X_GPIO_MODE_RGMII), |
| 74 | + GRP("sdram", sdram_func, 1, RT305X_GPIO_MODE_SDRAM), |
| 75 | + { 0 } |
| 76 | +}; |
| 77 | + |
| 78 | +static struct rt2880_pmx_group rt3352_pinmux_data[] = { |
| 79 | + GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), |
| 80 | + GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), |
| 81 | + GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, |
| 82 | + RT305X_GPIO_MODE_UART0_SHIFT), |
| 83 | + GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1), |
| 84 | + GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG), |
| 85 | + GRP("mdio", mdio_func, 1, RT305X_GPIO_MODE_MDIO), |
| 86 | + GRP("rgmii", rt3352_rgmii_func, 1, RT305X_GPIO_MODE_RGMII), |
| 87 | + GRP("lna", rt3352_lna_func, 1, RT3352_GPIO_MODE_LNA), |
| 88 | + GRP("pa", rt3352_pa_func, 1, RT3352_GPIO_MODE_PA), |
| 89 | + GRP("led", rt3352_led_func, 1, RT5350_GPIO_MODE_PHY_LED), |
| 90 | + GRP("spi_cs1", rt3352_cs1_func, 2, RT5350_GPIO_MODE_SPI_CS1), |
| 91 | + { 0 } |
| 92 | +}; |
| 93 | + |
| 94 | +static struct rt2880_pmx_group rt5350_pinmux_data[] = { |
| 95 | + GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), |
| 96 | + GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), |
| 97 | + GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, |
| 98 | + RT305X_GPIO_MODE_UART0_SHIFT), |
| 99 | + GRP("uartlite", uartlite_func, 1, RT305X_GPIO_MODE_UART1), |
| 100 | + GRP("jtag", jtag_func, 1, RT305X_GPIO_MODE_JTAG), |
| 101 | + GRP("led", rt5350_led_func, 1, RT5350_GPIO_MODE_PHY_LED), |
| 102 | + GRP("spi_cs1", rt5350_cs1_func, 2, RT5350_GPIO_MODE_SPI_CS1), |
| 103 | + { 0 } |
| 104 | +}; |
| 105 | + |
| 106 | +static int rt305x_pinmux_probe(struct platform_device *pdev) |
| 107 | +{ |
| 108 | + if (soc_is_rt5350()) |
| 109 | + return rt2880_pinmux_init(pdev, rt5350_pinmux_data); |
| 110 | + else if (soc_is_rt305x() || soc_is_rt3350()) |
| 111 | + return rt2880_pinmux_init(pdev, rt3050_pinmux_data); |
| 112 | + else if (soc_is_rt3352()) |
| 113 | + return rt2880_pinmux_init(pdev, rt3352_pinmux_data); |
| 114 | + else |
| 115 | + return -EINVAL; |
| 116 | +} |
| 117 | + |
| 118 | +static const struct of_device_id rt305x_pinmux_match[] = { |
| 119 | + { .compatible = "ralink,rt2880-pinmux" }, |
| 120 | + {} |
| 121 | +}; |
| 122 | +MODULE_DEVICE_TABLE(of, rt305x_pinmux_match); |
| 123 | + |
| 124 | +static struct platform_driver rt305x_pinmux_driver = { |
| 125 | + .probe = rt305x_pinmux_probe, |
| 126 | + .driver = { |
| 127 | + .name = "rt2880-pinmux", |
| 128 | + .of_match_table = rt305x_pinmux_match, |
| 129 | + }, |
| 130 | +}; |
| 131 | + |
| 132 | +static int __init rt305x_pinmux_init(void) |
| 133 | +{ |
| 134 | + return platform_driver_register(&rt305x_pinmux_driver); |
| 135 | +} |
| 136 | +core_initcall_sync(rt305x_pinmux_init); |
0 commit comments