]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: pwm: Add complete abstraction layer
authorMichal Wilczynski <m.wilczynski@samsung.com>
Thu, 16 Oct 2025 13:38:03 +0000 (15:38 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Fri, 7 Nov 2025 09:03:55 +0000 (10:03 +0100)
commitd8046cd50879db371bbf6220477ec521692ab2f6
tree14ca0a5ba6ac7282cce2ee4176562e4c6954bb51
parent7b3dce814a15bc5d9fb6124cd945291012c4ebb9
rust: pwm: Add complete abstraction layer

Introduce a comprehensive abstraction layer for the PWM subsystem to
enable writing drivers in Rust.

Because `Device`, `Chip`, and `PwmOps` all refer to each other, they
form a single, indivisible unit with circular dependencies. They are
introduced together in this single commit to create a complete,
compilable abstraction layer.

The main components are:
 - Data Wrappers: Safe, idiomatic wrappers for core C types like
   `pwm_device`, and `pwm_chip`.

 - PwmOps Trait: An interface that drivers can implement to provide
   their hardware-specific logic, mirroring the C `pwm_ops` interface.

 - FFI VTable and Adapter: A bridge to connect the high-level PwmOps trait
   to the C kernel's pwm_ops vtable.

 - Allocation and Lifetime Management: A high-level `Chip::new()`
   API to safely allocate a chip and a `Registration` guard that integrates
   with `devres` to manage the chip's registration with the PWM core.
   An `AlwaysRefCounted` implementation and a custom release handler
   prevent memory leaks by managing the chip's lifetime and freeing
   driver data correctly.

Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com>
Link: https://patch.msgid.link/20251016-rust-next-pwm-working-fan-for-sending-v16-3-a5df2405d2bd@samsung.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
rust/kernel/pwm.rs