[PATCH v4] pwm: mtk-disp: Fix the parameters calculated by the enabled flag of disp_pwm

xinlei.lee@mediatek.com posted 1 patch 1 year, 11 months ago
drivers/pwm/pwm-mtk-disp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH v4] pwm: mtk-disp: Fix the parameters calculated by the enabled flag of disp_pwm
Posted by xinlei.lee@mediatek.com 1 year, 11 months ago
From: xinlei lee <xinlei.lee@mediatek.com>

In the original mtk_disp_pwm_get_state() function wrongly uses bit 0 of
CON0 to judge if the PWM is enabled.
However that is indicated by a bit (at a machine dependent position) in
the DISP_PWM_EN register. Fix this accordingly.

Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()")
Signed-off-by: xinlei lee <xinlei.lee@mediatek.com>
---
Rebase on linus/master v6.1-rc1.

change since v3:
1. Remove the empty line between Fixes: and S-o-b.

change since v2:
1. Modify the code for readability.

change since v1:
1. Modify the way to set disp_pwm enbale.
---
---
 drivers/pwm/pwm-mtk-disp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
index c605013e4114..3fbb4bae93a4 100644
--- a/drivers/pwm/pwm-mtk-disp.c
+++ b/drivers/pwm/pwm-mtk-disp.c
@@ -178,7 +178,7 @@ static void mtk_disp_pwm_get_state(struct pwm_chip *chip,
 {
 	struct mtk_disp_pwm *mdp = to_mtk_disp_pwm(chip);
 	u64 rate, period, high_width;
-	u32 clk_div, con0, con1;
+	u32 clk_div, pwm_en, con0, con1;
 	int err;
 
 	err = clk_prepare_enable(mdp->clk_main);
@@ -197,7 +197,8 @@ static void mtk_disp_pwm_get_state(struct pwm_chip *chip,
 	rate = clk_get_rate(mdp->clk_main);
 	con0 = readl(mdp->base + mdp->data->con0);
 	con1 = readl(mdp->base + mdp->data->con1);
-	state->enabled = !!(con0 & BIT(0));
+	pwm_en = readl(mdp->base + DISP_PWM_EN);
+	state->enabled = !!(pwm_en & mdp->data->enable_mask);
 	clk_div = FIELD_GET(PWM_CLKDIV_MASK, con0);
 	period = FIELD_GET(PWM_PERIOD_MASK, con1);
 	/*
-- 
2.18.0
Re: [PATCH v4] pwm: mtk-disp: Fix the parameters calculated by the enabled flag of disp_pwm
Posted by AngeloGioacchino Del Regno 1 year, 11 months ago
Il 19/10/22 11:42, xinlei.lee@mediatek.com ha scritto:
> From: xinlei lee <xinlei.lee@mediatek.com>
> 
> In the original mtk_disp_pwm_get_state() function wrongly uses bit 0 of
> CON0 to judge if the PWM is enabled.
> However that is indicated by a bit (at a machine dependent position) in
> the DISP_PWM_EN register. Fix this accordingly.
> 
> Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()")
> Signed-off-by: xinlei lee <xinlei.lee@mediatek.com>
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



Re: [PATCH v4] pwm: mtk-disp: Fix the parameters calculated by the enabled flag of disp_pwm
Posted by Uwe Kleine-König 1 year, 11 months ago
On Wed, Oct 19, 2022 at 05:42:18PM +0800, xinlei.lee@mediatek.com wrote:
> From: xinlei lee <xinlei.lee@mediatek.com>
> 
> In the original mtk_disp_pwm_get_state() function wrongly uses bit 0 of
> CON0 to judge if the PWM is enabled.
> However that is indicated by a bit (at a machine dependent position) in
> the DISP_PWM_EN register. Fix this accordingly.
> 
> Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()")
> Signed-off-by: xinlei lee <xinlei.lee@mediatek.com>

Nice commit log text :-)

This now matches the bit that the .apply() callback sets, so looks
right.

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |