Re: [patch 2.6.25-rc5 1/2] gpiolib: dynamic gpio number allocation
From: Andrew Morton
Date: Thu Mar 13 2008 - 19:01:19 EST
On Thu, 13 Mar 2008 14:49:53 -0800
David Brownell <david-b@xxxxxxxxxxx> wrote:
> From: Anton Vorontsov <avorontsov@xxxxxxxxxxxxx>
>
> If gpio_chip->base is negative during registration, gpiolib performs
> dynamic base allocation. This is useful for devices that aren't always
> present, such as GPIOs on hotplugged devices rather than mainboards.
> (This behavior was previously specified but not implemented.)
>
> To avoid using any numbers that may have been explicitly assigned but
> not yet registered, this dynamic allocation assigns GPIO numbers from
> the biggest number on down, instead of from the smallest on up.
>
> ..
>
> +/* dynamic allocation of GPIOs, e.g. on a hotplugged device */
> +static int gpiochip_find_base(int ngpio)
> +{
> + int i;
> + int spare = 0;
> + int base = -ENOSPC;
> +
> + 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;
> + break;
> + }
> + } else {
> + spare = 0;
> + i -= chip->ngpio - 1;
> + }
> + }
> +
> + if (gpio_is_valid(base))
> + pr_debug("%s: found new base at %d\n", __func__, base);
> + return base;
> +}
hm. I suppose that if someone want a huge number of GPIOs then we can
convert this to a bitmap or an IDR tree easily enough.
Shouldn't ARCH_NR_GPIOS be CONFIG_NR_GPIOS?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/