aa9f879e3aa7468f01d3a70cf1892022b7f2d0bd
[openwrt/staging/jow.git] /
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
5 use
6
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
9
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>
14 ---
15 drivers/pinctrl/mediatek/pinctrl-moore.c | 18 ++++++++++++++++++
16 1 file changed, 18 insertions(+)
17
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];
22
23 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
24 + if (!desc->name)
25 + return -ENOTSUPP;
26
27 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
28 pin_modes[i]);
29 @@ -76,6 +78,8 @@ static int mtk_pinmux_gpio_request_enabl
30 const struct mtk_pin_desc *desc;
31
32 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
33 + if (!desc->name)
34 + return -ENOTSUPP;
35
36 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
37 hw->soc->gpio_m);
38 @@ -89,6 +93,8 @@ static int mtk_pinmux_gpio_set_direction
39 const struct mtk_pin_desc *desc;
40
41 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
42 + if (!desc->name)
43 + return -ENOTSUPP;
44
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;
49
50 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
51 + if (!desc->name)
52 + return -ENOTSUPP;
53
54 switch (param) {
55 case PIN_CONFIG_BIAS_DISABLE:
56 @@ -218,6 +226,8 @@ static int mtk_pinconf_set(struct pinctr
57 int cfg, err = 0;
58
59 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
60 + if (!desc->name)
61 + return -ENOTSUPP;
62
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
66 int value, err;
67
68 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
69 + if (!desc->name)
70 + return -ENOTSUPP;
71
72 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
73 if (err)
74 @@ -449,6 +461,10 @@ static void mtk_gpio_set(struct gpio_chi
75 const struct mtk_pin_desc *desc;
76
77 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
78 + if (!desc->name) {
79 + dev_err(hw->dev, "Failed to set gpio %d\n", gpio);
80 + return;
81 + }
82
83 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
84 }
85 @@ -490,6 +506,8 @@ static int mtk_gpio_set_config(struct gp
86 u32 debounce;
87
88 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
89 + if (!desc->name)
90 + return -ENOTSUPP;
91
92 if (!hw->eint ||
93 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE ||