From: Marek Vasut <marex@denx.de>
To: Daniel Thompson <daniel.thompson@linaro.org>
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
Christian Gmeiner <christian.gmeiner@gmail.com>,
Heiko Stuebner <heiko@sntech.de>,
Philipp Zabel <p.zabel@pengutronix.de>,
Thierry Reding <treding@nvidia.com>,
linux-pwm@vger.kernel.org
Subject: Re: [PATCH] backlight: pwm_bl: Avoid backlight flicker if backlight control GPIO is input
Date: Tue, 20 Jul 2021 22:28:32 +0200 [thread overview]
Message-ID: <bbaad78e-91c7-0787-fa72-b5cfabcc6dbd@denx.de> (raw)
In-Reply-To: <20210719112202.4fvmn57ibgy3yesa@maple.lan>
On 7/19/21 1:22 PM, Daniel Thompson wrote:
> On Sun, Jul 18, 2021 at 11:14:15PM +0200, Marek Vasut wrote:
>> If the backlight enable GPIO is configured as input, the driver currently
>> unconditionally forces the GPIO to output-enable. This can cause backlight
>> flicker on boot e.g. in case the GPIO should not be enabled before the PWM
>> is configured and is correctly pulled low by external resistor.
>>
>> Fix this by extending the current check to differentiate between backlight
>> GPIO enable set as input and set as direction unknown. In case of input,
>> read the GPIO value to determine the pull resistor placement, set the GPIO
>> as output, and drive that exact value it was pulled to. In case of unknown
>> direction, retain previous behavior, that is set the GPIO as output-enable.
>>
>> Fixes: 3698d7e7d221 ("backlight: pwm_bl: Avoid backlight flicker when probed from DT")
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
>> Cc: Daniel Thompson <daniel.thompson@linaro.org>
>> Cc: Heiko Stuebner <heiko@sntech.de>
>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>> Cc: Thierry Reding <treding@nvidia.com>
>> Cc: linux-pwm@vger.kernel.org
>> Cc: linux-fbdev@vger.kernel.org
>> To: dri-devel@lists.freedesktop.org
>> ---
>> NOTE: I think this whole auto-detection scheme should just be replaced by a
>> DT prop, because it is very fragile.
>
> I have some sympathy for this view... although I think the boat has
> already set sail.
I'm not sure that's correct, we can simply say that any new uses of the
pwm-backlight should specify the initial GPIO configuration, and for the
legacy ones, use whatever is in the code now.
> However, on the basis of making things less fragile, I think the
> underlying problem here is the assumption that it is safe to modify
> enable_gpio before the driver has imposed state upon the PWM (this
> assumption has always been made and, in addition to systems where the BL
> has a phandle will also risks flicker problems on systems where
> power_pwm_on_delay is not zero).
It is safe to modify the GPIO into defined state, but that defined state
is not always out/enabled, that defined state depends on the hardware.
> This patch does not change the assumption that we can configure the
> GPIO before we modify the PWM state. This means it won't fix the problem
> for cases there the pin is HiZ by default but whose GPIOD_ASIS state is
> neither input nor output.
That is correct, for pin that is floating, we lost. But then I would
argue that if your backlight-enable GPIO is floating, the hardware is
buggy, I would expect some pull resistor to keep the backlight off on
power on on that GPIO.
> I wonder if it might be better to move the code to configure the
> direction of enable_gpio out of the probe function and into
> pwm_backlight_power_on():
No, I tried that already.
The first thing that is called on boot is pwm_backlight_power_off() to
set the backlight to 0 (and thus set pwm to 0), but since pb->enabled is
false, that is where the function exits with configuring PWM and without
configuring the GPIO state.
I also experimented with some "first time only" flag in those functions,
but that looked ugly and complicated the runtime code.
> if (pb->enable_gpio) {
> if (gpiod_get_direction(pb->enable_gpio) != 0))
> gpiod_direction_output(pb->enable_gpio, 1);
> else
> gpiod_set_value_can_sleep(pb->enable_gpio, 1);
> }
>
> By the time we reach this function the driver explicitly applies state
> to the GPIO then we know what the value must be.
See above, I don't think that's the best option.
next prev parent reply other threads:[~2021-07-20 20:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-18 21:14 [PATCH] backlight: pwm_bl: Avoid backlight flicker if backlight control GPIO is input Marek Vasut
2021-07-19 11:22 ` Daniel Thompson
2021-07-20 20:28 ` Marek Vasut [this message]
2021-07-21 10:49 ` Daniel Thompson
2021-07-21 15:09 ` Marek Vasut
2021-07-21 16:12 ` Daniel Thompson
2021-07-21 18:46 ` Marek Vasut
2021-07-22 11:28 ` Daniel Thompson
2021-07-22 19:02 ` Marek Vasut
2021-07-23 10:15 ` Daniel Thompson
2021-07-23 11:17 ` Daniel Thompson
2021-07-23 12:27 ` Marek Vasut
2021-07-21 16:43 ` Daniel Thompson
2021-07-21 19:01 ` Marek Vasut
2021-07-21 20:10 ` Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bbaad78e-91c7-0787-fa72-b5cfabcc6dbd@denx.de \
--to=marex@denx.de \
--cc=christian.gmeiner@gmail.com \
--cc=daniel.thompson@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=heiko@sntech.de \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=treding@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).