diff options
Diffstat (limited to 'drivers/base/power/runtime.c')
| -rw-r--r-- | drivers/base/power/runtime.c | 36 | 
1 files changed, 27 insertions, 9 deletions
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 16134a69bf6f..99c7da112c95 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1087,29 +1087,47 @@ 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. + * pm_runtime_get_if_active - 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. + * Otherwise, if the device's runtime PM status is RPM_ACTIVE and either + * ign_usage_count is true or the device's usage_count is non-zero, increment + * the counter and return 1. Otherwise return 0 without changing the counter. + * + * If ign_usage_count is true, the function can be used to prevent suspending + * the device when its runtime PM status is RPM_ACTIVE. + * + * If ign_usage_count is false, the function can be used to prevent suspending + * the device when both its runtime PM status is RPM_ACTIVE and its usage_count + * is non-zero. + * + * The caller is resposible for putting the device's usage count when ther + * return value is greater than zero.   */ -int pm_runtime_get_if_in_use(struct device *dev) +int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)  {  	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); +	if (dev->power.disable_depth > 0) { +		retval = -EINVAL; +	} else if (dev->power.runtime_status != RPM_ACTIVE) { +		retval = 0; +	} else if (ign_usage_count) { +		retval = 1; +		atomic_inc(&dev->power.usage_count); +	} else { +		retval = atomic_inc_not_zero(&dev->power.usage_count); +	}  	trace_rpm_usage_rcuidle(dev, 0);  	spin_unlock_irqrestore(&dev->power.lock, flags); +  	return retval;  } -EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use); +EXPORT_SYMBOL_GPL(pm_runtime_get_if_active);  /**   * __pm_runtime_set_status - Set runtime PM status of a device.  |