diff options
Diffstat (limited to 'drivers/usb/core/driver.c')
-rw-r--r-- | drivers/usb/core/driver.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 2be37fe466f2..5a7fa6f09958 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -230,6 +230,13 @@ static int usb_probe_interface(struct device *dev) | |||
230 | */ | 230 | */ |
231 | intf->pm_usage_cnt = !(driver->supports_autosuspend); | 231 | intf->pm_usage_cnt = !(driver->supports_autosuspend); |
232 | 232 | ||
233 | /* Carry out a deferred switch to altsetting 0 */ | ||
234 | if (intf->needs_altsetting0) { | ||
235 | usb_set_interface(udev, intf->altsetting[0]. | ||
236 | desc.bInterfaceNumber, 0); | ||
237 | intf->needs_altsetting0 = 0; | ||
238 | } | ||
239 | |||
233 | error = driver->probe(intf, id); | 240 | error = driver->probe(intf, id); |
234 | if (error) { | 241 | if (error) { |
235 | mark_quiesced(intf); | 242 | mark_quiesced(intf); |
@@ -266,8 +273,17 @@ static int usb_unbind_interface(struct device *dev) | |||
266 | 273 | ||
267 | driver->disconnect(intf); | 274 | driver->disconnect(intf); |
268 | 275 | ||
269 | /* reset other interface state */ | 276 | /* Reset other interface state. |
270 | usb_set_interface(udev, intf->altsetting[0].desc.bInterfaceNumber, 0); | 277 | * We cannot do a Set-Interface if the device is suspended or |
278 | * if it is prepared for a system sleep (since installing a new | ||
279 | * altsetting means creating new endpoint device entries). | ||
280 | * When either of these happens, defer the Set-Interface. | ||
281 | */ | ||
282 | if (!error && intf->dev.power.status == DPM_ON) | ||
283 | usb_set_interface(udev, intf->altsetting[0]. | ||
284 | desc.bInterfaceNumber, 0); | ||
285 | else | ||
286 | intf->needs_altsetting0 = 1; | ||
271 | usb_set_intfdata(intf, NULL); | 287 | usb_set_intfdata(intf, NULL); |
272 | 288 | ||
273 | intf->condition = USB_INTERFACE_UNBOUND; | 289 | intf->condition = USB_INTERFACE_UNBOUND; |
@@ -798,7 +814,8 @@ void usb_forced_unbind_intf(struct usb_interface *intf) | |||
798 | * The caller must hold @intf's device's lock, but not its pm_mutex | 814 | * The caller must hold @intf's device's lock, but not its pm_mutex |
799 | * and not @intf->dev.sem. | 815 | * and not @intf->dev.sem. |
800 | * | 816 | * |
801 | * FIXME: The caller must block system sleep transitions. | 817 | * Note: Rebinds will be skipped if a system sleep transition is in |
818 | * progress and the PM "complete" callback hasn't occurred yet. | ||
802 | */ | 819 | */ |
803 | void usb_rebind_intf(struct usb_interface *intf) | 820 | void usb_rebind_intf(struct usb_interface *intf) |
804 | { | 821 | { |
@@ -814,10 +831,12 @@ void usb_rebind_intf(struct usb_interface *intf) | |||
814 | } | 831 | } |
815 | 832 | ||
816 | /* Try to rebind the interface */ | 833 | /* Try to rebind the interface */ |
817 | intf->needs_binding = 0; | 834 | if (intf->dev.power.status == DPM_ON) { |
818 | rc = device_attach(&intf->dev); | 835 | intf->needs_binding = 0; |
819 | if (rc < 0) | 836 | rc = device_attach(&intf->dev); |
820 | dev_warn(&intf->dev, "rebind failed: %d\n", rc); | 837 | if (rc < 0) |
838 | dev_warn(&intf->dev, "rebind failed: %d\n", rc); | ||
839 | } | ||
821 | } | 840 | } |
822 | 841 | ||
823 | #ifdef CONFIG_PM | 842 | #ifdef CONFIG_PM |
@@ -829,7 +848,6 @@ void usb_rebind_intf(struct usb_interface *intf) | |||
829 | * or rebind interfaces that have been unbound, according to @action. | 848 | * or rebind interfaces that have been unbound, according to @action. |
830 | * | 849 | * |
831 | * The caller must hold @udev's device lock. | 850 | * The caller must hold @udev's device lock. |
832 | * FIXME: For rebinds, the caller must block system sleep transitions. | ||
833 | */ | 851 | */ |
834 | static void do_unbind_rebind(struct usb_device *udev, int action) | 852 | static void do_unbind_rebind(struct usb_device *udev, int action) |
835 | { | 853 | { |
@@ -851,22 +869,8 @@ static void do_unbind_rebind(struct usb_device *udev, int action) | |||
851 | } | 869 | } |
852 | break; | 870 | break; |
853 | case DO_REBIND: | 871 | case DO_REBIND: |
854 | if (intf->needs_binding) { | 872 | if (intf->needs_binding) |
855 | |||
856 | /* FIXME: The next line is needed because we are going to probe | ||
857 | * the interface, but as far as the PM core is concerned the | ||
858 | * interface is still suspended. The problem wouldn't exist | ||
859 | * if we could rebind the interface during the interface's own | ||
860 | * resume() call, but at the time the usb_device isn't locked! | ||
861 | * | ||
862 | * The real solution will be to carry this out during the device's | ||
863 | * complete() callback. Until that is implemented, we have to | ||
864 | * use this hack. | ||
865 | */ | ||
866 | // intf->dev.power.sleeping = 0; | ||
867 | |||
868 | usb_rebind_intf(intf); | 873 | usb_rebind_intf(intf); |
869 | } | ||
870 | break; | 874 | break; |
871 | } | 875 | } |
872 | } | 876 | } |
@@ -926,14 +930,14 @@ static int usb_resume_device(struct usb_device *udev) | |||
926 | } | 930 | } |
927 | 931 | ||
928 | /* Caller has locked intf's usb_device's pm mutex */ | 932 | /* Caller has locked intf's usb_device's pm mutex */ |
929 | static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg) | 933 | static int usb_suspend_interface(struct usb_device *udev, |
934 | struct usb_interface *intf, pm_message_t msg) | ||
930 | { | 935 | { |
931 | struct usb_driver *driver; | 936 | struct usb_driver *driver; |
932 | int status = 0; | 937 | int status = 0; |
933 | 938 | ||
934 | /* with no hardware, USB interfaces only use FREEZE and ON states */ | 939 | /* with no hardware, USB interfaces only use FREEZE and ON states */ |
935 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || | 940 | if (udev->state == USB_STATE_NOTATTACHED || !is_active(intf)) |
936 | !is_active(intf)) | ||
937 | goto done; | 941 | goto done; |
938 | 942 | ||
939 | if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */ | 943 | if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */ |
@@ -944,7 +948,7 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg) | |||
944 | status = driver->suspend(intf, msg); | 948 | status = driver->suspend(intf, msg); |
945 | if (status == 0) | 949 | if (status == 0) |
946 | mark_quiesced(intf); | 950 | mark_quiesced(intf); |
947 | else if (!interface_to_usbdev(intf)->auto_pm) | 951 | else if (!udev->auto_pm) |
948 | dev_err(&intf->dev, "%s error %d\n", | 952 | dev_err(&intf->dev, "%s error %d\n", |
949 | "suspend", status); | 953 | "suspend", status); |
950 | } else { | 954 | } else { |
@@ -961,13 +965,13 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg) | |||
961 | } | 965 | } |
962 | 966 | ||
963 | /* Caller has locked intf's usb_device's pm_mutex */ | 967 | /* Caller has locked intf's usb_device's pm_mutex */ |
964 | static int usb_resume_interface(struct usb_interface *intf, int reset_resume) | 968 | static int usb_resume_interface(struct usb_device *udev, |
969 | struct usb_interface *intf, int reset_resume) | ||
965 | { | 970 | { |
966 | struct usb_driver *driver; | 971 | struct usb_driver *driver; |
967 | int status = 0; | 972 | int status = 0; |
968 | 973 | ||
969 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || | 974 | if (udev->state == USB_STATE_NOTATTACHED || is_active(intf)) |
970 | is_active(intf)) | ||
971 | goto done; | 975 | goto done; |
972 | 976 | ||
973 | /* Don't let autoresume interfere with unbinding */ | 977 | /* Don't let autoresume interfere with unbinding */ |
@@ -975,8 +979,17 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume) | |||
975 | goto done; | 979 | goto done; |
976 | 980 | ||
977 | /* Can't resume it if it doesn't have a driver. */ | 981 | /* Can't resume it if it doesn't have a driver. */ |
978 | if (intf->condition == USB_INTERFACE_UNBOUND) | 982 | if (intf->condition == USB_INTERFACE_UNBOUND) { |
983 | |||
984 | /* Carry out a deferred switch to altsetting 0 */ | ||
985 | if (intf->needs_altsetting0 && | ||
986 | intf->dev.power.status == DPM_ON) { | ||
987 | usb_set_interface(udev, intf->altsetting[0]. | ||
988 | desc.bInterfaceNumber, 0); | ||
989 | intf->needs_altsetting0 = 0; | ||
990 | } | ||
979 | goto done; | 991 | goto done; |
992 | } | ||
980 | 993 | ||
981 | /* Don't resume if the interface is marked for rebinding */ | 994 | /* Don't resume if the interface is marked for rebinding */ |
982 | if (intf->needs_binding) | 995 | if (intf->needs_binding) |
@@ -1151,7 +1164,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1151 | if (udev->actconfig) { | 1164 | if (udev->actconfig) { |
1152 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { | 1165 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { |
1153 | intf = udev->actconfig->interface[i]; | 1166 | intf = udev->actconfig->interface[i]; |
1154 | status = usb_suspend_interface(intf, msg); | 1167 | status = usb_suspend_interface(udev, intf, msg); |
1155 | if (status != 0) | 1168 | if (status != 0) |
1156 | break; | 1169 | break; |
1157 | } | 1170 | } |
@@ -1163,7 +1176,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1163 | if (status != 0) { | 1176 | if (status != 0) { |
1164 | while (--i >= 0) { | 1177 | while (--i >= 0) { |
1165 | intf = udev->actconfig->interface[i]; | 1178 | intf = udev->actconfig->interface[i]; |
1166 | usb_resume_interface(intf, 0); | 1179 | usb_resume_interface(udev, intf, 0); |
1167 | } | 1180 | } |
1168 | 1181 | ||
1169 | /* Try another autosuspend when the interfaces aren't busy */ | 1182 | /* Try another autosuspend when the interfaces aren't busy */ |
@@ -1276,7 +1289,7 @@ static int usb_resume_both(struct usb_device *udev) | |||
1276 | if (status == 0 && udev->actconfig) { | 1289 | if (status == 0 && udev->actconfig) { |
1277 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | 1290 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
1278 | intf = udev->actconfig->interface[i]; | 1291 | intf = udev->actconfig->interface[i]; |
1279 | usb_resume_interface(intf, udev->reset_resume); | 1292 | usb_resume_interface(udev, intf, udev->reset_resume); |
1280 | } | 1293 | } |
1281 | } | 1294 | } |
1282 | 1295 | ||
@@ -1605,12 +1618,10 @@ int usb_external_resume_device(struct usb_device *udev) | |||
1605 | return status; | 1618 | return status; |
1606 | } | 1619 | } |
1607 | 1620 | ||
1608 | static int usb_suspend(struct device *dev, pm_message_t message) | 1621 | int usb_suspend(struct device *dev, pm_message_t message) |
1609 | { | 1622 | { |
1610 | struct usb_device *udev; | 1623 | struct usb_device *udev; |
1611 | 1624 | ||
1612 | if (!is_usb_device(dev)) /* Ignore PM for interfaces */ | ||
1613 | return 0; | ||
1614 | udev = to_usb_device(dev); | 1625 | udev = to_usb_device(dev); |
1615 | 1626 | ||
1616 | /* If udev is already suspended, we can skip this suspend and | 1627 | /* If udev is already suspended, we can skip this suspend and |
@@ -1629,12 +1640,10 @@ static int usb_suspend(struct device *dev, pm_message_t message) | |||
1629 | return usb_external_suspend_device(udev, message); | 1640 | return usb_external_suspend_device(udev, message); |
1630 | } | 1641 | } |
1631 | 1642 | ||
1632 | static int usb_resume(struct device *dev) | 1643 | int usb_resume(struct device *dev) |
1633 | { | 1644 | { |
1634 | struct usb_device *udev; | 1645 | struct usb_device *udev; |
1635 | 1646 | ||
1636 | if (!is_usb_device(dev)) /* Ignore PM for interfaces */ | ||
1637 | return 0; | ||
1638 | udev = to_usb_device(dev); | 1647 | udev = to_usb_device(dev); |
1639 | 1648 | ||
1640 | /* If udev->skip_sys_resume is set then udev was already suspended | 1649 | /* If udev->skip_sys_resume is set then udev was already suspended |
@@ -1646,17 +1655,10 @@ static int usb_resume(struct device *dev) | |||
1646 | return usb_external_resume_device(udev); | 1655 | return usb_external_resume_device(udev); |
1647 | } | 1656 | } |
1648 | 1657 | ||
1649 | #else | ||
1650 | |||
1651 | #define usb_suspend NULL | ||
1652 | #define usb_resume NULL | ||
1653 | |||
1654 | #endif /* CONFIG_PM */ | 1658 | #endif /* CONFIG_PM */ |
1655 | 1659 | ||
1656 | struct bus_type usb_bus_type = { | 1660 | struct bus_type usb_bus_type = { |
1657 | .name = "usb", | 1661 | .name = "usb", |
1658 | .match = usb_device_match, | 1662 | .match = usb_device_match, |
1659 | .uevent = usb_uevent, | 1663 | .uevent = usb_uevent, |
1660 | .suspend = usb_suspend, | ||
1661 | .resume = usb_resume, | ||
1662 | }; | 1664 | }; |