linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Marek Vasut <marex@denx.de>
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: Thu, 22 Jul 2021 12:28:24 +0100	[thread overview]
Message-ID: <20210722112824.z5s2fst2q3vrblcr@maple.lan> (raw)
In-Reply-To: <298f6a35-2120-60a6-598a-87b141118bfa@denx.de>

On Wed, Jul 21, 2021 at 08:46:42PM +0200, Marek Vasut wrote:
> On 7/21/21 6:12 PM, Daniel Thompson wrote:
> > On Wed, Jul 21, 2021 at 05:09:57PM +0200, Marek Vasut wrote:
> > > On 7/21/21 12:49 PM, Daniel Thompson wrote:
> > > > > 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.
> > > > 
> > > > I'm not 100% against the idea... however if we still have to get the
> > > > code to read state from the hardware right for legacy cases that means
> > > > we have to do the same work but with fewer people testing it.
> > > 
> > > We can do something like this:
> > > 
> > > if (of_property_read_bool(np, "enable-active-high"))
> > >    gpiod_direction_output(pb->enable_gpio, 1);
> > > else if (of_property_read_bool(np, "enable-active-low"))
> > >    gpiod_direction_output(pb->enable_gpio, 0);
> > > else {
> > >    WARN_ON_ONCE("Fix your DT"); // or some such notification
> > >    ... legacy code path ...
> > > }
> > > 
> > > Note that I picked the same DT prop names as drivers/gpio/gpiolib-of.c
> > > of_gpio_flags_quirks() uses, because we are headed into similar mess here
> > > I'm afraid.
> > 
> > I don't quite understand what you mean here. We are using gpiolib so
> > for us there is no concept of active-high or active-low. The only
> > concept for us is whether enable_gpio is asserted or not.
> 
> It would look the same -- just substitute in "enable-on-boot" and
> "disable-on-boot" DT property.
> 
> > What the DT property would be describing is purely whether the
> > bootloader left the backlight on or off.
> 
> Rather, it would simply control what is the default state of the backlight
> enable GPIO (enabled/disabled).

What do you mean by default state? The current value of the pin or the
desired state when the probe completes?


> > This sails very close to the
> > edge of what is in-scope for DT (at least it does it we can read
> > the inherited state directly from the hardware).
> 
> The problem with reading it out of hardware is that the hardware might be in
> undefined state and expects Linux to define that state, so that does not
> always work. Hence my initial suggestion to add a DT property to define the
> state up front, instead of using these fragile heuristics.

To achieve a flicker-free boot we must know the initial state of the
backlight (not just the enable pin).


> > What it also means decisions about the DT bindings are more about
> > whether, if the backlight is lit up, the bootloader should also disclose
> > what it thinks it has established as the PWM duty cycle as well.
> 
> Please also consider the case where bootloader configures total minimum of
> the hardware to start Linux as soon as possible, i.e. it puts Linux in DRAM
> and jumps to Linux.

I think I have been. I understood that preventing a flicker when booting
with an unconfigured (and off) backlight[1] was the purpose of your patch!

However that is a relatively easy case when considering flicker-free
handover from bootloader since we don't have to inherit the duty cycle.


[1] I guessed that the difference between your platform and the other
    pwm_bl users is that, for you, an uninitialized PWM looks like a
    100% duty cycle hence you get a full-brightness flicker when we change
    the state of the enable_gpio pin before we have established the
    correct PWM duty cycle. Was I right?


> > Overall I have fairly grave concerns that this simply moves
> > fragility into the bootloader rather then reducing it.
> 
> Wait a minute, I think we disconnected somewhere. I would rather prefer to
> remove the fragility and bootloader dependency altogether, exactly to avoid
> depending on the state the bootloader left the hardware in.

The two fully flicker-free cases we support in pwm_bl are:

1. Backlight off after bootloader has completed. Backlight must be
   off after the probe completes (and never flicker on/off during the
   probe). This allows the display to put a splash image on the screen
   before lighting up the backlight (this avoids a flicker if there are
   a few frames between backlight coming on and the splash image being
   drawn). Naturally this requires help from the display system (and
   that the display system is aware of the backlight to be able to start
   it).

2. Backlight on with a splash image after bootloader has completed.
   Backlight must be on after the probe completes (and never flicker
   off/on during the probe). This also requires that the display system
   can take over the frame buffer without a flicker but that is
   completely independent of backlight.

There is also a simpler case which is not "flicker-free" since the
backlight may change level during the boot and may light up before
there is an image on the screen (although we'd still to minimise
flicker by ensuring there is only one change of backlight state/level
during the probe (something your work will see fixed?):

3. Backlight is on after the probe completes. This is default if
   we don't know the display system will activate the backlight.
   This is an important legacy case since few userspaces know how
   to change the backlight power-state at boot.

One oddity here is that #3 *also* needs to know the state of the
backlight (on/off) to turn the backlight on without flickering
(so it can figure out how to handle power_pwm_on_delay correctly)
even though the final state is unconditionally on. That is the main
reason I proposed an alternative to your patch (since this is
currently broken).

The other oddity is that the difference between #1 and #3 is due to
*software* (which driver ends up responsible for unmuting the display)
meaning that the bootloader/DT has no business discriminating between
these two cases.

Thus pwm_bl.c is based on making #2/#3 (which are similar) the default
and switching to case #1 if there is a display driver to do the unblank
(software) *and* that the backlight is currently off (currently read
from hardware). Note that this is intentionally designed to that
if the logic does go wrong we should get a small bug (a flicker) rather
than a big one (a black screen).

Wow! That is *way* longer than I intended when I started writing it.
Anyhow I suspect any disconnect comes about due to the difference in
backlight state *after* probe being, in part, to software structure
rather than purely a hardware property.


Daniel.

  reply	other threads:[~2021-07-22 11:28 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
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 [this message]
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=20210722112824.z5s2fst2q3vrblcr@maple.lan \
    --to=daniel.thompson@linaro.org \
    --cc=christian.gmeiner@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=heiko@sntech.de \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=marex@denx.de \
    --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).