linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gpiolib and sleeping gpios
@ 2010-06-17 21:47 Ryan Mallon
  2010-06-18  5:27 ` Uwe Kleine-König
  2010-06-18  6:16 ` David Brownell
  0 siblings, 2 replies; 33+ messages in thread
From: Ryan Mallon @ 2010-06-17 21:47 UTC (permalink / raw)
  To: linux kernel
  Cc: linux-arm-kernel, Andrew Morton, David Brownell, gregkh,
	Uwe Kleine-König, ext-jani.1.nikula

Hi,

Currently implementors of gpiolib must provide implementations for
gpio_get_value, gpio_set_value and gpio_cansleep. Most of the
implementations just #define these to the double underscore prefixed
versions in drivers/gpio/gpiolib.c. A few implementations have a simple
wrapper function which provides a fast path for the SoC gpios, and calls
gpiolib for the any additional gpios, such as those added by an io expander.

Although gpio_chips know whether or not they may sleep, gpios which can
sleep need to call gpio_[set/get]_value_cansleep. The only difference
between __gpio_(set/get)_value and gpio_(set/get)_value_cansleep is that
the cansleep versions calls might_sleep_if. Most drivers call
gpio_(get/set)_value, rather than the cansleep variants. I haven't done
a full audit of all of the drivers (which is a reasonably involved
task), but I would hazard a guess that some of these could be replaced
by the cansleep versions.

Would it not be simpler to combine the calls and have something like this:

void __gpio_get_value(unsigned gpio, int value)
{
	struct gpio_chip *chip;

	chip = gpio_to_chip(gpio);
	might_sleep_if(extra_checks && chip->can_sleep);
	chip->set(chip, gpio - chip->base, value);
}

Then all drivers can just call gpio_(set/get)_value and any attempts to
use sleeping gpios from an non-sleeping context will be caught by the
might_sleep_if check. Is there something I am missing about this?

I can prepare a patch which combines the non-sleeping and sleeping
variants, but I wanted to check that I'm not missing something
fundamental first.

Thanks,
~Ryan

-- 
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
ryan@bluewatersys.com         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934

^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleepinggpios)
@ 2010-06-24 10:36 David Brownell
  0 siblings, 0 replies; 33+ messages in thread
From: David Brownell @ 2010-06-24 10:36 UTC (permalink / raw)
  To: Ryan Mallon, Jon Povey
  Cc: David Brownell, gregkh, linux kernel, ext-jani.1.nikula,
	Uwe Kleine-König, Andrew Morton, linux-arm-kernel


--- On Wed, 6/23/10, Jon Povey <Jon.Povey@racelogic.co.uk> wrote:
>
> Date: Wednesday, June 23, 2010, 9:46 PM
> Ryan Mallon wrote:
> 
> > If we strip my patch back to just introducing
> gpio_request_cansleep,
> > which would be used in any driver where all of the
> calls are
> > gpio_(set/get)_cansleep, and make gpio_request only
> allow non-sleeping
> > gpios then incorrect use of gpios would be caught at
> request time and
> > returned to the caller as an error.
> 
> It seems like a good idea to catch these at request time.
> There is support in the API for this already
> (gpio_cansleep), but driver writers are not steered towards
> checking and thinking in these ways by the current API or
> 
> gpio_request_cansleep would be the same as current
> gpio_request

I wonder if, by the time I catch up on this
ever-extending email thread

... someone else will have noted that
because gpio_request() can now poke the GPIO
chip, that call might actually need to sleep.
So there'd be a difference between the two
calls:  one would *NEED* to be called in a
sleepable thread context, vs. that just being
well advised (e.g. as part of board setup in
arch init code after tasking is working)...

So that couldn't work quite that way.




^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2010-06-29  8:29 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-17 21:47 gpiolib and sleeping gpios Ryan Mallon
2010-06-18  5:27 ` Uwe Kleine-König
2010-06-18  6:16 ` David Brownell
2010-06-18 22:01   ` Ryan Mallon
2010-06-19  6:21     ` David Brownell
2010-06-20 21:31       ` Ryan Mallon
2010-06-21  2:40         ` David Brownell
2010-06-21  5:09           ` Uwe Kleine-König
2010-06-23  1:59             ` [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleeping gpios) Ryan Mallon
2010-06-23  4:37               ` David Brownell
2010-06-23  4:58                 ` Eric Miao
2010-06-23  9:51                   ` David Brownell
2010-06-23  5:02                 ` Ryan Mallon
2010-06-23  5:26                   ` Eric Miao
2010-06-23  9:39                   ` David Brownell
2010-06-23 19:12                     ` Ryan Mallon
2010-06-24  4:46                       ` [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleepinggpios) Jon Povey
2010-06-24  8:20                         ` Lars-Peter Clausen
2010-06-24  8:29                         ` Jani Nikula
2010-06-24 10:31                           ` Lars-Peter Clausen
2010-06-24  6:41                       ` [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleeping gpios) Uwe Kleine-König
2010-06-23 22:53                   ` Jamie Lokier
2010-06-23 23:06                     ` Ryan Mallon
2010-06-24  0:04                       ` Jamie Lokier
2010-06-24  0:10                         ` Ryan Mallon
2010-06-25  7:19                           ` David Brownell
2010-06-24  4:33                         ` [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleepinggpios) Jon Povey
2010-06-29  8:29         ` gpiolib and sleeping gpios CoffBeta
2010-06-23 11:53       ` Jani Nikula
2010-06-23 12:40         ` David Brownell
2010-06-23 13:22           ` Jani Nikula
2010-06-23 13:39             ` David Brownell
2010-06-24 10:36 [RFC PATCH] Rework gpio cansleep (was Re: gpiolib and sleepinggpios) David Brownell

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).