* [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot
@ 2023-04-03 13:30 AngeloGioacchino Del Regno
2023-04-03 13:30 ` [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-04-03 13:30 UTC (permalink / raw)
To: thierry.reding
Cc: u.kleine-koenig, matthias.bgg, weiqing.kong, jitao.shi, linux-pwm,
linux-arm-kernel, linux-mediatek, linux-kernel, kernel, wenst,
AngeloGioacchino Del Regno
Since the pwm-mtk-disp driver was fixed to get PWM_EN state from the
right register, an old two-wrongs-make-one-right issue emerged: as a
result, MT8192 Asurada Spherion got no backlight at boot unless a
suspend/resume cycle was performed.
Also, the backlight would sometimes not get updated with the requested
value, requiring the user to change it back and forth until it worked.
This series fixes both of the aforementioned issues found on MT8192
and similar issues on MT8183 Chromebooks.
AngeloGioacchino Del Regno (2):
pwm: mtk-disp: Disable shadow registers before setting backlight
values
pwm: mtk-disp: Configure double buffering before reading in
.get_state()
drivers/pwm/pwm-mtk-disp.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
--
2.39.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values 2023-04-03 13:30 [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot AngeloGioacchino Del Regno @ 2023-04-03 13:30 ` AngeloGioacchino Del Regno 2023-04-05 9:26 ` Alexandre Mergnat 2023-04-03 13:30 ` [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() AngeloGioacchino Del Regno 2023-04-06 14:24 ` [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot Thierry Reding 2 siblings, 1 reply; 6+ messages in thread From: AngeloGioacchino Del Regno @ 2023-04-03 13:30 UTC (permalink / raw) To: thierry.reding Cc: u.kleine-koenig, matthias.bgg, weiqing.kong, jitao.shi, linux-pwm, linux-arm-kernel, linux-mediatek, linux-kernel, kernel, wenst, AngeloGioacchino Del Regno, Nícolas F . R . A . Prado If shadow registers usage is not desired, disable that before performing any write to CON0/1 registers in the .apply() callback, otherwise we may lose clkdiv or period/width updates. Fixes: cd4b45ac449a ("pwm: Add MediaTek MT2701 display PWM driver support") 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> --- drivers/pwm/pwm-mtk-disp.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 692a06121b28..82b430d881a2 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -138,6 +138,19 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, high_width = mul_u64_u64_div_u64(state->duty_cycle, rate, div); value = period | (high_width << PWM_HIGH_WIDTH_SHIFT); + if (mdp->data->bls_debug && !mdp->data->has_commit) { + /* + * For MT2701, disable double buffer before writing register + * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. + */ + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, + mdp->data->bls_debug_mask, + mdp->data->bls_debug_mask); + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, + mdp->data->con0_sel, + mdp->data->con0_sel); + } + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, PWM_CLKDIV_MASK, clk_div << PWM_CLKDIV_SHIFT); @@ -152,17 +165,6 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, mtk_disp_pwm_update_bits(mdp, mdp->data->commit, mdp->data->commit_mask, 0x0); - } else { - /* - * For MT2701, disable double buffer before writing register - * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. - */ - mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, - mdp->data->bls_debug_mask, - mdp->data->bls_debug_mask); - mtk_disp_pwm_update_bits(mdp, mdp->data->con0, - mdp->data->con0_sel, - mdp->data->con0_sel); } mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask, -- 2.39.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values 2023-04-03 13:30 ` [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno @ 2023-04-05 9:26 ` Alexandre Mergnat 0 siblings, 0 replies; 6+ messages in thread From: Alexandre Mergnat @ 2023-04-05 9:26 UTC (permalink / raw) To: AngeloGioacchino Del Regno, thierry.reding Cc: u.kleine-koenig, matthias.bgg, weiqing.kong, jitao.shi, linux-pwm, linux-arm-kernel, linux-mediatek, linux-kernel, kernel, wenst, Nícolas F . R . A . Prado On 03/04/2023 15:30, AngeloGioacchino Del Regno wrote: > If shadow registers usage is not desired, disable that before performing > any write to CON0/1 registers in the .apply() callback, otherwise we may > lose clkdiv or period/width updates. > > Fixes: cd4b45ac449a ("pwm: Add MediaTek MT2701 display PWM driver support") > 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> > --- > drivers/pwm/pwm-mtk-disp.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c > index 692a06121b28..82b430d881a2 100644 > --- a/drivers/pwm/pwm-mtk-disp.c > +++ b/drivers/pwm/pwm-mtk-disp.c > @@ -138,6 +138,19 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > high_width = mul_u64_u64_div_u64(state->duty_cycle, rate, div); > value = period | (high_width << PWM_HIGH_WIDTH_SHIFT); > > + if (mdp->data->bls_debug && !mdp->data->has_commit) { > + /* > + * For MT2701, disable double buffer before writing register > + * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. > + */ > + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, > + mdp->data->bls_debug_mask, > + mdp->data->bls_debug_mask); > + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, > + mdp->data->con0_sel, > + mdp->data->con0_sel); > + } > + > mtk_disp_pwm_update_bits(mdp, mdp->data->con0, > PWM_CLKDIV_MASK, > clk_div << PWM_CLKDIV_SHIFT); > @@ -152,17 +165,6 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > mtk_disp_pwm_update_bits(mdp, mdp->data->commit, > mdp->data->commit_mask, > 0x0); > - } else { > - /* > - * For MT2701, disable double buffer before writing register > - * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. > - */ > - mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, > - mdp->data->bls_debug_mask, > - mdp->data->bls_debug_mask); > - mtk_disp_pwm_update_bits(mdp, mdp->data->con0, > - mdp->data->con0_sel, > - mdp->data->con0_sel); > } > > mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask, Hi, I've made a non-regression test for the mt8365-evk (i350-evk) board. It's fine for me. Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> Tested-by: Alexandre Mergnat <amergnat@baylibre.com> Regards, Alex ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() 2023-04-03 13:30 [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot AngeloGioacchino Del Regno 2023-04-03 13:30 ` [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno @ 2023-04-03 13:30 ` AngeloGioacchino Del Regno 2023-04-05 9:28 ` Alexandre Mergnat 2023-04-06 14:24 ` [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot Thierry Reding 2 siblings, 1 reply; 6+ messages in thread From: AngeloGioacchino Del Regno @ 2023-04-03 13:30 UTC (permalink / raw) To: thierry.reding Cc: u.kleine-koenig, matthias.bgg, weiqing.kong, jitao.shi, linux-pwm, linux-arm-kernel, linux-mediatek, linux-kernel, kernel, wenst, AngeloGioacchino Del Regno, Nícolas F . R . A . Prado 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> --- drivers/pwm/pwm-mtk-disp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 82b430d881a2..fe9593f968ee 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -196,6 +196,16 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip, return err; } + /* + * Apply DISP_PWM_DEBUG settings to choose whether to enable or disable + * registers double buffer and manual commit to working register before + * performing any read/write operation + */ + if (mdp->data->bls_debug) + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, + mdp->data->bls_debug_mask, + mdp->data->bls_debug_mask); + rate = clk_get_rate(mdp->clk_main); con0 = readl(mdp->base + mdp->data->con0); con1 = readl(mdp->base + mdp->data->con1); -- 2.39.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() 2023-04-03 13:30 ` [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() AngeloGioacchino Del Regno @ 2023-04-05 9:28 ` Alexandre Mergnat 0 siblings, 0 replies; 6+ messages in thread From: Alexandre Mergnat @ 2023-04-05 9:28 UTC (permalink / raw) To: AngeloGioacchino Del Regno, thierry.reding Cc: u.kleine-koenig, matthias.bgg, weiqing.kong, jitao.shi, linux-pwm, linux-arm-kernel, linux-mediatek, linux-kernel, kernel, wenst, Nícolas F . R . A . Prado On 03/04/2023 15:30, AngeloGioacchino Del Regno wrote: > 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> > --- > drivers/pwm/pwm-mtk-disp.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c > index 82b430d881a2..fe9593f968ee 100644 > --- a/drivers/pwm/pwm-mtk-disp.c > +++ b/drivers/pwm/pwm-mtk-disp.c > @@ -196,6 +196,16 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip, > return err; > } > > + /* > + * Apply DISP_PWM_DEBUG settings to choose whether to enable or disable > + * registers double buffer and manual commit to working register before > + * performing any read/write operation > + */ > + if (mdp->data->bls_debug) > + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, > + mdp->data->bls_debug_mask, > + mdp->data->bls_debug_mask); > + > rate = clk_get_rate(mdp->clk_main); > con0 = readl(mdp->base + mdp->data->con0); > con1 = readl(mdp->base + mdp->data->con1); Hi, Same test. Looks fine. Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> Tested-by: Alexandre Mergnat <amergnat@baylibre.com> Regards, Alex ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot 2023-04-03 13:30 [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot AngeloGioacchino Del Regno 2023-04-03 13:30 ` [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno 2023-04-03 13:30 ` [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() AngeloGioacchino Del Regno @ 2023-04-06 14:24 ` Thierry Reding 2 siblings, 0 replies; 6+ messages in thread From: Thierry Reding @ 2023-04-06 14:24 UTC (permalink / raw) To: AngeloGioacchino Del Regno Cc: linux-arm-kernel, matthias.bgg, linux-mediatek, u.kleine-koenig, wenst, kernel, linux-kernel, jitao.shi, weiqing.kong, linux-pwm On Mon, 3 Apr 2023 15:30:52 +0200, AngeloGioacchino Del Regno wrote: > Since the pwm-mtk-disp driver was fixed to get PWM_EN state from the > right register, an old two-wrongs-make-one-right issue emerged: as a > result, MT8192 Asurada Spherion got no backlight at boot unless a > suspend/resume cycle was performed. > Also, the backlight would sometimes not get updated with the requested > value, requiring the user to change it back and forth until it worked. > > [...] Applied, thanks! [1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values commit: 36dd7f530ae7d9ce9e853ffb8aa337de65c6600b [2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() commit: b16c310115f2084b8826a35b77ef42bab6786d9f Best regards, -- Thierry Reding <thierry.reding@gmail.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-04-06 14:24 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-04-03 13:30 [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot AngeloGioacchino Del Regno 2023-04-03 13:30 ` [PATCH RESEND 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno 2023-04-05 9:26 ` Alexandre Mergnat 2023-04-03 13:30 ` [PATCH RESEND 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() AngeloGioacchino Del Regno 2023-04-05 9:28 ` Alexandre Mergnat 2023-04-06 14:24 ` [PATCH RESEND 0/2] pwm: mtk-disp: Fix backlight configuration at boot Thierry Reding
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox