lkml.org 
[lkml]   [2009]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] drivers/w1/masters/w1-gpio.c: fix read_bit()
On Mon, Mar 09, 2009 at 07:14:19PM -0700, Andrew Morton wrote:
> On Mon, 9 Mar 2009 17:02:10 +0100 Daniel Mack <daniel@caiaq.de> wrote:
>
> > W1 master implementations are expected to return 0 or 1 from their
> > read_bit() function. However, not all platforms do return these values
> > from gpio_get_value() - namely PXAs won't. Hence the w1 gpio-master
> > needs to break the result down to 0 or 1 itself.
> >
> > Signed-off-by: Daniel Mack <daniel@caiaq.de>
> > Cc: Ville Syrjala <syrjala@sci.fi>
> > Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
> > ---
> > drivers/w1/masters/w1-gpio.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
> > index 9e1138a..a411702 100644
> > --- a/drivers/w1/masters/w1-gpio.c
> > +++ b/drivers/w1/masters/w1-gpio.c
> > @@ -39,7 +39,7 @@ static u8 w1_gpio_read_bit(void *data)
> > {
> > struct w1_gpio_platform_data *pdata = data;
> >
> > - return gpio_get_value(pdata->pin);
> > + return gpio_get_value(pdata->pin) ? 1 : 0;
> > }
> >
> > static int __init w1_gpio_probe(struct platform_device *pdev)
>
> We recently merged a patch (I forget where) which fixed one
> gpio_get_value() implementation so that it always returns 0 or 1.
>
> From which I deduce that the correct fix for <whatever problem you're
> seeing> is to fix <whichever driver that is>?

The documentation should be fixed to match if that's the desired
behaviour. From Documentation/gpio.txt:
/* GPIO INPUT: return zero or nonzero */
int gpio_get_value(unsigned gpio);

Maybe the gpio_get_value() return value should be changed to bool to
make things clear.

w1 itself is a bit odd as the documentation says that read_bit() must
return 0 or 1, but the core uses it like this 'read_bit() & 0x1'. Not
sure what the idea is here. Perhaps read_bit() returns the contents of
some shift register on some masters. But if the documentation is to be
trusted the '& 0x1' should be moved to the master drivers that need it.

--
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-03-10 15:17    [W:0.061 / U:3.220 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site