Skip to content

[PW_SID:970426] [v2,1/7] rust: Add basic PWM abstractions#499

Closed
linux-riscv-bot wants to merge 7 commits into
workflow__riscv__fixesfrom
pw970426
Closed

[PW_SID:970426] [v2,1/7] rust: Add basic PWM abstractions#499
linux-riscv-bot wants to merge 7 commits into
workflow__riscv__fixesfrom
pw970426

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

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

Michal Wilczynski added 7 commits June 10, 2025 15:48
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>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 104.80 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 930.66 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1255.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.47 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.38 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 71.44 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
kdoc
Desc: Detects for kdoc errors
Duration: 0.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
module-param
Desc: Detect module_param changes
Duration: 0.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/7] rust: Add basic PWM abstractions"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 102.84 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 930.49 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1250.11 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 22.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.76 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 72.13 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
kdoc
Desc: Detects for kdoc errors
Duration: 0.95 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
module-param
Desc: Detect module_param changes
Duration: 0.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/7] pwm: Add Rust driver for T-HEAD TH1520 SoC"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 71.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
kdoc
Desc: Detects for kdoc errors
Duration: 0.84 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 5: "[v2,5/7] riscv: dts: thead: Add PWM controller node"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 102.16 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 972.53 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1304.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.90 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 22.12 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.81 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 71.67 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
kdoc
Desc: Detects for kdoc errors
Duration: 0.88 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[v2,6/7] riscv: dts: thead: Add PVT node"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 102.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 975.56 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1309.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.80 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.78 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 71.62 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.42 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
kdoc
Desc: Detects for kdoc errors
Duration: 0.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[v2,7/7] riscv: dts: thead: Add PWM fan and thermal control"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant