summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinmux.c
diff options
context:
space:
mode:
authorStefan Wahren <stefan.wahren@i2se.com>2019-08-14 07:00:35 -0400
committerLinus Walleij <linus.walleij@linaro.org>2019-08-23 05:09:41 -0400
commit472a61e777fe78cdcb6cb6f25efee0ae9f629aca (patch)
treef3ee044b2383fa012881daf257e6b4ca90ceefd4 /drivers/pinctrl/pinmux.c
parent2dc889a8846d16574794669bbdca7401900695b7 (diff)
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/pinmux.c')
-rw-r--r--drivers/pinctrl/pinmux.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 020e54f843f9..e914f6efd39e 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -71,6 +71,30 @@ int pinmux_validate_map(const struct pinctrl_map *map, int i)
71} 71}
72 72
73/** 73/**
74 * pinmux_can_be_used_for_gpio() - check if a specific pin
75 * is either muxed to a different function or used as gpio.
76 *
77 * @pin: the pin number in the global pin space
78 *
79 * Controllers not defined as strict will always return true,
80 * menaning that the gpio can be used.
81 */
82bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
83{
84 struct pin_desc *desc = pin_desc_get(pctldev, pin);
85 const struct pinmux_ops *ops = pctldev->desc->pmxops;
86
87 /* Can't inspect pin, assume it can be used */
88 if (!desc)
89 return true;
90
91 if (ops->strict && desc->mux_usecount)
92 return false;
93
94 return !(ops->strict && !!desc->gpio_owner);
95}
96
97/**
74 * pin_request() - request a single pin to be muxed in, typically for GPIO 98 * pin_request() - request a single pin to be muxed in, typically for GPIO
75 * @pin: the pin number in the global pin space 99 * @pin: the pin number in the global pin space
76 * @owner: a representation of the owner of this pin; typically the device 100 * @owner: a representation of the owner of this pin; typically the device