Message ID | 20241104093609.156059-4-andriy.shevchenko@linux.intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | e6a2f0ea519fd2478920d02ce3de07a14fe36b2f |
Headers | show |
Series | gpio: Get rid of deprecated GPIOF_ACTIVE_LOW | expand |
On Mon, 04 Nov 2024, Andy Shevchenko wrote: > Avoid using GPIOF_ACTIVE_LOW as it's deprecated and subject to remove. > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > --- > drivers/leds/leds-gpio.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) Acked-by: Lee Jones <lee@kernel.org> > diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c > index 0d59b0bbc002..a3428b22de3a 100644 > --- a/drivers/leds/leds-gpio.c > +++ b/drivers/leds/leds-gpio.c > @@ -212,7 +212,6 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > const struct gpio_led *template) > { > struct gpio_desc *gpiod; > - unsigned long flags = GPIOF_OUT_INIT_LOW; > int ret; > > /* > @@ -239,10 +238,7 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > if (!gpio_is_valid(template->gpio)) > return ERR_PTR(-ENOENT); > > - if (template->active_low) > - flags |= GPIOF_ACTIVE_LOW; > - > - ret = devm_gpio_request_one(dev, template->gpio, flags, > + ret = devm_gpio_request_one(dev, template->gpio, GPIOF_OUT_INIT_LOW, > template->name); > if (ret < 0) > return ERR_PTR(ret); > @@ -251,6 +247,9 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > if (!gpiod) > return ERR_PTR(-EINVAL); > > + if (template->active_low ^ gpiod_is_active_low(gpiod)) > + gpiod_toggle_active_low(gpiod); > + > return gpiod; > } > > -- > 2.43.0.rc1.1336.g36b5255a03ac >
On Mon, Nov 4, 2024 at 10:36 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > Avoid using GPIOF_ACTIVE_LOW as it's deprecated and subject to remove. > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
Hi Andy, On Mon, Nov 4, 2024 at 10:37 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > Avoid using GPIOF_ACTIVE_LOW as it's deprecated and subject to remove. > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Thanks for your patch, which is now commit e6a2f0ea519fd247 ("leds: gpio: Avoid using GPIOF_ACTIVE_LOW") in gpio/gpio/for-next. > --- a/drivers/leds/leds-gpio.c > +++ b/drivers/leds/leds-gpio.c > @@ -212,7 +212,6 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > const struct gpio_led *template) > { > struct gpio_desc *gpiod; > - unsigned long flags = GPIOF_OUT_INIT_LOW; > int ret; > > /* > @@ -239,10 +238,7 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > if (!gpio_is_valid(template->gpio)) > return ERR_PTR(-ENOENT); > > - if (template->active_low) > - flags |= GPIOF_ACTIVE_LOW; > - > - ret = devm_gpio_request_one(dev, template->gpio, flags, > + ret = devm_gpio_request_one(dev, template->gpio, GPIOF_OUT_INIT_LOW, > template->name); Just wondering, as I am not 100% sure: can this change change the initial state of the GPIO? > if (ret < 0) > return ERR_PTR(ret); > @@ -251,6 +247,9 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, > if (!gpiod) > return ERR_PTR(-EINVAL); > > + if (template->active_low ^ gpiod_is_active_low(gpiod)) > + gpiod_toggle_active_low(gpiod); > + > return gpiod; > } Gr{oetje,eeting}s, Geert
On Mon, Nov 11, 2024 at 10:45:13AM +0100, Geert Uytterhoeven wrote: > On Mon, Nov 4, 2024 at 10:37 AM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: ... > > - if (template->active_low) > > - flags |= GPIOF_ACTIVE_LOW; > > - > > - ret = devm_gpio_request_one(dev, template->gpio, flags, > > + ret = devm_gpio_request_one(dev, template->gpio, GPIOF_OUT_INIT_LOW, > > template->name); > > Just wondering, as I am not 100% sure: can this change change the > initial state of the GPIO? You probably wonder how ACTIVE_LOW affects the OUT_INIT_LOW given above. I have an answer to you, however I might be mistaken as well, but I spent some time to investigate. The above mentioned call ends up in the gpiod_direction_output_raw_commit() which uses the value (low in this case) as an absolute value. It does not include the ACTIVE_LOW in the value calculations. Hence, setting ACTIVE_LOW before or afterwards has no effect on the existing flow. If you notice a mistake, please elaborate this, so I can fix the approach! > > if (ret < 0) > > return ERR_PTR(ret); ... > > + if (template->active_low ^ gpiod_is_active_low(gpiod)) > > + gpiod_toggle_active_low(gpiod); > > +
Hi Andy, On Mon, Nov 11, 2024 at 10:57 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Mon, Nov 11, 2024 at 10:45:13AM +0100, Geert Uytterhoeven wrote: > > On Mon, Nov 4, 2024 at 10:37 AM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: > > ... > > > > - if (template->active_low) > > > - flags |= GPIOF_ACTIVE_LOW; > > > - > > > - ret = devm_gpio_request_one(dev, template->gpio, flags, > > > + ret = devm_gpio_request_one(dev, template->gpio, GPIOF_OUT_INIT_LOW, > > > template->name); > > > > Just wondering, as I am not 100% sure: can this change change the > > initial state of the GPIO? > > You probably wonder how ACTIVE_LOW affects the OUT_INIT_LOW given above. > I have an answer to you, however I might be mistaken as well, but I spent some > time to investigate. > > The above mentioned call ends up in the gpiod_direction_output_raw_commit() which > uses the value (low in this case) as an absolute value. It does not include the > ACTIVE_LOW in the value calculations. Hence, setting ACTIVE_LOW before or afterwards > has no effect on the existing flow. > > If you notice a mistake, please elaborate this, so I can fix the approach! Thanks, I had discovered the same, but wanted to double-check! Gr{oetje,eeting}s, Geert
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 0d59b0bbc002..a3428b22de3a 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -212,7 +212,6 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, const struct gpio_led *template) { struct gpio_desc *gpiod; - unsigned long flags = GPIOF_OUT_INIT_LOW; int ret; /* @@ -239,10 +238,7 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, if (!gpio_is_valid(template->gpio)) return ERR_PTR(-ENOENT); - if (template->active_low) - flags |= GPIOF_ACTIVE_LOW; - - ret = devm_gpio_request_one(dev, template->gpio, flags, + ret = devm_gpio_request_one(dev, template->gpio, GPIOF_OUT_INIT_LOW, template->name); if (ret < 0) return ERR_PTR(ret); @@ -251,6 +247,9 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx, if (!gpiod) return ERR_PTR(-EINVAL); + if (template->active_low ^ gpiod_is_active_low(gpiod)) + gpiod_toggle_active_low(gpiod); + return gpiod; }
Avoid using GPIOF_ACTIVE_LOW as it's deprecated and subject to remove. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- drivers/leds/leds-gpio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)