]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
pinctrl: mediatek: add support for different pinctrl
authorSam Shih <sam.shih@mediatek.com>
Fri, 10 Jan 2020 08:30:28 +0000 (16:30 +0800)
committerTom Rini <trini@konsulko.com>
Thu, 16 Jan 2020 14:39:45 +0000 (09:39 -0500)
Due to the pinctrl hardware of MT7622 is difference from others
SoC which using the common part of mediatek pinctrl.
So we need to modify the common part of mediatek pinctrl.

Signed-off-by: Sam Shih <sam.shih@mediatek.com>
Reviewed-by: Ryder Lee <ryder.lee@mediatek.com>
drivers/pinctrl/mediatek/pinctrl-mt7622.c
drivers/pinctrl/mediatek/pinctrl-mt7623.c
drivers/pinctrl/mediatek/pinctrl-mt7629.c
drivers/pinctrl/mediatek/pinctrl-mt8516.c
drivers/pinctrl/mediatek/pinctrl-mt8518.c
drivers/pinctrl/mediatek/pinctrl-mtk-common.c
drivers/pinctrl/mediatek/pinctrl-mtk-common.h

index 2a4bf43c326e1672058f8d34e48f2e2682779557..1aa323c009a16a13b2b05f6648e8f3764ccf4a67 100644 (file)
@@ -728,6 +728,8 @@ static struct mtk_pinctrl_soc mt7622_data = {
        .ngrps = ARRAY_SIZE(mt7622_groups),
        .funcs = mt7622_functions,
        .nfuncs = ARRAY_SIZE(mt7622_functions),
+       .gpio_mode = 1,
+       .rev = MTK_PINCTRL_V0,
 };
 
 static int mtk_pinctrl_mt7622_probe(struct udevice *dev)
index fd37dfa442959c1a1e12cc826190cfef61c75659..d58d840e08f2e688aadb657ed0ce08e6c3604d66 100644 (file)
@@ -1242,6 +1242,8 @@ static struct mtk_pinctrl_soc mt7623_data = {
        .ngrps = ARRAY_SIZE(mt7623_groups),
        .funcs = mt7623_functions,
        .nfuncs = ARRAY_SIZE(mt7623_functions),
+       .gpio_mode = 0,
+       .rev = MTK_PINCTRL_V1,
 };
 
 /*
index aa6d1c2d9144f52c1c43f166c076b83c11af0770..37640dd2b6d4981178620d5cbd791ab77087ae19 100644 (file)
@@ -387,6 +387,8 @@ static struct mtk_pinctrl_soc mt7629_data = {
        .ngrps = ARRAY_SIZE(mt7629_groups),
        .funcs = mt7629_functions,
        .nfuncs = ARRAY_SIZE(mt7629_functions),
+       .gpio_mode = 0,
+       .rev = MTK_PINCTRL_V1,
 };
 
 static int mtk_pinctrl_mt7629_probe(struct udevice *dev)
index 829b30e5a2af79a2ad13dfb85fa416185d620999..62e339e9310454174b7e10596d8e3e01a8b71d3c 100644 (file)
@@ -369,6 +369,8 @@ static struct mtk_pinctrl_soc mt8516_data = {
        .ngrps = ARRAY_SIZE(mt8516_groups),
        .funcs = mt8516_functions,
        .nfuncs = ARRAY_SIZE(mt8516_functions),
+       .gpio_mode = 0,
+       .rev = MTK_PINCTRL_V1,
 };
 
 static int mtk_pinctrl_mt8516_probe(struct udevice *dev)
index 8d2cd948f69e7db2dc32f91e4cee787e1f697f05..91427aed4b96699183c9368fa5c551fcfdace5ef 100644 (file)
@@ -389,6 +389,8 @@ static struct mtk_pinctrl_soc mt8518_data = {
        .ngrps = ARRAY_SIZE(mt8518_groups),
        .funcs = mt8518_functions,
        .nfuncs = ARRAY_SIZE(mt8518_functions),
+       .gpio_mode = 0,
+       .rev = MTK_PINCTRL_V1,
 };
 
 static int mtk_pinctrl_mt8518_probe(struct udevice *dev)
index 3004335c57e7228402e6b64957ad518c2c2c6e64..c7351f32bb60d60c1644f6795a881db6666e1051 100644 (file)
@@ -294,7 +294,72 @@ static const struct pinconf_param mtk_conf_params[] = {
        { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
 };
 
-int mtk_pinconf_drive_set(struct udevice *dev, u32 pin, u32 arg)
+
+int mtk_pinconf_bias_set_v0(struct udevice *dev, u32 pin, u32 arg)
+{
+       int err, disable, pullup;
+
+       disable = (arg == PIN_CONFIG_BIAS_DISABLE);
+       pullup = (arg == PIN_CONFIG_BIAS_PULL_UP);
+
+       if (disable) {
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PU, 0);
+               if (err)
+                       return err;
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PD, 0);
+               if (err)
+                       return err;
+
+       } else {
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PU, pullup);
+               if (err)
+                       return err;
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PD, !pullup);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
+int mtk_pinconf_bias_set_v1(struct udevice *dev, u32 pin, u32 arg)
+{
+       int err, disable, pullup;
+
+       disable = (arg == PIN_CONFIG_BIAS_DISABLE);
+       pullup = (arg == PIN_CONFIG_BIAS_PULL_UP);
+
+       if (disable) {
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLEN, 0);
+               if (err)
+                       return err;
+       } else {
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLEN, 1);
+               if (err)
+                       return err;
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLSEL,
+                                      pullup);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
+int mtk_pinconf_input_enable_v1(struct udevice *dev, u32 pin, u32 arg)
+{
+       int err;
+
+       err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_IES, 1);
+       if (err)
+               return err;
+       err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR, 0);
+       if (err)
+               return err;
+       return 0;
+}
+
+int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg)
 {
        struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
        const struct mtk_pin_desc *desc = &priv->soc->pins[pin];
@@ -309,7 +374,30 @@ int mtk_pinconf_drive_set(struct udevice *dev, u32 pin, u32 arg)
         */
        if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
                arg = (arg / tb->step - 1) * tb->scal;
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_E4,
+                                      arg & 0x1);
+               if (err)
+                       return err;
+               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_E8,
+                                      (arg & 0x2) >> 1);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
+
+int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg)
+{
+       struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
+       const struct mtk_pin_desc *desc = &priv->soc->pins[pin];
+       const struct mtk_drive_desc *tb;
+       int err = -ENOTSUPP;
 
+       tb = &mtk_drive[desc->drv_n];
+       if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
+               arg = (arg / tb->step - 1) * tb->scal;
                err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DRV, arg);
                if (err)
                        return err;
@@ -322,21 +410,17 @@ static int mtk_pinconf_set(struct udevice *dev, unsigned int pin,
                           unsigned int param, unsigned int arg)
 {
        int err = 0;
+       struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
+       int rev = priv->soc->rev;
 
        switch (param) {
        case PIN_CONFIG_BIAS_DISABLE:
        case PIN_CONFIG_BIAS_PULL_UP:
        case PIN_CONFIG_BIAS_PULL_DOWN:
-               arg = (param == PIN_CONFIG_BIAS_DISABLE) ? 0 :
-                       (param == PIN_CONFIG_BIAS_PULL_UP) ? 3 : 2;
-
-               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLSEL,
-                                      arg & 1);
-               if (err)
-                       goto err;
-
-               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_PULLEN,
-                                      !!(arg & 2));
+               if (rev == MTK_PINCTRL_V0)
+                       err = mtk_pinconf_bias_set_v0(dev, pin, param);
+               else
+                       err = mtk_pinconf_bias_set_v1(dev, pin, param);
                if (err)
                        goto err;
                break;
@@ -349,10 +433,8 @@ static int mtk_pinconf_set(struct udevice *dev, unsigned int pin,
                        goto err;
                break;
        case PIN_CONFIG_INPUT_ENABLE:
-               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_IES, 1);
-               if (err)
-                       goto err;
-               err = mtk_hw_set_value(dev, pin, PINCTRL_PIN_REG_DIR, 0);
+               if (rev == MTK_PINCTRL_V1)
+                       err = mtk_pinconf_input_enable_v1(dev, pin, param);
                if (err)
                        goto err;
                break;
@@ -381,7 +463,10 @@ static int mtk_pinconf_set(struct udevice *dev, unsigned int pin,
                        goto err;
                break;
        case PIN_CONFIG_DRIVE_STRENGTH:
-               err = mtk_pinconf_drive_set(dev, pin, arg);
+               if (rev == MTK_PINCTRL_V0)
+                       err = mtk_pinconf_drive_set_v0(dev, pin, arg);
+               else
+                       err = mtk_pinconf_drive_set_v1(dev, pin, arg);
                if (err)
                        goto err;
                break;
@@ -475,7 +560,10 @@ static int mtk_gpio_direction_output(struct udevice *dev,
 static int mtk_gpio_request(struct udevice *dev, unsigned int off,
                            const char *label)
 {
-       return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_MODE, 0);
+       struct mtk_pinctrl_priv *priv = dev_get_priv(dev->parent);
+
+       return mtk_hw_set_value(dev->parent, off, PINCTRL_PIN_REG_MODE,
+                               priv->soc->gpio_mode);
 }
 
 static int mtk_gpio_probe(struct udevice *dev)
index 86559f0f1444802b77392196b6c3480b2826e385..e81576145014c1726b9c8753f538130e70a2948a 100644 (file)
@@ -3,10 +3,12 @@
  * Copyright (C) 2018 MediaTek Inc.
  * Author: Ryder Lee <ryder.lee@mediatek.com>
  */
-
 #ifndef __PINCTRL_MEDIATEK_H__
 #define __PINCTRL_MEDIATEK_H__
 
+#define MTK_PINCTRL_V0 0x0
+#define MTK_PINCTRL_V1 0x1
+
 #define MTK_RANGE(_a)          { .range = (_a), .nranges = ARRAY_SIZE(_a), }
 #define MTK_PIN(_number, _name, _drv_n) {                              \
                .number = _number,                                      \
@@ -40,8 +42,12 @@ enum {
        PINCTRL_PIN_REG_DIR,
        PINCTRL_PIN_REG_DI,
        PINCTRL_PIN_REG_DO,
-       PINCTRL_PIN_REG_IES,
        PINCTRL_PIN_REG_SMT,
+       PINCTRL_PIN_REG_PD,
+       PINCTRL_PIN_REG_PU,
+       PINCTRL_PIN_REG_E4,
+       PINCTRL_PIN_REG_E8,
+       PINCTRL_PIN_REG_IES,
        PINCTRL_PIN_REG_PULLEN,
        PINCTRL_PIN_REG_PULLSEL,
        PINCTRL_PIN_REG_DRV,
@@ -161,6 +167,8 @@ struct mtk_pinctrl_soc {
        int ngrps;
        const struct mtk_function_desc *funcs;
        int nfuncs;
+       int gpio_mode;
+       int rev;
 };
 
 /**