[PATCH 3/3] USB: runtime pm: implement autosuspend by runtime pm core

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ming Lei <tom.leiming@xxxxxxxxx>

Since runtime pm core have implemnted generic autosuspend
mechanism, this patch replace the usb autosuspend with
runtime pm core autosuspend.

Signed-off-by: Ming Lei <tom.leiming@xxxxxxxxx>
---
 drivers/usb/core/driver.c |   25 +++++--------------------
 drivers/usb/core/hub.c    |    1 +
 drivers/usb/core/quirks.c |    2 +-
 drivers/usb/core/sysfs.c  |   25 +++----------------------
 drivers/usb/core/usb.c    |    2 +-
 include/linux/usb.h       |    1 -
 6 files changed, 11 insertions(+), 45 deletions(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 05a02c9..0c9c513 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1398,7 +1398,7 @@ void usb_autosuspend_device(struct usb_device *udev)
 	int	status;
 
 	usb_mark_last_busy(udev);
-	status = pm_runtime_put_sync(&udev->dev);
+	status = pm_runtime_put_sync_autosuspend(&udev->dev);
 	dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
 			__func__, atomic_read(&udev->dev.power.usage_count),
 			status);
@@ -1453,7 +1453,7 @@ int usb_autoresume_device(struct usb_device *udev)
 
 	status = pm_runtime_get_sync(&udev->dev);
 	if (status < 0)
-		pm_runtime_put_sync(&udev->dev);
+		pm_runtime_put_sync_autosuspend(&udev->dev);
 	dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
 			__func__, atomic_read(&udev->dev.power.usage_count),
 			status);
@@ -1530,9 +1530,7 @@ void usb_autopm_put_interface_async(struct usb_interface *intf)
 				round_jiffies_up(last_busy) !=
 				round_jiffies_up(jiffies)) {
 			status = pm_schedule_suspend(&intf->dev,
-					jiffies_to_msecs(
-					round_jiffies_up_relative(
-						udev->autosuspend_delay)));
+						udev->dev.power.autosuspend_delay);
 		}
 	}
 	dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
@@ -1661,8 +1659,6 @@ static int autosuspend_check(struct usb_device *udev)
 {
 	int			w, i;
 	struct usb_interface	*intf;
-	unsigned long		suspend_time, j;
-	unsigned long last_busy;
 
 	/* Fail if autosuspend is disabled, or any interfaces are in use, or
 	 * any interface drivers require remote wakeup but it isn't available.
@@ -1703,17 +1699,6 @@ static int autosuspend_check(struct usb_device *udev)
 	}
 	udev->do_remote_wakeup = w;
 
-	/* If everything is okay but the device hasn't been idle for long
-	 * enough, queue a delayed autosuspend request.
-	 */
-	j = ACCESS_ONCE(jiffies);
-	last_busy = udev->dev.power.last_busy;
-	suspend_time = last_busy + udev->autosuspend_delay;
-	if (time_before(j, suspend_time)) {
-		pm_schedule_suspend(&udev->dev, jiffies_to_msecs(
-				round_jiffies_up_relative(suspend_time - j)));
-		return -EAGAIN;
-	}
 	return 0;
 }
 
@@ -1738,7 +1723,7 @@ static int usb_runtime_suspend(struct device *dev)
 	 */
 	if (status) {
 		unsigned long last_busy = jiffies +
-				(udev->autosuspend_delay == 0 ?
+				(udev->dev.power.autosuspend_delay == 0 ?
 					HZ/2 : 0);
 		udev->dev.power.last_busy = last_busy;
 	}
@@ -1775,7 +1760,7 @@ static int usb_runtime_idle(struct device *dev)
 	if (autosuspend_check(udev) != 0)
 		return 0;
 
-	pm_runtime_suspend(dev);
+	pm_runtime_autosuspend(dev);
 	return 0;
 }
 
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 27115b4..d21ee91 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1804,6 +1804,7 @@ int usb_new_device(struct usb_device *udev)
 
 	/* Tell the runtime-PM framework the device is active */
 	pm_runtime_set_active(&udev->dev);
+	pm_runtime_use_autosuspend(&udev->dev);
 	pm_runtime_enable(&udev->dev);
 
 	err = usb_enumerate_device(udev);	/* Read descriptors */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 25719da..96d62f0 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -127,7 +127,7 @@ void usb_detect_quirks(struct usb_device *udev)
 	/* Autosuspend can also be disabled if the initial autosuspend_delay
 	 * is negative.
 	 */
-	if (udev->autosuspend_delay < 0)
+	if (udev->dev.power.autosuspend_delay < 0)
 		usb_autoresume_device(udev);
 
 #endif
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 448f5b4..aa32bdd 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -338,7 +338,7 @@ show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct usb_device *udev = to_usb_device(dev);
 
-	return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ);
+	return sprintf(buf, "%d\n", udev->dev.power.autosuspend_delay / 1000);
 }
 
 static ssize_t
@@ -346,34 +346,15 @@ set_autosuspend(struct device *dev, struct device_attribute *attr,
 		const char *buf, size_t count)
 {
 	struct usb_device *udev = to_usb_device(dev);
-	int value, old_delay;
-	int rc;
+	int value;
 
 	if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ ||
 			value <= - INT_MAX/HZ)
 		return -EINVAL;
 	value *= HZ;
 
-	usb_lock_device(udev);
-	old_delay = udev->autosuspend_delay;
-	udev->autosuspend_delay = value;
-
-	if (old_delay < 0) {	/* Autosuspend wasn't allowed */
-		if (value >= 0)
-			usb_autosuspend_device(udev);
-	} else {		/* Autosuspend was allowed */
-		if (value < 0) {
-			rc = usb_autoresume_device(udev);
-			if (rc < 0) {
-				count = rc;
-				udev->autosuspend_delay = old_delay;
-			}
-		} else {
-			usb_try_autosuspend_device(udev);
-		}
-	}
+	pm_runtime_set_autosuspend_delay(&udev->dev, jiffies_to_msecs(value));
 
-	usb_unlock_device(udev);
 	return count;
 }
 
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index fdd4130..0066a8b 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -445,7 +445,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
 	INIT_LIST_HEAD(&dev->filelist);
 
 #ifdef	CONFIG_PM
-	dev->autosuspend_delay = usb_autosuspend_delay * HZ;
+	dev->dev.power.autosuspend_delay = usb_autosuspend_delay * 1000;
 	dev->connect_time = jiffies;
 	dev->active_duration = -jiffies;
 #endif
diff --git a/include/linux/usb.h b/include/linux/usb.h
index c399031..06d2814 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -482,7 +482,6 @@ struct usb_device {
 	unsigned long active_duration;
 
 #ifdef CONFIG_PM
-	int autosuspend_delay;
 	unsigned long connect_time;
 
 	unsigned do_remote_wakeup:1;
-- 
1.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux