aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/driver.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2006-11-20 11:38:46 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-12-01 17:25:53 -0500
commit94fcda1f8ab5e0cacc381c5ca1cc9aa6ad523576 (patch)
treeffdcc2e33bce1343ce7e57e04e1beca190cf4201 /drivers/usb/core/driver.c
parentee49fb5dc89d34f1794ac9362fa97c1a640f7ddd (diff)
usbcore: remove unused argument in autosuspend
Thanks to several earlier patches, usb_autosuspend_device() and usb_autoresume_device() are never called with a second argument other than 1. This patch (as819) removes the now-redundant argument. It also consolidates some common code between those two routines, putting it into a new subroutine called usb_autopm_do_device(). And it includes a sizable kerneldoc update for the affected functions. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/driver.c')
-rw-r--r--drivers/usb/core/driver.c102
1 files changed, 56 insertions, 46 deletions
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 0fa15bd62c48..d6eb5ce1dd1d 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -205,7 +205,7 @@ static int usb_probe_interface(struct device *dev)
205 if (id) { 205 if (id) {
206 dev_dbg(dev, "%s - got id\n", __FUNCTION__); 206 dev_dbg(dev, "%s - got id\n", __FUNCTION__);
207 207
208 error = usb_autoresume_device(udev, 1); 208 error = usb_autoresume_device(udev);
209 if (error) 209 if (error)
210 return error; 210 return error;
211 211
@@ -229,7 +229,7 @@ static int usb_probe_interface(struct device *dev)
229 } else 229 } else
230 intf->condition = USB_INTERFACE_BOUND; 230 intf->condition = USB_INTERFACE_BOUND;
231 231
232 usb_autosuspend_device(udev, 1); 232 usb_autosuspend_device(udev);
233 } 233 }
234 234
235 return error; 235 return error;
@@ -247,7 +247,7 @@ static int usb_unbind_interface(struct device *dev)
247 247
248 /* Autoresume for set_interface call below */ 248 /* Autoresume for set_interface call below */
249 udev = interface_to_usbdev(intf); 249 udev = interface_to_usbdev(intf);
250 error = usb_autoresume_device(udev, 1); 250 error = usb_autoresume_device(udev);
251 251
252 /* release all urbs for this interface */ 252 /* release all urbs for this interface */
253 usb_disable_interface(interface_to_usbdev(intf), intf); 253 usb_disable_interface(interface_to_usbdev(intf), intf);
@@ -265,7 +265,7 @@ static int usb_unbind_interface(struct device *dev)
265 intf->needs_remote_wakeup = 0; 265 intf->needs_remote_wakeup = 0;
266 266
267 if (!error) 267 if (!error)
268 usb_autosuspend_device(udev, 1); 268 usb_autosuspend_device(udev);
269 269
270 return 0; 270 return 0;
271} 271}
@@ -940,6 +940,8 @@ done:
940 return status; 940 return status;
941} 941}
942 942
943#ifdef CONFIG_USB_SUSPEND
944
943/* Internal routine to check whether we may autosuspend a device. */ 945/* Internal routine to check whether we may autosuspend a device. */
944static int autosuspend_check(struct usb_device *udev) 946static int autosuspend_check(struct usb_device *udev)
945{ 947{
@@ -970,6 +972,12 @@ static int autosuspend_check(struct usb_device *udev)
970 return 0; 972 return 0;
971} 973}
972 974
975#else
976
977#define autosuspend_check(udev) 0
978
979#endif
980
973/** 981/**
974 * usb_suspend_both - suspend a USB device and its interfaces 982 * usb_suspend_both - suspend a USB device and its interfaces
975 * @udev: the usb_device to suspend 983 * @udev: the usb_device to suspend
@@ -1048,7 +1056,7 @@ int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1048 1056
1049 /* If the suspend succeeded, propagate it up the tree */ 1057 /* If the suspend succeeded, propagate it up the tree */
1050 } else if (parent) 1058 } else if (parent)
1051 usb_autosuspend_device(parent, 1); 1059 usb_autosuspend_device(parent);
1052 1060
1053 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); 1061 // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
1054 return status; 1062 return status;
@@ -1096,11 +1104,11 @@ int usb_resume_both(struct usb_device *udev)
1096 /* Propagate the resume up the tree, if necessary */ 1104 /* Propagate the resume up the tree, if necessary */
1097 if (udev->state == USB_STATE_SUSPENDED) { 1105 if (udev->state == USB_STATE_SUSPENDED) {
1098 if (parent) { 1106 if (parent) {
1099 status = usb_autoresume_device(parent, 1); 1107 status = usb_autoresume_device(parent);
1100 if (status == 0) { 1108 if (status == 0) {
1101 status = usb_resume_device(udev); 1109 status = usb_resume_device(udev);
1102 if (status) { 1110 if (status) {
1103 usb_autosuspend_device(parent, 1); 1111 usb_autosuspend_device(parent);
1104 1112
1105 /* It's possible usb_resume_device() 1113 /* It's possible usb_resume_device()
1106 * failed after the port was 1114 * failed after the port was
@@ -1146,39 +1154,53 @@ int usb_resume_both(struct usb_device *udev)
1146 1154
1147#ifdef CONFIG_USB_SUSPEND 1155#ifdef CONFIG_USB_SUSPEND
1148 1156
1157/* Internal routine to adjust a device's usage counter and change
1158 * its autosuspend state.
1159 */
1160static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt)
1161{
1162 int status = 0;
1163
1164 usb_pm_lock(udev);
1165 udev->pm_usage_cnt += inc_usage_cnt;
1166 WARN_ON(udev->pm_usage_cnt < 0);
1167 if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) {
1168 udev->auto_pm = 1;
1169 status = usb_resume_both(udev);
1170 if (status != 0)
1171 udev->pm_usage_cnt -= inc_usage_cnt;
1172 } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0)
1173 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1174 USB_AUTOSUSPEND_DELAY);
1175 usb_pm_unlock(udev);
1176 return status;
1177}
1178
1149/** 1179/**
1150 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces 1180 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces
1151 * @udev: the usb_device to autosuspend 1181 * @udev: the usb_device to autosuspend
1152 * @dec_usage_cnt: flag to decrement @udev's PM-usage counter
1153 * 1182 *
1154 * This routine should be called when a core subsystem is finished using 1183 * This routine should be called when a core subsystem is finished using
1155 * @udev and wants to allow it to autosuspend. Examples would be when 1184 * @udev and wants to allow it to autosuspend. Examples would be when
1156 * @udev's device file in usbfs is closed or after a configuration change. 1185 * @udev's device file in usbfs is closed or after a configuration change.
1157 * 1186 *
1158 * @dec_usage_cnt should be 1 if the subsystem previously incremented 1187 * @udev's usage counter is decremented. If it or any of the usage counters
1159 * @udev's usage counter (such as by passing 1 to usb_autoresume_device); 1188 * for an active interface is greater than 0, no autosuspend request will be
1160 * otherwise it should be 0. 1189 * queued. (If an interface driver does not support autosuspend then its
1161 * 1190 * usage counter is permanently positive.) Furthermore, if an interface
1162 * If the usage counter for @udev or any of its active interfaces is greater 1191 * driver requires remote-wakeup capability during autosuspend but remote
1163 * than 0, the autosuspend request will not be queued. (If an interface 1192 * wakeup is disabled, the autosuspend will fail.
1164 * driver does not support autosuspend then its usage counter is permanently
1165 * positive.) Likewise, if an interface driver requires remote-wakeup
1166 * capability during autosuspend but remote wakeup is disabled, the
1167 * autosuspend will fail.
1168 * 1193 *
1169 * Often the caller will hold @udev's device lock, but this is not 1194 * Often the caller will hold @udev's device lock, but this is not
1170 * necessary. 1195 * necessary.
1171 * 1196 *
1172 * This routine can run only in process context. 1197 * This routine can run only in process context.
1173 */ 1198 */
1174void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt) 1199void usb_autosuspend_device(struct usb_device *udev)
1175{ 1200{
1176 usb_pm_lock(udev); 1201 int status;
1177 udev->pm_usage_cnt -= dec_usage_cnt; 1202
1178 if (autosuspend_check(udev) == 0) 1203 status = usb_autopm_do_device(udev, -1);
1179 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1180 USB_AUTOSUSPEND_DELAY);
1181 usb_pm_unlock(udev);
1182 // dev_dbg(&udev->dev, "%s: cnt %d\n", 1204 // dev_dbg(&udev->dev, "%s: cnt %d\n",
1183 // __FUNCTION__, udev->pm_usage_cnt); 1205 // __FUNCTION__, udev->pm_usage_cnt);
1184} 1206}
@@ -1186,39 +1208,27 @@ void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt)
1186/** 1208/**
1187 * usb_autoresume_device - immediately autoresume a USB device and its interfaces 1209 * usb_autoresume_device - immediately autoresume a USB device and its interfaces
1188 * @udev: the usb_device to autoresume 1210 * @udev: the usb_device to autoresume
1189 * @inc_usage_cnt: flag to increment @udev's PM-usage counter
1190 * 1211 *
1191 * This routine should be called when a core subsystem wants to use @udev 1212 * This routine should be called when a core subsystem wants to use @udev
1192 * and needs to guarantee that it is not suspended. In addition, the 1213 * and needs to guarantee that it is not suspended. No autosuspend will
1193 * caller can prevent @udev from being autosuspended subsequently. (Note 1214 * occur until usb_autosuspend_device is called. (Note that this will not
1194 * that this will not prevent suspend events originating in the PM core.) 1215 * prevent suspend events originating in the PM core.) Examples would be
1195 * Examples would be when @udev's device file in usbfs is opened (autosuspend 1216 * when @udev's device file in usbfs is opened or when a remote-wakeup
1196 * should be prevented until the file is closed) or when a remote-wakeup 1217 * request is received.
1197 * request is received (later autosuspends should not be prevented).
1198 * 1218 *
1199 * @inc_usage_cnt should be 1 to increment @udev's usage counter and prevent 1219 * @udev's usage counter is incremented to prevent subsequent autosuspends.
1200 * autosuspends. This prevention will persist until the usage counter is 1220 * However if the autoresume fails then the usage counter is re-decremented.
1201 * decremented again (such as by passing 1 to usb_autosuspend_device).
1202 * Otherwise @inc_usage_cnt should be 0 to leave the usage counter unchanged.
1203 * Regardless, if the autoresume fails then the usage counter is not
1204 * incremented.
1205 * 1221 *
1206 * Often the caller will hold @udev's device lock, but this is not 1222 * Often the caller will hold @udev's device lock, but this is not
1207 * necessary (and attempting it might cause deadlock). 1223 * necessary (and attempting it might cause deadlock).
1208 * 1224 *
1209 * This routine can run only in process context. 1225 * This routine can run only in process context.
1210 */ 1226 */
1211int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt) 1227int usb_autoresume_device(struct usb_device *udev)
1212{ 1228{
1213 int status; 1229 int status;
1214 1230
1215 usb_pm_lock(udev); 1231 status = usb_autopm_do_device(udev, 1);
1216 udev->pm_usage_cnt += inc_usage_cnt;
1217 udev->auto_pm = 1;
1218 status = usb_resume_both(udev);
1219 if (status != 0)
1220 udev->pm_usage_cnt -= inc_usage_cnt;
1221 usb_pm_unlock(udev);
1222 // dev_dbg(&udev->dev, "%s: status %d cnt %d\n", 1232 // dev_dbg(&udev->dev, "%s: status %d cnt %d\n",
1223 // __FUNCTION__, status, udev->pm_usage_cnt); 1233 // __FUNCTION__, status, udev->pm_usage_cnt);
1224 return status; 1234 return status;