genirq: Add runtime power management support for IRQ chips
[cascardo/linux.git] / kernel / irq / chip.c
index 2f9f2b0..ad81314 100644 (file)
@@ -1093,3 +1093,43 @@ int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 
        return 0;
 }
+
+/**
+ * irq_chip_pm_get - Enable power for an IRQ chip
+ * @data:      Pointer to interrupt specific data
+ *
+ * Enable the power to the IRQ chip referenced by the interrupt data
+ * structure.
+ */
+int irq_chip_pm_get(struct irq_data *data)
+{
+       int retval;
+
+       if (IS_ENABLED(CONFIG_PM) && data->chip->parent_device) {
+               retval = pm_runtime_get_sync(data->chip->parent_device);
+               if (retval < 0) {
+                       pm_runtime_put_noidle(data->chip->parent_device);
+                       return retval;
+               }
+       }
+
+       return 0;
+}
+
+/**
+ * irq_chip_pm_put - Disable power for an IRQ chip
+ * @data:      Pointer to interrupt specific data
+ *
+ * Disable the power to the IRQ chip referenced by the interrupt data
+ * structure, belongs. Note that power will only be disabled, once this
+ * function has been called for all IRQs that have called irq_chip_pm_get().
+ */
+int irq_chip_pm_put(struct irq_data *data)
+{
+       int retval = 0;
+
+       if (IS_ENABLED(CONFIG_PM) && data->chip->parent_device)
+               retval = pm_runtime_put(data->chip->parent_device);
+
+       return (retval < 0) ? retval : 0;
+}