f130fdbc566909be814bcd47d81cec6bd830ec15
[openwrt/staging/ldir.git] /
1 From fae82621ac33e2a4a96220c56e90d1ec6237d394 Mon Sep 17 00:00:00 2001
2 From: Sam Shih <sam.shih@mediatek.com>
3 Date: Sun, 6 Nov 2022 09:01:12 +0100
4 Subject: [PATCH] pinctrl: mediatek: extend pinctrl-moore to support new bias
5 functions
6
7 Commit fb34a9ae383a ("pinctrl: mediatek: support rsel feature")
8 introduced SoC specify 'pull_type' attribute to mtk_pinconf_bias_set_combo
9 and mtk_pinconf_bias_get_combo, and make the functions able to support
10 almost all Mediatek SoCs that use pinctrl-mtk-common-v2.c.
11
12 This patch enables pinctrl_moore to support these functions.
13
14 Signed-off-by: Sam Shih <sam.shih@mediatek.com>
15 Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
16 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
17 Link: https://lore.kernel.org/r/20221106080114.7426-6-linux@fw-web.de
18 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
19 ---
20 drivers/pinctrl/mediatek/pinctrl-moore.c | 49 ++++++++++++++++++++----
21 1 file changed, 42 insertions(+), 7 deletions(-)
22
23 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c
24 +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
25 @@ -8,6 +8,7 @@
26 *
27 */
28
29 +#include <dt-bindings/pinctrl/mt65xx.h>
30 #include <linux/gpio/driver.h>
31 #include "pinctrl-moore.h"
32
33 @@ -105,7 +106,7 @@ static int mtk_pinconf_get(struct pinctr
34 {
35 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
36 u32 param = pinconf_to_config_param(*config);
37 - int val, val2, err, reg, ret = 1;
38 + int val, val2, err, pullup, reg, ret = 1;
39 const struct mtk_pin_desc *desc;
40
41 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
42 @@ -114,7 +115,13 @@ static int mtk_pinconf_get(struct pinctr
43
44 switch (param) {
45 case PIN_CONFIG_BIAS_DISABLE:
46 - if (hw->soc->bias_disable_get) {
47 + if (hw->soc->bias_get_combo) {
48 + err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret);
49 + if (err)
50 + return err;
51 + if (ret != MTK_PUPD_SET_R1R0_00 && ret != MTK_DISABLE)
52 + return -EINVAL;
53 + } else if (hw->soc->bias_disable_get) {
54 err = hw->soc->bias_disable_get(hw, desc, &ret);
55 if (err)
56 return err;
57 @@ -123,7 +130,15 @@ static int mtk_pinconf_get(struct pinctr
58 }
59 break;
60 case PIN_CONFIG_BIAS_PULL_UP:
61 - if (hw->soc->bias_get) {
62 + if (hw->soc->bias_get_combo) {
63 + err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret);
64 + if (err)
65 + return err;
66 + if (ret == MTK_PUPD_SET_R1R0_00 || ret == MTK_DISABLE)
67 + return -EINVAL;
68 + if (!pullup)
69 + return -EINVAL;
70 + } else if (hw->soc->bias_get) {
71 err = hw->soc->bias_get(hw, desc, 1, &ret);
72 if (err)
73 return err;
74 @@ -132,7 +147,15 @@ static int mtk_pinconf_get(struct pinctr
75 }
76 break;
77 case PIN_CONFIG_BIAS_PULL_DOWN:
78 - if (hw->soc->bias_get) {
79 + if (hw->soc->bias_get_combo) {
80 + err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret);
81 + if (err)
82 + return err;
83 + if (ret == MTK_PUPD_SET_R1R0_00 || ret == MTK_DISABLE)
84 + return -EINVAL;
85 + if (pullup)
86 + return -EINVAL;
87 + } else if (hw->soc->bias_get) {
88 err = hw->soc->bias_get(hw, desc, 0, &ret);
89 if (err)
90 return err;
91 @@ -235,7 +258,11 @@ static int mtk_pinconf_set(struct pinctr
92
93 switch (param) {
94 case PIN_CONFIG_BIAS_DISABLE:
95 - if (hw->soc->bias_disable_set) {
96 + if (hw->soc->bias_set_combo) {
97 + err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE);
98 + if (err)
99 + return err;
100 + } else if (hw->soc->bias_disable_set) {
101 err = hw->soc->bias_disable_set(hw, desc);
102 if (err)
103 return err;
104 @@ -244,7 +271,11 @@ static int mtk_pinconf_set(struct pinctr
105 }
106 break;
107 case PIN_CONFIG_BIAS_PULL_UP:
108 - if (hw->soc->bias_set) {
109 + if (hw->soc->bias_set_combo) {
110 + err = hw->soc->bias_set_combo(hw, desc, 1, arg);
111 + if (err)
112 + return err;
113 + } else if (hw->soc->bias_set) {
114 err = hw->soc->bias_set(hw, desc, 1);
115 if (err)
116 return err;
117 @@ -253,7 +284,11 @@ static int mtk_pinconf_set(struct pinctr
118 }
119 break;
120 case PIN_CONFIG_BIAS_PULL_DOWN:
121 - if (hw->soc->bias_set) {
122 + if (hw->soc->bias_set_combo) {
123 + err = hw->soc->bias_set_combo(hw, desc, 0, arg);
124 + if (err)
125 + return err;
126 + } else if (hw->soc->bias_set) {
127 err = hw->soc->bias_set(hw, desc, 0);
128 if (err)
129 return err;