diff options
author | Stefan Wahren <stefan.wahren@i2se.com> | 2019-08-14 14:00:35 +0300 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2019-08-23 11:09:41 +0200 |
commit | 472a61e777fe78cdcb6cb6f25efee0ae9f629aca (patch) | |
tree | f3ee044b2383fa012881daf257e6b4ca90ceefd4 /drivers/pinctrl/core.c | |
parent | 2dc889a8846d16574794669bbdca7401900695b7 (diff) | |
download | linux-472a61e777fe78cdcb6cb6f25efee0ae9f629aca.tar.bz2 |
pinctrl/gpio: Take MUX usage into account
The user space like gpioinfo only see the GPIO usage but not the
MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want
to know which pin is free/safe to use. So take the MUX usage of
strict pinmux controllers into account to get a more realistic
view for ioctl GPIO_GET_LINEINFO_IOCTL.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
Link: https://lore.kernel.org/r/20190814110035.13451-1-ramon.fried@linux.intel.com
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/core.c')
-rw-r--r-- | drivers/pinctrl/core.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index b70df27874d1..2bbd8ee93507 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, return -EINVAL; } +bool pinctrl_gpio_can_use_line(unsigned gpio) +{ + struct pinctrl_dev *pctldev; + struct pinctrl_gpio_range *range; + bool result; + int pin; + + /* + * Try to obtain GPIO range, if it fails + * we're probably dealing with GPIO driver + * without a backing pin controller - bail out. + */ + if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range)) + return true; + + mutex_lock(&pctldev->mutex); + + /* Convert to the pin controllers number space */ + pin = gpio_to_pin(range, gpio); + + result = pinmux_can_be_used_for_gpio(pctldev, pin); + + mutex_unlock(&pctldev->mutex); + + return result; +} +EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line); + /** * pinctrl_gpio_request() - request a single pin to be used as GPIO * @gpio: the GPIO pin number from the GPIO subsystem number space |