Skip to content

Commit e03724a

Browse files
Michal WilczynskiUwe Kleine-König
authored andcommitted
pwm: Add Rust driver for T-HEAD TH1520 SoC
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, except for the Send and Sync implementations for the driver data, which are explained in the comments. 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-4-a5df2405d2bd@samsung.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 51b4c0f commit e03724a

4 files changed

Lines changed: 391 additions & 0 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22189,6 +22189,7 @@ F: drivers/pinctrl/pinctrl-th1520.c
2218922189
F: drivers/pmdomain/thead/
2219022190
F: drivers/power/reset/th1520-aon-reboot.c
2219122191
F: drivers/power/sequencing/pwrseq-thead-gpu.c
22192+
F: drivers/pwm/pwm_th1520.rs
2219222193
F: drivers/reset/reset-th1520.c
2219322194
F: include/dt-bindings/clock/thead,th1520-clk-ap.h
2219422195
F: include/dt-bindings/power/thead,th1520-power.h

drivers/pwm/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,17 @@ config PWM_TEGRA
748748
To compile this driver as a module, choose M here: the module
749749
will be called pwm-tegra.
750750

751+
config PWM_TH1520
752+
tristate "TH1520 PWM support"
753+
depends on RUST
754+
select RUST_PWM_ABSTRACTIONS
755+
help
756+
This option enables the driver for the PWM controller found on the
757+
T-HEAD TH1520 SoC.
758+
759+
To compile this driver as a module, choose M here; the module
760+
will be called pwm-th1520. If you are unsure, say N.
761+
751762
config PWM_TIECAP
752763
tristate "ECAP PWM support"
753764
depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE || ARCH_K3 || COMPILE_TEST

drivers/pwm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ obj-$(CONFIG_PWM_STMPE) += pwm-stmpe.o
6868
obj-$(CONFIG_PWM_SUN4I) += pwm-sun4i.o
6969
obj-$(CONFIG_PWM_SUNPLUS) += pwm-sunplus.o
7070
obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o
71+
obj-$(CONFIG_PWM_TH1520) += pwm_th1520.o
7172
obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o
7273
obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o
7374
obj-$(CONFIG_PWM_TWL) += pwm-twl.o

0 commit comments

Comments
 (0)