diff options
author | Paul Mackerras <paulus@samba.org> | 2006-12-03 23:59:07 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-12-03 23:59:07 -0500 |
commit | 79acbb3ff2d8095b692e1502b9eb2ccec348de26 (patch) | |
tree | 6ab773e5a8f9de2cd6443362b21d0d6fffe3b35e /drivers/usb/core/hub.c | |
parent | 19a79859e168640f8e16d7b216d211c1c52b687a (diff) | |
parent | 2b5f6dcce5bf94b9b119e9ed8d537098ec61c3d2 (diff) |
Merge branch 'linux-2.6' into for-linus
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r-- | drivers/usb/core/hub.c | 237 |
1 files changed, 169 insertions, 68 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 66bff184a30c..0ce393eb3c4b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -31,6 +31,47 @@ | |||
31 | #include "hcd.h" | 31 | #include "hcd.h" |
32 | #include "hub.h" | 32 | #include "hub.h" |
33 | 33 | ||
34 | struct usb_hub { | ||
35 | struct device *intfdev; /* the "interface" device */ | ||
36 | struct usb_device *hdev; | ||
37 | struct urb *urb; /* for interrupt polling pipe */ | ||
38 | |||
39 | /* buffer for urb ... with extra space in case of babble */ | ||
40 | char (*buffer)[8]; | ||
41 | dma_addr_t buffer_dma; /* DMA address for buffer */ | ||
42 | union { | ||
43 | struct usb_hub_status hub; | ||
44 | struct usb_port_status port; | ||
45 | } *status; /* buffer for status reports */ | ||
46 | |||
47 | int error; /* last reported error */ | ||
48 | int nerrors; /* track consecutive errors */ | ||
49 | |||
50 | struct list_head event_list; /* hubs w/data or errs ready */ | ||
51 | unsigned long event_bits[1]; /* status change bitmask */ | ||
52 | unsigned long change_bits[1]; /* ports with logical connect | ||
53 | status change */ | ||
54 | unsigned long busy_bits[1]; /* ports being reset or | ||
55 | resumed */ | ||
56 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | ||
57 | #error event_bits[] is too short! | ||
58 | #endif | ||
59 | |||
60 | struct usb_hub_descriptor *descriptor; /* class descriptor */ | ||
61 | struct usb_tt tt; /* Transaction Translator */ | ||
62 | |||
63 | unsigned mA_per_port; /* current for each child */ | ||
64 | |||
65 | unsigned limited_power:1; | ||
66 | unsigned quiescing:1; | ||
67 | unsigned activating:1; | ||
68 | |||
69 | unsigned has_indicators:1; | ||
70 | u8 indicator[USB_MAXCHILDREN]; | ||
71 | struct work_struct leds; | ||
72 | }; | ||
73 | |||
74 | |||
34 | /* Protect struct usb_device->state and ->children members | 75 | /* Protect struct usb_device->state and ->children members |
35 | * Note: Both are also protected by ->dev.sem, except that ->state can | 76 | * Note: Both are also protected by ->dev.sem, except that ->state can |
36 | * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */ | 77 | * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */ |
@@ -45,6 +86,16 @@ static DECLARE_WAIT_QUEUE_HEAD(khubd_wait); | |||
45 | 86 | ||
46 | static struct task_struct *khubd_task; | 87 | static struct task_struct *khubd_task; |
47 | 88 | ||
89 | /* multithreaded probe logic */ | ||
90 | static int multithread_probe = | ||
91 | #ifdef CONFIG_USB_MULTITHREAD_PROBE | ||
92 | 1; | ||
93 | #else | ||
94 | 0; | ||
95 | #endif | ||
96 | module_param(multithread_probe, bool, S_IRUGO); | ||
97 | MODULE_PARM_DESC(multithread_probe, "Run each USB device probe in a new thread"); | ||
98 | |||
48 | /* cycle leds on hubs that aren't blinking for attention */ | 99 | /* cycle leds on hubs that aren't blinking for attention */ |
49 | static int blinkenlights = 0; | 100 | static int blinkenlights = 0; |
50 | module_param (blinkenlights, bool, S_IRUGO); | 101 | module_param (blinkenlights, bool, S_IRUGO); |
@@ -276,6 +327,9 @@ static void kick_khubd(struct usb_hub *hub) | |||
276 | { | 327 | { |
277 | unsigned long flags; | 328 | unsigned long flags; |
278 | 329 | ||
330 | /* Suppress autosuspend until khubd runs */ | ||
331 | to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; | ||
332 | |||
279 | spin_lock_irqsave(&hub_event_lock, flags); | 333 | spin_lock_irqsave(&hub_event_lock, flags); |
280 | if (list_empty(&hub->event_list)) { | 334 | if (list_empty(&hub->event_list)) { |
281 | list_add_tail(&hub->event_list, &hub_event_list); | 335 | list_add_tail(&hub->event_list, &hub_event_list); |
@@ -457,7 +511,6 @@ static void hub_quiesce(struct usb_hub *hub) | |||
457 | /* (nonblocking) khubd and related activity won't re-trigger */ | 511 | /* (nonblocking) khubd and related activity won't re-trigger */ |
458 | hub->quiescing = 1; | 512 | hub->quiescing = 1; |
459 | hub->activating = 0; | 513 | hub->activating = 0; |
460 | hub->resume_root_hub = 0; | ||
461 | 514 | ||
462 | /* (blocking) stop khubd and related activity */ | 515 | /* (blocking) stop khubd and related activity */ |
463 | usb_kill_urb(hub->urb); | 516 | usb_kill_urb(hub->urb); |
@@ -473,7 +526,7 @@ static void hub_activate(struct usb_hub *hub) | |||
473 | 526 | ||
474 | hub->quiescing = 0; | 527 | hub->quiescing = 0; |
475 | hub->activating = 1; | 528 | hub->activating = 1; |
476 | hub->resume_root_hub = 0; | 529 | |
477 | status = usb_submit_urb(hub->urb, GFP_NOIO); | 530 | status = usb_submit_urb(hub->urb, GFP_NOIO); |
478 | if (status < 0) | 531 | if (status < 0) |
479 | dev_err(hub->intfdev, "activate --> %d\n", status); | 532 | dev_err(hub->intfdev, "activate --> %d\n", status); |
@@ -759,7 +812,12 @@ static int hub_configure(struct usb_hub *hub, | |||
759 | dev_dbg(hub_dev, "%sover-current condition exists\n", | 812 | dev_dbg(hub_dev, "%sover-current condition exists\n", |
760 | (hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no "); | 813 | (hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no "); |
761 | 814 | ||
762 | /* set up the interrupt endpoint */ | 815 | /* set up the interrupt endpoint |
816 | * We use the EP's maxpacket size instead of (PORTS+1+7)/8 | ||
817 | * bytes as USB2.0[11.12.3] says because some hubs are known | ||
818 | * to send more data (and thus cause overflow). For root hubs, | ||
819 | * maxpktsize is defined in hcd.c's fake endpoint descriptors | ||
820 | * to be big enough for at least USB_MAXCHILDREN ports. */ | ||
763 | pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); | 821 | pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); |
764 | maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe)); | 822 | maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe)); |
765 | 823 | ||
@@ -883,6 +941,7 @@ descriptor_error: | |||
883 | INIT_WORK(&hub->leds, led_work, hub); | 941 | INIT_WORK(&hub->leds, led_work, hub); |
884 | 942 | ||
885 | usb_set_intfdata (intf, hub); | 943 | usb_set_intfdata (intf, hub); |
944 | intf->needs_remote_wakeup = 1; | ||
886 | 945 | ||
887 | if (hdev->speed == USB_SPEED_HIGH) | 946 | if (hdev->speed == USB_SPEED_HIGH) |
888 | highspeed_hubs++; | 947 | highspeed_hubs++; |
@@ -980,6 +1039,8 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev) | |||
980 | if (udev->children[i]) | 1039 | if (udev->children[i]) |
981 | recursively_mark_NOTATTACHED(udev->children[i]); | 1040 | recursively_mark_NOTATTACHED(udev->children[i]); |
982 | } | 1041 | } |
1042 | if (udev->state == USB_STATE_SUSPENDED) | ||
1043 | udev->discon_suspended = 1; | ||
983 | udev->state = USB_STATE_NOTATTACHED; | 1044 | udev->state = USB_STATE_NOTATTACHED; |
984 | } | 1045 | } |
985 | 1046 | ||
@@ -1169,6 +1230,14 @@ void usb_disconnect(struct usb_device **pdev) | |||
1169 | *pdev = NULL; | 1230 | *pdev = NULL; |
1170 | spin_unlock_irq(&device_state_lock); | 1231 | spin_unlock_irq(&device_state_lock); |
1171 | 1232 | ||
1233 | /* Decrement the parent's count of unsuspended children */ | ||
1234 | if (udev->parent) { | ||
1235 | usb_pm_lock(udev); | ||
1236 | if (!udev->discon_suspended) | ||
1237 | usb_autosuspend_device(udev->parent); | ||
1238 | usb_pm_unlock(udev); | ||
1239 | } | ||
1240 | |||
1172 | put_device(&udev->dev); | 1241 | put_device(&udev->dev); |
1173 | } | 1242 | } |
1174 | 1243 | ||
@@ -1188,31 +1257,20 @@ static inline void show_string(struct usb_device *udev, char *id, char *string) | |||
1188 | 1257 | ||
1189 | #ifdef CONFIG_USB_OTG | 1258 | #ifdef CONFIG_USB_OTG |
1190 | #include "otg_whitelist.h" | 1259 | #include "otg_whitelist.h" |
1260 | static int __usb_port_suspend(struct usb_device *, int port1); | ||
1191 | #endif | 1261 | #endif |
1192 | 1262 | ||
1193 | /** | 1263 | static int __usb_new_device(void *void_data) |
1194 | * usb_new_device - perform initial device setup (usbcore-internal) | ||
1195 | * @udev: newly addressed device (in ADDRESS state) | ||
1196 | * | ||
1197 | * This is called with devices which have been enumerated, but not yet | ||
1198 | * configured. The device descriptor is available, but not descriptors | ||
1199 | * for any device configuration. The caller must have locked either | ||
1200 | * the parent hub (if udev is a normal device) or else the | ||
1201 | * usb_bus_list_lock (if udev is a root hub). The parent's pointer to | ||
1202 | * udev has already been installed, but udev is not yet visible through | ||
1203 | * sysfs or other filesystem code. | ||
1204 | * | ||
1205 | * Returns 0 for success (device is configured and listed, with its | ||
1206 | * interfaces, in sysfs); else a negative errno value. | ||
1207 | * | ||
1208 | * This call is synchronous, and may not be used in an interrupt context. | ||
1209 | * | ||
1210 | * Only the hub driver or root-hub registrar should ever call this. | ||
1211 | */ | ||
1212 | int usb_new_device(struct usb_device *udev) | ||
1213 | { | 1264 | { |
1265 | struct usb_device *udev = void_data; | ||
1214 | int err; | 1266 | int err; |
1215 | 1267 | ||
1268 | /* Lock ourself into memory in order to keep a probe sequence | ||
1269 | * sleeping in a new thread from allowing us to be unloaded. | ||
1270 | */ | ||
1271 | if (!try_module_get(THIS_MODULE)) | ||
1272 | return -EINVAL; | ||
1273 | |||
1216 | err = usb_get_configuration(udev); | 1274 | err = usb_get_configuration(udev); |
1217 | if (err < 0) { | 1275 | if (err < 0) { |
1218 | dev_err(&udev->dev, "can't read configurations, error %d\n", | 1276 | dev_err(&udev->dev, "can't read configurations, error %d\n", |
@@ -1289,8 +1347,6 @@ int usb_new_device(struct usb_device *udev) | |||
1289 | * (Includes HNP test device.) | 1347 | * (Includes HNP test device.) |
1290 | */ | 1348 | */ |
1291 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { | 1349 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { |
1292 | static int __usb_port_suspend(struct usb_device *, | ||
1293 | int port1); | ||
1294 | err = __usb_port_suspend(udev, udev->bus->otg_port); | 1350 | err = __usb_port_suspend(udev, udev->bus->otg_port); |
1295 | if (err < 0) | 1351 | if (err < 0) |
1296 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); | 1352 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); |
@@ -1310,13 +1366,56 @@ int usb_new_device(struct usb_device *udev) | |||
1310 | goto fail; | 1366 | goto fail; |
1311 | } | 1367 | } |
1312 | 1368 | ||
1313 | return 0; | 1369 | /* Increment the parent's count of unsuspended children */ |
1370 | if (udev->parent) | ||
1371 | usb_autoresume_device(udev->parent); | ||
1372 | |||
1373 | exit: | ||
1374 | module_put(THIS_MODULE); | ||
1375 | return err; | ||
1314 | 1376 | ||
1315 | fail: | 1377 | fail: |
1316 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1378 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1317 | return err; | 1379 | goto exit; |
1318 | } | 1380 | } |
1319 | 1381 | ||
1382 | /** | ||
1383 | * usb_new_device - perform initial device setup (usbcore-internal) | ||
1384 | * @udev: newly addressed device (in ADDRESS state) | ||
1385 | * | ||
1386 | * This is called with devices which have been enumerated, but not yet | ||
1387 | * configured. The device descriptor is available, but not descriptors | ||
1388 | * for any device configuration. The caller must have locked either | ||
1389 | * the parent hub (if udev is a normal device) or else the | ||
1390 | * usb_bus_list_lock (if udev is a root hub). The parent's pointer to | ||
1391 | * udev has already been installed, but udev is not yet visible through | ||
1392 | * sysfs or other filesystem code. | ||
1393 | * | ||
1394 | * The return value for this function depends on if the | ||
1395 | * multithread_probe variable is set or not. If it's set, it will | ||
1396 | * return a if the probe thread was successfully created or not. If the | ||
1397 | * variable is not set, it will return if the device is configured | ||
1398 | * properly or not. interfaces, in sysfs); else a negative errno value. | ||
1399 | * | ||
1400 | * This call is synchronous, and may not be used in an interrupt context. | ||
1401 | * | ||
1402 | * Only the hub driver or root-hub registrar should ever call this. | ||
1403 | */ | ||
1404 | int usb_new_device(struct usb_device *udev) | ||
1405 | { | ||
1406 | struct task_struct *probe_task; | ||
1407 | int ret = 0; | ||
1408 | |||
1409 | if (multithread_probe) { | ||
1410 | probe_task = kthread_run(__usb_new_device, udev, | ||
1411 | "usb-probe-%s", udev->devnum); | ||
1412 | if (IS_ERR(probe_task)) | ||
1413 | ret = PTR_ERR(probe_task); | ||
1414 | } else | ||
1415 | ret = __usb_new_device(udev); | ||
1416 | |||
1417 | return ret; | ||
1418 | } | ||
1320 | 1419 | ||
1321 | static int hub_port_status(struct usb_hub *hub, int port1, | 1420 | static int hub_port_status(struct usb_hub *hub, int port1, |
1322 | u16 *status, u16 *change) | 1421 | u16 *status, u16 *change) |
@@ -1324,10 +1423,12 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
1324 | int ret; | 1423 | int ret; |
1325 | 1424 | ||
1326 | ret = get_port_status(hub->hdev, port1, &hub->status->port); | 1425 | ret = get_port_status(hub->hdev, port1, &hub->status->port); |
1327 | if (ret < 0) | 1426 | if (ret < 4) { |
1328 | dev_err (hub->intfdev, | 1427 | dev_err (hub->intfdev, |
1329 | "%s failed (err = %d)\n", __FUNCTION__, ret); | 1428 | "%s failed (err = %d)\n", __FUNCTION__, ret); |
1330 | else { | 1429 | if (ret >= 0) |
1430 | ret = -EIO; | ||
1431 | } else { | ||
1331 | *status = le16_to_cpu(hub->status->port.wPortStatus); | 1432 | *status = le16_to_cpu(hub->status->port.wPortStatus); |
1332 | *change = le16_to_cpu(hub->status->port.wPortChange); | 1433 | *change = le16_to_cpu(hub->status->port.wPortChange); |
1333 | ret = 0; | 1434 | ret = 0; |
@@ -1675,6 +1776,12 @@ static int | |||
1675 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | 1776 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) |
1676 | { | 1777 | { |
1677 | int status; | 1778 | int status; |
1779 | u16 portchange, portstatus; | ||
1780 | |||
1781 | /* Skip the initial Clear-Suspend step for a remote wakeup */ | ||
1782 | status = hub_port_status(hub, port1, &portstatus, &portchange); | ||
1783 | if (status == 0 && !(portstatus & USB_PORT_STAT_SUSPEND)) | ||
1784 | goto SuspendCleared; | ||
1678 | 1785 | ||
1679 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); | 1786 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); |
1680 | 1787 | ||
@@ -1688,9 +1795,6 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1688 | "can't resume port %d, status %d\n", | 1795 | "can't resume port %d, status %d\n", |
1689 | port1, status); | 1796 | port1, status); |
1690 | } else { | 1797 | } else { |
1691 | u16 devstatus; | ||
1692 | u16 portchange; | ||
1693 | |||
1694 | /* drive resume for at least 20 msec */ | 1798 | /* drive resume for at least 20 msec */ |
1695 | if (udev) | 1799 | if (udev) |
1696 | dev_dbg(&udev->dev, "usb %sresume\n", | 1800 | dev_dbg(&udev->dev, "usb %sresume\n", |
@@ -1705,16 +1809,15 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1705 | * stop resume signaling. Then finish the resume | 1809 | * stop resume signaling. Then finish the resume |
1706 | * sequence. | 1810 | * sequence. |
1707 | */ | 1811 | */ |
1708 | devstatus = portchange = 0; | 1812 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
1709 | status = hub_port_status(hub, port1, | 1813 | SuspendCleared: |
1710 | &devstatus, &portchange); | ||
1711 | if (status < 0 | 1814 | if (status < 0 |
1712 | || (devstatus & LIVE_FLAGS) != LIVE_FLAGS | 1815 | || (portstatus & LIVE_FLAGS) != LIVE_FLAGS |
1713 | || (devstatus & USB_PORT_STAT_SUSPEND) != 0 | 1816 | || (portstatus & USB_PORT_STAT_SUSPEND) != 0 |
1714 | ) { | 1817 | ) { |
1715 | dev_dbg(hub->intfdev, | 1818 | dev_dbg(hub->intfdev, |
1716 | "port %d status %04x.%04x after resume, %d\n", | 1819 | "port %d status %04x.%04x after resume, %d\n", |
1717 | port1, portchange, devstatus, status); | 1820 | port1, portchange, portstatus, status); |
1718 | if (status >= 0) | 1821 | if (status >= 0) |
1719 | status = -ENODEV; | 1822 | status = -ENODEV; |
1720 | } else { | 1823 | } else { |
@@ -1775,23 +1878,16 @@ static int remote_wakeup(struct usb_device *udev) | |||
1775 | { | 1878 | { |
1776 | int status = 0; | 1879 | int status = 0; |
1777 | 1880 | ||
1778 | /* All this just to avoid sending a port-resume message | ||
1779 | * to the parent hub! */ | ||
1780 | |||
1781 | usb_lock_device(udev); | 1881 | usb_lock_device(udev); |
1782 | usb_pm_lock(udev); | ||
1783 | if (udev->state == USB_STATE_SUSPENDED) { | 1882 | if (udev->state == USB_STATE_SUSPENDED) { |
1784 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); | 1883 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
1785 | /* TRSMRCY = 10 msec */ | 1884 | status = usb_autoresume_device(udev); |
1786 | msleep(10); | 1885 | |
1787 | status = finish_port_resume(udev); | 1886 | /* Give the interface drivers a chance to do something, |
1887 | * then autosuspend the device again. */ | ||
1788 | if (status == 0) | 1888 | if (status == 0) |
1789 | udev->dev.power.power_state.event = PM_EVENT_ON; | 1889 | usb_autosuspend_device(udev); |
1790 | } | 1890 | } |
1791 | usb_pm_unlock(udev); | ||
1792 | |||
1793 | if (status == 0) | ||
1794 | usb_autoresume_device(udev, 0); | ||
1795 | usb_unlock_device(udev); | 1891 | usb_unlock_device(udev); |
1796 | return status; | 1892 | return status; |
1797 | } | 1893 | } |
@@ -1855,6 +1951,8 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
1855 | } | 1951 | } |
1856 | } | 1952 | } |
1857 | 1953 | ||
1954 | dev_dbg(&intf->dev, "%s\n", __FUNCTION__); | ||
1955 | |||
1858 | /* "global suspend" of the downstream HC-to-USB interface */ | 1956 | /* "global suspend" of the downstream HC-to-USB interface */ |
1859 | if (!hdev->parent) { | 1957 | if (!hdev->parent) { |
1860 | struct usb_bus *bus = hdev->bus; | 1958 | struct usb_bus *bus = hdev->bus; |
@@ -1877,10 +1975,12 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
1877 | 1975 | ||
1878 | static int hub_resume(struct usb_interface *intf) | 1976 | static int hub_resume(struct usb_interface *intf) |
1879 | { | 1977 | { |
1880 | struct usb_device *hdev = interface_to_usbdev(intf); | ||
1881 | struct usb_hub *hub = usb_get_intfdata (intf); | 1978 | struct usb_hub *hub = usb_get_intfdata (intf); |
1979 | struct usb_device *hdev = hub->hdev; | ||
1882 | int status; | 1980 | int status; |
1883 | 1981 | ||
1982 | dev_dbg(&intf->dev, "%s\n", __FUNCTION__); | ||
1983 | |||
1884 | /* "global resume" of the downstream HC-to-USB interface */ | 1984 | /* "global resume" of the downstream HC-to-USB interface */ |
1885 | if (!hdev->parent) { | 1985 | if (!hdev->parent) { |
1886 | struct usb_bus *bus = hdev->bus; | 1986 | struct usb_bus *bus = hdev->bus; |
@@ -1919,7 +2019,6 @@ void usb_resume_root_hub(struct usb_device *hdev) | |||
1919 | { | 2019 | { |
1920 | struct usb_hub *hub = hdev_to_hub(hdev); | 2020 | struct usb_hub *hub = hdev_to_hub(hdev); |
1921 | 2021 | ||
1922 | hub->resume_root_hub = 1; | ||
1923 | kick_khubd(hub); | 2022 | kick_khubd(hub); |
1924 | } | 2023 | } |
1925 | 2024 | ||
@@ -2556,16 +2655,13 @@ static void hub_events(void) | |||
2556 | intf = to_usb_interface(hub->intfdev); | 2655 | intf = to_usb_interface(hub->intfdev); |
2557 | hub_dev = &intf->dev; | 2656 | hub_dev = &intf->dev; |
2558 | 2657 | ||
2559 | i = hub->resume_root_hub; | 2658 | dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n", |
2560 | |||
2561 | dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x%s\n", | ||
2562 | hdev->state, hub->descriptor | 2659 | hdev->state, hub->descriptor |
2563 | ? hub->descriptor->bNbrPorts | 2660 | ? hub->descriptor->bNbrPorts |
2564 | : 0, | 2661 | : 0, |
2565 | /* NOTE: expects max 15 ports... */ | 2662 | /* NOTE: expects max 15 ports... */ |
2566 | (u16) hub->change_bits[0], | 2663 | (u16) hub->change_bits[0], |
2567 | (u16) hub->event_bits[0], | 2664 | (u16) hub->event_bits[0]); |
2568 | i ? ", resume root" : ""); | ||
2569 | 2665 | ||
2570 | usb_get_intf(intf); | 2666 | usb_get_intf(intf); |
2571 | spin_unlock_irq(&hub_event_lock); | 2667 | spin_unlock_irq(&hub_event_lock); |
@@ -2586,16 +2682,16 @@ static void hub_events(void) | |||
2586 | goto loop; | 2682 | goto loop; |
2587 | } | 2683 | } |
2588 | 2684 | ||
2589 | /* Is this is a root hub wanting to reactivate the downstream | 2685 | /* Autoresume */ |
2590 | * ports? If so, be sure the interface resumes even if its | 2686 | ret = usb_autopm_get_interface(intf); |
2591 | * stub "device" node was never suspended. | 2687 | if (ret) { |
2592 | */ | 2688 | dev_dbg(hub_dev, "Can't autoresume: %d\n", ret); |
2593 | if (i) | 2689 | goto loop; |
2594 | usb_autoresume_device(hdev, 0); | 2690 | } |
2595 | 2691 | ||
2596 | /* If this is an inactive or suspended hub, do nothing */ | 2692 | /* If this is an inactive hub, do nothing */ |
2597 | if (hub->quiescing) | 2693 | if (hub->quiescing) |
2598 | goto loop; | 2694 | goto loop_autopm; |
2599 | 2695 | ||
2600 | if (hub->error) { | 2696 | if (hub->error) { |
2601 | dev_dbg (hub_dev, "resetting for error %d\n", | 2697 | dev_dbg (hub_dev, "resetting for error %d\n", |
@@ -2605,7 +2701,7 @@ static void hub_events(void) | |||
2605 | if (ret) { | 2701 | if (ret) { |
2606 | dev_dbg (hub_dev, | 2702 | dev_dbg (hub_dev, |
2607 | "error resetting hub: %d\n", ret); | 2703 | "error resetting hub: %d\n", ret); |
2608 | goto loop; | 2704 | goto loop_autopm; |
2609 | } | 2705 | } |
2610 | 2706 | ||
2611 | hub->nerrors = 0; | 2707 | hub->nerrors = 0; |
@@ -2733,6 +2829,10 @@ static void hub_events(void) | |||
2733 | if (!hdev->parent && !hub->busy_bits[0]) | 2829 | if (!hdev->parent && !hub->busy_bits[0]) |
2734 | usb_enable_root_hub_irq(hdev->bus); | 2830 | usb_enable_root_hub_irq(hdev->bus); |
2735 | 2831 | ||
2832 | loop_autopm: | ||
2833 | /* Allow autosuspend if we're not going to run again */ | ||
2834 | if (list_empty(&hub->event_list)) | ||
2835 | usb_autopm_enable(intf); | ||
2736 | loop: | 2836 | loop: |
2737 | usb_unlock_device(hdev); | 2837 | usb_unlock_device(hdev); |
2738 | usb_put_intf(intf); | 2838 | usb_put_intf(intf); |
@@ -2774,6 +2874,7 @@ static struct usb_driver hub_driver = { | |||
2774 | .post_reset = hub_post_reset, | 2874 | .post_reset = hub_post_reset, |
2775 | .ioctl = hub_ioctl, | 2875 | .ioctl = hub_ioctl, |
2776 | .id_table = hub_id_table, | 2876 | .id_table = hub_id_table, |
2877 | .supports_autosuspend = 1, | ||
2777 | }; | 2878 | }; |
2778 | 2879 | ||
2779 | int usb_hub_init(void) | 2880 | int usb_hub_init(void) |
@@ -2998,7 +3099,7 @@ int usb_reset_composite_device(struct usb_device *udev, | |||
2998 | } | 3099 | } |
2999 | 3100 | ||
3000 | /* Prevent autosuspend during the reset */ | 3101 | /* Prevent autosuspend during the reset */ |
3001 | usb_autoresume_device(udev, 1); | 3102 | usb_autoresume_device(udev); |
3002 | 3103 | ||
3003 | if (iface && iface->condition != USB_INTERFACE_BINDING) | 3104 | if (iface && iface->condition != USB_INTERFACE_BINDING) |
3004 | iface = NULL; | 3105 | iface = NULL; |
@@ -3041,7 +3142,7 @@ int usb_reset_composite_device(struct usb_device *udev, | |||
3041 | } | 3142 | } |
3042 | } | 3143 | } |
3043 | 3144 | ||
3044 | usb_autosuspend_device(udev, 1); | 3145 | usb_autosuspend_device(udev); |
3045 | return ret; | 3146 | return ret; |
3046 | } | 3147 | } |
3047 | EXPORT_SYMBOL(usb_reset_composite_device); | 3148 | EXPORT_SYMBOL(usb_reset_composite_device); |