pinctrl: sh-pfc: Implement pinconf power-source param for voltage switching
authorBen Hutchings <ben.hutchings@codethink.co.uk>
Tue, 30 Jun 2015 16:53:59 +0000 (17:53 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 24 Aug 2015 08:44:54 +0000 (10:44 +0200)
The pfc in the R8A7790 (and probably others in the R-Car gen 2 family)
supports switching SDHI signals between 3.3V and 1.8V nominal voltage,
and the SD driver should do that when switching to and from UHS modes.

Add a flag for pins that have configurable I/O voltage and SoC
operations to get and set the nominal voltage.  Implement the pinconf
power-source parameter using these operations.

Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Documentation/devicetree/bindings/pinctrl/renesas,pfc-pinctrl.txt
drivers/pinctrl/sh-pfc/pinctrl.c
drivers/pinctrl/sh-pfc/sh_pfc.h

index e089142..9496934 100644 (file)
@@ -71,7 +71,9 @@ Pin Configuration Node Properties:
 
 The pin configuration parameters use the generic pinconf bindings defined in
 pinctrl-bindings.txt in this directory. The supported parameters are
-bias-disable, bias-pull-up and bias-pull-down.
+bias-disable, bias-pull-up, bias-pull-down and power-source. For pins that
+have a configurable I/O voltage, the power-source value should be the
+nominal I/O voltage in millivolts.
 
 
 GPIO
index 6fe7459..863c3e3 100644 (file)
@@ -491,6 +491,9 @@ static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
        case PIN_CONFIG_BIAS_PULL_DOWN:
                return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
 
+       case PIN_CONFIG_POWER_SOURCE:
+               return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE;
+
        default:
                return false;
        }
@@ -503,7 +506,6 @@ static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
        struct sh_pfc *pfc = pmx->pfc;
        enum pin_config_param param = pinconf_to_config_param(*config);
        unsigned long flags;
-       unsigned int bias;
 
        if (!sh_pfc_pinconf_validate(pfc, _pin, param))
                return -ENOTSUPP;
@@ -511,7 +513,9 @@ static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
        switch (param) {
        case PIN_CONFIG_BIAS_DISABLE:
        case PIN_CONFIG_BIAS_PULL_UP:
-       case PIN_CONFIG_BIAS_PULL_DOWN:
+       case PIN_CONFIG_BIAS_PULL_DOWN: {
+               unsigned int bias;
+
                if (!pfc->info->ops || !pfc->info->ops->get_bias)
                        return -ENOTSUPP;
 
@@ -524,6 +528,24 @@ static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
 
                *config = 0;
                break;
+       }
+
+       case PIN_CONFIG_POWER_SOURCE: {
+               int ret;
+
+               if (!pfc->info->ops || !pfc->info->ops->get_io_voltage)
+                       return -ENOTSUPP;
+
+               spin_lock_irqsave(&pfc->lock, flags);
+               ret = pfc->info->ops->get_io_voltage(pfc, _pin);
+               spin_unlock_irqrestore(&pfc->lock, flags);
+
+               if (ret < 0)
+                       return ret;
+
+               *config = ret;
+               break;
+       }
 
        default:
                return -ENOTSUPP;
@@ -560,6 +582,24 @@ static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
 
                        break;
 
+               case PIN_CONFIG_POWER_SOURCE: {
+                       unsigned int arg =
+                               pinconf_to_config_argument(configs[i]);
+                       int ret;
+
+                       if (!pfc->info->ops || !pfc->info->ops->set_io_voltage)
+                               return -ENOTSUPP;
+
+                       spin_lock_irqsave(&pfc->lock, flags);
+                       ret = pfc->info->ops->set_io_voltage(pfc, _pin, arg);
+                       spin_unlock_irqrestore(&pfc->lock, flags);
+
+                       if (ret)
+                               return ret;
+
+                       break;
+               }
+
                default:
                        return -ENOTSUPP;
                }
index c7508d5..734f7a9 100644 (file)
@@ -12,6 +12,7 @@
 #define __SH_PFC_H
 
 #include <linux/bug.h>
+#include <linux/pinctrl/pinconf-generic.h>
 #include <linux/stringify.h>
 
 enum {
@@ -26,6 +27,7 @@ enum {
 #define SH_PFC_PIN_CFG_OUTPUT          (1 << 1)
 #define SH_PFC_PIN_CFG_PULL_UP         (1 << 2)
 #define SH_PFC_PIN_CFG_PULL_DOWN       (1 << 3)
+#define SH_PFC_PIN_CFG_IO_VOLTAGE      (1 << 4)
 #define SH_PFC_PIN_CFG_NO_GPIO         (1 << 31)
 
 struct sh_pfc_pin {
@@ -121,6 +123,9 @@ struct sh_pfc_soc_operations {
        unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
        void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
                         unsigned int bias);
+       int (*get_io_voltage)(struct sh_pfc *pfc, unsigned int pin);
+       int (*set_io_voltage)(struct sh_pfc *pfc, unsigned int pin,
+                             u16 voltage_mV);
 };
 
 struct sh_pfc_soc_info {