All of lore.kernel.org
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno  <angelogioacchino.delregno@collabora.com>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>
Cc: thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de,
	matthias.bgg@gmail.com, weiqing.kong@mediatek.com,
	jitao.shi@mediatek.com, linux-pwm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com
Subject: Re: [PATCH 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state()
Date: Thu, 26 Jan 2023 16:24:29 +0100	[thread overview]
Message-ID: <aa17fa46-0f16-2102-1bd3-6d76cee90ee1@collabora.com> (raw)
In-Reply-To: <20230126151914.rhwhioz6yyhaq3z2@notapiano>

Il 26/01/23 16:19, Nícolas F. R. A. Prado ha scritto:
> On Mon, Jan 23, 2023 at 05:06:15PM +0100, 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>
>> ---
>>   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)
> 
> I feel like this condition should be the same as in the apply() callback, since
> they're doing the same write operation, so also have '&& !has_commit'.
> 

The bls_debug register is used to both enable and/or disable various features,
including the one that I'm targeting in this commit, which is disabling shadow
registers.

As I explained in the commit message, we don't want to - and cannot - assume that
the bootloader doesn't *reset* the backlight controller before booting Linux: a
reset would re-enable the shadow registers, and this function being called as
first to check the backlight EN status may fail to do so.

This is as well true in the opposite situation where, in the future, we may want
to set shadow registers ON, while the bootloader sets them OFF before booting:
adding a (x && !has_commit) check in this branch would defeat that purpose and
make this commit... well.. partially broken! :-)

Cheers!
Angelo

> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> 
> On MT8192 Asurada Spherion.
> 
> Thanks,
> Nícolas
> 
>> +		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
>>
>>



WARNING: multiple messages have this Message-ID (diff)
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>
Cc: thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de,
	matthias.bgg@gmail.com, weiqing.kong@mediatek.com,
	jitao.shi@mediatek.com, linux-pwm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com
Subject: Re: [PATCH 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state()
Date: Thu, 26 Jan 2023 16:24:29 +0100	[thread overview]
Message-ID: <aa17fa46-0f16-2102-1bd3-6d76cee90ee1@collabora.com> (raw)
In-Reply-To: <20230126151914.rhwhioz6yyhaq3z2@notapiano>

Il 26/01/23 16:19, Nícolas F. R. A. Prado ha scritto:
> On Mon, Jan 23, 2023 at 05:06:15PM +0100, 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>
>> ---
>>   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)
> 
> I feel like this condition should be the same as in the apply() callback, since
> they're doing the same write operation, so also have '&& !has_commit'.
> 

The bls_debug register is used to both enable and/or disable various features,
including the one that I'm targeting in this commit, which is disabling shadow
registers.

As I explained in the commit message, we don't want to - and cannot - assume that
the bootloader doesn't *reset* the backlight controller before booting Linux: a
reset would re-enable the shadow registers, and this function being called as
first to check the backlight EN status may fail to do so.

This is as well true in the opposite situation where, in the future, we may want
to set shadow registers ON, while the bootloader sets them OFF before booting:
adding a (x && !has_commit) check in this branch would defeat that purpose and
make this commit... well.. partially broken! :-)

Cheers!
Angelo

> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> 
> On MT8192 Asurada Spherion.
> 
> Thanks,
> Nícolas
> 
>> +		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
>>
>>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-01-26 15:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 16:06 [PATCH 0/2] pwm: mtk-disp: Fix backlight configuration at boot AngeloGioacchino Del Regno
2023-01-23 16:06 ` AngeloGioacchino Del Regno
2023-01-23 16:06 ` [PATCH 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values AngeloGioacchino Del Regno
2023-01-23 16:06   ` AngeloGioacchino Del Regno
2023-01-26 15:06   ` Nícolas F. R. A. Prado
2023-01-26 15:06     ` Nícolas F. R. A. Prado
2023-01-26 15:20     ` AngeloGioacchino Del Regno
2023-01-26 15:20       ` AngeloGioacchino Del Regno
2023-01-23 16:06 ` [PATCH 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() AngeloGioacchino Del Regno
2023-01-23 16:06   ` AngeloGioacchino Del Regno
2023-01-26 15:19   ` Nícolas F. R. A. Prado
2023-01-26 15:19     ` Nícolas F. R. A. Prado
2023-01-26 15:24     ` AngeloGioacchino Del Regno [this message]
2023-01-26 15:24       ` AngeloGioacchino Del Regno
2023-01-26 16:09       ` Nícolas F. R. A. Prado
2023-01-26 16:09         ` Nícolas F. R. A. Prado
2023-01-26 16:16         ` AngeloGioacchino Del Regno
2023-01-26 16:16           ` AngeloGioacchino Del Regno
2023-01-26 15:31 ` [PATCH 0/2] pwm: mtk-disp: Fix backlight configuration at boot Adrian Ratiu
2023-01-26 15:31   ` Adrian Ratiu
2023-02-23 14:16 ` AngeloGioacchino Del Regno
2023-02-23 14:16   ` AngeloGioacchino Del Regno
2023-03-08 11:46   ` AngeloGioacchino Del Regno
2023-03-08 11:46     ` AngeloGioacchino Del Regno
2023-03-08 14:50     ` Greg Kroah-Hartman
2023-03-08 14:50       ` Greg Kroah-Hartman
2023-03-08 14:55       ` AngeloGioacchino Del Regno
2023-03-08 14:55         ` AngeloGioacchino Del Regno
2023-03-08 15:43         ` Greg Kroah-Hartman
2023-03-08 15:43           ` Greg Kroah-Hartman
2023-03-08 16:04           ` AngeloGioacchino Del Regno
2023-03-08 16:04             ` AngeloGioacchino Del Regno
2023-03-08 16:07           ` Uwe Kleine-König
2023-03-08 16:07             ` Uwe Kleine-König

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=aa17fa46-0f16-2102-1bd3-6d76cee90ee1@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=jitao.shi@mediatek.com \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=weiqing.kong@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.