]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
pinctrl: Allow configuration of pins from gpiolib based drivers
authorMika Westerberg <mika.westerberg@linux.intel.com>
Mon, 23 Jan 2017 12:34:33 +0000 (15:34 +0300)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 26 Jan 2017 14:23:01 +0000 (15:23 +0100)
When a GPIO driver is backed by a pinctrl driver the GPIO driver
sometimes needs to call the pinctrl driver to configure certain things,
like whether the pin is used as input or output. In addition to this
there are other configurations applicable to GPIOs such as setting
debounce time of the GPIO.

To support this we introduce a new function pinctrl_gpio_set_config()
that can be used by gpiolib based driver to pass configuration requests
to the backing pinctrl driver.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/core.c
drivers/pinctrl/pinconf.c
drivers/pinctrl/pinconf.h
include/linux/pinctrl/consumer.h

index fb38e208f32dd2199f427207fe6a0e19d3987a5a..597d4641e3483bb52b7ab20e636f9fa22c534c1d 100644 (file)
@@ -688,6 +688,35 @@ int pinctrl_gpio_direction_output(unsigned gpio)
 }
 EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
 
+/**
+ * pinctrl_gpio_set_config() - Apply config to given GPIO pin
+ * @gpio: the GPIO pin number from the GPIO subsystem number space
+ * @config: the configuration to apply to the GPIO
+ *
+ * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
+ * they need to call the underlying pin controller to change GPIO config
+ * (for example set debounce time).
+ */
+int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
+{
+       unsigned long configs[] = { config };
+       struct pinctrl_gpio_range *range;
+       struct pinctrl_dev *pctldev;
+       int ret, pin;
+
+       ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
+       if (ret)
+               return ret;
+
+       mutex_lock(&pctldev->mutex);
+       pin = gpio_to_pin(range, gpio);
+       ret = pinconf_set_config(pctldev, pin, configs, ARRAY_SIZE(configs));
+       mutex_unlock(&pctldev->mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
+
 static struct pinctrl_state *find_state(struct pinctrl *p,
                                        const char *name)
 {
index 799048f3c8d4ec271c5c8849d3a8f17c8ac4e1ff..c1c1ccc58267f58c95ef83f028ce7880c9975d65 100644 (file)
@@ -200,6 +200,18 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
        return 0;
 }
 
+int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
+                      unsigned long *configs, size_t nconfigs)
+{
+       const struct pinconf_ops *ops;
+
+       ops = pctldev->desc->confops;
+       if (!ops)
+               return -ENOTSUPP;
+
+       return ops->pin_config_set(pctldev, pin, configs, nconfigs);
+}
+
 #ifdef CONFIG_DEBUG_FS
 
 static void pinconf_show_config(struct seq_file *s, struct pinctrl_dev *pctldev,
index 55c75780b3b29e2dbefcefba6c9ff5556e70f21c..bf8aff9abf32338eafb783b1ffb62e2742084481 100644 (file)
@@ -20,6 +20,9 @@ int pinconf_map_to_setting(struct pinctrl_map const *map,
 void pinconf_free_setting(struct pinctrl_setting const *setting);
 int pinconf_apply_setting(struct pinctrl_setting const *setting);
 
+int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
+                      unsigned long *configs, size_t nconfigs);
+
 /*
  * You will only be interested in these if you're using PINCONF
  * so don't supply any stubs for these.
@@ -56,6 +59,12 @@ static inline int pinconf_apply_setting(struct pinctrl_setting const *setting)
        return 0;
 }
 
+static inline int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
+                                    unsigned long *configs, size_t nconfigs)
+{
+       return -ENOTSUPP;
+}
+
 #endif
 
 #if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)
index d7e5d608faa7db52543fbb4c7cc221171dca2744..a0f2aba72fa9bc9c27335799e0b428a2c2815113 100644 (file)
@@ -29,6 +29,7 @@ extern int pinctrl_request_gpio(unsigned gpio);
 extern void pinctrl_free_gpio(unsigned gpio);
 extern int pinctrl_gpio_direction_input(unsigned gpio);
 extern int pinctrl_gpio_direction_output(unsigned gpio);
+extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
 
 extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
 extern void pinctrl_put(struct pinctrl *p);
@@ -80,6 +81,11 @@ static inline int pinctrl_gpio_direction_output(unsigned gpio)
        return 0;
 }
 
+static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
+{
+       return 0;
+}
+
 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
 {
        return NULL;