summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2017-01-23 07:34:33 -0500
committerLinus Walleij <linus.walleij@linaro.org>2017-01-26 09:23:01 -0500
commit15381bc7c7f52d56f87c56dd7c948ad78704b852 (patch)
tree5c01f17ccd72d81802efdaf5da1751ee98d5f1ac /drivers/pinctrl
parent58957d2edfa19e9b8f80385ba042495058e5e60e (diff)
pinctrl: Allow configuration of pins from gpiolib based drivers
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>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/core.c29
-rw-r--r--drivers/pinctrl/pinconf.c12
-rw-r--r--drivers/pinctrl/pinconf.h9
3 files changed, 50 insertions, 0 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index fb38e208f32d..597d4641e348 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -688,6 +688,35 @@ int pinctrl_gpio_direction_output(unsigned gpio)
688} 688}
689EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); 689EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
690 690
691/**
692 * pinctrl_gpio_set_config() - Apply config to given GPIO pin
693 * @gpio: the GPIO pin number from the GPIO subsystem number space
694 * @config: the configuration to apply to the GPIO
695 *
696 * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
697 * they need to call the underlying pin controller to change GPIO config
698 * (for example set debounce time).
699 */
700int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
701{
702 unsigned long configs[] = { config };
703 struct pinctrl_gpio_range *range;
704 struct pinctrl_dev *pctldev;
705 int ret, pin;
706
707 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
708 if (ret)
709 return ret;
710
711 mutex_lock(&pctldev->mutex);
712 pin = gpio_to_pin(range, gpio);
713 ret = pinconf_set_config(pctldev, pin, configs, ARRAY_SIZE(configs));
714 mutex_unlock(&pctldev->mutex);
715
716 return ret;
717}
718EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
719
691static struct pinctrl_state *find_state(struct pinctrl *p, 720static struct pinctrl_state *find_state(struct pinctrl *p,
692 const char *name) 721 const char *name)
693{ 722{
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index 799048f3c8d4..c1c1ccc58267 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -200,6 +200,18 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
200 return 0; 200 return 0;
201} 201}
202 202
203int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
204 unsigned long *configs, size_t nconfigs)
205{
206 const struct pinconf_ops *ops;
207
208 ops = pctldev->desc->confops;
209 if (!ops)
210 return -ENOTSUPP;
211
212 return ops->pin_config_set(pctldev, pin, configs, nconfigs);
213}
214
203#ifdef CONFIG_DEBUG_FS 215#ifdef CONFIG_DEBUG_FS
204 216
205static void pinconf_show_config(struct seq_file *s, struct pinctrl_dev *pctldev, 217static void pinconf_show_config(struct seq_file *s, struct pinctrl_dev *pctldev,
diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h
index 55c75780b3b2..bf8aff9abf32 100644
--- a/drivers/pinctrl/pinconf.h
+++ b/drivers/pinctrl/pinconf.h
@@ -20,6 +20,9 @@ int pinconf_map_to_setting(struct pinctrl_map const *map,
20void pinconf_free_setting(struct pinctrl_setting const *setting); 20void pinconf_free_setting(struct pinctrl_setting const *setting);
21int pinconf_apply_setting(struct pinctrl_setting const *setting); 21int pinconf_apply_setting(struct pinctrl_setting const *setting);
22 22
23int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
24 unsigned long *configs, size_t nconfigs);
25
23/* 26/*
24 * You will only be interested in these if you're using PINCONF 27 * You will only be interested in these if you're using PINCONF
25 * so don't supply any stubs for these. 28 * so don't supply any stubs for these.
@@ -56,6 +59,12 @@ static inline int pinconf_apply_setting(struct pinctrl_setting const *setting)
56 return 0; 59 return 0;
57} 60}
58 61
62static inline int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
63 unsigned long *configs, size_t nconfigs)
64{
65 return -ENOTSUPP;
66}
67
59#endif 68#endif
60 69
61#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS) 70#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)