|
@@ -154,6 +154,31 @@ static int rpm_check_suspend_allowed(struct device *dev)
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * __rpm_callback - Run a given runtime PM callback for a given device.
|
|
|
|
+ * @cb: Runtime PM callback to run.
|
|
|
|
+ * @dev: Device to run the callback for.
|
|
|
|
+ */
|
|
|
|
+static int __rpm_callback(int (*cb)(struct device *), struct device *dev)
|
|
|
|
+ __releases(&dev->power.lock) __acquires(&dev->power.lock)
|
|
|
|
+{
|
|
|
|
+ int retval;
|
|
|
|
+
|
|
|
|
+ if (dev->power.irq_safe)
|
|
|
|
+ spin_unlock(&dev->power.lock);
|
|
|
|
+ else
|
|
|
|
+ spin_unlock_irq(&dev->power.lock);
|
|
|
|
+
|
|
|
|
+ retval = cb(dev);
|
|
|
|
+
|
|
|
|
+ if (dev->power.irq_safe)
|
|
|
|
+ spin_lock(&dev->power.lock);
|
|
|
|
+ else
|
|
|
|
+ spin_lock_irq(&dev->power.lock);
|
|
|
|
+
|
|
|
|
+ return retval;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* rpm_idle - Notify device bus type if the device can be suspended.
|
|
* rpm_idle - Notify device bus type if the device can be suspended.
|
|
* @dev: Device to notify the bus type about.
|
|
* @dev: Device to notify the bus type about.
|
|
@@ -225,19 +250,8 @@ static int rpm_idle(struct device *dev, int rpmflags)
|
|
else
|
|
else
|
|
callback = NULL;
|
|
callback = NULL;
|
|
|
|
|
|
- if (callback) {
|
|
|
|
- if (dev->power.irq_safe)
|
|
|
|
- spin_unlock(&dev->power.lock);
|
|
|
|
- else
|
|
|
|
- spin_unlock_irq(&dev->power.lock);
|
|
|
|
-
|
|
|
|
- callback(dev);
|
|
|
|
-
|
|
|
|
- if (dev->power.irq_safe)
|
|
|
|
- spin_lock(&dev->power.lock);
|
|
|
|
- else
|
|
|
|
- spin_lock_irq(&dev->power.lock);
|
|
|
|
- }
|
|
|
|
|
|
+ if (callback)
|
|
|
|
+ __rpm_callback(callback, dev);
|
|
|
|
|
|
dev->power.idle_notification = false;
|
|
dev->power.idle_notification = false;
|
|
wake_up_all(&dev->power.wait_queue);
|
|
wake_up_all(&dev->power.wait_queue);
|
|
@@ -252,22 +266,14 @@ static int rpm_idle(struct device *dev, int rpmflags)
|
|
* @dev: Device to run the callback for.
|
|
* @dev: Device to run the callback for.
|
|
*/
|
|
*/
|
|
static int rpm_callback(int (*cb)(struct device *), struct device *dev)
|
|
static int rpm_callback(int (*cb)(struct device *), struct device *dev)
|
|
- __releases(&dev->power.lock) __acquires(&dev->power.lock)
|
|
|
|
{
|
|
{
|
|
int retval;
|
|
int retval;
|
|
|
|
|
|
if (!cb)
|
|
if (!cb)
|
|
return -ENOSYS;
|
|
return -ENOSYS;
|
|
|
|
|
|
- if (dev->power.irq_safe) {
|
|
|
|
- retval = cb(dev);
|
|
|
|
- } else {
|
|
|
|
- spin_unlock_irq(&dev->power.lock);
|
|
|
|
-
|
|
|
|
- retval = cb(dev);
|
|
|
|
|
|
+ retval = __rpm_callback(cb, dev);
|
|
|
|
|
|
- spin_lock_irq(&dev->power.lock);
|
|
|
|
- }
|
|
|
|
dev->power.runtime_error = retval;
|
|
dev->power.runtime_error = retval;
|
|
return retval != -EACCES ? retval : -EIO;
|
|
return retval != -EACCES ? retval : -EIO;
|
|
}
|
|
}
|
|
@@ -347,6 +353,15 @@ static int rpm_suspend(struct device *dev, int rpmflags)
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (dev->power.irq_safe) {
|
|
|
|
+ spin_unlock(&dev->power.lock);
|
|
|
|
+
|
|
|
|
+ cpu_relax();
|
|
|
|
+
|
|
|
|
+ spin_lock(&dev->power.lock);
|
|
|
|
+ goto repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* Wait for the other suspend running in parallel with us. */
|
|
/* Wait for the other suspend running in parallel with us. */
|
|
for (;;) {
|
|
for (;;) {
|
|
prepare_to_wait(&dev->power.wait_queue, &wait,
|
|
prepare_to_wait(&dev->power.wait_queue, &wait,
|
|
@@ -496,6 +511,15 @@ static int rpm_resume(struct device *dev, int rpmflags)
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (dev->power.irq_safe) {
|
|
|
|
+ spin_unlock(&dev->power.lock);
|
|
|
|
+
|
|
|
|
+ cpu_relax();
|
|
|
|
+
|
|
|
|
+ spin_lock(&dev->power.lock);
|
|
|
|
+ goto repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* Wait for the operation carried out in parallel with us. */
|
|
/* Wait for the operation carried out in parallel with us. */
|
|
for (;;) {
|
|
for (;;) {
|
|
prepare_to_wait(&dev->power.wait_queue, &wait,
|
|
prepare_to_wait(&dev->power.wait_queue, &wait,
|