1 From 3cf9e2daca330a0ba89d3793ceb09037c788db46 Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 20 May 2022 11:22:49 +0800
4 Subject: [PATCH 10/25] pinctrl: mtmips: add support for MediaTek MT7621 SoC
6 This patch adds pinctrl support for MediaTek MT7621 SoC.
7 The MT7621 SoC supports pinconf, but it is not the same as mt7628.
9 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
10 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
12 drivers/pinctrl/mtmips/Kconfig | 9 +
13 drivers/pinctrl/mtmips/Makefile | 1 +
14 drivers/pinctrl/mtmips/pinctrl-mt7621.c | 306 ++++++++++++++++++
15 .../pinctrl/mtmips/pinctrl-mtmips-common.c | 4 +-
16 .../pinctrl/mtmips/pinctrl-mtmips-common.h | 12 +
17 5 files changed, 330 insertions(+), 2 deletions(-)
18 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mt7621.c
20 diff --git a/drivers/pinctrl/mtmips/Kconfig b/drivers/pinctrl/mtmips/Kconfig
21 index 844d5b743f..456f3ea25d 100644
22 --- a/drivers/pinctrl/mtmips/Kconfig
23 +++ b/drivers/pinctrl/mtmips/Kconfig
24 @@ -12,6 +12,15 @@ config PINCTRL_MT7620
25 The driver is controlled by a device tree node which contains
26 the pin mux functions for each available pin groups.
28 +config PINCTRL_MT7621
29 + bool "MediaTek MT7621 pin control driver"
30 + select PINCTRL_MTMIPS
31 + depends on SOC_MT7621 && PINCTRL_GENERIC
33 + Support pin multiplexing control on MediaTek MT7621.
34 + The driver is controlled by a device tree node which contains
35 + the pin mux functions for each available pin groups.
38 bool "MediaTek MT7628 pin control driver"
40 diff --git a/drivers/pinctrl/mtmips/Makefile b/drivers/pinctrl/mtmips/Makefile
41 index ba945a89a7..8fece4f5fa 100644
42 --- a/drivers/pinctrl/mtmips/Makefile
43 +++ b/drivers/pinctrl/mtmips/Makefile
44 @@ -5,4 +5,5 @@ obj-$(CONFIG_PINCTRL_MTMIPS) += pinctrl-mtmips-common.o
47 obj-$(CONFIG_PINCTRL_MT7620) += pinctrl-mt7620.o
48 +obj-$(CONFIG_PINCTRL_MT7621) += pinctrl-mt7621.o
49 obj-$(CONFIG_PINCTRL_MT7628) += pinctrl-mt7628.o
50 diff --git a/drivers/pinctrl/mtmips/pinctrl-mt7621.c b/drivers/pinctrl/mtmips/pinctrl-mt7621.c
52 index 0000000000..3e98a01bad
54 +++ b/drivers/pinctrl/mtmips/pinctrl-mt7621.c
56 +// SPDX-License-Identifier: GPL-2.0
58 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
60 + * Author: Weijie Gao <weijie.gao@mediatek.com>
64 +#include <dm/pinctrl.h>
65 +#include <dm/device_compat.h>
66 +#include <linux/bitops.h>
67 +#include <linux/io.h>
69 +#include "pinctrl-mtmips-common.h"
71 +#define SYSC_MAP_SIZE 0x100
73 +#define PAD_UART1_GPIO0_OFS 0x00
74 +#define PAD_UART3_I2C_OFS 0x04
75 +#define PAD_UART2_JTAG_OFS 0x08
76 +#define PAD_PERST_WDT_OFS 0x0c
77 +#define PAD_RGMII2_MDIO_OFS 0x10
78 +#define PAD_SDXC_SPI_OFS 0x14
79 +#define GPIOMODE_OFS 0x18
80 +#define PAD_BOPT_ESWINT_OFS 0x28
82 +#define ESWINT_SHIFT 20
83 +#define SDXC_SHIFT 18
85 +#define RGMII2_SHIFT 15
86 +#define RGMII1_SHIFT 14
87 +#define MDIO_SHIFT 12
88 +#define PERST_SHIFT 10
91 +#define UART2_SHIFT 5
92 +#define UART3_SHIFT 3
94 +#define UART1_SHIFT 1
95 +#define GPIO0_SHIFT 0 /* Dummy */
101 +#define PULL_UP BIT(3)
102 +#define PULL_DOWN BIT(2)
106 +struct mt7621_pinctrl_priv {
107 + struct mtmips_pinctrl_priv mp;
110 +#if CONFIG_IS_ENABLED(PINMUX)
111 +static const struct mtmips_pmx_func esw_int_grp[] = {
113 + FUNC("esw int", 0),
116 +static const struct mtmips_pmx_func sdxc_grp[] = {
122 +static const struct mtmips_pmx_func spi_grp[] = {
128 +static const struct mtmips_pmx_func rgmii2_grp[] = {
133 +static const struct mtmips_pmx_func rgmii1_grp[] = {
138 +static const struct mtmips_pmx_func mdio_grp[] = {
143 +static const struct mtmips_pmx_func perst_grp[] = {
146 + FUNC("pcie reset", 0),
149 +static const struct mtmips_pmx_func wdt_grp[] = {
152 + FUNC("wdt rst", 0),
155 +static const struct mtmips_pmx_func jtag_grp[] = {
160 +static const struct mtmips_pmx_func uart2_grp[] = {
167 +static const struct mtmips_pmx_func uart3_grp[] = {
174 +static const struct mtmips_pmx_func i2c_grp[] = {
179 +static const struct mtmips_pmx_func uart1_grp[] = {
184 +static const struct mtmips_pmx_func gpio0_grp[] = {
188 +static const struct mtmips_pmx_group mt7621_pmx_data[] = {
189 + GRP_PCONF("esw int", esw_int_grp, GPIOMODE_OFS, ESWINT_SHIFT, 1,
190 + PAD_BOPT_ESWINT_OFS, 0),
191 + GRP_PCONF("sdxc", sdxc_grp, GPIOMODE_OFS, SDXC_SHIFT, GM4_MASK,
192 + PAD_SDXC_SPI_OFS, 16),
193 + GRP_PCONF("spi", spi_grp, GPIOMODE_OFS, SPI_SHIFT, GM4_MASK,
194 + PAD_SDXC_SPI_OFS, 0),
195 + GRP_PCONF("rgmii2", rgmii2_grp, GPIOMODE_OFS, RGMII2_SHIFT, 1,
196 + PAD_RGMII2_MDIO_OFS, 16),
197 + GRP("rgmii1", rgmii1_grp, GPIOMODE_OFS, RGMII1_SHIFT, 1),
198 + GRP_PCONF("mdio", mdio_grp, GPIOMODE_OFS, MDIO_SHIFT, GM4_MASK,
199 + PAD_RGMII2_MDIO_OFS, 0),
200 + GRP_PCONF("pcie reset", perst_grp, GPIOMODE_OFS, PERST_SHIFT, GM4_MASK,
201 + PAD_PERST_WDT_OFS, 16),
202 + GRP_PCONF("wdt", wdt_grp, GPIOMODE_OFS, WDT_SHIFT, GM4_MASK,
203 + PAD_PERST_WDT_OFS, 0),
204 + GRP_PCONF("jtag", jtag_grp, GPIOMODE_OFS, JTAG_SHIFT, 1,
205 + PAD_UART2_JTAG_OFS, 16),
206 + GRP_PCONF("uart2", uart2_grp, GPIOMODE_OFS, UART2_SHIFT, GM4_MASK,
207 + PAD_UART2_JTAG_OFS, 0),
208 + GRP_PCONF("uart3", uart3_grp, GPIOMODE_OFS, UART3_SHIFT, GM4_MASK,
209 + PAD_UART3_I2C_OFS, 16),
210 + GRP_PCONF("i2c", i2c_grp, GPIOMODE_OFS, I2C_SHIFT, 1,
211 + PAD_UART3_I2C_OFS, 0),
212 + GRP_PCONF("uart1", uart1_grp, GPIOMODE_OFS, UART1_SHIFT, 1,
213 + PAD_UART1_GPIO0_OFS, 16),
214 + GRP_PCONF("gpio0", gpio0_grp, GPIOMODE_OFS, GPIO0_SHIFT, 1,
215 + PAD_UART1_GPIO0_OFS, 0),
218 +static int mt7621_get_groups_count(struct udevice *dev)
220 + return ARRAY_SIZE(mt7621_pmx_data);
223 +static const char *mt7621_get_group_name(struct udevice *dev,
224 + unsigned int selector)
226 + return mt7621_pmx_data[selector].name;
228 +#endif /* CONFIG_IS_ENABLED(PINMUX) */
230 +#if CONFIG_IS_ENABLED(PINCONF)
231 +static const struct pinconf_param mt7621_conf_params[] = {
232 + { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
233 + { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
234 + { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
235 + { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 },
236 + { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 },
237 + { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
238 + { "slew-rate", PIN_CONFIG_SLEW_RATE, 0 },
241 +static const u32 mt7621_pconf_drv_strength_tbl[] = {2, 4, 6, 8};
243 +static int mt7621_pinconf_group_set(struct udevice *dev,
244 + unsigned int group_selector,
245 + unsigned int param, unsigned int arg)
247 + struct mt7621_pinctrl_priv *priv = dev_get_priv(dev);
248 + const struct mtmips_pmx_group *grp = &mt7621_pmx_data[group_selector];
249 + u32 clr = 0, set = 0;
252 + if (!grp->pconf_avail)
256 + case PIN_CONFIG_BIAS_DISABLE:
257 + clr = PULL_UP | PULL_DOWN;
260 + case PIN_CONFIG_BIAS_PULL_UP:
265 + case PIN_CONFIG_BIAS_PULL_DOWN:
270 + case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
277 + case PIN_CONFIG_DRIVE_STRENGTH:
278 + for (i = 0; i < ARRAY_SIZE(mt7621_pconf_drv_strength_tbl); i++)
279 + if (mt7621_pconf_drv_strength_tbl[i] == arg)
282 + if (i >= ARRAY_SIZE(mt7621_pconf_drv_strength_tbl))
285 + clr = E4_E2_M << E4_E2_S;
286 + set = i << E4_E2_S;
289 + case PIN_CONFIG_SLEW_RATE:
300 + mtmips_pinctrl_reg_set(&priv->mp, grp->pconf_reg, grp->pconf_shift,
307 +static int mt7621_pinctrl_probe(struct udevice *dev)
309 + struct mt7621_pinctrl_priv *priv = dev_get_priv(dev);
312 +#if CONFIG_IS_ENABLED(PINMUX)
313 + ret = mtmips_pinctrl_probe(&priv->mp, ARRAY_SIZE(mt7621_pmx_data),
315 +#endif /* CONFIG_IS_ENABLED(PINMUX) */
320 +static int mt7621_pinctrl_of_to_plat(struct udevice *dev)
322 + struct mt7621_pinctrl_priv *priv = dev_get_priv(dev);
324 + priv->mp.base = (void __iomem *)dev_remap_addr_index(dev, 0);
326 + if (!priv->mp.base)
332 +static const struct pinctrl_ops mt7621_pinctrl_ops = {
333 +#if CONFIG_IS_ENABLED(PINMUX)
334 + .get_groups_count = mt7621_get_groups_count,
335 + .get_group_name = mt7621_get_group_name,
336 + .get_functions_count = mtmips_get_functions_count,
337 + .get_function_name = mtmips_get_function_name,
338 + .pinmux_group_set = mtmips_pinmux_group_set,
339 +#endif /* CONFIG_IS_ENABLED(PINMUX) */
340 +#if CONFIG_IS_ENABLED(PINCONF)
341 + .pinconf_num_params = ARRAY_SIZE(mt7621_conf_params),
342 + .pinconf_params = mt7621_conf_params,
343 + .pinconf_group_set = mt7621_pinconf_group_set,
344 +#endif /* CONFIG_IS_ENABLED(PINCONF) */
345 + .set_state = pinctrl_generic_set_state,
348 +static const struct udevice_id mt7621_pinctrl_ids[] = {
349 + { .compatible = "mediatek,mt7621-pinctrl" },
353 +U_BOOT_DRIVER(mt7621_pinctrl) = {
354 + .name = "mt7621-pinctrl",
355 + .id = UCLASS_PINCTRL,
356 + .of_match = mt7621_pinctrl_ids,
357 + .of_to_plat = mt7621_pinctrl_of_to_plat,
358 + .ops = &mt7621_pinctrl_ops,
359 + .probe = mt7621_pinctrl_probe,
360 + .priv_auto = sizeof(struct mt7621_pinctrl_priv),
362 diff --git a/drivers/pinctrl/mtmips/pinctrl-mtmips-common.c b/drivers/pinctrl/mtmips/pinctrl-mtmips-common.c
363 index e361916eb2..869b781068 100644
364 --- a/drivers/pinctrl/mtmips/pinctrl-mtmips-common.c
365 +++ b/drivers/pinctrl/mtmips/pinctrl-mtmips-common.c
368 #include "pinctrl-mtmips-common.h"
370 -static void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
371 - u32 reg, u32 shift, u32 mask, u32 value)
372 +void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
373 + u32 reg, u32 shift, u32 mask, u32 value)
377 diff --git a/drivers/pinctrl/mtmips/pinctrl-mtmips-common.h b/drivers/pinctrl/mtmips/pinctrl-mtmips-common.h
378 index b51d8f009c..1f1023ef42 100644
379 --- a/drivers/pinctrl/mtmips/pinctrl-mtmips-common.h
380 +++ b/drivers/pinctrl/mtmips/pinctrl-mtmips-common.h
381 @@ -22,6 +22,10 @@ struct mtmips_pmx_group {
390 const struct mtmips_pmx_func *funcs;
392 @@ -42,6 +46,14 @@ struct mtmips_pinctrl_priv {
393 { .name = (_name), .reg = (_reg), .shift = (_shift), .mask = (_mask), \
394 .funcs = (_funcs), .nfuncs = ARRAY_SIZE(_funcs) }
396 +#define GRP_PCONF(_name, _funcs, _reg, _shift, _mask, _pconf_reg, _pconf_shift) \
397 + { .name = (_name), .reg = (_reg), .shift = (_shift), .mask = (_mask), \
398 + .funcs = (_funcs), .nfuncs = ARRAY_SIZE(_funcs), .pconf_avail = 1, \
399 + .pconf_reg = (_pconf_reg), .pconf_shift = (_pconf_shift) }
401 +void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
402 + u32 reg, u32 shift, u32 mask, u32 value);
404 int mtmips_get_functions_count(struct udevice *dev);
405 const char *mtmips_get_function_name(struct udevice *dev,
406 unsigned int selector);