Skip to content

Commit cafe19d

Browse files
Light Hsiehlinusw
authored andcommitted
pinctrl: mediatek: Backward compatible to previous Mediatek's bias-pull usage
Refine mtk_pinconf_set()/mtk_pinconf_get() for backward compatibility to previous MediaTek's bias-pull usage. In PINCTRL_MTK that use pinctrl-mtk-common.c, bias-pull setting for pins with 2 pull resistors can be specified as value for bias-pull-up and bias-pull-down. For example: bias-pull-up = <MTK_PUPD_SET_R1R0_00>; bias-pull-up = <MTK_PUPD_SET_R1R0_01>; bias-pull-up = <MTK_PUPD_SET_R1R0_10>; bias-pull-up = <MTK_PUPD_SET_R1R0_11>; bias-pull-down = <MTK_PUPD_SET_R1R0_00>; bias-pull-down = <MTK_PUPD_SET_R1R0_01>; bias-pull-down = <MTK_PUPD_SET_R1R0_10>; bias-pull-down = <MTK_PUPD_SET_R1R0_11>; On the other hand, PINCTRL_MTK_PARIS use customized properties "mediatek,pull-up-adv" and "mediatek,pull-down-adv" to specify bias-pull setting for pins with 2 pull resistors. This introduce in-compatibility in device tree and increase porting effort to MediaTek's customer that had already used PINCTRL_MTK version. Besides, if customers are not aware of this change and still write devicetree for PINCTRL_MTK version, they may encounter runtime failure with pinctrl and spent time to debug. This patch adds backward compatible to previous MediaTek's bias-pull usage so that Mediatek's customer need not use a new devicetree property name. The rationale is that: changing driver implementation had better leave interface unchanged. Signed-off-by: Light Hsieh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Sean Wang <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 1bea6af commit cafe19d

File tree

5 files changed

+265
-28
lines changed

5 files changed

+265
-28
lines changed

drivers/pinctrl/mediatek/pinctrl-mt6765.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,8 @@ static const struct mtk_pin_soc mt6765_data = {
10721072
.gpio_m = 0,
10731073
.base_names = mt6765_pinctrl_register_base_names,
10741074
.nbase_names = ARRAY_SIZE(mt6765_pinctrl_register_base_names),
1075-
.bias_disable_set = mtk_pinconf_bias_disable_set,
1076-
.bias_disable_get = mtk_pinconf_bias_disable_get,
1077-
.bias_set = mtk_pinconf_bias_set,
1078-
.bias_get = mtk_pinconf_bias_get,
1075+
.bias_set_combo = mtk_pinconf_bias_set_combo,
1076+
.bias_get_combo = mtk_pinconf_bias_get_combo,
10791077
.drive_set = mtk_pinconf_drive_set_raw,
10801078
.drive_get = mtk_pinconf_drive_get_raw,
10811079
.adv_pull_get = mtk_pinconf_adv_pull_get,

drivers/pinctrl/mediatek/pinctrl-mt8183.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,8 @@ static const struct mtk_pin_soc mt8183_data = {
556556
.gpio_m = 0,
557557
.base_names = mt8183_pinctrl_register_base_names,
558558
.nbase_names = ARRAY_SIZE(mt8183_pinctrl_register_base_names),
559-
.bias_disable_set = mtk_pinconf_bias_disable_set_rev1,
560-
.bias_disable_get = mtk_pinconf_bias_disable_get_rev1,
561-
.bias_set = mtk_pinconf_bias_set_rev1,
562-
.bias_get = mtk_pinconf_bias_get_rev1,
559+
.bias_set_combo = mtk_pinconf_bias_set_combo,
560+
.bias_get_combo = mtk_pinconf_bias_get_combo,
563561
.drive_set = mtk_pinconf_drive_set_rev1,
564562
.drive_get = mtk_pinconf_drive_get_rev1,
565563
.adv_pull_get = mtk_pinconf_adv_pull_get,

drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88

9+
#include <dt-bindings/pinctrl/mt65xx.h>
910
#include <linux/device.h>
1011
#include <linux/err.h>
1112
#include <linux/gpio/driver.h>
@@ -517,6 +518,226 @@ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
517518
return 0;
518519
}
519520

521+
/* Combo for the following pull register type:
522+
* 1. PU + PD
523+
* 2. PULLSEL + PULLEN
524+
* 3. PUPD + R0 + R1
525+
*/
526+
static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
527+
const struct mtk_pin_desc *desc,
528+
u32 pullup, u32 arg)
529+
{
530+
int err, pu, pd;
531+
532+
if (arg == MTK_DISABLE) {
533+
pu = 0;
534+
pd = 0;
535+
} else if ((arg == MTK_ENABLE) && pullup) {
536+
pu = 1;
537+
pd = 0;
538+
} else if ((arg == MTK_ENABLE) && !pullup) {
539+
pu = 0;
540+
pd = 1;
541+
} else {
542+
err = -EINVAL;
543+
goto out;
544+
}
545+
546+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
547+
if (err)
548+
goto out;
549+
550+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
551+
552+
out:
553+
return err;
554+
}
555+
556+
static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw,
557+
const struct mtk_pin_desc *desc,
558+
u32 pullup, u32 arg)
559+
{
560+
int err, enable;
561+
562+
if (arg == MTK_DISABLE)
563+
enable = 0;
564+
else if (arg == MTK_ENABLE)
565+
enable = 1;
566+
else {
567+
err = -EINVAL;
568+
goto out;
569+
}
570+
571+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
572+
if (err)
573+
goto out;
574+
575+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
576+
577+
out:
578+
return err;
579+
}
580+
581+
static int mtk_pinconf_bias_set_pupd_r1_r0(struct mtk_pinctrl *hw,
582+
const struct mtk_pin_desc *desc,
583+
u32 pullup, u32 arg)
584+
{
585+
int err, r0, r1;
586+
587+
if ((arg == MTK_DISABLE) || (arg == MTK_PUPD_SET_R1R0_00)) {
588+
pullup = 0;
589+
r0 = 0;
590+
r1 = 0;
591+
} else if (arg == MTK_PUPD_SET_R1R0_01) {
592+
r0 = 1;
593+
r1 = 0;
594+
} else if (arg == MTK_PUPD_SET_R1R0_10) {
595+
r0 = 0;
596+
r1 = 1;
597+
} else if (arg == MTK_PUPD_SET_R1R0_11) {
598+
r0 = 1;
599+
r1 = 1;
600+
} else {
601+
err = -EINVAL;
602+
goto out;
603+
}
604+
605+
/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
606+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup);
607+
if (err)
608+
goto out;
609+
610+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, r0);
611+
if (err)
612+
goto out;
613+
614+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, r1);
615+
616+
out:
617+
return err;
618+
}
619+
620+
static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
621+
const struct mtk_pin_desc *desc,
622+
u32 *pullup, u32 *enable)
623+
{
624+
int err, pu, pd;
625+
626+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu);
627+
if (err)
628+
goto out;
629+
630+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
631+
if (err)
632+
goto out;
633+
634+
if (pu == 0 && pd == 0) {
635+
*pullup = 0;
636+
*enable = MTK_DISABLE;
637+
} else if (pu == 1 && pd == 0) {
638+
*pullup = 1;
639+
*enable = MTK_ENABLE;
640+
} else if (pu == 0 && pd == 1) {
641+
*pullup = 0;
642+
*enable = MTK_ENABLE;
643+
} else
644+
err = -EINVAL;
645+
646+
out:
647+
return err;
648+
}
649+
650+
static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw,
651+
const struct mtk_pin_desc *desc,
652+
u32 *pullup, u32 *enable)
653+
{
654+
int err;
655+
656+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
657+
if (err)
658+
goto out;
659+
660+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
661+
662+
out:
663+
return err;
664+
}
665+
666+
static int mtk_pinconf_bias_get_pupd_r1_r0(struct mtk_pinctrl *hw,
667+
const struct mtk_pin_desc *desc,
668+
u32 *pullup, u32 *enable)
669+
{
670+
int err, r0, r1;
671+
672+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup);
673+
if (err)
674+
goto out;
675+
/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
676+
*pullup = !(*pullup);
677+
678+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &r0);
679+
if (err)
680+
goto out;
681+
682+
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &r1);
683+
if (err)
684+
goto out;
685+
686+
if ((r1 == 0) && (r0 == 0))
687+
*enable = MTK_PUPD_SET_R1R0_00;
688+
else if ((r1 == 0) && (r0 == 1))
689+
*enable = MTK_PUPD_SET_R1R0_01;
690+
else if ((r1 == 1) && (r0 == 0))
691+
*enable = MTK_PUPD_SET_R1R0_10;
692+
else if ((r1 == 1) && (r0 == 1))
693+
*enable = MTK_PUPD_SET_R1R0_11;
694+
else
695+
err = -EINVAL;
696+
697+
out:
698+
return err;
699+
}
700+
701+
int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
702+
const struct mtk_pin_desc *desc,
703+
u32 pullup, u32 arg)
704+
{
705+
int err;
706+
707+
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
708+
if (!err)
709+
goto out;
710+
711+
err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc, pullup, arg);
712+
if (!err)
713+
goto out;
714+
715+
err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg);
716+
717+
out:
718+
return err;
719+
}
720+
721+
int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
722+
const struct mtk_pin_desc *desc,
723+
u32 *pullup, u32 *enable)
724+
{
725+
int err;
726+
727+
err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
728+
if (!err)
729+
goto out;
730+
731+
err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc, pullup, enable);
732+
if (!err)
733+
goto out;
734+
735+
err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable);
736+
737+
out:
738+
return err;
739+
}
740+
520741
/* Revision 0 */
521742
int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
522743
const struct mtk_pin_desc *desc, u32 arg)

drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ struct mtk_pin_soc {
216216
int (*bias_get)(struct mtk_pinctrl *hw,
217217
const struct mtk_pin_desc *desc, bool pullup, int *res);
218218

219+
int (*bias_set_combo)(struct mtk_pinctrl *hw,
220+
const struct mtk_pin_desc *desc, u32 pullup, u32 arg);
221+
int (*bias_get_combo)(struct mtk_pinctrl *hw,
222+
const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg);
223+
219224
int (*drive_set)(struct mtk_pinctrl *hw,
220225
const struct mtk_pin_desc *desc, u32 arg);
221226
int (*drive_get)(struct mtk_pinctrl *hw,
@@ -277,6 +282,12 @@ int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
277282
int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
278283
const struct mtk_pin_desc *desc, bool pullup,
279284
int *res);
285+
int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
286+
const struct mtk_pin_desc *desc,
287+
u32 pullup, u32 enable);
288+
int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
289+
const struct mtk_pin_desc *desc,
290+
u32 *pullup, u32 *enable);
280291

281292
int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
282293
const struct mtk_pin_desc *desc, u32 arg);

drivers/pinctrl/mediatek/pinctrl-paris.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
7878
{
7979
struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
8080
u32 param = pinconf_to_config_param(*config);
81-
int err, reg, ret = 1;
81+
int pullup, err, reg, ret = 1;
8282
const struct mtk_pin_desc *desc;
8383

8484
if (pin >= hw->soc->npins) {
@@ -89,22 +89,31 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
8989

9090
switch (param) {
9191
case PIN_CONFIG_BIAS_DISABLE:
92-
if (hw->soc->bias_disable_get)
93-
err = hw->soc->bias_disable_get(hw, desc, &ret);
94-
else
95-
err = -ENOTSUPP;
96-
break;
9792
case PIN_CONFIG_BIAS_PULL_UP:
98-
if (hw->soc->bias_get)
99-
err = hw->soc->bias_get(hw, desc, 1, &ret);
100-
else
101-
err = -ENOTSUPP;
102-
break;
10393
case PIN_CONFIG_BIAS_PULL_DOWN:
104-
if (hw->soc->bias_get)
105-
err = hw->soc->bias_get(hw, desc, 0, &ret);
106-
else
94+
if (hw->soc->bias_get_combo) {
95+
err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret);
96+
if (err)
97+
goto out;
98+
if (param == PIN_CONFIG_BIAS_DISABLE) {
99+
if (ret == MTK_PUPD_SET_R1R0_00)
100+
ret = MTK_DISABLE;
101+
} else if (param == PIN_CONFIG_BIAS_PULL_UP) {
102+
/* When desire to get pull-up value, return
103+
* error if current setting is pull-down
104+
*/
105+
if (!pullup)
106+
err = -EINVAL;
107+
} else if (param == PIN_CONFIG_BIAS_PULL_DOWN) {
108+
/* When desire to get pull-down value, return
109+
* error if current setting is pull-up
110+
*/
111+
if (pullup)
112+
err = -EINVAL;
113+
}
114+
} else {
107115
err = -ENOTSUPP;
116+
}
108117
break;
109118
case PIN_CONFIG_SLEW_RATE:
110119
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &ret);
@@ -196,20 +205,20 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
196205

197206
switch ((u32)param) {
198207
case PIN_CONFIG_BIAS_DISABLE:
199-
if (hw->soc->bias_disable_set)
200-
err = hw->soc->bias_disable_set(hw, desc);
208+
if (hw->soc->bias_set_combo)
209+
err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE);
201210
else
202211
err = -ENOTSUPP;
203212
break;
204213
case PIN_CONFIG_BIAS_PULL_UP:
205-
if (hw->soc->bias_set)
206-
err = hw->soc->bias_set(hw, desc, 1);
214+
if (hw->soc->bias_set_combo)
215+
err = hw->soc->bias_set_combo(hw, desc, 1, arg);
207216
else
208217
err = -ENOTSUPP;
209218
break;
210219
case PIN_CONFIG_BIAS_PULL_DOWN:
211-
if (hw->soc->bias_set)
212-
err = hw->soc->bias_set(hw, desc, 0);
220+
if (hw->soc->bias_set_combo)
221+
err = hw->soc->bias_set_combo(hw, desc, 0, arg);
213222
else
214223
err = -ENOTSUPP;
215224
break;

0 commit comments

Comments
 (0)