Merge branch 'pm-wakeirq'
[linux-2.6-microblaze.git] / drivers / base / power / wakeup.c
index 87c2603..40f7160 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/suspend.h>
 #include <linux/seq_file.h>
 #include <linux/debugfs.h>
+#include <linux/pm_wakeirq.h>
 #include <trace/events/power.h>
 
 #include "power.h"
@@ -272,6 +273,97 @@ int device_wakeup_enable(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(device_wakeup_enable);
 
+/**
+ * device_wakeup_attach_irq - Attach a wakeirq to a wakeup source
+ * @dev: Device to handle
+ * @wakeirq: Device specific wakeirq entry
+ *
+ * Attach a device wakeirq to the wakeup source so the device
+ * wake IRQ can be configured automatically for suspend and
+ * resume.
+ */
+int device_wakeup_attach_irq(struct device *dev,
+                            struct wake_irq *wakeirq)
+{
+       struct wakeup_source *ws;
+       int ret = 0;
+
+       spin_lock_irq(&dev->power.lock);
+       ws = dev->power.wakeup;
+       if (!ws) {
+               dev_err(dev, "forgot to call call device_init_wakeup?\n");
+               ret = -EINVAL;
+               goto unlock;
+       }
+
+       if (ws->wakeirq) {
+               ret = -EEXIST;
+               goto unlock;
+       }
+
+       ws->wakeirq = wakeirq;
+
+unlock:
+       spin_unlock_irq(&dev->power.lock);
+
+       return ret;
+}
+
+/**
+ * device_wakeup_detach_irq - Detach a wakeirq from a wakeup source
+ * @dev: Device to handle
+ *
+ * Removes a device wakeirq from the wakeup source.
+ */
+void device_wakeup_detach_irq(struct device *dev)
+{
+       struct wakeup_source *ws;
+
+       spin_lock_irq(&dev->power.lock);
+       ws = dev->power.wakeup;
+       if (!ws)
+               goto unlock;
+
+       ws->wakeirq = NULL;
+
+unlock:
+       spin_unlock_irq(&dev->power.lock);
+}
+
+/**
+ * device_wakeup_arm_wake_irqs(void)
+ *
+ * Itereates over the list of device wakeirqs to arm them.
+ */
+void device_wakeup_arm_wake_irqs(void)
+{
+       struct wakeup_source *ws;
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+               if (ws->wakeirq)
+                       dev_pm_arm_wake_irq(ws->wakeirq);
+       }
+       rcu_read_unlock();
+}
+
+/**
+ * device_wakeup_disarm_wake_irqs(void)
+ *
+ * Itereates over the list of device wakeirqs to disarm them.
+ */
+void device_wakeup_disarm_wake_irqs(void)
+{
+       struct wakeup_source *ws;
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
+               if (ws->wakeirq)
+                       dev_pm_disarm_wake_irq(ws->wakeirq);
+       }
+       rcu_read_unlock();
+}
+
 /**
  * device_wakeup_detach - Detach a device's wakeup source object from it.
  * @dev: Device to detach the wakeup source object from.