Re: [PATCH v15 0/7] Rust Abstractions for PWM subsystem with TH1520 PWM driver

Michal Wilczynski
2025-10-15T17:52:43Z

On 10/13/25 18:48, Uwe Kleine-König wrote:
> Hello,
>
> my diff on top of your changes looks as follows:
>
> diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
> index dd6db01832ee..e7f770ecfe84 100644
> --- a/drivers/pwm/Kconfig
> +++ b/drivers/pwm/Kconfig
> @@ -812,9 +812,8 @@ config PWM_XILINX
> will be called pwm-xilinx.
>
> config RUST_PWM_ABSTRACTIONS
> - bool "Rust PWM abstractions support"
> + bool
> depends on RUST
> - depends on PWM=y
> help
> This option enables the safe Rust abstraction layer for the PWM
> subsystem. It provides idiomatic wrappers and traits necessary for
>
> i.e. make RUST_PWM_ABSTRACTIONS invisible, it is only supposed to be
> selected and there is little (or even no?) use to enable it without a
> selector.
>
> diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs
> index c9fd1d8d17bc..a5666052b7ce 100644
> --- a/drivers/pwm/pwm_th1520.rs
> +++ b/drivers/pwm/pwm_th1520.rs
> @@ -121,6 +121,7 @@ fn round_waveform_tohw(
> wf: &pwm::Waveform,
> ) -> Result<pwm::RoundedWaveform<Self::WfHw>> {
> let data = chip.drvdata();
> + let status = 0;
>
> if wf.period_length_ns == 0 {
> dev_dbg!(chip.device(), "Requested period is 0, disabling PWM.\n");
> @@ -141,18 +142,13 @@ fn round_waveform_tohw(
> if period_cycles == 0 {
> dev_dbg!(
> chip.device(),
> - "Requested period {} ns is too small for clock rate {} Hz, disabling PWM.\n",
> + "Requested period {} ns is too small for clock rate {} Hz, rounding up.\n",
> wf.period_length_ns,
> rate_hz
> );
>
> - return Ok(pwm::RoundedWaveform {
> - status: 0,
> - hardware_waveform: Th1520WfHw {
> - enabled: false,
> - ..Default::default()
> - },
> - });
> + period_cycles = 1;
> + status = 1;
> }
>
> let mut duty_cycles = ns_to_cycles(wf.duty_length_ns, rate_hz).min(u64::from(u32::MAX));
>
> i.e. round up for too small period requests ...
>
> @@ -189,7 +185,7 @@ fn round_waveform_tohw(
> );
>
> Ok(pwm::RoundedWaveform {
> - status: 0,
> + status: status,
> hardware_waveform: wfhw,
> })
> }
>
> ... and return 1 then
>
> @@ -355,7 +351,7 @@ fn probe(
> "Clock rate {} Hz is too high, not supported.\n",
> rate_hz
> );
> - return Err(ERANGE);
> + return Err(EINVAL);
> }
>
> let chip = pwm::Chip::new(
>
> at least pwm-stm32 uses EINVAL. Having said that, I wonder if this check
> is sensible here at all. pwm-stm32 does it to ensure that
> mul_u64_u64_div_u64() does the right thing, but this exact issue doesn't
> exist here.

I think your changes are correct. For the existence of check I think it
is helpful as it fails early with a helpful message, but isn't strictly
necessary.

I will incorporate these changes and send another revision.

>
> Otherwise looks fine I think.
>
> Best regards
> Uwe

Best regards,
--
Michal Wilczynski <m.wilczynski@samsung.com>