Commit 7b3dce81 authored by Michal Wilczynski's avatar Michal Wilczynski Committed by Uwe Kleine-König
Browse files

rust: pwm: Add Kconfig and basic data structures



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`.
- `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.

Tested-by: default avatarDrew Fustini <fustini@kernel.org>
Reviewed-by: default avatarDaniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: default avatarElle Rhumsaa <elle@weathered-steel.dev>
Signed-off-by: default avatarMichal Wilczynski <m.wilczynski@samsung.com>
Link: https://patch.msgid.link/20251016-rust-next-pwm-working-fan-for-sending-v16-2-a5df2405d2bd@samsung.com


Signed-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
parent ce284f88
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -20763,6 +20763,14 @@ F: include/linux/pwm.h
F:	include/linux/pwm_backlight.h
K:	pwm_(config|apply_might_sleep|apply_atomic|ops)
PWM SUBSYSTEM BINDINGS [RUST]
M:	Michal Wilczynski <m.wilczynski@samsung.com>
L:	linux-pwm@vger.kernel.org
L:	rust-for-linux@vger.kernel.org
S:	Maintained
F:	rust/helpers/pwm.c
F:	rust/kernel/pwm.rs
PXA GPIO DRIVER
M:	Robert Jarzmik <robert.jarzmik@free.fr>
L:	linux-gpio@vger.kernel.org
+12 −0
Original line number Diff line number Diff line
@@ -819,4 +819,16 @@ config PWM_XILINX
	  To compile this driver as a module, choose M here: the module
	  will be called pwm-xilinx.

 config RUST_PWM_ABSTRACTIONS
	bool
	depends on RUST
	help
	  This option enables the safe Rust abstraction layer for the PWM
	  subsystem. It provides idiomatic wrappers and traits necessary for
	  writing PWM controller drivers in Rust.

	  The abstractions handle resource management (like memory and reference
	  counting) and provide safe interfaces to the underlying C core,
	  allowing driver logic to be written in safe Rust.

endif
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@
#include <linux/pm_opp.h>
#include <linux/poll.h>
#include <linux/property.h>
#include <linux/pwm.h>
#include <linux/random.h>
#include <linux/refcount.h>
#include <linux/regulator/consumer.h>
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#include "poll.c"
#include "processor.c"
#include "property.c"
#include "pwm.c"
#include "rbtree.c"
#include "rcu.c"
#include "refcount.c"

rust/helpers/pwm.c

0 → 100644
+20 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2025 Samsung Electronics Co., Ltd.
// Author: Michal Wilczynski <m.wilczynski@samsung.com>

#include <linux/pwm.h>

struct device *rust_helper_pwmchip_parent(const struct pwm_chip *chip)
{
	return pwmchip_parent(chip);
}

void *rust_helper_pwmchip_get_drvdata(struct pwm_chip *chip)
{
	return pwmchip_get_drvdata(chip);
}

void rust_helper_pwmchip_set_drvdata(struct pwm_chip *chip, void *data)
{
	pwmchip_set_drvdata(chip, data);
}
Loading