aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2011-11-14 04:06:22 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-01-03 03:10:01 -0500
commit542e704f3ffee1dc4539c9e8191e4dc215220f5e (patch)
treeda2f8aae8bedb6e3216b4808dc743eb94c3270e3 /drivers/pinctrl
parent75d6642a3ee1dfe2552028997cdcc2c4207bec8f (diff)
pinctrl: GPIO direction support for muxing
When requesting a single GPIO pin to be muxed in, some controllers will need to poke a different value into the control register depending on whether the pin will be used for GPIO output or GPIO input. So create pinmux counterparts to gpio_direction_[input|output] in the pinctrl framework. ChangeLog v1->v2: - This also amends the documentation to make it clear the this function and associated machinery is *ONLY* intended as a backend to gpiolib machinery, not for everyone and his dog to start playing around with pins. ChangeLog v2->v3: - Don't pass an argument to the common request function, instead provide pinmux_* counterparts to the gpio_direction_[input|output] calls, simpler and anyone can understand it. ChangeLog v3->v4: - Fix numerous spelling mistakes and dangling text in documentation. Add Ack and Rewewed-by. Cc: Igor Grinberg <grinberg@compulab.co.il> Acked-by: Stephen Warren <swarren@nvidia.com> Reviewed-by: Thomas Abraham <thomas.abraham@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/pinmux.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 92aa13ee2208..f3e4f031fe1c 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -214,6 +214,10 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
214/** 214/**
215 * pinmux_request_gpio() - request a single pin to be muxed in as GPIO 215 * pinmux_request_gpio() - request a single pin to be muxed in as GPIO
216 * @gpio: the GPIO pin number from the GPIO subsystem number space 216 * @gpio: the GPIO pin number from the GPIO subsystem number space
217 *
218 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
219 * as part of their gpio_request() semantics, platforms and individual drivers
220 * shall *NOT* request GPIO pins to be muxed in.
217 */ 221 */
218int pinmux_request_gpio(unsigned gpio) 222int pinmux_request_gpio(unsigned gpio)
219{ 223{
@@ -249,6 +253,10 @@ EXPORT_SYMBOL_GPL(pinmux_request_gpio);
249/** 253/**
250 * pinmux_free_gpio() - free a single pin, currently used as GPIO 254 * pinmux_free_gpio() - free a single pin, currently used as GPIO
251 * @gpio: the GPIO pin number from the GPIO subsystem number space 255 * @gpio: the GPIO pin number from the GPIO subsystem number space
256 *
257 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
258 * as part of their gpio_free() semantics, platforms and individual drivers
259 * shall *NOT* request GPIO pins to be muxed out.
252 */ 260 */
253void pinmux_free_gpio(unsigned gpio) 261void pinmux_free_gpio(unsigned gpio)
254{ 262{
@@ -270,6 +278,59 @@ void pinmux_free_gpio(unsigned gpio)
270} 278}
271EXPORT_SYMBOL_GPL(pinmux_free_gpio); 279EXPORT_SYMBOL_GPL(pinmux_free_gpio);
272 280
281static int pinmux_gpio_direction(unsigned gpio, bool input)
282{
283 struct pinctrl_dev *pctldev;
284 struct pinctrl_gpio_range *range;
285 const struct pinmux_ops *ops;
286 int ret;
287 int pin;
288
289 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
290 if (ret)
291 return ret;
292
293 ops = pctldev->desc->pmxops;
294
295 /* Convert to the pin controllers number space */
296 pin = gpio - range->base + range->pin_base;
297
298 if (ops->gpio_set_direction)
299 ret = ops->gpio_set_direction(pctldev, range, pin, input);
300 else
301 ret = 0;
302
303 return ret;
304}
305
306/**
307 * pinmux_gpio_direction_input() - request a GPIO pin to go into input mode
308 * @gpio: the GPIO pin number from the GPIO subsystem number space
309 *
310 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
311 * as part of their gpio_direction_input() semantics, platforms and individual
312 * drivers shall *NOT* touch pinmux GPIO calls.
313 */
314int pinmux_gpio_direction_input(unsigned gpio)
315{
316 return pinmux_gpio_direction(gpio, true);
317}
318EXPORT_SYMBOL_GPL(pinmux_gpio_direction_input);
319
320/**
321 * pinmux_gpio_direction_output() - request a GPIO pin to go into output mode
322 * @gpio: the GPIO pin number from the GPIO subsystem number space
323 *
324 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
325 * as part of their gpio_direction_output() semantics, platforms and individual
326 * drivers shall *NOT* touch pinmux GPIO calls.
327 */
328int pinmux_gpio_direction_output(unsigned gpio)
329{
330 return pinmux_gpio_direction(gpio, false);
331}
332EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output);
333
273/** 334/**
274 * pinmux_register_mappings() - register a set of pinmux mappings 335 * pinmux_register_mappings() - register a set of pinmux mappings
275 * @maps: the pinmux mappings table to register 336 * @maps: the pinmux mappings table to register