1 From d8b94c9ff96c2024a527086d850eb0b314337ff9 Mon Sep 17 00:00:00 2001
2 From: Sam Shih <sam.shih@mediatek.com>
3 Date: Tue, 14 Sep 2021 16:51:32 +0800
4 Subject: [PATCH] pinctrl: mediatek: moore: check if pin_desc is valid before
7 Certain SoC are missing the middle part gpios in consecutive pins,
8 it's better to check if mtk_pin_desc is a valid pin for the extensibility
10 Signed-off-by: Sam Shih <sam.shih@mediatek.com>
11 Acked-by: Sean Wang <sean.wang@mediatek.com>
12 Link: https://lore.kernel.org/r/20210914085137.31761-5-sam.shih@mediatek.com
13 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
15 drivers/pinctrl/mediatek/pinctrl-moore.c | 18 ++++++++++++++++++
16 1 file changed, 18 insertions(+)
18 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c
19 +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
20 @@ -60,6 +60,8 @@ static int mtk_pinmux_set_mux(struct pin
21 int pin = grp->pins[i];
23 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
27 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
29 @@ -76,6 +78,8 @@ static int mtk_pinmux_gpio_request_enabl
30 const struct mtk_pin_desc *desc;
32 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
36 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
38 @@ -89,6 +93,8 @@ static int mtk_pinmux_gpio_set_direction
39 const struct mtk_pin_desc *desc;
41 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
45 /* hardware would take 0 as input direction */
46 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input);
47 @@ -103,6 +109,8 @@ static int mtk_pinconf_get(struct pinctr
48 const struct mtk_pin_desc *desc;
50 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
55 case PIN_CONFIG_BIAS_DISABLE:
56 @@ -218,6 +226,8 @@ static int mtk_pinconf_set(struct pinctr
59 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
63 for (cfg = 0; cfg < num_configs; cfg++) {
64 param = pinconf_to_config_param(configs[cfg]);
65 @@ -435,6 +445,8 @@ static int mtk_gpio_get(struct gpio_chip
68 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
72 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
74 @@ -449,6 +461,10 @@ static void mtk_gpio_set(struct gpio_chi
75 const struct mtk_pin_desc *desc;
77 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
79 + dev_err(hw->dev, "Failed to set gpio %d\n", gpio);
83 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
85 @@ -490,6 +506,8 @@ static int mtk_gpio_set_config(struct gp
88 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
93 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE ||