Thread (26 messages) 26 messages, 8 authors, 2024-11-11

Re: [PATCH v1 3/6] leds: gpio: Avoid using GPIOF_ACTIVE_LOW

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: 2024-11-11 09:56:58
Also in: linux-arm-kernel, linux-gpio, linux-leds, linux-usb, lkml

On Mon, Nov 11, 2024 at 10:45:13AM +0100, Geert Uytterhoeven wrote:
On Mon, Nov 4, 2024 at 10:37 AM Andy Shevchenko
[off-list ref] wrote:
...
quoted
-       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!
quoted
        if (ret < 0)
                return ERR_PTR(ret);
...
quoted
+       if (template->active_low ^ gpiod_is_active_low(gpiod))
+               gpiod_toggle_active_low(gpiod);
+
-- 
With Best Regards,
Andy Shevchenko

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help