mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrej Picej <andrej.picej@norik.com>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH] gpio: allocate dynamic gpio numbers top down
Date: Tue, 29 Mar 2022 12:59:05 +0200	[thread overview]
Message-ID: <a89898ee-945a-2286-c116-eea1e975df1e@norik.com> (raw)
In-Reply-To: <20220329085207.2779958-1-s.hauer@pengutronix.de>



On 29. 03. 22 10:52, Sascha Hauer wrote:
> For GPIO controllers with dynamic GPIO number bases a free base
> is searched for bottom up. This means that GPIO controllers with
> fixed GPIO numbers must be registered before any controller with
> dynamic GPIO number base is registered, because otherwise the
> GPIO controllers with fixed GPIO numbers find their range occupied
> and can't be registered anymore.
> 
> The probe order normally makes sure the SoC internal GPIO controllers
> with fixed numbers are registered first. With deep probe enabled
> we can't rely on the probe order anymore, so we need another solution.
> 
> With this patch a free GPIO number range is searched for top down
> intead of bottom up, so as long as we have enough space in the
> ARCH_NR_GPIOS range the SoC internal GPIO controllers find their
> base unoccupied. GPIO controllers with dynamic GPIO numbers will
> change their numbers with this patch, but code shouldn't rely on
> these numbers anyway.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Tested on PHYTEC Mira and Nunki board. If you want you can add:
Tested-by: Andrej Picej <andrej.picej@norik.com>

Thanks.
> ---
>   drivers/gpio/gpiolib.c | 26 +++++++++++++-------------
>   1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index f709d11f75..c9b33bcd6c 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -414,22 +414,19 @@ free_array:
>   }
>   EXPORT_SYMBOL(gpio_array_to_id);
>   
> -static int gpiochip_find_base(int start, int ngpio)
> +static int gpiochip_find_base(int ngpio)
>   {
>   	int i;
>   	int spare = 0;
>   	int base = -ENOSPC;
>   
> -	if (start < 0)
> -		start = 0;
> -
> -	for (i = start; i < ARCH_NR_GPIOS; i++) {
> +	for (i = ARCH_NR_GPIOS - 1; i >= 0; i--) {
>   		struct gpio_chip *chip = gpio_desc[i].chip;
>   
>   		if (!chip) {
>   			spare++;
>   			if (spare == ngpio) {
> -				base = i + 1 - ngpio;
> +				base = i;
>   				break;
>   			}
>   		} else {
> @@ -614,14 +611,17 @@ int gpiochip_add(struct gpio_chip *chip)
>   {
>   	int base, i;
>   
> -	base = gpiochip_find_base(chip->base, chip->ngpio);
> -	if (base < 0)
> -		return base;
> -
> -	if (chip->base >= 0 && chip->base != base)
> -		return -EBUSY;
> +	if (chip->base >= 0) {
> +		for (i = 0; i < chip->ngpio; i++) {
> +			if (gpio_desc[chip->base + i].chip)
> +				return -EBUSY;
> +		}
> +	} else {
> +		chip->base = gpiochip_find_base(chip->ngpio);
> +		if (chip->base < 0)
> +			return -ENOSPC;
> +	}
>   
> -	chip->base = base;
>   
>   	list_add_tail(&chip->list, &chip_list);
>   

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


      reply	other threads:[~2022-03-29 11:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  8:52 Sascha Hauer
2022-03-29 10:59 ` Andrej Picej [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a89898ee-945a-2286-c116-eea1e975df1e@norik.com \
    --to=andrej.picej@norik.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --subject='Re: [PATCH] gpio: allocate dynamic gpio numbers top down' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox