[PW_SID:973019] [v3,1/9] rust: pwm: Add Kconfig and basic data structures#545
[PW_SID:973019] [v3,1/9] rust: pwm: Add Kconfig and basic data structures#545linux-riscv-bot wants to merge 9 commits into
Conversation
Introduce the foundational support for PWM abstractions in Rust. This commit adds the `RUST_PWM_ABSTRACTIONS` Kconfig option to enable the feature, along with the necessary build-system support and C helpers. It also introduces the first set of safe wrappers for the PWM subsystem, covering the basic data carrying C structs and enums: - `Polarity`: A safe wrapper for `enum pwm_polarity`. - `Waveform`: A wrapper for `struct pwm_waveform`. - `Args`: A wrapper for `struct pwm_args`. - `State`: A wrapper for `struct pwm_state`. These types provide memory safe, idiomatic Rust representations of the core PWM data structures and form the building blocks for the abstractions that will follow. Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Building on the basic data types, this commit introduces the central
object abstractions for the PWM subsystem: Device and Chip. It also
includes the core trait implementations that make the Chip wrapper a
complete, safe, and managed object.
The main components of this change are:
- Device and Chip Structs: These structs wrap the underlying struct
pwm_device and struct pwm_chip C objects, providing safe, idiomatic
methods to access their fields.
- Core Trait Implementations for Chip:
- AlwaysRefCounted: Links the Chip's lifetime to its embedded
struct device reference counter. This enables automatic lifetime
management via ARef.
- Send and Sync: Marks the Chip wrapper as safe for use across
threads. This is sound because the C core handles all necessary
locking for the underlying object's state.
These wrappers and traits form a robust foundation for building PWM
drivers in Rust.
Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Complete the PWM abstraction layer by adding the final components required to implement and register a driver. The main additions are: - PwmOps Trait: An interface that drivers can implement to provide their hardware specific logic. It mirrors the C pwm_ops interface, providing hooks for standard PWM operations like apply, request, and waveform handling. - FFI VTable and Adapter: The Adapter struct, PwmOpsVTable wrapper, and create_pwm_ops function are introduced. This scaffolding handles the unsafe FFI translation, bridging the gap between the idiomatic PwmOps trait and the C kernel's function-pointer-based vtable. - Registration Guard: A final RAII guard that uses the vtable to safely register a Chip with the PWM core via pwmchip_add. Its Drop implementation guarantees that pwmchip_remove is always called, preventing resource leaks. With this patch, the PWM abstraction layer is now complete and ready to be used for writing 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.
Link: https://lore.kernel.org/all/9e8a12db-236d-474c-b110-b3be96edf057@samsung.com/ [1]
Reviewed-by: Drew Fustini <drew@pdp7.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. Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> 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: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 1: "[v3,1/9] rust: pwm: Add Kconfig and basic data structures" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 2: "[v3,2/9] rust: pwm: Add core 'Device' and 'Chip' object wrappers" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 3: "[v3,3/9] rust: pwm: Add driver operations trait and registration support" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 4: "[v3,4/9] pwm: Add Rust driver for T-HEAD TH1520 SoC" |
|
Patch 5: "[v3,5/9] clk: thead: Mark essential bus clocks as CLK_IGNORE_UNUSED" |
|
Patch 5: "[v3,5/9] clk: thead: Mark essential bus clocks as CLK_IGNORE_UNUSED" |
PR for series 973019 applied to workflow__riscv__fixes
Name: [v3,1/9] rust: pwm: Add Kconfig and basic data structures
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=973019
Version: 3