|
@@ -965,6 +965,30 @@ int __pm_runtime_resume(struct device *dev, int rpmflags)
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(__pm_runtime_resume);
|
|
|
|
|
|
+/**
|
|
|
+ * pm_runtime_get_if_in_use - Conditionally bump up the device's usage counter.
|
|
|
+ * @dev: Device to handle.
|
|
|
+ *
|
|
|
+ * Return -EINVAL if runtime PM is disabled for the device.
|
|
|
+ *
|
|
|
+ * If that's not the case and if the device's runtime PM status is RPM_ACTIVE
|
|
|
+ * and the runtime PM usage counter is nonzero, increment the counter and
|
|
|
+ * return 1. Otherwise return 0 without changing the counter.
|
|
|
+ */
|
|
|
+int pm_runtime_get_if_in_use(struct device *dev)
|
|
|
+{
|
|
|
+ unsigned long flags;
|
|
|
+ int retval;
|
|
|
+
|
|
|
+ spin_lock_irqsave(&dev->power.lock, flags);
|
|
|
+ retval = dev->power.disable_depth > 0 ? -EINVAL :
|
|
|
+ dev->power.runtime_status == RPM_ACTIVE
|
|
|
+ && atomic_inc_not_zero(&dev->power.usage_count);
|
|
|
+ spin_unlock_irqrestore(&dev->power.lock, flags);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
|
|
|
+
|
|
|
/**
|
|
|
* __pm_runtime_set_status - Set runtime PM status of a device.
|
|
|
* @dev: Device to handle.
|