[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <99a41538-ce1a-4130-a093-d0c600e63d16@samsung.com>
Date: Wed, 15 Oct 2025 19:52:14 +0200
From: Michal Wilczynski <m.wilczynski@...sung.com>
To: Uwe Kleine-König <ukleinek@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas
Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, Trevor
Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, Guo Ren
<guoren@...nel.org>, Fu Wei <wefu@...hat.com>, Rob Herring
<robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, Paul Walmsley <paul.walmsley@...ive.com>, Palmer
Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>, Alexandre
Ghiti <alex@...ti.fr>, Marek Szyprowski <m.szyprowski@...sung.com>, Benno
Lossin <lossin@...nel.org>, Michael Turquette <mturquette@...libre.com>,
Drew Fustini <fustini@...nel.org>, Daniel Almeida
<daniel.almeida@...labora.com>, linux-kernel@...r.kernel.org,
linux-pwm@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-riscv@...ts.infradead.org, devicetree@...r.kernel.org, Elle Rhumsaa
<elle@...thered-steel.dev>, Krzysztof Kozlowski
<krzysztof.kozlowski@...aro.org>
Subject: Re: [PATCH v15 0/7] Rust Abstractions for PWM subsystem with TH1520
PWM driver
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@...sung.com>
Powered by blists - more mailing lists