[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup
From: |
Ulrich Hecht |
Subject: |
Re: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup |
Date: |
Thu, 28 Nov 2019 04:38:55 +0100 (CET) |
> On November 27, 2019 at 9:42 AM Geert Uytterhoeven <address@hidden> wrote:
>
>
> Currently GPIO controllers can only be referred to by label in GPIO
> lookup tables.
>
> Add support for looking them up by "gpiochipN" name, with "N" either the
> corresponding GPIO device's ID number, or the GPIO controller's first
> GPIO number.
>
> Signed-off-by: Geert Uytterhoeven <address@hidden>
> ---
> If this is rejected, the GPIO Aggregator documentation must be updated.
>
> The second variant is currently used by the legacy sysfs interface only,
> so perhaps the chip->base check should be dropped?
>
> v3:
> - New.
> ---
> drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index c9e47620d2434983..d24a3d79dcfe69ad 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1746,9 +1746,29 @@ static int gpiochip_match_name(struct gpio_chip *chip,
> void *data)
> return !strcmp(chip->label, name);
> }
>
> +static int gpiochip_match_id(struct gpio_chip *chip, void *data)
> +{
> + int id = (uintptr_t)data;
> +
> + return id == chip->base || id == chip->gpiodev->id;
> +}
> +
> static struct gpio_chip *find_chip_by_name(const char *name)
> {
> - return gpiochip_find((void *)name, gpiochip_match_name);
> + struct gpio_chip *chip;
> + int id;
> +
> + chip = gpiochip_find((void *)name, gpiochip_match_name);
> + if (chip)
> + return chip;
> +
> + if (!str_has_prefix(name, GPIOCHIP_NAME))
> + return NULL;
> +
> + if (kstrtoint(name + strlen(GPIOCHIP_NAME), 10, &id))
> + return NULL;
> +
> + return gpiochip_find((void *)(uintptr_t)id, gpiochip_match_id);
> }
>
> #ifdef CONFIG_GPIOLIB_IRQCHIP
> --
> 2.17.1
>
Reviewed-by: Ulrich Hecht <address@hidden>
CU
Uli
- [PATCH v3 0/7] gpio: Add GPIO Aggregator/Repeater, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 7/7] MAINTAINERS: Add GPIO Aggregator/Repeater section, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 3/7] gpiolib: Add support for GPIO line table lookup, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 4/7] dt-bindings: gpio: Add gpio-repeater bindings, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 1/7] gpiolib: Add GPIOCHIP_NAME definition, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup, Geert Uytterhoeven, 2019/11/27
- Re: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup,
Ulrich Hecht <=
- [PATCH v3 6/7] docs: gpio: Add GPIO Aggregator/Repeater documentation, Geert Uytterhoeven, 2019/11/27
- [PATCH v3 5/7] gpio: Add GPIO Aggregator/Repeater driver, Geert Uytterhoeven, 2019/11/27