Skip to content

Commit 264b501

Browse files
Michal WilczynskiUwe Kleine-König
authored andcommitted
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@samsung.com> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://patch.msgid.link/20251028-pwm_fixes-v1-2-25a532d31998@samsung.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent d8046cd commit 264b501

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

rust/kernel/pwm.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,26 @@ impl<T: PwmOps> Drop for Registration<T> {
760760
unsafe { bindings::pwmchip_remove(chip_raw); }
761761
}
762762
}
763+
764+
/// Declares a kernel module that exposes a single PWM driver.
765+
///
766+
/// # Examples
767+
///
768+
///```ignore
769+
/// kernel::module_pwm_platform_driver! {
770+
/// type: MyDriver,
771+
/// name: "Module name",
772+
/// authors: ["Author name"],
773+
/// description: "Description",
774+
/// license: "GPL v2",
775+
/// }
776+
///```
777+
#[macro_export]
778+
macro_rules! module_pwm_platform_driver {
779+
($($user_args:tt)*) => {
780+
$crate::module_platform_driver! {
781+
$($user_args)*
782+
imports_ns: ["PWM"],
783+
}
784+
};
785+
}

0 commit comments

Comments
 (0)