[PATCH 05/15] counter: rz-mtu3-cnt: read enable value from cache

From: Cosmin Tanislav

Date: Mon Sep 14 2026 - 16:43:53 EST


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>
---
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 b99dd67703df..d3daf258a3b8 100644
--- a/drivers/counter/rz-mtu3-cnt.c
+++ b/drivers/counter/rz-mtu3-cnt.c
@@ -471,21 +471,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.55.0