pinctrl: max77620: add support to configure pull up/down
Laxman Dewangan [Fri, 24 Apr 2015 11:19:36 +0000 (16:19 +0530)]
Add support to configure pull up and down of GPIOs pins.

Change-Id: Id772048686da6211fecfcad37188b6b56b631ef0
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/735621
GVS: Gerrit_Virtual_Submit

Documentation/devicetree/bindings/mfd/max77620.txt
drivers/pinctrl/pinctrl-max77620.c

index 63f3d9c..47b5018 100644 (file)
@@ -82,7 +82,8 @@ is required:
                                gpio6, gpio7
 
                Optional properties:
-                       function, drive-push-pull, drive-open-drain.
+                       function, drive-push-pull, drive-open-drain,
+                       bias-pull-up, bias-pull-down.
                                Definitions are in the pinmux dt binding
                        devicetree/bindings/pinctrl/pinctrl-bindings.txt
                        Absense of properties will leave the configuration
index ea049e0..715706b 100644 (file)
@@ -96,6 +96,7 @@ struct max77620_pingroup {
 
 struct max77620_pin_info {
        enum max77620_pin_ppdrv drv_type;
+       int pull_config;
 };
 
 struct max77620_pctrl_info {
@@ -299,7 +300,9 @@ static int max77620_pinconf_get(struct pinctrl_dev *pctldev,
        struct max77620_pctrl_info *max77620_pci =
                                        pinctrl_dev_get_drvdata(pctldev);
        enum pin_config_param param = pinconf_to_config_param(*config);
+       u8 val;
        int arg = 0;
+       int ret;
 
        switch (param) {
        case PIN_CONFIG_DRIVE_OPEN_DRAIN:
@@ -312,6 +315,30 @@ static int max77620_pinconf_get(struct pinctrl_dev *pctldev,
                        arg = 1;
                break;
 
+       case PIN_CONFIG_BIAS_PULL_UP:
+               ret = max77620_reg_read(max77620_pci->max77620->dev,
+                       MAX77620_PWR_SLAVE, MAX77620_REG_PUE_GPIO, &val);
+               if (ret < 0) {
+                       dev_err(max77620_pci->dev,
+                               "Reg PUE_GPIO read failed: %d\n", ret);
+                       return ret;
+               }
+               if (val & BIT(pin))
+                       arg = 1;
+               break;
+
+       case PIN_CONFIG_BIAS_PULL_DOWN:
+               ret = max77620_reg_read(max77620_pci->max77620->dev,
+                       MAX77620_PWR_SLAVE, MAX77620_REG_PDE_GPIO, &val);
+               if (ret < 0) {
+                       dev_err(max77620_pci->dev,
+                               "Reg PDE_GPIO read failed: %d\n", ret);
+                       return ret;
+               }
+               if (val & BIT(pin))
+                       arg = 1;
+               break;
+
        default:
                dev_err(max77620_pci->dev, "Properties not supported\n");
                return -ENOTSUPP;
@@ -330,6 +357,8 @@ static int max77620_pinconf_set(struct pinctrl_dev *pctldev,
        int param = pinconf_to_config_param(config);
        u16 param_val = pinconf_to_config_argument(config);
        unsigned int val;
+       unsigned int pu_val;
+       unsigned int pd_val;
        int mask, shift;
        int addr, ret;
 
@@ -352,6 +381,30 @@ static int max77620_pinconf_set(struct pinctrl_dev *pctldev,
                        MAX77620_PIN_PP_DRV : MAX77620_PIN_OD_DRV;
                break;
 
+       case PIN_CONFIG_BIAS_PULL_UP:
+       case PIN_CONFIG_BIAS_PULL_DOWN:
+               pu_val = (param == PIN_CONFIG_BIAS_PULL_UP) ? BIT(pin) : 0;
+               pd_val = (param == PIN_CONFIG_BIAS_PULL_DOWN) ? BIT(pin) : 0;
+
+               ret = max77620_reg_update(max77620_pci->max77620->dev,
+                       MAX77620_PWR_SLAVE, MAX77620_REG_PUE_GPIO, BIT(pin),
+                       pu_val);
+               if (ret < 0) {
+                       dev_err(max77620_pci->dev,
+                               "Reg PUE_GPIO update failed: %d\n", ret);
+                       return ret;
+               }
+
+               ret = max77620_reg_update(max77620_pci->max77620->dev,
+                       MAX77620_PWR_SLAVE, MAX77620_REG_PDE_GPIO, BIT(pin),
+                       pd_val);
+               if (ret < 0) {
+                       dev_err(max77620_pci->dev,
+                               "Reg PDE_GPIO update failed: %d\n", ret);
+                       return ret;
+               }
+               break;
+
        case MAX77620_FPS_SOURCE:
        case MAX77620_FPS_POWER_ON_PERIOD:
        case MAX77620_FPS_POWER_OFF_PERIOD: