* GPIO update to allow code to get at gpio_chip @ 2010-01-08 6:32 Ben Dooks 2010-01-08 6:32 ` [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio Ben Dooks 0 siblings, 1 reply; 5+ messages in thread From: Ben Dooks @ 2010-01-08 6:32 UTC (permalink / raw) To: linux-arm-kernel Allowing gpiolib implementations to get at the gpio_chip from the gpio number is useful to allow gpiolib gpio numbering to be used for other gpio purposes such as changing pin configuration. The following patch exports this information. A patch showing the reason for my wanting this can be supplied on request. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio 2010-01-08 6:32 GPIO update to allow code to get at gpio_chip Ben Dooks @ 2010-01-08 6:32 ` Ben Dooks 2010-01-08 7:30 ` Eric Miao 2010-01-21 6:12 ` Andrew Morton 0 siblings, 2 replies; 5+ messages in thread From: Ben Dooks @ 2010-01-08 6:32 UTC (permalink / raw) To: linux-arm-kernel Add a call to get the 'struct gpio_chip' pointer for a given gpio, so that core implementations which want to use gpiolib gpio numbering for things like mux configuration can get back to the gpio_chip that they registered without having to have their own list of gpio. This is especially useful for the Samsung S3C64XX series where the GPIO bank sizes can vary from 32 down to 3, making it difficult to store an array to convert a number to chip. Signed-off-by: Ben Dooks <ben-linux@fluff.org> --- drivers/gpio/gpiolib.c | 26 ++++++++++++++++++++++++++ include/asm-generic/gpio.h | 2 ++ 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a25ad28..d748600 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -120,6 +120,32 @@ static inline struct gpio_chip *gpio_to_chip(unsigned gpio) return gpio_desc[gpio].chip; } +/** + * gpio_lookup_chip - return the chip for a given gpio + * @gpio: The GPIO number to lookup + * + * Returns NULL if the GPIO chip is not valid or there is no chip registered + * for that GPIO. This call is available for core code to turn a GPIO number + * into a chip so that further information can be looked up. + * + * This call makes no guarantees about the actuall gpio_chip's state, or + * whether the @gpio itself is requested. + */ +struct gpio_chip *gpio_lookup_chip(unsigned gpio) +{ + struct gpio_chip *chip; + unsigned long flags; + + if (!gpio_is_valid(gpio)) + return NULL; + + spin_lock_irqsave(&gpio_lock, flags); + chip = gpio_to_chip(gpio); + spin_unlock_irqrestore(&gpio_lock, flags); + + return chip; +} + /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base(int ngpio) { diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 485eeb6..34b3276 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -103,6 +103,8 @@ struct gpio_chip { unsigned exported:1; }; +extern struct gpio_chip *gpio_lookup_chip(unsigned gpio); + extern const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset); extern int __must_check gpiochip_reserve(int start, int ngpio); -- 1.6.0.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio 2010-01-08 6:32 ` [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio Ben Dooks @ 2010-01-08 7:30 ` Eric Miao 2010-01-08 8:28 ` Ben Dooks 2010-01-21 6:12 ` Andrew Morton 1 sibling, 1 reply; 5+ messages in thread From: Eric Miao @ 2010-01-08 7:30 UTC (permalink / raw) To: linux-arm-kernel On Fri, Jan 8, 2010 at 2:32 PM, Ben Dooks <ben-linux@fluff.org> wrote: > Add a call to get the 'struct gpio_chip' pointer for a given gpio, so > that core implementations which want to use gpiolib gpio numbering for > things like mux configuration can get back to the gpio_chip that they > registered without having to have their own list of gpio. > > This is especially useful for the Samsung S3C64XX series where the GPIO > bank sizes can vary from 32 down to 3, making it difficult to store an > array to convert a number to chip. > I think this is generally a good idea. Will most likely be useful to pxa platforms as well. Not sure though if you want to export this symbol as well since we do allow gpio chip drivers to be modules. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio 2010-01-08 7:30 ` Eric Miao @ 2010-01-08 8:28 ` Ben Dooks 0 siblings, 0 replies; 5+ messages in thread From: Ben Dooks @ 2010-01-08 8:28 UTC (permalink / raw) To: linux-arm-kernel On Fri, Jan 08, 2010 at 03:30:36PM +0800, Eric Miao wrote: > On Fri, Jan 8, 2010 at 2:32 PM, Ben Dooks <ben-linux@fluff.org> wrote: > > Add a call to get the 'struct gpio_chip' pointer for a given gpio, so > > that core implementations which want to use gpiolib gpio numbering for > > things like mux configuration can get back to the gpio_chip that they > > registered without having to have their own list of gpio. > > > > This is especially useful for the Samsung S3C64XX series where the GPIO > > bank sizes can vary from 32 down to 3, making it difficult to store an > > array to convert a number to chip. > > > > I think this is generally a good idea. Will most likely be useful to > pxa platforms as well. Not sure though if you want to export this > symbol as well since we do allow gpio chip drivers to be modules. Probably not, since all the gpio call methods pass gpio_chip as their first parameter. This is only in the case we want to use gpios for something other than in/out/irq. -- Ben Q: What's a light-year? A: One-third less calories than a regular year. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio 2010-01-08 6:32 ` [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio Ben Dooks 2010-01-08 7:30 ` Eric Miao @ 2010-01-21 6:12 ` Andrew Morton 1 sibling, 0 replies; 5+ messages in thread From: Andrew Morton @ 2010-01-21 6:12 UTC (permalink / raw) To: linux-arm-kernel On Fri, 8 Jan 2010 06:32:28 +0000 Ben Dooks <ben-linux@fluff.org> wrote: > Add a call to get the 'struct gpio_chip' pointer for a given gpio, so > that core implementations which want to use gpiolib gpio numbering for > things like mux configuration can get back to the gpio_chip that they > registered without having to have their own list of gpio. > > This is especially useful for the Samsung S3C64XX series where the GPIO > bank sizes can vary from 32 down to 3, making it difficult to store an > array to convert a number to chip. > > ... > > +/** > + * gpio_lookup_chip - return the chip for a given gpio > + * @gpio: The GPIO number to lookup > + * > + * Returns NULL if the GPIO chip is not valid or there is no chip registered > + * for that GPIO. This call is available for core code to turn a GPIO number > + * into a chip so that further information can be looked up. > + * > + * This call makes no guarantees about the actuall gpio_chip's state, or > + * whether the @gpio itself is requested. > + */ > +struct gpio_chip *gpio_lookup_chip(unsigned gpio) > +{ > + struct gpio_chip *chip; > + unsigned long flags; > + > + if (!gpio_is_valid(gpio)) > + return NULL; > + > + spin_lock_irqsave(&gpio_lock, flags); > + chip = gpio_to_chip(gpio); > + spin_unlock_irqrestore(&gpio_lock, flags); > + > + return chip; > +} > + The locking looks fishy. What's the point in locking the array lookup and then returning the thing which was looked up after dropping the lock? Should this function have been exported to modules? Please cc myself and David Brownell on gpio patches. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-01-21 6:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-01-08 6:32 GPIO update to allow code to get at gpio_chip Ben Dooks 2010-01-08 6:32 ` [PATCH] gpiolib: add gpio_lookup_chip() to get chip information for gpio Ben Dooks 2010-01-08 7:30 ` Eric Miao 2010-01-08 8:28 ` Ben Dooks 2010-01-21 6:12 ` Andrew Morton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).