@@ -72,6 +72,8 @@
#include <linux/pid_namespace.h>
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/pm_wakeup.h>
#include <linux/poll.h>
#include <linux/property.h>
#include <linux/pwm.h>
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/device.h>
+#include <linux/pm_wakeup.h>
int rust_helper_devm_add_action(struct device *dev,
void (*action)(void *),
@@ -25,3 +26,8 @@ void rust_helper_dev_set_drvdata(struct device *dev, void *data)
{
dev_set_drvdata(dev, data);
}
+
+int rust_helper_devm_device_init_wakeup(struct device *dev)
+{
+ return devm_device_init_wakeup(dev);
+}
@@ -5,7 +5,9 @@
//! C header: [`include/linux/device.h`](srctree/include/linux/device.h)
use crate::{
- bindings, fmt,
+ bindings,
+ error::to_result,
+ fmt,
prelude::*,
sync::aref::ARef,
types::{ForeignOwnable, Opaque},
@@ -324,6 +326,20 @@ pub fn drvdata<T: 'static>(&self) -> Result<Pin<&T>> {
// - We've just checked that the type of the driver's private data is in fact `T`.
Ok(unsafe { self.drvdata_unchecked() })
}
+
+ /// Initialize device wakeup capability.
+ ///
+ /// Marks the device as wakeup-capable and enables wakeup. Both the
+ /// wakeup capability and wakeup enable state are automatically
+ /// cleared when the device is removed (resource-managed).
+ ///
+ /// Returns `Ok(())` on success, or an error code on failure.
+ pub fn devm_init_wakeup(&self) -> Result {
+ // SAFETY: `self.as_raw()` is a valid pointer to a `struct device`.
+ // The function is exported from bindings_helper module via pub use.
+ let ret = unsafe { bindings::devm_device_init_wakeup(self.as_raw()) };
+ to_result(ret)
+ }
}
impl<Ctx: DeviceContext> Device<Ctx> {
@@ -120,6 +120,23 @@ pub(crate) unsafe fn new(dev: &'a Device<Bound>, irq: u32) -> Self {
pub fn irq(&self) -> u32 {
self.irq
}
+
+ /// Attach the IRQ as a device wake IRQ.
+ ///
+ /// Attaches the device IO interrupt as a wake IRQ. The wake IRQ gets
+ /// automatically configured for wake-up from suspend based on the
+ /// device's sysfs wakeup entry. Typically called during driver probe
+ /// after calling `devm_init_wakeup()`.
+ ///
+ /// The wake IRQ is automatically cleared when the device is removed
+ /// (resource-managed).
+ ///
+ /// Returns `Ok(())` on success, or an error code on failure.
+ pub fn devm_set_wake_irq(&self) -> Result {
+ // SAFETY: `self.as_raw()` is a valid pointer to a `struct device`.
+ let ret = unsafe { bindings::devm_pm_set_wake_irq(self.dev.as_raw(), self.irq as i32) };
+ to_result(ret)
+ }
}
/// A registration of an IRQ handler for a given IRQ line.
Add Rust bindings and wrappers for device wakeup functionality, including devm_device_init_wakeup() and dev_pm_set_wake_irq(). Signed-off-by: Ke Sun <sunke@kylinos.cn> --- Changes: - Add new include headers in alphabetical order --- rust/bindings/bindings_helper.h | 2 ++ rust/helpers/device.c | 6 ++++++ rust/kernel/device.rs | 18 +++++++++++++++++- rust/kernel/irq/request.rs | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)