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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
> ---
>  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.

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

s/untill/until/

> +	udelay(5);

This delay looks rather arbitrary. Is it really necessary?

> +	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 ?

Sascha


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

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux