RE: [PATCH v3 04/14] counter: rz-mtu3-cnt: read enable value from cache

From: Biju Das

Date: Tue Nov 17 2026 - 09:05:55 EST




> -----Original Message-----
> From: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@xxxxxxxxxxx>
> Sent: 17 November 2026 10:26
> Subject: [PATCH v3 04/14] counter: rz-mtu3-cnt: read enable value from cache
>
> Reading the enable value when PWM is in use returns -EINVAL because of the checks inside
> rz_mtu3_lock_if_count_is_enabled(). Reading the enable value should not be an issue even if PWM on
> that specific MTU channel is enabled.
>
> There is no need to check whether the underlying MTU3 channel is enabled when determining whether a
> count is enabled, as we have a local count_is_enabled array containing exactly that information, which
> cannot be wrong.
>
> Use the information in the local count_is_enabled array and allow reading it even if PWM is in use.
>
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@xxxxxxxxxxx>

Reviewed-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> ---
>
> V3:
> * no changes
>
> V2:
> * no changes
>
> drivers/counter/rz-mtu3-cnt.c | 15 ++-------------
> 1 file changed, 2 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index
> b1848a0b17e5..db30470215c2 100644
> --- a/drivers/counter/rz-mtu3-cnt.c
> +++ b/drivers/counter/rz-mtu3-cnt.c
> @@ -469,21 +469,10 @@ static void rz_mtu3_terminate_counter(struct counter_device *counter, int id)
> static int rz_mtu3_count_enable_read(struct counter_device *counter,
> struct counter_count *count, u8 *enable) {
> - struct rz_mtu3_channel *const ch = rz_mtu3_get_ch(counter, count->id);
> - struct rz_mtu3_channel *const ch1 = rz_mtu3_get_ch(counter, 0);
> - struct rz_mtu3_channel *const ch2 = rz_mtu3_get_ch(counter, 1);
> struct rz_mtu3_cnt *const priv = counter_priv(counter);
> - int ret;
> -
> - ret = rz_mtu3_lock_if_count_is_enabled(ch, priv, count->id);
> - if (ret)
> - return ret;
> -
> - if (count->id == RZ_MTU3_32_BIT_CH)
> - *enable = rz_mtu3_is_enabled(ch1) && rz_mtu3_is_enabled(ch2);
> - else
> - *enable = rz_mtu3_is_enabled(ch);
>
> + mutex_lock(&priv->lock);
> + *enable = priv->count_is_enabled[count->id];
> mutex_unlock(&priv->lock);
>
> return 0;
> --
> 2.56.0