Message ID | 20230905185309.131295-8-brgl@bgdev.pl (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | gpio: convert users to gpio_device_find() and remove gpiochip_find() | expand |
On Tue, Sep 5, 2023 at 8:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Let's start adding getters for the opaque struct gpio_device. Start with > a function allowing to retrieve the base GPIO number. > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> I guess you have a solid usecase for drivers needing to do this crazy thing, because I suppose you feel as much as me that this should rather be gpiolib-internal and confined to drivers/gpio/gpiolib.h? If you add a valid reason for making this globally visible outside of drivers/[gpio|pinctrl] to the commit message I guess I can live with it because we need to think of the bigger picture: Acked-by: Linus Walleij <linus.walleij@linaro.org> It brings to mind the now confusing "base" inside of struct gpio_chip. We all know it should go away, but since it is never used during the lifetime of the gpio_chip - or SHOULD never be used - it should rather be an argument to [devm_]gpiochip_add_data( .... int base);... Maybe something we should add to our TODO file. Yours, Linus Walleij
On Thu, Sep 7, 2023 at 9:17 AM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Tue, Sep 5, 2023 at 8:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > Let's start adding getters for the opaque struct gpio_device. Start with > > a function allowing to retrieve the base GPIO number. > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > I guess you have a solid usecase for drivers needing to do this > crazy thing, because I suppose you feel as much as me that > this should rather be gpiolib-internal and confined to > drivers/gpio/gpiolib.h? > > If you add a valid reason for making this globally visible outside > of drivers/[gpio|pinctrl] to the commit message I guess I can live > with it because we need to think of the bigger picture: > Acked-by: Linus Walleij <linus.walleij@linaro.org> > > It brings to mind the now confusing "base" inside of > struct gpio_chip. We all know it should go away, but since it > is never used during the lifetime of the gpio_chip - or SHOULD > never be used - it should rather be an argument to > [devm_]gpiochip_add_data( .... int base);... > > Maybe something we should add to our TODO file. > > Yours, > Linus Walleij For this series it's the HTE driver that uses it and I don't have a good idea about how to change it. Dipen? I would also love to make pinctrl not use the internal GPIOLIB header so it'll be another user, unless you can figure out a way to not use gc->base? :) I think we're stuck with it for now. Bart
On 9/7/23 12:57 AM, Bartosz Golaszewski wrote: > On Thu, Sep 7, 2023 at 9:17 AM Linus Walleij <linus.walleij@linaro.org> wrote: >> >> On Tue, Sep 5, 2023 at 8:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: >> >>> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> >>> >>> Let's start adding getters for the opaque struct gpio_device. Start with >>> a function allowing to retrieve the base GPIO number. >>> >>> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> >> >> I guess you have a solid usecase for drivers needing to do this >> crazy thing, because I suppose you feel as much as me that >> this should rather be gpiolib-internal and confined to >> drivers/gpio/gpiolib.h? >> >> If you add a valid reason for making this globally visible outside >> of drivers/[gpio|pinctrl] to the commit message I guess I can live >> with it because we need to think of the bigger picture: >> Acked-by: Linus Walleij <linus.walleij@linaro.org> >> >> It brings to mind the now confusing "base" inside of >> struct gpio_chip. We all know it should go away, but since it >> is never used during the lifetime of the gpio_chip - or SHOULD >> never be used - it should rather be an argument to >> [devm_]gpiochip_add_data( .... int base);... >> >> Maybe something we should add to our TODO file. >> >> Yours, >> Linus Walleij > > For this series it's the HTE driver that uses it and I don't have a > good idea about how to change it. Dipen? Missed responding to this, apologies. I believe we are having similar discussion in the hte only patch. We can continue discussing there. > > I would also love to make pinctrl not use the internal GPIOLIB header > so it'll be another user, unless you can figure out a way to not use > gc->base? :) > > I think we're stuck with it for now. > > Bart
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9637a79a9a60..9715bbc698e9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -233,6 +233,19 @@ struct gpio_device *gpiod_to_device(struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_to_device); +/** + * gpio_device_get_base() - Get the base GPIO number allocated by this device + * @gdev: GPIO device + * + * Returns: + * First GPIO number in the global GPIO numberspace for this device. + */ +int gpio_device_get_base(struct gpio_device *gdev) +{ + return gdev->base; +} +EXPORT_SYMBOL_GPL(gpio_device_get_base); + /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base(int ngpio) { diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index e3747e730ed1..b68b3493b29d 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -780,6 +780,9 @@ void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset); struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); struct gpio_device *gpiod_to_device(struct gpio_desc *desc); +/* struct gpio_device getters */ +int gpio_device_get_base(struct gpio_device *gdev); + #else /* CONFIG_GPIOLIB */ #include <linux/err.h>