[PW_SID:970426] [v2,1/7] rust: Add basic PWM abstractions#499
[PW_SID:970426] [v2,1/7] rust: Add basic PWM abstractions#499linux-riscv-bot wants to merge 7 commits into
Conversation
Introduce safe Rust abstractions for the Linux PWM subsystem. These abstractions provide ergonomic, lifetime managed wrappers around the core C data structures and functions, enabling the development of PWM chip drivers in safe Rust. This initial version provides the core building blocks for writing a PWM chip provider driver, with a focus on safety, resource management, and idiomatic Rust patterns. The main components are: Ownership and Lifetime Management: - The pwm::Chip type, an ARef managed wrapper for struct pwm_chip, correctly handles the object's lifetime by using the embedded struct device's reference counter. - A pwm::Registration RAII guard ensures that a call to register a chip (pwmchip_add) is always paired with a call to unregister it (pwmchip_remove), preventing resource leaks. Safe Type Wrappers: - Safe, idiomatic Rust types (Polarity, Waveform, State, Args, Device) are provided to abstract away the raw C structs and enums. The State wrapper holds its data by value, avoiding unnecessary heap allocations. Driver Operations (PwmOps): - A generic PwmOps trait allows drivers to implement the standard PWM operations. It uses an associated type (WfHw) for the driver's hardware specific waveform data, moving unsafe serialization logic into the abstraction layer. The trait exposes the modern waveform API (round_waveform_tohw, write_waveform, etc.) as well as the other standard kernel callbacks (get_state, request, apply). - A create_pwm_ops function generates a C-compatible vtable from a PwmOps implementor. This foundational layer is designed to be used by subsequent patches to implement specific PWM chip drivers in Rust. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Introduce a PWM driver for the T-HEAD TH1520 SoC, written in Rust and utilizing the safe PWM abstractions from the preceding commit. The driver implements the pwm::PwmOps trait using the modern waveform API (round_waveform_tohw, write_waveform, etc.) to support configuration of period, duty cycle, and polarity for the TH1520's PWM channels. Resource management is handled using idiomatic Rust patterns. The PWM chip object is allocated via pwm::Chip::new and its registration with the PWM core is managed by the pwm::Registration RAII guard. This ensures pwmchip_remove is always called when the driver unbinds, preventing resource leaks. Device managed resources are used for the MMIO region, and the clock lifecycle is correctly managed in the driver's private data Drop implementation. The driver's core logic is written entirely in safe Rust, with no unsafe blocks. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Probing peripherals in the AON and PERI domains, such as the PVT thermal
sensor and the PWM controller, can lead to boot hangs or unresponsive
devices on the LPi4A board. The root cause is that their parent bus
clocks ('CLK_CPU2AON_X2H' and the 'CLK_PERISYS_APB' clocks) are
automatically gated by the kernel's power-saving mechanisms when the bus
is perceived as idle.
Alternative solutions were investigated, including modeling the parent
bus in the Device Tree with 'simple-pm-bus' or refactoring the clock
driver's parentage. The 'simple-pm-bus' approach is not viable due to
the lack of defined bus address ranges in the hardware manual and its
creation of improper dependencies on the 'pm_runtime' API for consumer
drivers.
Therefore, applying the'`CLK_IGNORE_UNUSED' flag directly to the
essential bus clocks is the most direct and targeted fix. This prevents
the kernel from auto-gating these buses and ensures peripherals remain
accessible.
This change fixes the boot hang associated with the PVT sensor and
resolves the functional issues with the PWM controller.
[1] - https://lore.kernel.org/all/9e8a12db-236d-474c-b110-b3be96edf057@samsung.com/
Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add the Device Tree binding documentation for the T-HEAD TH1520 SoC PWM controller. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add the Device Tree node for the T-HEAD TH1520 SoC's PWM controller. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add PVT DT node for thermal sensor. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add Device Tree nodes to enable a PWM controlled fan and it's associated thermal management for the Lichee Pi 4A board. This enables temperature-controlled active cooling for the Lichee Pi 4A board based on SoC temperature. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 1: "[v2,1/7] rust: Add basic PWM abstractions" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
|
Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control" |
PR for series 970426 applied to workflow__riscv__fixes
Name: [v2,1/7] rust: Add basic PWM abstractions
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=970426
Version: 2