Message ID | 1358494279-16503-7-git-send-email-haojian.zhuang@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, Jan 18, 2013 at 8:31 AM, Haojian Zhuang <haojian.zhuang@linaro.org> wrote: > gpiochip_find_base() always tries to find valid gpio with descend order. > It's inconvient if gpio information is passing from DTS. Now try to find > valid gpio with ascend order. > > Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> Grant, can you comment on this? You know DT and GPIO better than me.... Yours, Linus Walleij
On Fri, 18 Jan 2013 15:31:10 +0800, Haojian Zhuang <haojian.zhuang@linaro.org> wrote: > gpiochip_find_base() always tries to find valid gpio with descend order. > It's inconvient if gpio information is passing from DTS. Now try to find > valid gpio with ascend order. Why is it more convenient? Just to make the numbers smaller? The reason it uses a descending search is to mimimize the possibility of collision with fixed GPIO numbers. g.
On 9 February 2013 21:45, Grant Likely <grant.likely@secretlab.ca> wrote: > On Fri, 18 Jan 2013 15:31:10 +0800, Haojian Zhuang <haojian.zhuang@linaro.org> wrote: >> gpiochip_find_base() always tries to find valid gpio with descend order. >> It's inconvient if gpio information is passing from DTS. Now try to find >> valid gpio with ascend order. > > Why is it more convenient? Just to make the numbers smaller? The reason > it uses a descending search is to mimimize the possibility of collision > with fixed GPIO numbers. > > g. > I tried to parse global gpio number dynamically from DT, so I also used gpiochip_find_base() to seek gpio number. If it's descending order, all the gpio number are not also descending order. It will be inconvenient for linking it to SoC datasheet & schematic. Since changing it to ascending order may break user space application, Linus NACKed. Now I'm trying to use fixed gpio number from machine driver. Regards Haojian
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 199fca1..8af57e7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -128,20 +128,21 @@ static int gpiochip_find_base(int ngpio) int spare = 0; int base = -ENOSPC; - for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) { + for (i = 0, base = 0; i < ARCH_NR_GPIOS; i++) { struct gpio_desc *desc = &gpio_desc[i]; struct gpio_chip *chip = desc->chip; - if (!chip && !test_bit(FLAG_RESERVED, &desc->flags)) { + if (chip) { + spare = 0; + i += chip->ngpio - 1; + base = i + 1; + } else if (test_bit(FLAG_RESERVED, &desc->flags)) { + spare = 0; + base = i + 1; + } else { spare++; - if (spare == ngpio) { - base = i; + if (spare == ngpio) break; - } - } else { - spare = 0; - if (chip) - i -= chip->ngpio - 1; } }
gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order. Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> --- drivers/gpio/gpiolib.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)