pwm: mtk-disp: Configure double buffering before reading in .get_state()
authorAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Mon, 3 Apr 2023 13:30:54 +0000 (15:30 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Thu, 6 Apr 2023 14:23:23 +0000 (16:23 +0200)
commitb16c310115f2084b8826a35b77ef42bab6786d9f
treed527ac4f51dc88d4cf8d9d72152b6562623448f7
parent36dd7f530ae7d9ce9e853ffb8aa337de65c6600b
pwm: mtk-disp: Configure double buffering before reading in .get_state()

The DISP_PWM controller's default behavior is to always use register
double buffering: all reads/writes are then performed on shadow
registers instead of working registers and this becomes an issue
in case our chosen configuration in Linux is different from the
default (or from the one that was pre-applied by the bootloader).

An example of broken behavior is when the controller is configured
to use shadow registers, but this driver wants to configure it
otherwise: what happens is that the .get_state() callback is called
right after registering the pwmchip and checks whether the PWM is
enabled by reading the DISP_PWM_EN register;
At this point, if shadow registers are enabled but their content
was not committed before booting Linux, we are *not* reading the
current PWM enablement status, leading to the kernel knowing that
the hardware is actually enabled when, in reality, it's not.

The aforementioned issue emerged since this driver was fixed with
commit 0b5ef3429d8f ("pwm: mtk-disp: Fix the parameters calculated
by the enabled flag of disp_pwm") making it to read the enablement
status from the right register.

Configure the controller in the .get_state() callback to avoid
this desync issue and get the backlight properly working again.

Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Tested-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Tested-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-mtk-disp.c