Message ID | 20231009-pxa-gpio-v7-2-c8f5f403e856@skole.hr |
---|---|
State | Superseded |
Headers | show |
Series | ARM: pxa: GPIO descriptor conversions | expand |
On Mon, Oct 9, 2023 at 8:34 PM Duje Mihanović <duje.mihanovic@skole.hr> wrote: > > Sharp's Spitz board still uses the legacy GPIO interface for configuring > its two onboard LEDs. > > Convert them to use the GPIO descriptor interface. > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr> > --- > arch/arm/mach-pxa/spitz.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c > index 535e2b2e997b..29907abc4513 100644 > --- a/arch/arm/mach-pxa/spitz.c > +++ b/arch/arm/mach-pxa/spitz.c > @@ -452,16 +452,25 @@ static inline void spitz_keys_init(void) {} > * LEDs > ******************************************************************************/ > #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) > +static struct gpiod_lookup_table spitz_led_gpio_table = { > + .dev_id = "leds-gpio", > + .table = { > + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, 0, > + GPIO_ACTIVE_HIGH), > + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, 1, > + GPIO_ACTIVE_HIGH), > + { } > + } > +}; > + > static struct gpio_led spitz_gpio_leds[] = { > { > .name = "spitz:amber:charge", > .default_trigger = "sharpsl-charge", > - .gpio = SPITZ_GPIO_LED_ORANGE, > }, > { > .name = "spitz:green:hddactivity", > .default_trigger = "disk-activity", > - .gpio = SPITZ_GPIO_LED_GREEN, > }, > }; > > @@ -478,9 +487,16 @@ static struct platform_device spitz_led_device = { > }, > }; > > +static struct gpio_descs *leds; > + > static void __init spitz_leds_init(void) > { > + gpiod_add_lookup_table(&spitz_led_gpio_table); > platform_device_register(&spitz_led_device); > + leds = gpiod_get_array_optional(&spitz_led_device.dev, > + NULL, GPIOD_ASIS); > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > } > #else > static inline void spitz_leds_init(void) {} > > -- > 2.42.0 > > Gah! I should have noticed this earlier but this is a perfect candidate for using hogs. Can you use gpiod_add_hogs() from linux/gpio/machine.h instead? That would save you having the lookup and the static leds descriptor array. Bart
On Tuesday, October 10, 2023 1:12:05 PM CEST Bartosz Golaszewski wrote: > Gah! I should have noticed this earlier but this is a perfect > candidate for using hogs. Can you use gpiod_add_hogs() from > linux/gpio/machine.h instead? That would save you having the lookup > and the static leds descriptor array.
On Tue, Oct 10, 2023 at 6:33 PM Duje Mihanović <duje.mihanovic@skole.hr> wrote: > > On Tuesday, October 10, 2023 1:12:05 PM CEST Bartosz Golaszewski wrote: > > Gah! I should have noticed this earlier but this is a perfect > > candidate for using hogs. Can you use gpiod_add_hogs() from > > linux/gpio/machine.h instead? That would save you having the lookup > > and the static leds descriptor array. > > From what I can tell, the hogs keep a certain pin at a certain state as long > as the machine is powered on. Is this really what we want to do with LEDs or > am I missing something? > It doesn't seem like anyone is using these GPIOs once they're requested? Wouldn't the above definitios be analogous to: GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) ? Bart
On Tue, Oct 10, 2023 at 7:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > It doesn't seem like anyone is using these GPIOs once they're > requested? Wouldn't the above definitios be analogous to: > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) They are used: + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; The descriptors are passed to the leds-gpio driver. But wait: no. This whole thing: +static struct gpio_descs *leds; + (...) + leds = gpiod_get_array_optional(&spitz_led_device.dev, + NULL, GPIOD_ASIS); + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; Just delete all that. The leds-gpio driver will request and use the lines. It was just so unorthodox that I missed it. Adding the descriptor table is enough. Yours, Linus Walleij
On Tue, Oct 10, 2023 at 10:04 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Tue, Oct 10, 2023 at 7:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > It doesn't seem like anyone is using these GPIOs once they're > > requested? Wouldn't the above definitios be analogous to: > > > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > > They are used: > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > > The descriptors are passed to the leds-gpio driver. > > But wait: no. > > This whole thing: > > +static struct gpio_descs *leds; > + > (...) > + leds = gpiod_get_array_optional(&spitz_led_device.dev, > + NULL, GPIOD_ASIS); > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > > Just delete all that. > > The leds-gpio driver will request and use the lines. > > It was just so unorthodox that I missed it. Adding the descriptor > table is enough. Ah, good catch. Your suggestion is of course the correct one. Bart > > Yours, > Linus Walleij
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index 535e2b2e997b..29907abc4513 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -452,16 +452,25 @@ static inline void spitz_keys_init(void) {} * LEDs ******************************************************************************/ #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) +static struct gpiod_lookup_table spitz_led_gpio_table = { + .dev_id = "leds-gpio", + .table = { + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, 0, + GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, 1, + GPIO_ACTIVE_HIGH), + { } + } +}; + static struct gpio_led spitz_gpio_leds[] = { { .name = "spitz:amber:charge", .default_trigger = "sharpsl-charge", - .gpio = SPITZ_GPIO_LED_ORANGE, }, { .name = "spitz:green:hddactivity", .default_trigger = "disk-activity", - .gpio = SPITZ_GPIO_LED_GREEN, }, }; @@ -478,9 +487,16 @@ static struct platform_device spitz_led_device = { }, }; +static struct gpio_descs *leds; + static void __init spitz_leds_init(void) { + gpiod_add_lookup_table(&spitz_led_gpio_table); platform_device_register(&spitz_led_device); + leds = gpiod_get_array_optional(&spitz_led_device.dev, + NULL, GPIOD_ASIS); + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; } #else static inline void spitz_leds_init(void) {}