Re: [PATCH v6 0/7] Clk improvements
From: Danilo Krummrich
Date: Thu Dec 03 2026 - 11:16:05 EST
On Tue Oct 13, 2026 at 7:07 PM CEST, Daniel Almeida wrote:
> This series contains a few improvements that simplify clock handling for
> drivers.
>
> Patch 1 converts clk.rs to the kernel-vertical style for imports.
>
> Patch 2 replaces OptionalClk with Clk::get_optional(). There is no struct
> optional_clk in C, and Clk already allows a NULL pointer.
>
> Patch 3 implements the same typestate pattern that has been used
> successfully for Regulators. This is needed because otherwise drivers
> will be responsible for unpreparing and disabling clocks themselves and
> ultimately handling the reference counts on their own. This is
> undesirable. The patch automatically encodes this information using the
> type system so that no misuse can occur.
>
> Patch 4 adds guards that prepare and/or enable a clock for the lifetime
> of the guard without consuming the Clk, so that a driver can keep a
> long-lived Clk<Prepared> and enable it for scoped sections.
>
> Patch 5 makes things more convenient by offering devres-managed APIs. This
> lets drivers set clock parameters once and forget about lifetime
> management.
>
> Patch 6 adds ExclusiveClk<T>, which holds rate exclusivity over a Clk<T>
> in any state until it is dropped.
>
> Patch 7 uses it in pwm-th1520 to lock the clock rate for the lifetime of
> the driver data.
Except for the devres one,
Acked-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Constraining the driver facing types with the Device<Bound> lifetime is fine for
me to address in a follow up series.