gpiolib: request/free hooks
Subsystems (3)
PATCH 1/1 gpiolib: request/free hooks
From: David Brownell <[email protected]>
Add a new internal mechanism to gpiolib to support low power operations by letting gpio_chip instances see when their GPIOs are in use. When no GPIOs are active, chips may be able to enter lower powered runtime states by disabling clocks and/or power domains.
--- Documentation/gpio.txt | 4 ++++ drivers/gpio/gpiolib.c | 42 ++++++++++++++++++++++++++++++------------ include/asm-generic/gpio.h | 9 +++++++++ 3 files changed, 43 insertions(+), 12 deletions(-)
Documentation/gpio.txt +4 -0
@@ -240,6 +240,10 @@ signal, or (b) something wrongly believe needed to manage a signal that's in active use. That is, requesting a GPIO can serve as a kind of lock. +Some platforms may also use knowledge about what GPIOs are active for +power management, such as by powering down unused chip sectors and, more +easily, gating off unused clocks. + These two calls are optional because not not all current Linux platforms offer such functionality in their GPIO support; a valid implementation could return success for all gpio_request() calls. Unlike the other calls,
drivers/gpio/gpiolib.c +30 -12
100 lines not on this page · raw message
include/asm-generic/gpio.h +9 -0
@@ -35,6 +35,10 @@ struct module;* @label: for diagnostics * @dev: optional device providing the GPIOs * @owner: helps prevent removal of modules exporting active GPIOs +* @request: optional hook for chip-specific activation, such as +* enabling module power and clock; may sleep +* @free: optional hook for chip-specific deactivation, such as +* disabling module power and clock; may sleep * @direction_input: configures signal "offset" as input, or returns error * @get: returns value for signal "offset"; for output signals this * returns either the value actually sensed, or zero
@@ -67,6 +71,11 @@ struct gpio_chip {struct device *dev;struct module *owner; +int (*request)(struct gpio_chip *chip, +unsigned offset); +void (*free)(struct gpio_chip *chip, +unsigned offset); +int (*direction_input)(struct gpio_chip *chip,unsigned offset); int (*get)(struct gpio_chip *chip,
Hi David,
Quoted 9 lines · David Brownell
From: David Brownell <[email protected]>
Add a new internal mechanism to gpiolib to support low power operations by letting
gpio_chipinstances see when their GPIOs are in use. When no GPIOs are active, chips may be able to enter lower powered runtime states by disabling clocks and/or power domains.Signed-off-by David Brownell <[email protected]>
Looking good. I'm currently hacking on some pinmuxed gpio code for SuperH, and I'd like to use these request/free callbacks to select proper pinmux state.
I have one comment below though:
Quoted 36 lines
drivers/gpio/gpiolib.c +13
-3@@ -781,6 +785,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove);int gpio_request (unsigned gpio,const char *label) {struct gpio_desc *desc; +struct gpio_chip *chip;int status = -EINVAL ;unsigned long flags;@@ -789,22 +794,31 @@ int gpio_request(unsigned gpio, const chif (!gpio_is_valid (gpio)) goto done; desc = &gpio_desc[gpio]; -if (desc->chip ==NULL ) + chip = desc->chip; +if (chip ==NULL ) goto done; -if (!try_module_get (desc->chip->owner)) +if (!try_module_get (chip->owner)) goto done;/* NOTE: gpio_request() can be called in early boot, -* before IRQs are enabled. +* before IRQs are enabled, for non-sleeping (SOC) GPIOs. */ +if (chip->request) { + status = chip->request (chip, gpio - chip->base); +if (status <0 ) { +module_put (chip->owner); + goto done; + } + } +
drivers/gpio/gpiolib.c int gpio_request(unsigned gpio, const ch · line 824
Quoted 10 lines
drivers/gpio/gpiolib.c +1
-1if (test_and_set_bit (FLAG_REQUESTED , &desc->flags) ==0 ) {desc_set_label (desc, label ? :"?" ); status =0 ; }else { status = -EBUSY ; -module_put (desc->chip->owner); +module_put (chip->owner); } done:
The code above doesn't catch double gpio_request() user calls properly. Or rather, the user will receive an error but the chip->request() callback may get called twice.
What about modifying the gpiolib code to handle that? I think that sounds like a better idea than cover ing that case in the chip code...
Thanks!
/ magnus
Quoted 4 lines · Magnus Damm
Looking good. I'm currently hacking on some pinmuxed gpio code for SuperH, and I'd like to use these request/free callbacks to select proper pinmux state.
I'm not so keen on that particular overloading, but I can understand why it might be wanted on systems which have a happy one-to-one mapping between GPIOs and pins.
If you do that, be ready to provide a pinmux-only interface at some point when this "piggybacking" breaks something...
Quoted 12 lines
I have one comment below though:
drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_remove); · line 785
Quoted 5 lines
drivers/gpio/gpiolib.c +0
-0@@ -781,6 +785,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove);int gpio_request (unsigned gpio,const char *label)The code above doesn't catch double
gpio_request()user calls properly. Or rather, the user will receive an error but thechip->request()callback may get called twice.
Quoted 2 lines
What about modifying the gpiolib code to handle that? I think that sounds like a better idea than cover ing that case in the chip code...
Yeah. Better to test-and-set the flag and then request, and backout if it fails, than the other way. Just who wrote that crap in the first place? Sigh. (Notice it's done that way already in the code path handling implicit requesting ... )
I'll send an updated patch along soonish.
- Dave
Quoted 9 lines · David Brownell
Quoted 4 lines · Magnus Damm
Looking good. I'm currently hacking on some pinmuxed gpio code for SuperH, and I'd like to use these request/free callbacks to select proper pinmux state.
I'm not so keen on that particular overloading, but I can understand why it might be wanted on systems which have a happy one-to-one mapping between GPIOs and pins.
Hm, sounds like you prefer to keep pinmuxing and GPIO code separated?
Quoted 2 lines
If you do that, be ready to provide a pinmux-only interface at some point when this "piggybacking" breaks something...
In the SuperH case GPIO pin direction selection is done in the same way as selecting pin function. So in and out directions can be seen as two pin functions. And since we want to support GPIO pin direction we may as well support setting pin functions as well.
But maybe there are better ways to integrate it, I'm not sure.
Quoted 10 lines
Quoted 10 lines
drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_remove); · line 785
Quoted 5 lines
drivers/gpio/gpiolib.c +0
-0@@ -781,6 +785,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove);int gpio_request (unsigned gpio,const char *label)The code above doesn't catch double
gpio_request()user calls properly. Or rather, the user will receive an error but thechip->request()callback may get called twice.
Quoted 7 lines
Quoted 2 lines
What about modifying the gpiolib code to handle that? I think that sounds like a better idea than cover ing that case in the chip code...
Yeah. Better to test-and-set the flag and then request, and backout if it fails, than the other way. Just who wrote that crap in the first place? Sigh. (Notice it's done that way already in the code path handling implicit requesting ... )
Sounds good.
Quoted 1 line
I'll send an updated patch along soonish.
Thank you!
/ magnus
Quoted 1 line · Magnus Damm
Hm, sounds like you prefer to keep pinmuxing and GPIO code separated?
Yep.
Quoted 9 lines
Quoted 2 lines
If you do that, be ready to provide a pinmux-only interface at some point when this "piggybacking" breaks something...
In the SuperH case GPIO pin direction selection is done in the same way as selecting pin function. So in and out directions can be seen as two pin functions. And since we want to support GPIO pin direction we may as well support setting pin functions as well.
But maybe there are better ways to integrate it, I'm not sure.
Just don't expect the GPIO framework to address the problem of how to configure one of those pins for a non-GPIO function.
Such pinmux problems deserve different programming interfaces.
\
Quoted 10 lines
Quoted 4 lines
Yeah. Better to test-and-set the flag and then request, and backout if it fails, than the other way. Just who wrote that crap in the first place? Sigh. (Notice it's done that way already in the code path handling implicit requesting ... )
Sounds good.
Quoted 1 line
I'll send an updated patch along soonish.
Thank you!
... after I come up with a happy fix for the locking goofs; those new methods may not be called under spinlock protection.
- Dave
Quoted 1 line
Quoted 1 line
Quoted 1 line
I'll send an updated patch along soonish.
This updated version seems to behave for me; against RC8. It resolves the locking issues I noticed, as well as the record-keeping one you commented on. Comments?
- Dave
==================
From: David Brownell <[email protected]>
Add a new internal mechanism to gpiolib to support low power operations by letting gpio_chip instances see when their GPIOs are in use. When no GPIOs are active, chips may be able to enter lower powered runtime states by disabling clocks and/or power domains.
--- Documentation/gpio.txt | 4 + drivers/gpio/gpiolib.c | 91 ++++++++++++++++++++++++++++++++++++------- include/asm-generic/gpio.h | 9 ++++ 3 files changed, 91 insertions(+), 13 deletions(-)
Documentation/gpio.txt +4 -0
@@ -240,6 +240,10 @@ signal, or (b) something wrongly believe needed to manage a signal that's in active use. That is, requesting a GPIO can serve as a kind of lock. +Some platforms may also use knowledge about what GPIOs are active for +power management, such as by powering down unused chip sectors and, more +easily, gating off unused clocks. + These two calls are optional because not not all current Linux platforms offer such functionality in their GPIO support; a valid implementation could return success for all gpio_request() calls. Unlike the other calls,
drivers/gpio/gpiolib.c +78 -13
169 lines not on this page · raw message
include/asm-generic/gpio.h +9 -0
@@ -35,6 +35,10 @@ struct module;* @label: for diagnostics * @dev: optional device providing the GPIOs * @owner: helps prevent removal of modules exporting active GPIOs +* @request: optional hook for chip-specific activation, such as +* enabling module power and clock; may sleep +* @free: optional hook for chip-specific deactivation, such as +* disabling module power and clock; may sleep * @direction_input: configures signal "offset" as input, or returns error * @get: returns value for signal "offset"; for output signals this * returns either the value actually sensed, or zero
@@ -67,6 +71,11 @@ struct gpio_chip {struct device *dev;struct module *owner; +int (*request)(struct gpio_chip *chip, +unsigned offset); +void (*free)(struct gpio_chip *chip, +unsigned offset); +int (*direction_input)(struct gpio_chip *chip,unsigned offset); int (*get)(struct gpio_chip *chip,