public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Renesas MTU3 PWM / counter fixes
@ 2026-01-30 12:23 Cosmin Tanislav
  2026-01-30 12:23 ` [PATCH 1/5] pwm: rz-mtu3: fix prescale check when enabling 2nd channel Cosmin Tanislav
                   ` (6 more replies)
  0 siblings, 7 replies; 20+ messages in thread
From: Cosmin Tanislav @ 2026-01-30 12:23 UTC (permalink / raw)
  To: Biju Das, William Breathitt Gray, Uwe Kleine-König,
	Lee Jones, Thierry Reding
  Cc: linux-iio, linux-renesas-soc, linux-kernel, linux-pwm,
	Cosmin Tanislav

The Renesas MTU3 PWM and counter drivers have some issues which have
been observed while adding support for the Renesas RZ/T2H and RZ/N2H
SoCs.

This series fixes the most important issues which prevent normal
functioning of the driver, while other less important issues will be
handled in a future series.

Questions for the PWM maintainer:

1)

The handling introduced in patches 1 and 2 is similar to the approach
taken in commits [1] and [2].

Is this the right approach?

This code snippet below extracted from drivers/pwm/pwm-rzg2l-gpt.c
entirely prevents the period ticks from changing at all when two PWM
channels backed by the same HW channel are in use.

if (rzg2l_gpt->channel_request_count[ch] > 1) {
  u8 sibling_ch = rzg2l_gpt_sibling(pwm->hwpwm);

  if (rzg2l_gpt_is_ch_enabled(rzg2l_gpt, sibling_ch)) {
    if (period_ticks < rzg2l_gpt->period_ticks[ch])
      return -EBUSY;

    period_ticks = rzg2l_gpt->period_ticks[ch];
  }
}

Same logic has been imposed in patches 1 and 2 as the HW limitation is
similar.

Based on the logic here, a second channel can be enabled as long as its
period is larger than the period of the first enabled channel, and the
period and duty cycle will be adjusted to be <= to the period of the
first enabled channel.

But once the second channel is enabled, there's no way to adjust the
period of either channels anymore.

Wouldn't a better solution be that the smallest period between the two
channels is used, so that adjustment is still possible dynamically?

Here is an example.

echo 0 > /sys/class/pwm/pwmchip0/export
echo 1 > /sys/class/pwm/pwmchip0/export
echo 0xFFF000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 0x7FF800 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 0xFFF000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 0x7FF800 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

Now both LEDs are on, let's increase the period.

echo 0xFFFF000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 0x7FFF800 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

The effective period did not change.

echo 0xFFFF000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 0x7FFF800 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle

The effective period didn't change now either.

echo 0 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 0 > /sys/class/pwm/pwmchip0/pwm1/enable

echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable

After turning the PWMs off and on again, the effective period is
updated.

If we were to change the period dynamically to the smallest one, the
LEDs would have changed their effective period without needing to be
turned off and on again.

Would this approach be better than the current approach? I can see that
other drivers just refuse updating the period entirely when the PWM
channels must share the same period.


2)

Another issue that I've encountered is that PWM is left enabled even if
the channel is unexported.

Here is an example.

echo 0 > /sys/class/pwm/pwmchip0/export
echo 0xFFFF000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 0x7FFF800 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 0 > /sys/class/pwm/pwmchip0/unexport

The connected LED is kept blinking as 0 was not written to enable.

Is this intended? Or should the PWM turn off on unexport?


3)

Should the .get_state() ops read the period and duty cycle from the
hardware if the PWM is not enabled?

Currently the MTU3 driver guards reading period and duty cycle based on
whether the PWM is enabled.

[1]: e373991eb9ff ("pwm: rzg2l-gpt: Accept requests for too high period length")
[2]: fae00ea9f003 ("pwm: rzg2l-gpt: Allow checking period_tick cache value only if sibling channel is enabled")

Cosmin Tanislav (5):
  pwm: rz-mtu3: fix prescale check when enabling 2nd channel
  pwm: rz-mtu3: impose period restrictions
  pwm: rz-mtu3: correctly enable HW channel 4 and 7
  counter: rz-mtu3-cnt: prevent counter from being toggled multiple
    times
  counter: rz-mtu3-cnt: do not use struct rz_mtu3_channel's dev member

 drivers/counter/rz-mtu3-cnt.c | 67 +++++++++++++-----------
 drivers/pwm/pwm-rz-mtu3.c     | 99 ++++++++++++++++++++++++++++-------
 include/linux/mfd/rz-mtu3.h   |  2 +
 3 files changed, 117 insertions(+), 51 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-03-22 18:57 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30 12:23 [PATCH 0/5] Renesas MTU3 PWM / counter fixes Cosmin Tanislav
2026-01-30 12:23 ` [PATCH 1/5] pwm: rz-mtu3: fix prescale check when enabling 2nd channel Cosmin Tanislav
2026-03-05  8:57   ` Uwe Kleine-König
2026-03-05 21:59     ` Cosmin-Gabriel Tanislav
2026-03-06  9:29   ` Uwe Kleine-König
2026-03-06 13:26     ` Cosmin-Gabriel Tanislav
2026-03-16 15:49       ` Cosmin-Gabriel Tanislav
2026-03-16 18:26         ` Geert Uytterhoeven
2026-03-16 19:12           ` Cosmin-Gabriel Tanislav
2026-03-17  8:23             ` Geert Uytterhoeven
2026-03-17  9:11         ` Uwe Kleine-König
2026-03-17 23:02           ` Cosmin-Gabriel Tanislav
2026-01-30 12:23 ` [PATCH 2/5] pwm: rz-mtu3: impose period restrictions Cosmin Tanislav
2026-01-30 12:23 ` [PATCH 3/5] pwm: rz-mtu3: correctly enable HW channel 4 and 7 Cosmin Tanislav
2026-01-30 12:23 ` [PATCH 4/5] counter: rz-mtu3-cnt: prevent counter from being toggled multiple times Cosmin Tanislav
2026-01-30 12:23 ` [PATCH 5/5] counter: rz-mtu3-cnt: do not use struct rz_mtu3_channel's dev member Cosmin Tanislav
2026-03-22  6:58   ` William Breathitt Gray
2026-03-22 18:57     ` Cosmin-Gabriel Tanislav
2026-03-05  8:49 ` [PATCH 0/5] Renesas MTU3 PWM / counter fixes Uwe Kleine-König
2026-03-22  7:11 ` (subset) " William Breathitt Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox