]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
pinctrl: mediatek: add pull related support to pinctrl-mtk-common-v2.c
authorSean Wang <sean.wang@mediatek.com>
Sat, 8 Sep 2018 11:07:24 +0000 (19:07 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 18 Sep 2018 21:52:55 +0000 (14:52 -0700)
Put pull control support related functions to pinctrl-mtk-common-v2.c
as these operations might be different by chips and allow different
type of driver to reuse them.

Signed-off-by: Ryder.Lee <ryder.lee@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/mediatek/pinctrl-moore.c
drivers/pinctrl/mediatek/pinctrl-mt7622.c
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h

index 1f0cd306a940ee222a2d3aab71e7e0c435eec791..d69f024c416d44ed4bb10762b2495ab033ca8be3 100644 (file)
@@ -88,27 +88,34 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
        switch (param) {
        case PIN_CONFIG_BIAS_DISABLE:
-               err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_PU, &val);
-               if (err)
-                       return err;
-
-               err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_PD, &val2);
-               if (err)
-                       return err;
-
-               if (val || val2)
-                       return -EINVAL;
-
+               if (hw->soc->bias_disable_get) {
+                       err = hw->soc->bias_disable_get(hw, desc, &ret);
+                       if (err)
+                               return err;
+               } else {
+                       return -ENOTSUPP;
+               }
                break;
        case PIN_CONFIG_BIAS_PULL_UP:
+               if (hw->soc->bias_get) {
+                       err = hw->soc->bias_get(hw, desc, 1, &ret);
+                       if (err)
+                               return err;
+               } else {
+                       return -ENOTSUPP;
+               }
+               break;
        case PIN_CONFIG_BIAS_PULL_DOWN:
+               if (hw->soc->bias_get) {
+                       err = hw->soc->bias_get(hw, desc, 0, &ret);
+                       if (err)
+                               return err;
+               } else {
+                       return -ENOTSUPP;
+               }
+               break;
        case PIN_CONFIG_SLEW_RATE:
-               reg = (param == PIN_CONFIG_BIAS_PULL_UP) ?
-                     PINCTRL_PIN_REG_PU :
-                     (param == PIN_CONFIG_BIAS_PULL_DOWN) ?
-                     PINCTRL_PIN_REG_PD : PINCTRL_PIN_REG_SR;
-
-               err = mtk_hw_get_value(hw, pin, reg, &val);
+               err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SR, &val);
                if (err)
                        return err;
 
@@ -187,20 +194,31 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 
                switch (param) {
                case PIN_CONFIG_BIAS_DISABLE:
+                       if (hw->soc->bias_disable_set) {
+                               err = hw->soc->bias_disable_set(hw, desc);
+                               if (err)
+                                       return err;
+                       } else {
+                               return -ENOTSUPP;
+                       }
+                       break;
                case PIN_CONFIG_BIAS_PULL_UP:
+                       if (hw->soc->bias_set) {
+                               err = hw->soc->bias_set(hw, desc, 1);
+                               if (err)
+                                       return err;
+                       } else {
+                               return -ENOTSUPP;
+                       }
+                       break;
                case PIN_CONFIG_BIAS_PULL_DOWN:
-                       arg = (param == PIN_CONFIG_BIAS_DISABLE) ? 0 :
-                              (param == PIN_CONFIG_BIAS_PULL_UP) ? 1 : 2;
-
-                       err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_PU,
-                                              arg & 1);
-                       if (err)
-                               goto err;
-
-                       err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_PD,
-                                              !!(arg & 2));
-                       if (err)
-                               goto err;
+                       if (hw->soc->bias_set) {
+                               err = hw->soc->bias_set(hw, desc, 0);
+                               if (err)
+                                       return err;
+                       } else {
+                               return -ENOTSUPP;
+                       }
                        break;
                case PIN_CONFIG_OUTPUT_ENABLE:
                        err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
index f6904a9257550fb22aa00e219716d5c7a84a5f2b..9a5b13a2826ebe1978d093c2373e4c11ffd3403b 100644 (file)
@@ -767,6 +767,10 @@ static const struct mtk_pin_soc mt7622_data = {
        .eint_hw = &mt7622_eint_hw,
        .gpio_m = 1,
        .eint_m = 1,
+       .bias_disable_set = mtk_pinconf_bias_disable_set,
+       .bias_disable_get = mtk_pinconf_bias_disable_get,
+       .bias_set = mtk_pinconf_bias_set,
+       .bias_get = mtk_pinconf_bias_get,
        .drive_set = mtk_pinconf_drive_set,
        .drive_get = mtk_pinconf_drive_get,
 };
index 3f0917967f2a792ae4f9b20ab7ab0fc5cb1e4117..67c95ef85ba984cd5670faa1f69070aca3fec750 100644 (file)
@@ -190,6 +190,84 @@ int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value)
        return 0;
 }
 
+int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
+                                const struct mtk_pin_desc *desc)
+{
+       int err;
+
+       err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU,
+                              MTK_DISABLE);
+       if (err)
+               return err;
+
+       err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+                              MTK_DISABLE);
+       if (err)
+               return err;
+
+       return 0;
+}
+
+int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
+                                const struct mtk_pin_desc *desc, int *res)
+{
+       int v, v2;
+       int err;
+
+       err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PU, &v);
+       if (err)
+               return err;
+
+       err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PD, &v2);
+       if (err)
+               return err;
+
+       if (v == MTK_ENABLE || v2 == MTK_ENABLE)
+               return -EINVAL;
+
+       *res = 1;
+
+       return 0;
+}
+
+int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
+                        const struct mtk_pin_desc *desc, bool pullup)
+{
+       int err, arg;
+
+       arg = pullup ? 1 : 2;
+
+       err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, arg & 1);
+       if (err)
+               return err;
+
+       err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+                              !!(arg & 2));
+       if (err)
+               return err;
+
+       return 0;
+}
+
+int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
+                        const struct mtk_pin_desc *desc, bool pullup, int *res)
+{
+       int reg, err, v;
+
+       reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
+
+       err = mtk_hw_get_value(hw, desc->number, reg, &v);
+       if (err)
+               return err;
+
+       if (!v)
+               return -EINVAL;
+
+       *res = 1;
+
+       return 0;
+}
+
 /* Revision 0 */
 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
                          const struct mtk_pin_desc *desc, u32 arg)
index cbc9a720d516d4fdf174fe35e3f6393a515c88b0..3a55ef70e01b00e5f1915e04ffe10023973a8f5e 100644 (file)
@@ -150,6 +150,15 @@ struct mtk_pin_soc {
        u8                              eint_m;
 
        /* Specific pinconfig operations */
+       int (*bias_disable_set)(struct mtk_pinctrl *hw,
+                               const struct mtk_pin_desc *desc);
+       int (*bias_disable_get)(struct mtk_pinctrl *hw,
+                               const struct mtk_pin_desc *desc, int *res);
+       int (*bias_set)(struct mtk_pinctrl *hw,
+                       const struct mtk_pin_desc *desc, bool pullup);
+       int (*bias_get)(struct mtk_pinctrl *hw,
+                       const struct mtk_pin_desc *desc, bool pullup, int *res);
+
        int (*drive_set)(struct mtk_pinctrl *hw,
                         const struct mtk_pin_desc *desc, u32 arg);
        int (*drive_get)(struct mtk_pinctrl *hw,
@@ -170,6 +179,16 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
 int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value);
 int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value);
 
+int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
+                                const struct mtk_pin_desc *desc);
+int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
+                                const struct mtk_pin_desc *desc, int *res);
+int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
+                        const struct mtk_pin_desc *desc, bool pullup);
+int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
+                        const struct mtk_pin_desc *desc, bool pullup,
+                        int *res);
+
 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
                          const struct mtk_pin_desc *desc, u32 arg);
 int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,