[PATCH v1 08/11] gpiolib: add gpio_array_to_id helper to get ID out of GPIO array

Oleksij Rempel o.rempel at pengutronix.de
Tue Aug 4 01:22:37 EDT 2020


Hi Sascha,

On Mon, Aug 03, 2020 at 10:22:22PM +0200, Sascha Hauer wrote:
> Hi Oleksij,
> 
> On Thu, Jul 23, 2020 at 12:33:23PM +0200, Oleksij Rempel wrote:
> > Some boards provide a board version and/or ID coded by pull-up/down
> > resistors connected to the gpio pins (or pins which can be multiplexed
> > at some point as gpio). In this case every one implements own gpio id
> > reader function.
> > 
> > To avoid it, provide the common helper function to extract a value out
> > of provided gpio array.
> > 
> > Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> > ---
> >  drivers/gpio/gpiolib.c | 28 ++++++++++++++++++++++++++++
> >  include/gpio.h         |  5 +++++
> >  2 files changed, 33 insertions(+)
> > 
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index 27674af54c..2e9150d2ea 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -381,6 +381,34 @@ void gpio_free_array(const struct gpio *array, size_t num)
> >  }
> >  EXPORT_SYMBOL_GPL(gpio_free_array);
> >  
> > +int gpio_array_to_id(const struct gpio *array, size_t num, u32 *val)
> > +{
> > +	u32 id = 0;
> > +	int ret, i;
> > +
> > +	if (num > 32)
> > +		return -EOVERFLOW;
> > +
> > +	ret = gpio_request_array(array, num);
> > +	if (ret)
> > +		return ret;
> 
> This function expects an unrequested array and returns with the array
> requested. This is at least inconsistent.

fixed

> > +
> > +	/* Wait untill logic level will be stable */
> 
> s/untill/until/

fixed

> > +	udelay(5);
> 
> This delay looks rather arbitrary. Is it really necessary?

The vendor reported that otherwise will not always read proper value.

> > +	for (i = 0; i < num; i++) {
> > +		ret = gpio_is_active(array[i].gpio);
> > +		if (ret < 0)
> > +			return ret;
> > +
> > +		id |= ret << i;
> 
> 'ret' is signed. Does this work when i == 31 ?

yes, it works

Regards,
Oleksij

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20200804/a282cf37/attachment.sig>


More information about the barebox mailing list