[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251028-pwm_fixes-v1-2-25a532d31998@samsung.com>
Date: Tue, 28 Oct 2025 13:22:33 +0100
From: Michal Wilczynski <m.wilczynski@...sung.com>
To: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, 
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,  Benno Lossin
	<lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,  Alice Ryhl
	<aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,  Danilo Krummrich
	<dakr@...nel.org>,  Michal Wilczynski <m.wilczynski@...sung.com>,  Drew
	Fustini <fustini@...nel.org>, Guo Ren <guoren@...nel.org>,  Fu Wei
	<wefu@...hat.com>,  Uwe Kleine-König <ukleinek@...nel.org>
Cc: Stephen Rothwell <sfr@...b.auug.org.au>, rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-pwm@...r.kernel.org, 
	linux-riscv@...ts.infradead.org
Subject: [PATCH 2/4] rust: pwm: Add module_pwm_platform_driver! macro
Rust PWM drivers using the abstractions in `kernel/pwm.rs` typically
call C functions (like `pwmchip_alloc`, `__pwmchip_add`, etc.) that are
exported to the `PWM` C symbol namespace.
With the introduction of `imports_ns` support in the `module!` macro,
every PWM driver would need to manually include `imports_ns: ["PWM"]` in
its module declaration.
To simplify this for driver authors and ensure consistency, introduce a
new helper macro `module_pwm_platform_driver!` in `pwm.rs`. This macro
wraps the standard `module_platform_driver!`, forwards all user provided
arguments using the `($($user_args:tt)*)` pattern, and automatically
injects the `imports_ns: ["PWM"]` declaration.
This follows the pattern used in other subsystems (e.g.,
`module_pci_driver!`) to provide specialized module registration
helpers. It makes writing PWM drivers slightly simpler and less error
prone regarding namespace imports.
Signed-off-by: Michal Wilczynski <m.wilczynski@...sung.com>
---
 rust/kernel/pwm.rs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs
index 79fbb13cd47f75681283648ddc4fffb7889be930..6f2f78c687d5b924739f59052e9b3393c922540d 100644
--- a/rust/kernel/pwm.rs
+++ b/rust/kernel/pwm.rs
@@ -760,3 +760,26 @@ fn drop(&mut self) {
         unsafe { bindings::pwmchip_remove(chip_raw); }
     }
 }
+
+/// Declares a kernel module that exposes a single PWM driver.
+///
+/// # Examples
+///
+///```ignore
+/// kernel::module_pwm_platform_driver! {
+///     type: MyDriver,
+///     name: "Module name",
+///     authors: ["Author name"],
+///     description: "Description",
+///     license: "GPL v2",
+/// }
+///```
+#[macro_export]
+macro_rules! module_pwm_platform_driver {
+    ($($user_args:tt)*) => {
+        $crate::module_platform_driver! {
+            $($user_args)*
+            imports_ns: ["PWM"],
+        }
+    };
+}
-- 
2.34.1
Powered by blists - more mailing lists
 
