diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2011-11-14 04:06:22 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-01-03 03:10:01 -0500 |
commit | 542e704f3ffee1dc4539c9e8191e4dc215220f5e (patch) | |
tree | da2f8aae8bedb6e3216b4808dc743eb94c3270e3 | |
parent | 75d6642a3ee1dfe2552028997cdcc2c4207bec8f (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>
-rw-r--r-- | Documentation/pinctrl.txt | 32 | ||||
-rw-r--r-- | drivers/pinctrl/pinmux.c | 61 | ||||
-rw-r--r-- | include/linux/pinctrl/pinmux.h | 24 |
3 files changed, 108 insertions, 9 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 43ba411d157..3846264c597 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt | |||
@@ -645,6 +645,17 @@ All the above functions are mandatory to implement for a pinmux driver. | |||
645 | Pinmux interaction with the GPIO subsystem | 645 | Pinmux interaction with the GPIO subsystem |
646 | ========================================== | 646 | ========================================== |
647 | 647 | ||
648 | The public pinmux API contains two functions named pinmux_request_gpio() | ||
649 | and pinmux_free_gpio(). These two functions shall *ONLY* be called from | ||
650 | gpiolib-based drivers as part of their gpio_request() and | ||
651 | gpio_free() semantics. Likewise the pinmux_gpio_direction_[input|output] | ||
652 | shall only be called from within respective gpio_direction_[input|output] | ||
653 | gpiolib implementation. | ||
654 | |||
655 | NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be | ||
656 | muxed in. Instead, implement a proper gpiolib driver and have that driver | ||
657 | request proper muxing for its pins. | ||
658 | |||
648 | The function list could become long, especially if you can convert every | 659 | The function list could become long, especially if you can convert every |
649 | individual pin into a GPIO pin independent of any other pins, and then try | 660 | individual pin into a GPIO pin independent of any other pins, and then try |
650 | the approach to define every pin as a function. | 661 | the approach to define every pin as a function. |
@@ -652,19 +663,24 @@ the approach to define every pin as a function. | |||
652 | In this case, the function array would become 64 entries for each GPIO | 663 | In this case, the function array would become 64 entries for each GPIO |
653 | setting and then the device functions. | 664 | setting and then the device functions. |
654 | 665 | ||
655 | For this reason there is an additional function a pinmux driver can implement | 666 | For this reason there are two functions a pinmux driver can implement |
656 | to enable only GPIO on an individual pin: .gpio_request_enable(). The same | 667 | to enable only GPIO on an individual pin: .gpio_request_enable() and |
657 | .free() function as for other functions is assumed to be usable also for | 668 | .gpio_disable_free(). |
658 | GPIO pins. | ||
659 | 669 | ||
660 | This function will pass in the affected GPIO range identified by the pin | 670 | This function will pass in the affected GPIO range identified by the pin |
661 | controller core, so you know which GPIO pins are being affected by the request | 671 | controller core, so you know which GPIO pins are being affected by the request |
662 | operation. | 672 | operation. |
663 | 673 | ||
664 | Alternatively it is fully allowed to use named functions for each GPIO | 674 | If your driver needs to have an indication from the framework of whether the |
665 | pin, the pinmux_request_gpio() will attempt to obtain the function "gpioN" | 675 | GPIO pin shall be used for input or output you can implement the |
666 | where "N" is the global GPIO pin number if no special GPIO-handler is | 676 | .gpio_set_direction() function. As described this shall be called from the |
667 | registered. | 677 | gpiolib driver and the affected GPIO range, pin offset and desired direction |
678 | will be passed along to this function. | ||
679 | |||
680 | Alternatively to using these special functions, it is fully allowed to use | ||
681 | named functions for each GPIO pin, the pinmux_request_gpio() will attempt to | ||
682 | obtain the function "gpioN" where "N" is the global GPIO pin number if no | ||
683 | special GPIO-handler is registered. | ||
668 | 684 | ||
669 | 685 | ||
670 | Pinmux board/machine configuration | 686 | Pinmux board/machine configuration |
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 92aa13ee220..f3e4f031fe1 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 | */ |
218 | int pinmux_request_gpio(unsigned gpio) | 222 | int 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 | */ |
253 | void pinmux_free_gpio(unsigned gpio) | 261 | void pinmux_free_gpio(unsigned gpio) |
254 | { | 262 | { |
@@ -270,6 +278,59 @@ void pinmux_free_gpio(unsigned gpio) | |||
270 | } | 278 | } |
271 | EXPORT_SYMBOL_GPL(pinmux_free_gpio); | 279 | EXPORT_SYMBOL_GPL(pinmux_free_gpio); |
272 | 280 | ||
281 | static 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 | */ | ||
314 | int pinmux_gpio_direction_input(unsigned gpio) | ||
315 | { | ||
316 | return pinmux_gpio_direction(gpio, true); | ||
317 | } | ||
318 | EXPORT_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 | */ | ||
328 | int pinmux_gpio_direction_output(unsigned gpio) | ||
329 | { | ||
330 | return pinmux_gpio_direction(gpio, false); | ||
331 | } | ||
332 | EXPORT_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 |
diff --git a/include/linux/pinctrl/pinmux.h b/include/linux/pinctrl/pinmux.h index bb7a9792f1e..937b3e2fa36 100644 --- a/include/linux/pinctrl/pinmux.h +++ b/include/linux/pinctrl/pinmux.h | |||
@@ -54,7 +54,13 @@ struct pinctrl_dev; | |||
54 | * Implement this only if you can mux every pin individually as GPIO. The | 54 | * Implement this only if you can mux every pin individually as GPIO. The |
55 | * affected GPIO range is passed along with an offset(pin number) into that | 55 | * affected GPIO range is passed along with an offset(pin number) into that |
56 | * specific GPIO range - function selectors and pin groups are orthogonal | 56 | * specific GPIO range - function selectors and pin groups are orthogonal |
57 | * to this, the core will however make sure the pins do not collide | 57 | * to this, the core will however make sure the pins do not collide. |
58 | * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of | ||
59 | * @gpio_request_enable | ||
60 | * @gpio_set_direction: Since controllers may need different configurations | ||
61 | * depending on whether the GPIO is configured as input or output, | ||
62 | * a direction selector function may be implemented as a backing | ||
63 | * to the GPIO controllers that need pin muxing. | ||
58 | */ | 64 | */ |
59 | struct pinmux_ops { | 65 | struct pinmux_ops { |
60 | int (*request) (struct pinctrl_dev *pctldev, unsigned offset); | 66 | int (*request) (struct pinctrl_dev *pctldev, unsigned offset); |
@@ -76,11 +82,17 @@ struct pinmux_ops { | |||
76 | void (*gpio_disable_free) (struct pinctrl_dev *pctldev, | 82 | void (*gpio_disable_free) (struct pinctrl_dev *pctldev, |
77 | struct pinctrl_gpio_range *range, | 83 | struct pinctrl_gpio_range *range, |
78 | unsigned offset); | 84 | unsigned offset); |
85 | int (*gpio_set_direction) (struct pinctrl_dev *pctldev, | ||
86 | struct pinctrl_gpio_range *range, | ||
87 | unsigned offset, | ||
88 | bool input); | ||
79 | }; | 89 | }; |
80 | 90 | ||
81 | /* External interface to pinmux */ | 91 | /* External interface to pinmux */ |
82 | extern int pinmux_request_gpio(unsigned gpio); | 92 | extern int pinmux_request_gpio(unsigned gpio); |
83 | extern void pinmux_free_gpio(unsigned gpio); | 93 | extern void pinmux_free_gpio(unsigned gpio); |
94 | extern int pinmux_gpio_direction_input(unsigned gpio); | ||
95 | extern int pinmux_gpio_direction_output(unsigned gpio); | ||
84 | extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name); | 96 | extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name); |
85 | extern void pinmux_put(struct pinmux *pmx); | 97 | extern void pinmux_put(struct pinmux *pmx); |
86 | extern int pinmux_enable(struct pinmux *pmx); | 98 | extern int pinmux_enable(struct pinmux *pmx); |
@@ -97,6 +109,16 @@ static inline void pinmux_free_gpio(unsigned gpio) | |||
97 | { | 109 | { |
98 | } | 110 | } |
99 | 111 | ||
112 | static inline int pinmux_gpio_direction_input(unsigned gpio) | ||
113 | { | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static inline int pinmux_gpio_direction_output(unsigned gpio) | ||
118 | { | ||
119 | return 0; | ||
120 | } | ||
121 | |||
100 | static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name) | 122 | static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name) |
101 | { | 123 | { |
102 | return NULL; | 124 | return NULL; |