[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260130122353.2263273-4-cosmin-gabriel.tanislav.xa@renesas.com>
Date: Fri, 30 Jan 2026 14:23:51 +0200
From: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@...esas.com>
To: Biju Das <biju.das.jz@...renesas.com>,
William Breathitt Gray <wbg@...nel.org>,
Uwe Kleine-König <ukleinek@...nel.org>,
Lee Jones <lee@...nel.org>,
Thierry Reding <thierry.reding@...il.com>
Cc: linux-iio@...r.kernel.org,
linux-renesas-soc@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-pwm@...r.kernel.org,
Cosmin Tanislav <cosmin-gabriel.tanislav.xa@...esas.com>,
stable@...r.kernel.org
Subject: [PATCH 3/5] pwm: rz-mtu3: correctly enable HW channel 4 and 7
HW channels 4 and 7 require an additional bit to be set in the TOER{A,B}
registers in order to enable PWM output.
Add the necessary logic to update these bits when enabling or disabling
PWM on these channels.
Cc: stable@...r.kernel.org
Fixes: 254d3a727421 ("pwm: Add Renesas RZ/G2L MTU3a PWM driver")
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@...esas.com>
---
drivers/pwm/pwm-rz-mtu3.c | 40 +++++++++++++++++++++++++++++++++++--
include/linux/mfd/rz-mtu3.h | 2 ++
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-rz-mtu3.c b/drivers/pwm/pwm-rz-mtu3.c
index 7558e28f4786..ed5fbc4015aa 100644
--- a/drivers/pwm/pwm-rz-mtu3.c
+++ b/drivers/pwm/pwm-rz-mtu3.c
@@ -226,10 +226,37 @@ static void rz_mtu3_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
mutex_unlock(&rz_mtu3_pwm->lock);
}
+static void rz_mtu3_pwm_set_toer_bit(struct rz_mtu3_pwm_chip *rz_mtu3_pwm,
+ struct rz_mtu3_pwm_channel *priv,
+ bool is_primary, bool set)
+{
+ u8 bitpos;
+ u16 reg;
+
+ /*
+ * HW channels 4 and 7 require an additional register write to enable
+ * PWM output.
+ */
+ if (priv->mtu->channel_number == RZ_MTU3_CHAN_4)
+ reg = RZ_MTU3_TOERA;
+ else if (priv->mtu->channel_number == RZ_MTU3_CHAN_7)
+ reg = RZ_MTU3_TOERB;
+ else
+ return;
+
+ if (is_primary)
+ bitpos = 1;
+ else
+ bitpos = 4;
+
+ rz_mtu3_shared_reg_update_bit(priv->mtu, reg, bitpos, set);
+}
+
static int rz_mtu3_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
struct rz_mtu3_pwm_channel *priv;
+ bool is_primary;
u32 ch;
u8 val;
int rc;
@@ -240,10 +267,15 @@ static int rz_mtu3_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
ch = priv - rz_mtu3_pwm->channel_data;
+ is_primary = priv->map->base_pwm_number == pwm->hwpwm;
+
val = RZ_MTU3_TIOR_OC_IOB_TOGGLE | RZ_MTU3_TIOR_OC_IOA_H_COMP_MATCH;
rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TMDR1, RZ_MTU3_TMDR1_MD_PWMMODE1);
- if (priv->map->base_pwm_number == pwm->hwpwm)
+
+ rz_mtu3_pwm_set_toer_bit(rz_mtu3_pwm, priv, is_primary, true);
+
+ if (is_primary)
rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORH, val);
else
rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORL, val);
@@ -262,17 +294,21 @@ static void rz_mtu3_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct rz_mtu3_pwm_chip *rz_mtu3_pwm = to_rz_mtu3_pwm_chip(chip);
struct rz_mtu3_pwm_channel *priv;
+ bool is_primary;
u32 ch;
priv = rz_mtu3_get_channel(rz_mtu3_pwm, pwm->hwpwm);
ch = priv - rz_mtu3_pwm->channel_data;
+ is_primary = priv->map->base_pwm_number == pwm->hwpwm;
/* Disable output pins of MTU3 channel */
- if (priv->map->base_pwm_number == pwm->hwpwm)
+ if (is_primary)
rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORH, RZ_MTU3_TIOR_OC_RETAIN);
else
rz_mtu3_8bit_ch_write(priv->mtu, RZ_MTU3_TIORL, RZ_MTU3_TIOR_OC_RETAIN);
+ rz_mtu3_pwm_set_toer_bit(rz_mtu3_pwm, priv, is_primary, false);
+
mutex_lock(&rz_mtu3_pwm->lock);
rz_mtu3_pwm->enable_count[ch]--;
if (!rz_mtu3_pwm->enable_count[ch])
diff --git a/include/linux/mfd/rz-mtu3.h b/include/linux/mfd/rz-mtu3.h
index 8421d49500bf..37da5f7bb83a 100644
--- a/include/linux/mfd/rz-mtu3.h
+++ b/include/linux/mfd/rz-mtu3.h
@@ -10,6 +10,8 @@
#include <linux/mutex.h>
/* 8-bit shared register offsets macros */
+#define RZ_MTU3_TOERA 0x00A /* Timer output master enable register A */
+#define RZ_MTU3_TOERB 0x80A /* Timer output master enable register B */
#define RZ_MTU3_TSTRA 0x080 /* Timer start register A */
#define RZ_MTU3_TSTRB 0x880 /* Timer start register B */
--
2.52.0
Powered by blists - more mailing lists