On 7/22/21 1:28 PM, Daniel Thompson wrote:
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?
I think that would be the later.
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).
The backlight hardware might be in uninitialized state and then Linux
should set the state, likely based on something in DT, because there is
no previous state to read.
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?
Right, that. In my case the enable GPIO is input (default) with pull
resistor.
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?):
Actually no, my usecase is the backlight is not initialized by the
bootloader at all, the pins are just strapped to default to the right
values, the init is left to the kernel to do.
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.
Maybe this should be added to documentation.