]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: mediatek: add support for MTK_PULL_PD_TYPE
authorDaniel Golle <daniel@makrotopia.org>
Tue, 17 Dec 2024 08:54:26 +0000 (09:54 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 27 Dec 2024 08:21:48 +0000 (09:21 +0100)
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>
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h

index 54301fbba524af52cff3700e646d1aa15d4cf0ed..7b704cc55c9fdfdf1154840f5f3bd9777605f3fe 100644 (file)
@@ -573,7 +573,7 @@ EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_rev1);
  */
 static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
                                const struct mtk_pin_desc *desc,
-                               u32 pullup, u32 arg)
+                               u32 pullup, u32 arg, bool pd_only)
 {
        int err, pu, pd;
 
@@ -587,18 +587,34 @@ static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
                pu = 0;
                pd = 1;
        } else {
-               err = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
-       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
-       if (err)
-               goto out;
+       if (!pd_only) {
+               err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
+               if (err)
+                       return err;
+       }
 
-       err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
+       return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
+}
+
+static int mtk_pinconf_bias_set_pd(struct mtk_pinctrl *hw,
+                               const struct mtk_pin_desc *desc,
+                               u32 pullup, u32 arg)
+{
+       int err, pd;
+
+       if (arg != MTK_DISABLE && arg != MTK_ENABLE)
+               return -EINVAL;
+
+       if (arg == MTK_DISABLE || pullup)
+               pd = 0;
+       else if (!pullup)
+               pd = 1;
+
+       return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
 
-out:
-       return err;
 }
 
 static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw,
@@ -737,7 +753,7 @@ static int mtk_pinconf_bias_set_pu_pd_rsel(struct mtk_pinctrl *hw,
                        return err;
        }
 
-       return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable);
+       return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable, false);
 }
 
 int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
@@ -758,8 +774,14 @@ int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
                        return 0;
        }
 
+       if (try_all_type & MTK_PULL_PD_TYPE) {
+               err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, true);
+               if (!err)
+                       return err;
+       }
+
        if (try_all_type & MTK_PULL_PU_PD_TYPE) {
-               err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
+               err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, false);
                if (!err)
                        return 0;
        }
@@ -878,6 +900,29 @@ out:
        return err;
 }
 
+static int mtk_pinconf_bias_get_pd(struct mtk_pinctrl *hw,
+                               const struct mtk_pin_desc *desc,
+                               u32 *pullup, u32 *enable)
+{
+       int err, pd;
+
+       err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
+       if (err)
+               goto out;
+
+       if (pd == 0) {
+               *pullup = 0;
+               *enable = MTK_DISABLE;
+       } else if (pd == 1) {
+               *pullup = 0;
+               *enable = MTK_ENABLE;
+       } else
+               err = -EINVAL;
+
+out:
+       return err;
+}
+
 static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw,
                                const struct mtk_pin_desc *desc,
                                u32 *pullup, u32 *enable)
@@ -947,6 +992,12 @@ int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
                        return 0;
        }
 
+       if (try_all_type & MTK_PULL_PD_TYPE) {
+               err = mtk_pinconf_bias_get_pd(hw, desc, pullup, enable);
+               if (!err)
+                       return err;
+       }
+
        if (try_all_type & MTK_PULL_PU_PD_TYPE) {
                err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
                if (!err)
index 23688ca6d04e81c2af67cb15062a0f3726b844fe..9c271dc2b5218c19a52ec01d6f993c807bd3a9ad 100644 (file)
@@ -24,6 +24,7 @@
  * turned on/off itself. But it can't be selected pull up/down
  */
 #define MTK_PULL_RSEL_TYPE             BIT(3)
+#define MTK_PULL_PD_TYPE        BIT(4)
 /* MTK_PULL_PU_PD_RSEL_TYPE is a type which is controlled by
  * MTK_PULL_PU_PD_TYPE and MTK_PULL_RSEL_TYPE.
  */