lkml.org 
[lkml]   [2008]   [Mar]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [patch 2.6.25-rc5 1/2] gpiolib: dynamic gpio number allocation
    On Thu, 13 Mar 2008 14:49:53 -0800
    David Brownell <david-b@pacbell.net> wrote:

    > From: Anton Vorontsov <avorontsov@ru.mvista.com>
    >
    > 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?




    \
     
     \ /
      Last update: 2008-03-14 00:03    [W:0.055 / U:31.080 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site