Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: mediatek: add support for MTK_PULL_PD_TYPE

The MediaTek MT7988 SoC got some pins which only got configurable
pull-down but unlike previous designs there is no pull-up option.
Add new type MTK_PULL_PD_TYPE to support configuring such pins.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/20241217085435.9586-2-linux@fw-web.de
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Daniel Golle and committed by
Linus Walleij
1673d720 1c679926

+63 -11
+62 -11
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
··· 573 573 */ 574 574 static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw, 575 575 const struct mtk_pin_desc *desc, 576 - u32 pullup, u32 arg) 576 + u32 pullup, u32 arg, bool pd_only) 577 577 { 578 578 int err, pu, pd; 579 579 ··· 587 587 pu = 0; 588 588 pd = 1; 589 589 } else { 590 - err = -EINVAL; 591 - goto out; 590 + return -EINVAL; 592 591 } 593 592 594 - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu); 595 - if (err) 596 - goto out; 593 + if (!pd_only) { 594 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu); 595 + if (err) 596 + return err; 597 + } 597 598 598 - err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); 599 + return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); 600 + } 599 601 600 - out: 601 - return err; 602 + static int mtk_pinconf_bias_set_pd(struct mtk_pinctrl *hw, 603 + const struct mtk_pin_desc *desc, 604 + u32 pullup, u32 arg) 605 + { 606 + int err, pd; 607 + 608 + if (arg != MTK_DISABLE && arg != MTK_ENABLE) 609 + return -EINVAL; 610 + 611 + if (arg == MTK_DISABLE || pullup) 612 + pd = 0; 613 + else if (!pullup) 614 + pd = 1; 615 + 616 + return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); 617 + 602 618 } 603 619 604 620 static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw, ··· 753 737 return err; 754 738 } 755 739 756 - return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable); 740 + return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable, false); 757 741 } 758 742 759 743 int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw, ··· 774 758 return 0; 775 759 } 776 760 761 + if (try_all_type & MTK_PULL_PD_TYPE) { 762 + err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, true); 763 + if (!err) 764 + return err; 765 + } 766 + 777 767 if (try_all_type & MTK_PULL_PU_PD_TYPE) { 778 - err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg); 768 + err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, false); 779 769 if (!err) 780 770 return 0; 781 771 } ··· 900 878 return err; 901 879 } 902 880 881 + static int mtk_pinconf_bias_get_pd(struct mtk_pinctrl *hw, 882 + const struct mtk_pin_desc *desc, 883 + u32 *pullup, u32 *enable) 884 + { 885 + int err, pd; 886 + 887 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); 888 + if (err) 889 + goto out; 890 + 891 + if (pd == 0) { 892 + *pullup = 0; 893 + *enable = MTK_DISABLE; 894 + } else if (pd == 1) { 895 + *pullup = 0; 896 + *enable = MTK_ENABLE; 897 + } else 898 + err = -EINVAL; 899 + 900 + out: 901 + return err; 902 + } 903 + 903 904 static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw, 904 905 const struct mtk_pin_desc *desc, 905 906 u32 *pullup, u32 *enable) ··· 990 945 err = mtk_pinconf_bias_get_pu_pd_rsel(hw, desc, pullup, enable); 991 946 if (!err) 992 947 return 0; 948 + } 949 + 950 + if (try_all_type & MTK_PULL_PD_TYPE) { 951 + err = mtk_pinconf_bias_get_pd(hw, desc, pullup, enable); 952 + if (!err) 953 + return err; 993 954 } 994 955 995 956 if (try_all_type & MTK_PULL_PU_PD_TYPE) {
+1
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
··· 24 24 * turned on/off itself. But it can't be selected pull up/down 25 25 */ 26 26 #define MTK_PULL_RSEL_TYPE BIT(3) 27 + #define MTK_PULL_PD_TYPE BIT(4) 27 28 /* MTK_PULL_PU_PD_RSEL_TYPE is a type which is controlled by 28 29 * MTK_PULL_PU_PD_TYPE and MTK_PULL_RSEL_TYPE. 29 30 */