drivers/pwm/pwm-rzg2l-gpt.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
From: Biju Das <biju.das.jz@bp.renesas.com>
The rzg2l_gpt_config() test the rzg2l_gpt->period_tick variable. This
check is not valid, if enabling of a channel happens after disabling all
the channels as it test against the cached value. Therefore, reinitialize
the variable rzg2l_gpt->period_tick to 0 in rzg2l_gpt_disable(), when
all the logical channels of a hardware channel is disabled.
Cc: stable@kernel.org
Fixes: 061f087f5d0b ("pwm: Add support for RZ/G2L GPT")
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3->v4:
* Split the patch as separate from [1] for easy merging.
* Updated commit description
* Added comments about the fix in rzg2l_gpt_disable()
v3:
* New patch
[1] https://lore.kernel.org/all/20250915163637.3572-1-biju.das.jz@bp.renesas.com/#t
---
drivers/pwm/pwm-rzg2l-gpt.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c
index 360c8bf3b190..ab91bfd7da48 100644
--- a/drivers/pwm/pwm-rzg2l-gpt.c
+++ b/drivers/pwm/pwm-rzg2l-gpt.c
@@ -190,8 +190,17 @@ static void rzg2l_gpt_disable(struct rzg2l_gpt_chip *rzg2l_gpt,
/* Stop count, Output low on GTIOCx pin when counting stops */
rzg2l_gpt->channel_enable_count[ch]--;
- if (!rzg2l_gpt->channel_enable_count[ch])
+ if (!rzg2l_gpt->channel_enable_count[ch]) {
rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), RZG2L_GTCR_CST, 0);
+ /*
+ * The rzg2l_gpt_config() test the rzg2l_gpt->period_tick
+ * variable. This check is not valid, if enabling of a channel
+ * happens after disabling all the channels as it test against
+ * the cached value. Therefore, reinitialize the variable
+ * rzg2l_gpt->period_tick to 0.
+ */
+ rzg2l_gpt->period_ticks[ch] = 0;
+ }
/* Disable pin output */
rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTIOR(ch), RZG2L_GTIOR_OxE(sub_ch), 0);
--
2.43.0
Hello Biju,
On Fri, Nov 14, 2025 at 02:56:01PM +0000, Biju wrote:
> From: Biju Das <biju.das.jz@bp.renesas.com>
>
> The rzg2l_gpt_config() test the rzg2l_gpt->period_tick variable. This
> check is not valid, if enabling of a channel happens after disabling all
> the channels as it test against the cached value. Therefore, reinitialize
> the variable rzg2l_gpt->period_tick to 0 in rzg2l_gpt_disable(), when
> all the logical channels of a hardware channel is disabled.
>
> Cc: stable@kernel.org
> Fixes: 061f087f5d0b ("pwm: Add support for RZ/G2L GPT")
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v3->v4:
> * Split the patch as separate from [1] for easy merging.
> * Updated commit description
> * Added comments about the fix in rzg2l_gpt_disable()
> v3:
> * New patch
>
> [1] https://lore.kernel.org/all/20250915163637.3572-1-biju.das.jz@bp.renesas.com/#t
> ---
> drivers/pwm/pwm-rzg2l-gpt.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c
> index 360c8bf3b190..ab91bfd7da48 100644
> --- a/drivers/pwm/pwm-rzg2l-gpt.c
> +++ b/drivers/pwm/pwm-rzg2l-gpt.c
> @@ -190,8 +190,17 @@ static void rzg2l_gpt_disable(struct rzg2l_gpt_chip *rzg2l_gpt,
> /* Stop count, Output low on GTIOCx pin when counting stops */
> rzg2l_gpt->channel_enable_count[ch]--;
>
> - if (!rzg2l_gpt->channel_enable_count[ch])
> + if (!rzg2l_gpt->channel_enable_count[ch]) {
> rzg2l_gpt_modify(rzg2l_gpt, RZG2L_GTCR(ch), RZG2L_GTCR_CST, 0);
> + /*
> + * The rzg2l_gpt_config() test the rzg2l_gpt->period_tick
> + * variable. This check is not valid, if enabling of a channel
> + * happens after disabling all the channels as it test against
> + * the cached value. Therefore, reinitialize the variable
> + * rzg2l_gpt->period_tick to 0.
> + */
> + rzg2l_gpt->period_ticks[ch] = 0;
> + }
I think this is wrong. rzg2l_gpt_config() has:
if (rzg2l_gpt->channel_request_count[ch] > 1) {
if (period_ticks < rzg2l_gpt->period_ticks[ch])
return -EBUSY;
else
period_ticks = rzg2l_gpt->period_ticks[ch];
}
So if both PWMs of channel `ch` are requested but disabled,
rzg2l_gpt->period_ticks[ch] is 0 so you assign
period_ticks = rzg2l_gpt->period_ticks[ch];
. In that case however you don't want to change period_ticks, right?
Best regards
Uwe
© 2016 - 2026 Red Hat, Inc.