summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/mediatek
diff options
context:
space:
mode:
authorSean Wang <sean.wang@mediatek.com>2018-09-08 07:07:29 -0400
committerLinus Walleij <linus.walleij@linaro.org>2018-09-18 17:53:07 -0400
commitea051eb384139bd183757761aa83362f2290996d (patch)
tree9d38b3af43cd12690b63b888b145aa90857e5ec0 /drivers/pinctrl/mediatek
parente7507f57a93a194012e889aead13ea2bdc2e4889 (diff)
pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c
all use pin descriptor instead in pinctrl-mtk-common-v2.c for the consistency and extensibility. Signed-off-by: Sean Wang <sean.wang@mediatek.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/mediatek')
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-moore.c66
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c76
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h6
3 files changed, 88 insertions, 60 deletions
diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 219cfce6d3d9..2f3e3b594f8c 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -54,9 +54,13 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
54 func->name, grp->name); 54 func->name, grp->name);
55 55
56 for (i = 0; i < grp->num_pins; i++) { 56 for (i = 0; i < grp->num_pins; i++) {
57 const struct mtk_pin_desc *desc;
57 int *pin_modes = grp->data; 58 int *pin_modes = grp->data;
59 int pin = grp->pins[i];
58 60
59 mtk_hw_set_value(hw, grp->pins[i], PINCTRL_PIN_REG_MODE, 61 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
62
63 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
60 pin_modes[i]); 64 pin_modes[i]);
61 } 65 }
62 66
@@ -68,8 +72,12 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
68 unsigned int pin) 72 unsigned int pin)
69{ 73{
70 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); 74 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
75 const struct mtk_pin_desc *desc;
76
77 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
71 78
72 return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_MODE, hw->soc->gpio_m); 79 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
80 hw->soc->gpio_m);
73} 81}
74 82
75static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev, 83static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
@@ -77,9 +85,12 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
77 unsigned int pin, bool input) 85 unsigned int pin, bool input)
78{ 86{
79 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); 87 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
88 const struct mtk_pin_desc *desc;
89
90 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
80 91
81 /* hardware would take 0 as input direction */ 92 /* hardware would take 0 as input direction */
82 return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, !input); 93 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input);
83} 94}
84 95
85static int mtk_pinconf_get(struct pinctrl_dev *pctldev, 96static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
@@ -121,7 +132,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
121 } 132 }
122 break; 133 break;
123 case PIN_CONFIG_SLEW_RATE: 134 case PIN_CONFIG_SLEW_RATE:
124 err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SR, &val); 135 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &val);
125 if (err) 136 if (err)
126 return err; 137 return err;
127 138
@@ -131,7 +142,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
131 break; 142 break;
132 case PIN_CONFIG_INPUT_ENABLE: 143 case PIN_CONFIG_INPUT_ENABLE:
133 case PIN_CONFIG_OUTPUT_ENABLE: 144 case PIN_CONFIG_OUTPUT_ENABLE:
134 err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val); 145 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
135 if (err) 146 if (err)
136 return err; 147 return err;
137 148
@@ -142,11 +153,11 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
142 153
143 break; 154 break;
144 case PIN_CONFIG_INPUT_SCHMITT_ENABLE: 155 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
145 err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val); 156 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
146 if (err) 157 if (err)
147 return err; 158 return err;
148 159
149 err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SMT, &val2); 160 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &val2);
150 if (err) 161 if (err)
151 return err; 162 return err;
152 163
@@ -168,7 +179,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
168 reg = (param == MTK_PIN_CONFIG_TDSEL) ? 179 reg = (param == MTK_PIN_CONFIG_TDSEL) ?
169 PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL; 180 PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
170 181
171 err = mtk_hw_get_value(hw, pin, reg, &val); 182 err = mtk_hw_get_value(hw, desc, reg, &val);
172 if (err) 183 if (err)
173 return err; 184 return err;
174 185
@@ -240,12 +251,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
240 } 251 }
241 break; 252 break;
242 case PIN_CONFIG_OUTPUT_ENABLE: 253 case PIN_CONFIG_OUTPUT_ENABLE:
243 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT, 254 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
244 MTK_DISABLE); 255 MTK_DISABLE);
245 if (err) 256 if (err)
246 goto err; 257 goto err;
247 258
248 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, 259 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
249 MTK_OUTPUT); 260 MTK_OUTPUT);
250 if (err) 261 if (err)
251 goto err; 262 goto err;
@@ -253,29 +264,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
253 case PIN_CONFIG_INPUT_ENABLE: 264 case PIN_CONFIG_INPUT_ENABLE:
254 265
255 if (hw->soc->ies_present) { 266 if (hw->soc->ies_present) {
256 mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_IES, 267 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
257 MTK_ENABLE); 268 MTK_ENABLE);
258 } 269 }
259 270
260 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, 271 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
261 MTK_INPUT); 272 MTK_INPUT);
262 if (err) 273 if (err)
263 goto err; 274 goto err;
264 break; 275 break;
265 case PIN_CONFIG_SLEW_RATE: 276 case PIN_CONFIG_SLEW_RATE:
266 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SR, 277 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
267 arg); 278 arg);
268 if (err) 279 if (err)
269 goto err; 280 goto err;
270 281
271 break; 282 break;
272 case PIN_CONFIG_OUTPUT: 283 case PIN_CONFIG_OUTPUT:
273 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, 284 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
274 MTK_OUTPUT); 285 MTK_OUTPUT);
275 if (err) 286 if (err)
276 goto err; 287 goto err;
277 288
278 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DO, 289 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
279 arg); 290 arg);
280 if (err) 291 if (err)
281 goto err; 292 goto err;
@@ -285,12 +296,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
285 * arg = 0: Output mode & SMT disable 296 * arg = 0: Output mode & SMT disable
286 */ 297 */
287 arg = arg ? 2 : 1; 298 arg = arg ? 2 : 1;
288 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, 299 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
289 arg & 1); 300 arg & 1);
290 if (err) 301 if (err)
291 goto err; 302 goto err;
292 303
293 err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT, 304 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
294 !!(arg & 2)); 305 !!(arg & 2));
295 if (err) 306 if (err)
296 goto err; 307 goto err;
@@ -309,7 +320,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
309 reg = (param == MTK_PIN_CONFIG_TDSEL) ? 320 reg = (param == MTK_PIN_CONFIG_TDSEL) ?
310 PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL; 321 PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
311 322
312 err = mtk_hw_set_value(hw, pin, reg, arg); 323 err = mtk_hw_set_value(hw, desc, reg, arg);
313 if (err) 324 if (err)
314 goto err; 325 goto err;
315 break; 326 break;
@@ -419,9 +430,12 @@ static struct pinctrl_desc mtk_desc = {
419static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio) 430static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
420{ 431{
421 struct mtk_pinctrl *hw = gpiochip_get_data(chip); 432 struct mtk_pinctrl *hw = gpiochip_get_data(chip);
433 const struct mtk_pin_desc *desc;
422 int value, err; 434 int value, err;
423 435
424 err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value); 436 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
437
438 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
425 if (err) 439 if (err)
426 return err; 440 return err;
427 441
@@ -431,8 +445,11 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
431static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value) 445static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
432{ 446{
433 struct mtk_pinctrl *hw = gpiochip_get_data(chip); 447 struct mtk_pinctrl *hw = gpiochip_get_data(chip);
448 const struct mtk_pin_desc *desc;
434 449
435 mtk_hw_set_value(hw, gpio, PINCTRL_PIN_REG_DO, !!value); 450 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
451
452 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
436} 453}
437 454
438static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio) 455static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)
@@ -620,6 +637,7 @@ static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
620static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n) 637static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
621{ 638{
622 struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data; 639 struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
640 const struct mtk_pin_desc *desc;
623 struct gpio_chip *gpio_chip; 641 struct gpio_chip *gpio_chip;
624 unsigned int gpio_n; 642 unsigned int gpio_n;
625 int err; 643 int err;
@@ -628,16 +646,18 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
628 if (err) 646 if (err)
629 return err; 647 return err;
630 648
631 err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_MODE, 649 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
650
651 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
632 hw->soc->eint_m); 652 hw->soc->eint_m);
633 if (err) 653 if (err)
634 return err; 654 return err;
635 655
636 err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_DIR, MTK_INPUT); 656 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
637 if (err) 657 if (err)
638 return err; 658 return err;
639 659
640 err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_SMT, MTK_ENABLE); 660 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
641 if (err) 661 if (err)
642 return err; 662 return err;
643 663
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 86eefe899935..ed88b96eadea 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -59,7 +59,8 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set)
59 mtk_w32(pctl, reg, val); 59 mtk_w32(pctl, reg, val);
60} 60}
61 61
62static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin, 62static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
63 const struct mtk_pin_desc *desc,
63 const struct mtk_pin_reg_calc *rc, 64 const struct mtk_pin_reg_calc *rc,
64 struct mtk_pin_field *pfd) 65 struct mtk_pin_field *pfd)
65{ 66{
@@ -70,13 +71,14 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
70 e = c + rc->nranges; 71 e = c + rc->nranges;
71 72
72 while (c < e) { 73 while (c < e) {
73 if (pin >= c->s_pin && pin <= c->e_pin) 74 if (desc->number >= c->s_pin && desc->number <= c->e_pin)
74 break; 75 break;
75 c++; 76 c++;
76 } 77 }
77 78
78 if (c >= e) { 79 if (c >= e) {
79 dev_err(hw->dev, "Out of range for pin = %d\n", pin); 80 dev_err(hw->dev, "Out of range for pin = %d (%s)\n",
81 desc->number, desc->name);
80 return -EINVAL; 82 return -EINVAL;
81 } 83 }
82 84
@@ -84,7 +86,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
84 * if c->fixed is held, that determines the all the pins in the 86 * if c->fixed is held, that determines the all the pins in the
85 * range use the same field with the s_pin. 87 * range use the same field with the s_pin.
86 */ 88 */
87 bits = c->fixed ? c->s_bit : c->s_bit + (pin - c->s_pin) * (c->x_bits); 89 bits = c->fixed ? c->s_bit : c->s_bit +
90 (desc->number - c->s_pin) * (c->x_bits);
88 91
89 /* Fill pfd from bits. For example 32-bit register applied is assumed 92 /* Fill pfd from bits. For example 32-bit register applied is assumed
90 * when c->sz_reg is equal to 32. 93 * when c->sz_reg is equal to 32.
@@ -102,7 +105,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
102 return 0; 105 return 0;
103} 106}
104 107
105static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin, 108static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw,
109 const struct mtk_pin_desc *desc,
106 int field, struct mtk_pin_field *pfd) 110 int field, struct mtk_pin_field *pfd)
107{ 111{
108 const struct mtk_pin_reg_calc *rc; 112 const struct mtk_pin_reg_calc *rc;
@@ -119,7 +123,7 @@ static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
119 return -EINVAL; 123 return -EINVAL;
120 } 124 }
121 125
122 return mtk_hw_pin_field_lookup(hw, pin, rc, pfd); 126 return mtk_hw_pin_field_lookup(hw, desc, rc, pfd);
123} 127}
124 128
125static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l) 129static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
@@ -155,12 +159,13 @@ static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw,
155 *value = (h << nbits_l) | l; 159 *value = (h << nbits_l) | l;
156} 160}
157 161
158int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value) 162int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
163 int field, int value)
159{ 164{
160 struct mtk_pin_field pf; 165 struct mtk_pin_field pf;
161 int err; 166 int err;
162 167
163 err = mtk_hw_pin_field_get(hw, pin, field, &pf); 168 err = mtk_hw_pin_field_get(hw, desc, field, &pf);
164 if (err) 169 if (err)
165 return err; 170 return err;
166 171
@@ -173,12 +178,13 @@ int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
173 return 0; 178 return 0;
174} 179}
175 180
176int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value) 181int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
182 int field, int *value)
177{ 183{
178 struct mtk_pin_field pf; 184 struct mtk_pin_field pf;
179 int err; 185 int err;
180 186
181 err = mtk_hw_pin_field_get(hw, pin, field, &pf); 187 err = mtk_hw_pin_field_get(hw, desc, field, &pf);
182 if (err) 188 if (err)
183 return err; 189 return err;
184 190
@@ -196,12 +202,12 @@ int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
196{ 202{
197 int err; 203 int err;
198 204
199 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, 205 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU,
200 MTK_DISABLE); 206 MTK_DISABLE);
201 if (err) 207 if (err)
202 return err; 208 return err;
203 209
204 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD, 210 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
205 MTK_DISABLE); 211 MTK_DISABLE);
206 if (err) 212 if (err)
207 return err; 213 return err;
@@ -215,11 +221,11 @@ int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
215 int v, v2; 221 int v, v2;
216 int err; 222 int err;
217 223
218 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PU, &v); 224 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v);
219 if (err) 225 if (err)
220 return err; 226 return err;
221 227
222 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PD, &v2); 228 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2);
223 if (err) 229 if (err)
224 return err; 230 return err;
225 231
@@ -238,11 +244,11 @@ int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
238 244
239 arg = pullup ? 1 : 2; 245 arg = pullup ? 1 : 2;
240 246
241 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, arg & 1); 247 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1);
242 if (err) 248 if (err)
243 return err; 249 return err;
244 250
245 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD, 251 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
246 !!(arg & 2)); 252 !!(arg & 2));
247 if (err) 253 if (err)
248 return err; 254 return err;
@@ -257,7 +263,7 @@ int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
257 263
258 reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD; 264 reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
259 265
260 err = mtk_hw_get_value(hw, desc->number, reg, &v); 266 err = mtk_hw_get_value(hw, desc, reg, &v);
261 if (err) 267 if (err)
262 return err; 268 return err;
263 269
@@ -275,7 +281,7 @@ int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
275{ 281{
276 int err; 282 int err;
277 283
278 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, 284 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
279 MTK_DISABLE); 285 MTK_DISABLE);
280 if (err) 286 if (err)
281 return err; 287 return err;
@@ -288,7 +294,7 @@ int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
288{ 294{
289 int v, err; 295 int v, err;
290 296
291 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v); 297 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
292 if (err) 298 if (err)
293 return err; 299 return err;
294 300
@@ -307,12 +313,12 @@ int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
307 313
308 arg = pullup ? MTK_PULLUP : MTK_PULLDOWN; 314 arg = pullup ? MTK_PULLUP : MTK_PULLDOWN;
309 315
310 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, 316 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
311 MTK_ENABLE); 317 MTK_ENABLE);
312 if (err) 318 if (err)
313 return err; 319 return err;
314 320
315 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, arg); 321 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg);
316 if (err) 322 if (err)
317 return err; 323 return err;
318 324
@@ -325,14 +331,14 @@ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
325{ 331{
326 int err, v; 332 int err, v;
327 333
328 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v); 334 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
329 if (err) 335 if (err)
330 return err; 336 return err;
331 337
332 if (v == MTK_DISABLE) 338 if (v == MTK_DISABLE)
333 return -EINVAL; 339 return -EINVAL;
334 340
335 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, &v); 341 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v);
336 if (err) 342 if (err)
337 return err; 343 return err;
338 344
@@ -359,12 +365,12 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
359 */ 365 */
360 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { 366 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
361 arg = (arg / tb->step - 1) * tb->scal; 367 arg = (arg / tb->step - 1) * tb->scal;
362 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E4, 368 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4,
363 arg & 0x1); 369 arg & 0x1);
364 if (err) 370 if (err)
365 return err; 371 return err;
366 372
367 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E8, 373 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8,
368 (arg & 0x2) >> 1); 374 (arg & 0x2) >> 1);
369 if (err) 375 if (err)
370 return err; 376 return err;
@@ -381,11 +387,11 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
381 387
382 tb = &mtk_drive[desc->drv_n]; 388 tb = &mtk_drive[desc->drv_n];
383 389
384 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E4, &val1); 390 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
385 if (err) 391 if (err)
386 return err; 392 return err;
387 393
388 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E8, &val2); 394 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2);
389 if (err) 395 if (err)
390 return err; 396 return err;
391 397
@@ -409,7 +415,7 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
409 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { 415 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
410 arg = (arg / tb->step - 1) * tb->scal; 416 arg = (arg / tb->step - 1) * tb->scal;
411 417
412 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_DRV, 418 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV,
413 arg); 419 arg);
414 if (err) 420 if (err)
415 return err; 421 return err;
@@ -426,7 +432,7 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
426 432
427 tb = &mtk_drive[desc->drv_n]; 433 tb = &mtk_drive[desc->drv_n];
428 434
429 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_DRV, &val1); 435 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
430 if (err) 436 if (err)
431 return err; 437 return err;
432 438
@@ -446,18 +452,18 @@ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
446 * 10K on & 50K (75K) off, when (R0, R1) = (1, 0); 452 * 10K on & 50K (75K) off, when (R0, R1) = (1, 0);
447 * 10K on & 50K (75K) on, when (R0, R1) = (1, 1) 453 * 10K on & 50K (75K) on, when (R0, R1) = (1, 1)
448 */ 454 */
449 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R0, arg & 1); 455 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1);
450 if (err) 456 if (err)
451 return 0; 457 return 0;
452 458
453 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R1, 459 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1,
454 !!(arg & 2)); 460 !!(arg & 2));
455 if (err) 461 if (err)
456 return 0; 462 return 0;
457 463
458 arg = pullup ? 0 : 1; 464 arg = pullup ? 0 : 1;
459 465
460 err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, arg); 466 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg);
461 467
462 return err; 468 return err;
463} 469}
@@ -469,7 +475,7 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
469 u32 t, t2; 475 u32 t, t2;
470 int err; 476 int err;
471 477
472 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, &t); 478 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t);
473 if (err) 479 if (err)
474 return err; 480 return err;
475 481
@@ -477,11 +483,11 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
477 if (pullup ^ !t) 483 if (pullup ^ !t)
478 return -EINVAL; 484 return -EINVAL;
479 485
480 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R0, &t); 486 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t);
481 if (err) 487 if (err)
482 return err; 488 return err;
483 489
484 err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R1, &t2); 490 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2);
485 if (err) 491 if (err)
486 return err; 492 return err;
487 493
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
index d90788b0bd18..6e66bdc4f9e7 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
@@ -192,8 +192,10 @@ struct mtk_pinctrl {
192 192
193void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set); 193void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
194 194
195int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value); 195int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
196int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value); 196 int field, int value);
197int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
198 int field, int *value);
197 199
198int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw, 200int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
199 const struct mtk_pin_desc *desc); 201 const struct mtk_pin_desc *desc);