From 545abf2ec49211df4d15e9ddd7bc128334fc18ad Mon Sep 17 00:00:00 2001 From: David Wu Date: Fri, 22 Dec 2017 10:37:32 +0800 Subject: [PATCH] gpio: rockchip: Make the gpio base added at gpiolib It looks like should add gpio base in the gpiolib instead of each gpio or pinctrl driver, and base defined in the gpio.h. If the definition of base is 0, then it is the same as the original, now the definition of base is 1000. The dynamic assignment of a range of valid GPIOs should be also from the defined base. Change-Id: I636bc71a5ba078fd5e1bc9a476cdcf942aa8010a Signed-off-by: David Wu --- drivers/gpio/gpiolib.c | 11 +++++++---- drivers/pinctrl/pinctrl-rockchip.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 06d345b087f8..3c5ea1ce2f9e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -126,7 +126,7 @@ EXPORT_SYMBOL_GPL(gpiod_to_chip); static int gpiochip_find_base(int ngpio) { struct gpio_chip *chip; - int base = ARCH_NR_GPIOS - ngpio; + int base = ARCH_NR_GPIOS - ngpio + ARCH_GPIO_BASE; list_for_each_entry_reverse(chip, &gpio_chips, list) { /* found a free space? */ @@ -301,18 +301,21 @@ int gpiochip_add(struct gpio_chip *chip) unsigned long flags; int status = 0; unsigned id; - int base = chip->base; + int base; struct gpio_desc *descs; + chip->base += ARCH_GPIO_BASE; + base = chip->base; + descs = kcalloc(chip->ngpio, sizeof(descs[0]), GFP_KERNEL); if (!descs) return -ENOMEM; spin_lock_irqsave(&gpio_lock, flags); - if (base < 0) { + if (base < ARCH_GPIO_BASE) { base = gpiochip_find_base(chip->ngpio); - if (base < 0) { + if (base < ARCH_GPIO_BASE) { status = base; spin_unlock_irqrestore(&gpio_lock, flags); goto err_free_descs; diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index d6ec1435164a..3ff72716424b 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -3179,7 +3179,7 @@ static int rockchip_gpiolib_register(struct platform_device *pdev, bank->gpio_chip = rockchip_gpiolib_chip; gc = &bank->gpio_chip; - gc->base = ARCH_GPIO_BASE + bank->pin_base; + gc->base = bank->pin_base; gc->ngpio = bank->nr_pins; gc->dev = &pdev->dev; gc->of_node = bank->of_node;