Skip to content

Commit 166bf8a

Browse files
nfrapradolinusw
authored andcommitted
pinctrl: mediatek: common-v2: Fix broken bias-disable for PULL_PU_PD_RSEL_TYPE
Despite its name, commit fed74d7 ("pinctrl: mediatek: common-v2: Fix bias-disable for PULL_PU_PD_RSEL_TYPE") actually broke bias-disable for PULL_PU_PD_RSEL_TYPE. mtk_pinconf_bias_set_combo() tries every bias method supported by the pin until one succeeds. For PULL_PU_PD_RSEL_TYPE pins, before the breaking commit, mtk_pinconf_bias_set_rsel() would be called first to try and set the RSEL value (as well as PU and PD), and if that failed, the only other valid option was that bias-disable was specified, which would then be handled by calling mtk_pinconf_bias_set_pu_pd() and disabling both PU and PD. The breaking commit misunderstood this logic and added an early "return 0" in mtk_pinconf_bias_set_rsel(). The result was that in the bias-disable case, the bias was left unchanged, since by returning success, mtk_pinconf_bias_set_combo() no longer tried calling mtk_pinconf_bias_set_pu_pd() to disable the bias. Since the logic for configuring bias-disable on PULL_PU_PD_RSEL_TYPE pins required mtk_pinconf_bias_set_rsel() to fail first, in that case, an error was printed to the log, eg: mt8195-pinctrl 10005000.pinctrl: Not support rsel value 0 Ohm for pin = 29 (GPIO29) This is what the breaking commit actually got rid of, and likely part of the reason why that commit was thought to be fixing functionality, while in reality it was breaking it. Instead of simply reverting that commit, restore the functionality but in a way that avoids the error from being printed and makes the code less confusing: * Return 0 explicitly if a bias method was successful * Introduce an extra function mtk_pinconf_bias_set_pu_pd_rsel() that calls both mtk_pinconf_bias_set_rsel() (only if needed) and mtk_pinconf_bias_set_pu_pd() * And analogously for the corresponding getters Fixes: fed74d7 ("pinctrl: mediatek: common-v2: Fix bias-disable for PULL_PU_PD_RSEL_TYPE") Signed-off-by: Nícolas F. R. A. Prado <[email protected]> Link: https://lore.kernel.org/20240808-mtk-rsel-bias-disable-fix-v1-1-1b4e85bf596c@collabora.com Signed-off-by: Linus Walleij <[email protected]>
1 parent 1c38a62 commit 166bf8a

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -709,32 +709,35 @@ static int mtk_pinconf_bias_set_rsel(struct mtk_pinctrl *hw,
709709
{
710710
int err, rsel_val;
711711

712-
if (!pullup && arg == MTK_DISABLE)
713-
return 0;
714-
715712
if (hw->rsel_si_unit) {
716713
/* find pin rsel_index from pin_rsel array*/
717714
err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val);
718715
if (err)
719-
goto out;
716+
return err;
720717
} else {
721-
if (arg < MTK_PULL_SET_RSEL_000 ||
722-
arg > MTK_PULL_SET_RSEL_111) {
723-
err = -EINVAL;
724-
goto out;
725-
}
718+
if (arg < MTK_PULL_SET_RSEL_000 || arg > MTK_PULL_SET_RSEL_111)
719+
return -EINVAL;
726720

727721
rsel_val = arg - MTK_PULL_SET_RSEL_000;
728722
}
729723

730-
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_RSEL, rsel_val);
731-
if (err)
732-
goto out;
724+
return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_RSEL, rsel_val);
725+
}
733726

734-
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, MTK_ENABLE);
727+
static int mtk_pinconf_bias_set_pu_pd_rsel(struct mtk_pinctrl *hw,
728+
const struct mtk_pin_desc *desc,
729+
u32 pullup, u32 arg)
730+
{
731+
u32 enable = arg == MTK_DISABLE ? MTK_DISABLE : MTK_ENABLE;
732+
int err;
735733

736-
out:
737-
return err;
734+
if (arg != MTK_DISABLE) {
735+
err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg);
736+
if (err)
737+
return err;
738+
}
739+
740+
return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable);
738741
}
739742

740743
int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
@@ -750,22 +753,22 @@ int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
750753
try_all_type = MTK_PULL_TYPE_MASK;
751754

752755
if (try_all_type & MTK_PULL_RSEL_TYPE) {
753-
err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg);
756+
err = mtk_pinconf_bias_set_pu_pd_rsel(hw, desc, pullup, arg);
754757
if (!err)
755-
return err;
758+
return 0;
756759
}
757760

758761
if (try_all_type & MTK_PULL_PU_PD_TYPE) {
759762
err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
760763
if (!err)
761-
return err;
764+
return 0;
762765
}
763766

764767
if (try_all_type & MTK_PULL_PULLSEL_TYPE) {
765768
err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc,
766769
pullup, arg);
767770
if (!err)
768-
return err;
771+
return 0;
769772
}
770773

771774
if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE)
@@ -803,9 +806,9 @@ static int mtk_rsel_get_si_unit(struct mtk_pinctrl *hw,
803806
return 0;
804807
}
805808

806-
static int mtk_pinconf_bias_get_rsel(struct mtk_pinctrl *hw,
807-
const struct mtk_pin_desc *desc,
808-
u32 *pullup, u32 *enable)
809+
static int mtk_pinconf_bias_get_pu_pd_rsel(struct mtk_pinctrl *hw,
810+
const struct mtk_pin_desc *desc,
811+
u32 *pullup, u32 *enable)
809812
{
810813
int pu, pd, rsel, err;
811814

@@ -939,22 +942,22 @@ int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
939942
try_all_type = MTK_PULL_TYPE_MASK;
940943

941944
if (try_all_type & MTK_PULL_RSEL_TYPE) {
942-
err = mtk_pinconf_bias_get_rsel(hw, desc, pullup, enable);
945+
err = mtk_pinconf_bias_get_pu_pd_rsel(hw, desc, pullup, enable);
943946
if (!err)
944-
return err;
947+
return 0;
945948
}
946949

947950
if (try_all_type & MTK_PULL_PU_PD_TYPE) {
948951
err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
949952
if (!err)
950-
return err;
953+
return 0;
951954
}
952955

953956
if (try_all_type & MTK_PULL_PULLSEL_TYPE) {
954957
err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc,
955958
pullup, enable);
956959
if (!err)
957-
return err;
960+
return 0;
958961
}
959962

960963
if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE)

0 commit comments

Comments
 (0)