diff options
-rw-r--r-- | drivers/usb/core/hub.c | 273 | ||||
-rw-r--r-- | drivers/usb/core/port.c | 10 | ||||
-rw-r--r-- | drivers/usb/core/usb-acpi.c | 60 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 4 |
4 files changed, 158 insertions, 189 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 77b91888abef..653f80c52486 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -412,30 +412,35 @@ static int set_port_feature(struct usb_device *hdev, int port1, int feature) | |||
412 | NULL, 0, 1000); | 412 | NULL, 0, 1000); |
413 | } | 413 | } |
414 | 414 | ||
415 | static char *to_led_name(int selector) | ||
416 | { | ||
417 | switch (selector) { | ||
418 | case HUB_LED_AMBER: | ||
419 | return "amber"; | ||
420 | case HUB_LED_GREEN: | ||
421 | return "green"; | ||
422 | case HUB_LED_OFF: | ||
423 | return "off"; | ||
424 | case HUB_LED_AUTO: | ||
425 | return "auto"; | ||
426 | default: | ||
427 | return "??"; | ||
428 | } | ||
429 | } | ||
430 | |||
415 | /* | 431 | /* |
416 | * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7 | 432 | * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7 |
417 | * for info about using port indicators | 433 | * for info about using port indicators |
418 | */ | 434 | */ |
419 | static void set_port_led( | 435 | static void set_port_led(struct usb_hub *hub, int port1, int selector) |
420 | struct usb_hub *hub, | ||
421 | int port1, | ||
422 | int selector | ||
423 | ) | ||
424 | { | 436 | { |
425 | int status = set_port_feature(hub->hdev, (selector << 8) | port1, | 437 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
438 | int status; | ||
439 | |||
440 | status = set_port_feature(hub->hdev, (selector << 8) | port1, | ||
426 | USB_PORT_FEAT_INDICATOR); | 441 | USB_PORT_FEAT_INDICATOR); |
427 | if (status < 0) | 442 | dev_dbg(&port_dev->dev, "indicator %s status %d\n", |
428 | dev_dbg (hub->intfdev, | 443 | to_led_name(selector), status); |
429 | "port %d indicator %s status %d\n", | ||
430 | port1, | ||
431 | ({ char *s; switch (selector) { | ||
432 | case HUB_LED_AMBER: s = "amber"; break; | ||
433 | case HUB_LED_GREEN: s = "green"; break; | ||
434 | case HUB_LED_OFF: s = "off"; break; | ||
435 | case HUB_LED_AUTO: s = "auto"; break; | ||
436 | default: s = "??"; break; | ||
437 | } s; }), | ||
438 | status); | ||
439 | } | 444 | } |
440 | 445 | ||
441 | #define LED_CYCLE_PERIOD ((2*HZ)/3) | 446 | #define LED_CYCLE_PERIOD ((2*HZ)/3) |
@@ -909,20 +914,20 @@ static int hub_usb3_port_disable(struct usb_hub *hub, int port1) | |||
909 | msleep(HUB_DEBOUNCE_STEP); | 914 | msleep(HUB_DEBOUNCE_STEP); |
910 | } | 915 | } |
911 | if (total_time >= HUB_DEBOUNCE_TIMEOUT) | 916 | if (total_time >= HUB_DEBOUNCE_TIMEOUT) |
912 | dev_warn(hub->intfdev, "Could not disable port %d after %d ms\n", | 917 | dev_warn(&hub->ports[port1 - 1]->dev, |
913 | port1, total_time); | 918 | "Could not disable after %d ms\n", total_time); |
914 | 919 | ||
915 | return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT); | 920 | return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT); |
916 | } | 921 | } |
917 | 922 | ||
918 | static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | 923 | static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) |
919 | { | 924 | { |
925 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
920 | struct usb_device *hdev = hub->hdev; | 926 | struct usb_device *hdev = hub->hdev; |
921 | int ret = 0; | 927 | int ret = 0; |
922 | 928 | ||
923 | if (hub->ports[port1 - 1]->child && set_state) | 929 | if (port_dev->child && set_state) |
924 | usb_set_device_state(hub->ports[port1 - 1]->child, | 930 | usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); |
925 | USB_STATE_NOTATTACHED); | ||
926 | if (!hub->error) { | 931 | if (!hub->error) { |
927 | if (hub_is_superspeed(hub->hdev)) | 932 | if (hub_is_superspeed(hub->hdev)) |
928 | ret = hub_usb3_port_disable(hub, port1); | 933 | ret = hub_usb3_port_disable(hub, port1); |
@@ -931,8 +936,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
931 | USB_PORT_FEAT_ENABLE); | 936 | USB_PORT_FEAT_ENABLE); |
932 | } | 937 | } |
933 | if (ret && ret != -ENODEV) | 938 | if (ret && ret != -ENODEV) |
934 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", | 939 | dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); |
935 | port1, ret); | ||
936 | return ret; | 940 | return ret; |
937 | } | 941 | } |
938 | 942 | ||
@@ -943,7 +947,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
943 | */ | 947 | */ |
944 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | 948 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) |
945 | { | 949 | { |
946 | dev_dbg(hub->intfdev, "logical disconnect on port %d\n", port1); | 950 | dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); |
947 | hub_port_disable(hub, port1, 1); | 951 | hub_port_disable(hub, port1, 1); |
948 | 952 | ||
949 | /* FIXME let caller ask to power down the port: | 953 | /* FIXME let caller ask to power down the port: |
@@ -1081,21 +1085,23 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1081 | } | 1085 | } |
1082 | init2: | 1086 | init2: |
1083 | 1087 | ||
1084 | /* Check each port and set hub->change_bits to let khubd know | 1088 | /* |
1089 | * Check each port and set hub->change_bits to let khubd know | ||
1085 | * which ports need attention. | 1090 | * which ports need attention. |
1086 | */ | 1091 | */ |
1087 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | 1092 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { |
1088 | struct usb_device *udev = hub->ports[port1 - 1]->child; | 1093 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
1094 | struct usb_device *udev = port_dev->child; | ||
1089 | u16 portstatus, portchange; | 1095 | u16 portstatus, portchange; |
1090 | 1096 | ||
1091 | portstatus = portchange = 0; | 1097 | portstatus = portchange = 0; |
1092 | status = hub_port_status(hub, port1, &portstatus, &portchange); | 1098 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
1093 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) | 1099 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) |
1094 | dev_dbg(hub->intfdev, | 1100 | dev_dbg(&port_dev->dev, "status %04x change %04x\n", |
1095 | "port %d: status %04x change %04x\n", | 1101 | portstatus, portchange); |
1096 | port1, portstatus, portchange); | ||
1097 | 1102 | ||
1098 | /* After anything other than HUB_RESUME (i.e., initialization | 1103 | /* |
1104 | * After anything other than HUB_RESUME (i.e., initialization | ||
1099 | * or any sort of reset), every port should be disabled. | 1105 | * or any sort of reset), every port should be disabled. |
1100 | * Unconnected ports should likewise be disabled (paranoia), | 1106 | * Unconnected ports should likewise be disabled (paranoia), |
1101 | * and so should ports for which we have no usb_device. | 1107 | * and so should ports for which we have no usb_device. |
@@ -2571,9 +2577,9 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
2571 | if (delay_time >= 2 * HUB_SHORT_RESET_TIME) | 2577 | if (delay_time >= 2 * HUB_SHORT_RESET_TIME) |
2572 | delay = HUB_LONG_RESET_TIME; | 2578 | delay = HUB_LONG_RESET_TIME; |
2573 | 2579 | ||
2574 | dev_dbg (hub->intfdev, | 2580 | dev_dbg(&hub->ports[port1 - 1]->dev, |
2575 | "port %d not %sreset yet, waiting %dms\n", | 2581 | "not %sreset yet, waiting %dms\n", |
2576 | port1, warm ? "warm " : "", delay); | 2582 | warm ? "warm " : "", delay); |
2577 | } | 2583 | } |
2578 | 2584 | ||
2579 | if ((portstatus & USB_PORT_STAT_RESET)) | 2585 | if ((portstatus & USB_PORT_STAT_RESET)) |
@@ -2657,6 +2663,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2657 | { | 2663 | { |
2658 | int i, status; | 2664 | int i, status; |
2659 | u16 portchange, portstatus; | 2665 | u16 portchange, portstatus; |
2666 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
2660 | 2667 | ||
2661 | if (!hub_is_superspeed(hub->hdev)) { | 2668 | if (!hub_is_superspeed(hub->hdev)) { |
2662 | if (warm) { | 2669 | if (warm) { |
@@ -2690,9 +2697,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2690 | if (status == -ENODEV) { | 2697 | if (status == -ENODEV) { |
2691 | ; /* The hub is gone */ | 2698 | ; /* The hub is gone */ |
2692 | } else if (status) { | 2699 | } else if (status) { |
2693 | dev_err(hub->intfdev, | 2700 | dev_err(&port_dev->dev, |
2694 | "cannot %sreset port %d (err = %d)\n", | 2701 | "cannot %sreset (err = %d)\n", |
2695 | warm ? "warm " : "", port1, status); | 2702 | warm ? "warm " : "", status); |
2696 | } else { | 2703 | } else { |
2697 | status = hub_port_wait_reset(hub, port1, udev, delay, | 2704 | status = hub_port_wait_reset(hub, port1, udev, delay, |
2698 | warm); | 2705 | warm); |
@@ -2725,21 +2732,19 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2725 | * hot or warm reset failed. Try another warm reset. | 2732 | * hot or warm reset failed. Try another warm reset. |
2726 | */ | 2733 | */ |
2727 | if (!warm) { | 2734 | if (!warm) { |
2728 | dev_dbg(hub->intfdev, "hot reset failed, warm reset port %d\n", | 2735 | dev_dbg(&port_dev->dev, |
2729 | port1); | 2736 | "hot reset failed, warm reset\n"); |
2730 | warm = true; | 2737 | warm = true; |
2731 | } | 2738 | } |
2732 | } | 2739 | } |
2733 | 2740 | ||
2734 | dev_dbg (hub->intfdev, | 2741 | dev_dbg(&port_dev->dev, |
2735 | "port %d not enabled, trying %sreset again...\n", | 2742 | "not enabled, trying %sreset again...\n", |
2736 | port1, warm ? "warm " : ""); | 2743 | warm ? "warm " : ""); |
2737 | delay = HUB_LONG_RESET_TIME; | 2744 | delay = HUB_LONG_RESET_TIME; |
2738 | } | 2745 | } |
2739 | 2746 | ||
2740 | dev_err (hub->intfdev, | 2747 | dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); |
2741 | "Cannot enable port %i. Maybe the USB cable is bad?\n", | ||
2742 | port1); | ||
2743 | 2748 | ||
2744 | done: | 2749 | done: |
2745 | if (!hub_is_superspeed(hub->hdev)) | 2750 | if (!hub_is_superspeed(hub->hdev)) |
@@ -2790,6 +2795,8 @@ static int check_port_resume_type(struct usb_device *udev, | |||
2790 | struct usb_hub *hub, int port1, | 2795 | struct usb_hub *hub, int port1, |
2791 | int status, unsigned portchange, unsigned portstatus) | 2796 | int status, unsigned portchange, unsigned portstatus) |
2792 | { | 2797 | { |
2798 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
2799 | |||
2793 | /* Is the device still present? */ | 2800 | /* Is the device still present? */ |
2794 | if (status || port_is_suspended(hub, portstatus) || | 2801 | if (status || port_is_suspended(hub, portstatus) || |
2795 | !port_is_power_on(hub, portstatus) || | 2802 | !port_is_power_on(hub, portstatus) || |
@@ -2809,9 +2816,8 @@ static int check_port_resume_type(struct usb_device *udev, | |||
2809 | } | 2816 | } |
2810 | 2817 | ||
2811 | if (status) { | 2818 | if (status) { |
2812 | dev_dbg(hub->intfdev, | 2819 | dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", |
2813 | "port %d status %04x.%04x after resume, %d\n", | 2820 | portchange, portstatus, status); |
2814 | port1, portchange, portstatus, status); | ||
2815 | } else if (udev->reset_resume) { | 2821 | } else if (udev->reset_resume) { |
2816 | 2822 | ||
2817 | /* Late port handoff can set status-change bits */ | 2823 | /* Late port handoff can set status-change bits */ |
@@ -3042,8 +3048,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
3042 | status = 0; | 3048 | status = 0; |
3043 | } | 3049 | } |
3044 | if (status) { | 3050 | if (status) { |
3045 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", | 3051 | dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); |
3046 | port1, status); | ||
3047 | 3052 | ||
3048 | /* Try to enable USB3 LPM and LTM again */ | 3053 | /* Try to enable USB3 LPM and LTM again */ |
3049 | usb_unlocked_enable_lpm(udev); | 3054 | usb_unlocked_enable_lpm(udev); |
@@ -3234,8 +3239,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3234 | if (status == 0 && !port_is_suspended(hub, portstatus)) | 3239 | if (status == 0 && !port_is_suspended(hub, portstatus)) |
3235 | goto SuspendCleared; | 3240 | goto SuspendCleared; |
3236 | 3241 | ||
3237 | /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */ | ||
3238 | |||
3239 | set_bit(port1, hub->busy_bits); | 3242 | set_bit(port1, hub->busy_bits); |
3240 | 3243 | ||
3241 | /* see 7.1.7.7; affects power usage, but not budgeting */ | 3244 | /* see 7.1.7.7; affects power usage, but not budgeting */ |
@@ -3245,8 +3248,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3245 | status = usb_clear_port_feature(hub->hdev, | 3248 | status = usb_clear_port_feature(hub->hdev, |
3246 | port1, USB_PORT_FEAT_SUSPEND); | 3249 | port1, USB_PORT_FEAT_SUSPEND); |
3247 | if (status) { | 3250 | if (status) { |
3248 | dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", | 3251 | dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); |
3249 | port1, status); | ||
3250 | } else { | 3252 | } else { |
3251 | /* drive resume for at least 20 msec */ | 3253 | /* drive resume for at least 20 msec */ |
3252 | dev_dbg(&udev->dev, "usb %sresume\n", | 3254 | dev_dbg(&udev->dev, "usb %sresume\n", |
@@ -3347,12 +3349,11 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
3347 | */ | 3349 | */ |
3348 | hub->wakeup_enabled_descendants = 0; | 3350 | hub->wakeup_enabled_descendants = 0; |
3349 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { | 3351 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { |
3350 | struct usb_device *udev; | 3352 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
3353 | struct usb_device *udev = port_dev->child; | ||
3351 | 3354 | ||
3352 | udev = hub->ports[port1 - 1]->child; | ||
3353 | if (udev && udev->can_submit) { | 3355 | if (udev && udev->can_submit) { |
3354 | dev_warn(&intf->dev, "port %d not suspended yet\n", | 3356 | dev_warn(&port_dev->dev, "not suspended yet\n"); |
3355 | port1); | ||
3356 | if (PMSG_IS_AUTO(msg)) | 3357 | if (PMSG_IS_AUTO(msg)) |
3357 | return -EBUSY; | 3358 | return -EBUSY; |
3358 | } | 3359 | } |
@@ -3892,9 +3893,10 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm); | |||
3892 | int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) | 3893 | int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) |
3893 | { | 3894 | { |
3894 | int ret; | 3895 | int ret; |
3895 | int total_time, stable_time = 0; | ||
3896 | u16 portchange, portstatus; | 3896 | u16 portchange, portstatus; |
3897 | unsigned connection = 0xffff; | 3897 | unsigned connection = 0xffff; |
3898 | int total_time, stable_time = 0; | ||
3899 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
3898 | 3900 | ||
3899 | for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { | 3901 | for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { |
3900 | ret = hub_port_status(hub, port1, &portstatus, &portchange); | 3902 | ret = hub_port_status(hub, port1, &portstatus, &portchange); |
@@ -3923,9 +3925,8 @@ int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) | |||
3923 | msleep(HUB_DEBOUNCE_STEP); | 3925 | msleep(HUB_DEBOUNCE_STEP); |
3924 | } | 3926 | } |
3925 | 3927 | ||
3926 | dev_dbg (hub->intfdev, | 3928 | dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", |
3927 | "debounce: port %d: total %dms stable %dms status 0x%x\n", | 3929 | total_time, stable_time, portstatus); |
3928 | port1, total_time, stable_time, portstatus); | ||
3929 | 3930 | ||
3930 | if (stable_time < HUB_DEBOUNCE_STABLE) | 3931 | if (stable_time < HUB_DEBOUNCE_STABLE) |
3931 | return -ETIMEDOUT; | 3932 | return -ETIMEDOUT; |
@@ -3984,13 +3985,14 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
3984 | */ | 3985 | */ |
3985 | static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) | 3986 | static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) |
3986 | { | 3987 | { |
3987 | int connect_type; | 3988 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); |
3989 | int connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; | ||
3988 | 3990 | ||
3989 | if (!udev->usb2_hw_lpm_capable) | 3991 | if (!udev->usb2_hw_lpm_capable) |
3990 | return; | 3992 | return; |
3991 | 3993 | ||
3992 | connect_type = usb_get_hub_port_connect_type(udev->parent, | 3994 | if (hub) |
3993 | udev->portnum); | 3995 | connect_type = hub->ports[udev->portnum - 1]->connect_type; |
3994 | 3996 | ||
3995 | if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || | 3997 | if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || |
3996 | connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 3998 | connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
@@ -4366,9 +4368,10 @@ hub_power_remaining (struct usb_hub *hub) | |||
4366 | 4368 | ||
4367 | remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; | 4369 | remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; |
4368 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | 4370 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { |
4369 | struct usb_device *udev = hub->ports[port1 - 1]->child; | 4371 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
4370 | int delta; | 4372 | struct usb_device *udev = port_dev->child; |
4371 | unsigned unit_load; | 4373 | unsigned unit_load; |
4374 | int delta; | ||
4372 | 4375 | ||
4373 | if (!udev) | 4376 | if (!udev) |
4374 | continue; | 4377 | continue; |
@@ -4388,9 +4391,8 @@ hub_power_remaining (struct usb_hub *hub) | |||
4388 | else | 4391 | else |
4389 | delta = 8; | 4392 | delta = 8; |
4390 | if (delta > hub->mA_per_port) | 4393 | if (delta > hub->mA_per_port) |
4391 | dev_warn(&udev->dev, | 4394 | dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", |
4392 | "%dmA is over %umA budget for port %d!\n", | 4395 | delta, hub->mA_per_port); |
4393 | delta, hub->mA_per_port, port1); | ||
4394 | remaining -= delta; | 4396 | remaining -= delta; |
4395 | } | 4397 | } |
4396 | if (remaining < 0) { | 4398 | if (remaining < 0) { |
@@ -4413,15 +4415,14 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4413 | u16 portstatus, u16 portchange) | 4415 | u16 portstatus, u16 portchange) |
4414 | { | 4416 | { |
4415 | struct usb_device *hdev = hub->hdev; | 4417 | struct usb_device *hdev = hub->hdev; |
4416 | struct device *hub_dev = hub->intfdev; | ||
4417 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | 4418 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
4419 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
4418 | struct usb_device *udev; | 4420 | struct usb_device *udev; |
4419 | int status, i; | 4421 | int status, i; |
4420 | unsigned unit_load; | 4422 | unsigned unit_load; |
4421 | 4423 | ||
4422 | dev_dbg (hub_dev, | 4424 | dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", |
4423 | "port %d, status %04x, change %04x, %s\n", | 4425 | portstatus, portchange, portspeed(hub, portstatus)); |
4424 | port1, portstatus, portchange, portspeed(hub, portstatus)); | ||
4425 | 4426 | ||
4426 | if (hub->has_indicators) { | 4427 | if (hub->has_indicators) { |
4427 | set_port_led(hub, port1, HUB_LED_AUTO); | 4428 | set_port_led(hub, port1, HUB_LED_AUTO); |
@@ -4436,7 +4437,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4436 | #endif | 4437 | #endif |
4437 | 4438 | ||
4438 | /* Try to resuscitate an existing device */ | 4439 | /* Try to resuscitate an existing device */ |
4439 | udev = hub->ports[port1 - 1]->child; | 4440 | udev = port_dev->child; |
4440 | if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && | 4441 | if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && |
4441 | udev->state != USB_STATE_NOTATTACHED) { | 4442 | udev->state != USB_STATE_NOTATTACHED) { |
4442 | usb_lock_device(udev); | 4443 | usb_lock_device(udev); |
@@ -4468,7 +4469,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4468 | if (hcd->phy && !hdev->parent && | 4469 | if (hcd->phy && !hdev->parent && |
4469 | !(portstatus & USB_PORT_STAT_CONNECTION)) | 4470 | !(portstatus & USB_PORT_STAT_CONNECTION)) |
4470 | usb_phy_notify_disconnect(hcd->phy, udev->speed); | 4471 | usb_phy_notify_disconnect(hcd->phy, udev->speed); |
4471 | usb_disconnect(&hub->ports[port1 - 1]->child); | 4472 | usb_disconnect(&port_dev->child); |
4472 | } | 4473 | } |
4473 | clear_bit(port1, hub->change_bits); | 4474 | clear_bit(port1, hub->change_bits); |
4474 | 4475 | ||
@@ -4484,8 +4485,8 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4484 | status = hub_port_debounce_be_stable(hub, port1); | 4485 | status = hub_port_debounce_be_stable(hub, port1); |
4485 | if (status < 0) { | 4486 | if (status < 0) { |
4486 | if (status != -ENODEV && printk_ratelimit()) | 4487 | if (status != -ENODEV && printk_ratelimit()) |
4487 | dev_err(hub_dev, "connect-debounce failed, " | 4488 | dev_err(&port_dev->dev, |
4488 | "port %d disabled\n", port1); | 4489 | "connect-debounce failed\n"); |
4489 | portstatus &= ~USB_PORT_STAT_CONNECTION; | 4490 | portstatus &= ~USB_PORT_STAT_CONNECTION; |
4490 | } else { | 4491 | } else { |
4491 | portstatus = status; | 4492 | portstatus = status; |
@@ -4520,9 +4521,8 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4520 | */ | 4521 | */ |
4521 | udev = usb_alloc_dev(hdev, hdev->bus, port1); | 4522 | udev = usb_alloc_dev(hdev, hdev->bus, port1); |
4522 | if (!udev) { | 4523 | if (!udev) { |
4523 | dev_err (hub_dev, | 4524 | dev_err(&port_dev->dev, |
4524 | "couldn't allocate port %d usb_device\n", | 4525 | "couldn't allocate usb_device\n"); |
4525 | port1); | ||
4526 | goto done; | 4526 | goto done; |
4527 | } | 4527 | } |
4528 | 4528 | ||
@@ -4604,7 +4604,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4604 | if (hdev->state == USB_STATE_NOTATTACHED) | 4604 | if (hdev->state == USB_STATE_NOTATTACHED) |
4605 | status = -ENOTCONN; | 4605 | status = -ENOTCONN; |
4606 | else | 4606 | else |
4607 | hub->ports[port1 - 1]->child = udev; | 4607 | port_dev->child = udev; |
4608 | spin_unlock_irq(&device_state_lock); | 4608 | spin_unlock_irq(&device_state_lock); |
4609 | 4609 | ||
4610 | /* Run it through the hoops (find a driver, etc) */ | 4610 | /* Run it through the hoops (find a driver, etc) */ |
@@ -4612,7 +4612,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4612 | status = usb_new_device(udev); | 4612 | status = usb_new_device(udev); |
4613 | if (status) { | 4613 | if (status) { |
4614 | spin_lock_irq(&device_state_lock); | 4614 | spin_lock_irq(&device_state_lock); |
4615 | hub->ports[port1 - 1]->child = NULL; | 4615 | port_dev->child = NULL; |
4616 | spin_unlock_irq(&device_state_lock); | 4616 | spin_unlock_irq(&device_state_lock); |
4617 | } | 4617 | } |
4618 | } | 4618 | } |
@@ -4622,7 +4622,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4622 | 4622 | ||
4623 | status = hub_power_remaining(hub); | 4623 | status = hub_power_remaining(hub); |
4624 | if (status) | 4624 | if (status) |
4625 | dev_dbg(hub_dev, "%dmA power budget left\n", status); | 4625 | dev_dbg(hub->intfdev, "%dmA power budget left\n", status); |
4626 | 4626 | ||
4627 | return; | 4627 | return; |
4628 | 4628 | ||
@@ -4640,8 +4640,8 @@ loop: | |||
4640 | !hcd->driver->port_handed_over || | 4640 | !hcd->driver->port_handed_over || |
4641 | !(hcd->driver->port_handed_over)(hcd, port1)) { | 4641 | !(hcd->driver->port_handed_over)(hcd, port1)) { |
4642 | if (status != -ENOTCONN && status != -ENODEV) | 4642 | if (status != -ENOTCONN && status != -ENODEV) |
4643 | dev_err(hub_dev, "unable to enumerate USB device on port %d\n", | 4643 | dev_err(&port_dev->dev, |
4644 | port1); | 4644 | "unable to enumerate USB device\n"); |
4645 | } | 4645 | } |
4646 | 4646 | ||
4647 | done: | 4647 | done: |
@@ -4654,13 +4654,14 @@ done: | |||
4654 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | 4654 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, |
4655 | u16 portstatus, u16 portchange) | 4655 | u16 portstatus, u16 portchange) |
4656 | { | 4656 | { |
4657 | struct usb_port *port_dev = hub->ports[port - 1]; | ||
4657 | struct usb_device *hdev; | 4658 | struct usb_device *hdev; |
4658 | struct usb_device *udev; | 4659 | struct usb_device *udev; |
4659 | int connect_change = 0; | 4660 | int connect_change = 0; |
4660 | int ret; | 4661 | int ret; |
4661 | 4662 | ||
4662 | hdev = hub->hdev; | 4663 | hdev = hub->hdev; |
4663 | udev = hub->ports[port - 1]->child; | 4664 | udev = port_dev->child; |
4664 | if (!hub_is_superspeed(hdev)) { | 4665 | if (!hub_is_superspeed(hdev)) { |
4665 | if (!(portchange & USB_PORT_STAT_C_SUSPEND)) | 4666 | if (!(portchange & USB_PORT_STAT_C_SUSPEND)) |
4666 | return 0; | 4667 | return 0; |
@@ -4685,8 +4686,7 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | |||
4685 | ret = -ENODEV; | 4686 | ret = -ENODEV; |
4686 | hub_port_disable(hub, port, 1); | 4687 | hub_port_disable(hub, port, 1); |
4687 | } | 4688 | } |
4688 | dev_dbg(hub->intfdev, "resume on port %d, status %d\n", | 4689 | dev_dbg(&port_dev->dev, "resume, status %d\n", ret); |
4689 | port, ret); | ||
4690 | return connect_change; | 4690 | return connect_change; |
4691 | } | 4691 | } |
4692 | 4692 | ||
@@ -4776,7 +4776,8 @@ static void hub_events(void) | |||
4776 | 4776 | ||
4777 | /* deal with port status changes */ | 4777 | /* deal with port status changes */ |
4778 | for (i = 1; i <= hdev->maxchild; i++) { | 4778 | for (i = 1; i <= hdev->maxchild; i++) { |
4779 | struct usb_device *udev = hub->ports[i - 1]->child; | 4779 | struct usb_port *port_dev = hub->ports[i - 1]; |
4780 | struct usb_device *udev = port_dev->child; | ||
4780 | 4781 | ||
4781 | if (test_bit(i, hub->busy_bits)) | 4782 | if (test_bit(i, hub->busy_bits)) |
4782 | continue; | 4783 | continue; |
@@ -4799,10 +4800,9 @@ static void hub_events(void) | |||
4799 | 4800 | ||
4800 | if (portchange & USB_PORT_STAT_C_ENABLE) { | 4801 | if (portchange & USB_PORT_STAT_C_ENABLE) { |
4801 | if (!connect_change) | 4802 | if (!connect_change) |
4802 | dev_dbg (hub_dev, | 4803 | dev_dbg(&port_dev->dev, |
4803 | "port %d enable change, " | 4804 | "enable change, status %08x\n", |
4804 | "status %08x\n", | 4805 | portstatus); |
4805 | i, portstatus); | ||
4806 | usb_clear_port_feature(hdev, i, | 4806 | usb_clear_port_feature(hdev, i, |
4807 | USB_PORT_FEAT_C_ENABLE); | 4807 | USB_PORT_FEAT_C_ENABLE); |
4808 | 4808 | ||
@@ -4813,13 +4813,9 @@ static void hub_events(void) | |||
4813 | * Works at least with mouse driver. | 4813 | * Works at least with mouse driver. |
4814 | */ | 4814 | */ |
4815 | if (!(portstatus & USB_PORT_STAT_ENABLE) | 4815 | if (!(portstatus & USB_PORT_STAT_ENABLE) |
4816 | && !connect_change | 4816 | && !connect_change && udev) { |
4817 | && hub->ports[i - 1]->child) { | 4817 | dev_err(&port_dev->dev, |
4818 | dev_err (hub_dev, | 4818 | "disabled by hub (EMI?), re-enabling...\n"); |
4819 | "port %i " | ||
4820 | "disabled by hub (EMI?), " | ||
4821 | "re-enabling...\n", | ||
4822 | i); | ||
4823 | connect_change = 1; | 4819 | connect_change = 1; |
4824 | } | 4820 | } |
4825 | } | 4821 | } |
@@ -4832,30 +4828,25 @@ static void hub_events(void) | |||
4832 | u16 status = 0; | 4828 | u16 status = 0; |
4833 | u16 unused; | 4829 | u16 unused; |
4834 | 4830 | ||
4835 | dev_dbg(hub_dev, "over-current change on port " | 4831 | dev_dbg(&port_dev->dev, "over-current change\n"); |
4836 | "%d\n", i); | ||
4837 | usb_clear_port_feature(hdev, i, | 4832 | usb_clear_port_feature(hdev, i, |
4838 | USB_PORT_FEAT_C_OVER_CURRENT); | 4833 | USB_PORT_FEAT_C_OVER_CURRENT); |
4839 | msleep(100); /* Cool down */ | 4834 | msleep(100); /* Cool down */ |
4840 | hub_power_on(hub, true); | 4835 | hub_power_on(hub, true); |
4841 | hub_port_status(hub, i, &status, &unused); | 4836 | hub_port_status(hub, i, &status, &unused); |
4842 | if (status & USB_PORT_STAT_OVERCURRENT) | 4837 | if (status & USB_PORT_STAT_OVERCURRENT) |
4843 | dev_err(hub_dev, "over-current " | 4838 | dev_err(&port_dev->dev, |
4844 | "condition on port %d\n", i); | 4839 | "over-current condition\n"); |
4845 | } | 4840 | } |
4846 | 4841 | ||
4847 | if (portchange & USB_PORT_STAT_C_RESET) { | 4842 | if (portchange & USB_PORT_STAT_C_RESET) { |
4848 | dev_dbg (hub_dev, | 4843 | dev_dbg(&port_dev->dev, "reset change\n"); |
4849 | "reset change on port %d\n", | ||
4850 | i); | ||
4851 | usb_clear_port_feature(hdev, i, | 4844 | usb_clear_port_feature(hdev, i, |
4852 | USB_PORT_FEAT_C_RESET); | 4845 | USB_PORT_FEAT_C_RESET); |
4853 | } | 4846 | } |
4854 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | 4847 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && |
4855 | hub_is_superspeed(hub->hdev)) { | 4848 | hub_is_superspeed(hub->hdev)) { |
4856 | dev_dbg(hub_dev, | 4849 | dev_dbg(&port_dev->dev, "warm reset change\n"); |
4857 | "warm reset change on port %d\n", | ||
4858 | i); | ||
4859 | usb_clear_port_feature(hdev, i, | 4850 | usb_clear_port_feature(hdev, i, |
4860 | USB_PORT_FEAT_C_BH_PORT_RESET); | 4851 | USB_PORT_FEAT_C_BH_PORT_RESET); |
4861 | } | 4852 | } |
@@ -4864,9 +4855,7 @@ static void hub_events(void) | |||
4864 | USB_PORT_FEAT_C_PORT_LINK_STATE); | 4855 | USB_PORT_FEAT_C_PORT_LINK_STATE); |
4865 | } | 4856 | } |
4866 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | 4857 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { |
4867 | dev_warn(hub_dev, | 4858 | dev_warn(&port_dev->dev, "config error\n"); |
4868 | "config error on port %d\n", | ||
4869 | i); | ||
4870 | usb_clear_port_feature(hub->hdev, i, | 4859 | usb_clear_port_feature(hub->hdev, i, |
4871 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | 4860 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); |
4872 | } | 4861 | } |
@@ -4877,7 +4866,7 @@ static void hub_events(void) | |||
4877 | if (hub_port_warm_reset_required(hub, portstatus)) { | 4866 | if (hub_port_warm_reset_required(hub, portstatus)) { |
4878 | int status; | 4867 | int status; |
4879 | 4868 | ||
4880 | dev_dbg(hub_dev, "warm reset port %d\n", i); | 4869 | dev_dbg(&port_dev->dev, "warm reset\n"); |
4881 | if (!udev || | 4870 | if (!udev || |
4882 | !(portstatus & USB_PORT_STAT_CONNECTION) || | 4871 | !(portstatus & USB_PORT_STAT_CONNECTION) || |
4883 | udev->state == USB_STATE_NOTATTACHED) { | 4872 | udev->state == USB_STATE_NOTATTACHED) { |
@@ -5478,56 +5467,26 @@ struct usb_device *usb_hub_find_child(struct usb_device *hdev, | |||
5478 | } | 5467 | } |
5479 | EXPORT_SYMBOL_GPL(usb_hub_find_child); | 5468 | EXPORT_SYMBOL_GPL(usb_hub_find_child); |
5480 | 5469 | ||
5481 | /** | ||
5482 | * usb_set_hub_port_connect_type - set hub port connect type. | ||
5483 | * @hdev: USB device belonging to the usb hub | ||
5484 | * @port1: port num of the port | ||
5485 | * @type: connect type of the port | ||
5486 | */ | ||
5487 | void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, | ||
5488 | enum usb_port_connect_type type) | ||
5489 | { | ||
5490 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5491 | |||
5492 | if (hub) | ||
5493 | hub->ports[port1 - 1]->connect_type = type; | ||
5494 | } | ||
5495 | |||
5496 | /** | ||
5497 | * usb_get_hub_port_connect_type - Get the port's connect type | ||
5498 | * @hdev: USB device belonging to the usb hub | ||
5499 | * @port1: port num of the port | ||
5500 | * | ||
5501 | * Return: The connect type of the port if successful. Or | ||
5502 | * USB_PORT_CONNECT_TYPE_UNKNOWN if input params are invalid. | ||
5503 | */ | ||
5504 | enum usb_port_connect_type | ||
5505 | usb_get_hub_port_connect_type(struct usb_device *hdev, int port1) | ||
5506 | { | ||
5507 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5508 | |||
5509 | if (!hub) | ||
5510 | return USB_PORT_CONNECT_TYPE_UNKNOWN; | ||
5511 | |||
5512 | return hub->ports[port1 - 1]->connect_type; | ||
5513 | } | ||
5514 | |||
5515 | void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | 5470 | void usb_hub_adjust_deviceremovable(struct usb_device *hdev, |
5516 | struct usb_hub_descriptor *desc) | 5471 | struct usb_hub_descriptor *desc) |
5517 | { | 5472 | { |
5473 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5518 | enum usb_port_connect_type connect_type; | 5474 | enum usb_port_connect_type connect_type; |
5519 | int i; | 5475 | int i; |
5520 | 5476 | ||
5477 | if (!hub) | ||
5478 | return; | ||
5479 | |||
5521 | if (!hub_is_superspeed(hdev)) { | 5480 | if (!hub_is_superspeed(hdev)) { |
5522 | for (i = 1; i <= hdev->maxchild; i++) { | 5481 | for (i = 1; i <= hdev->maxchild; i++) { |
5523 | connect_type = usb_get_hub_port_connect_type(hdev, i); | 5482 | struct usb_port *port_dev = hub->ports[i - 1]; |
5524 | 5483 | ||
5484 | connect_type = port_dev->connect_type; | ||
5525 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 5485 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
5526 | u8 mask = 1 << (i%8); | 5486 | u8 mask = 1 << (i%8); |
5527 | 5487 | ||
5528 | if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { | 5488 | if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { |
5529 | dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", | 5489 | dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); |
5530 | i); | ||
5531 | desc->u.hs.DeviceRemovable[i/8] |= mask; | 5490 | desc->u.hs.DeviceRemovable[i/8] |= mask; |
5532 | } | 5491 | } |
5533 | } | 5492 | } |
@@ -5536,14 +5495,14 @@ void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | |||
5536 | u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); | 5495 | u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); |
5537 | 5496 | ||
5538 | for (i = 1; i <= hdev->maxchild; i++) { | 5497 | for (i = 1; i <= hdev->maxchild; i++) { |
5539 | connect_type = usb_get_hub_port_connect_type(hdev, i); | 5498 | struct usb_port *port_dev = hub->ports[i - 1]; |
5540 | 5499 | ||
5500 | connect_type = port_dev->connect_type; | ||
5541 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 5501 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
5542 | u16 mask = 1 << i; | 5502 | u16 mask = 1 << i; |
5543 | 5503 | ||
5544 | if (!(port_removable & mask)) { | 5504 | if (!(port_removable & mask)) { |
5545 | dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", | 5505 | dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); |
5546 | i); | ||
5547 | port_removable |= mask; | 5506 | port_removable |= mask; |
5548 | } | 5507 | } |
5549 | } | 5508 | } |
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 168fa6ee3348..6a8999728cbf 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c | |||
@@ -152,6 +152,11 @@ struct device_type usb_port_device_type = { | |||
152 | .pm = &usb_port_pm_ops, | 152 | .pm = &usb_port_pm_ops, |
153 | }; | 153 | }; |
154 | 154 | ||
155 | static struct device_driver usb_port_driver = { | ||
156 | .name = "usb", | ||
157 | .owner = THIS_MODULE, | ||
158 | }; | ||
159 | |||
155 | int usb_hub_create_port_device(struct usb_hub *hub, int port1) | 160 | int usb_hub_create_port_device(struct usb_hub *hub, int port1) |
156 | { | 161 | { |
157 | struct usb_port *port_dev = NULL; | 162 | struct usb_port *port_dev = NULL; |
@@ -169,8 +174,9 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) | |||
169 | port_dev->dev.parent = hub->intfdev; | 174 | port_dev->dev.parent = hub->intfdev; |
170 | port_dev->dev.groups = port_dev_group; | 175 | port_dev->dev.groups = port_dev_group; |
171 | port_dev->dev.type = &usb_port_device_type; | 176 | port_dev->dev.type = &usb_port_device_type; |
172 | dev_set_name(&port_dev->dev, "port%d", port1); | 177 | port_dev->dev.driver = &usb_port_driver; |
173 | 178 | dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev), | |
179 | port1); | ||
174 | retval = device_register(&port_dev->dev); | 180 | retval = device_register(&port_dev->dev); |
175 | if (retval) | 181 | if (retval) |
176 | goto error_register; | 182 | goto error_register; |
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c index 5ca4070b1f38..f91ef0220066 100644 --- a/drivers/usb/core/usb-acpi.c +++ b/drivers/usb/core/usb-acpi.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include <linux/pci.h> | 17 | #include <linux/pci.h> |
18 | #include <linux/usb/hcd.h> | 18 | #include <linux/usb/hcd.h> |
19 | 19 | ||
20 | #include "usb.h" | 20 | #include "hub.h" |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * usb_acpi_power_manageable - check whether usb port has | 23 | * usb_acpi_power_manageable - check whether usb port has |
@@ -55,13 +55,18 @@ EXPORT_SYMBOL_GPL(usb_acpi_power_manageable); | |||
55 | */ | 55 | */ |
56 | int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) | 56 | int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) |
57 | { | 57 | { |
58 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
59 | struct usb_port *port_dev; | ||
58 | acpi_handle port_handle; | 60 | acpi_handle port_handle; |
59 | unsigned char state; | 61 | unsigned char state; |
60 | int port1 = index + 1; | 62 | int port1 = index + 1; |
61 | int error = -EINVAL; | 63 | int error = -EINVAL; |
62 | 64 | ||
63 | port_handle = (acpi_handle)usb_get_hub_port_acpi_handle(hdev, | 65 | if (!hub) |
64 | port1); | 66 | return -ENODEV; |
67 | port_dev = hub->ports[port1 - 1]; | ||
68 | |||
69 | port_handle = (acpi_handle) usb_get_hub_port_acpi_handle(hdev, port1); | ||
65 | if (!port_handle) | 70 | if (!port_handle) |
66 | return error; | 71 | return error; |
67 | 72 | ||
@@ -72,10 +77,9 @@ int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) | |||
72 | 77 | ||
73 | error = acpi_bus_set_power(port_handle, state); | 78 | error = acpi_bus_set_power(port_handle, state); |
74 | if (!error) | 79 | if (!error) |
75 | dev_dbg(&hdev->dev, "The power of hub port %d was set to %d\n", | 80 | dev_dbg(&port_dev->dev, "acpi: power was set to %d\n", enable); |
76 | port1, enable); | ||
77 | else | 81 | else |
78 | dev_dbg(&hdev->dev, "The power of hub port failed to be set\n"); | 82 | dev_dbg(&port_dev->dev, "acpi: power failed to be set\n"); |
79 | 83 | ||
80 | return error; | 84 | return error; |
81 | } | 85 | } |
@@ -84,12 +88,17 @@ EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); | |||
84 | static int usb_acpi_check_port_connect_type(struct usb_device *hdev, | 88 | static int usb_acpi_check_port_connect_type(struct usb_device *hdev, |
85 | acpi_handle handle, int port1) | 89 | acpi_handle handle, int port1) |
86 | { | 90 | { |
87 | acpi_status status; | 91 | enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; |
88 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 92 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
89 | union acpi_object *upc; | 93 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); |
90 | struct acpi_pld_info *pld; | 94 | struct acpi_pld_info *pld; |
95 | union acpi_object *upc; | ||
96 | acpi_status status; | ||
91 | int ret = 0; | 97 | int ret = 0; |
92 | 98 | ||
99 | if (!hub) | ||
100 | return 0; | ||
101 | |||
93 | /* | 102 | /* |
94 | * According to ACPI Spec 9.13. PLD indicates whether usb port is | 103 | * According to ACPI Spec 9.13. PLD indicates whether usb port is |
95 | * user visible and _UPC indicates whether it is connectable. If | 104 | * user visible and _UPC indicates whether it is connectable. If |
@@ -112,13 +121,12 @@ static int usb_acpi_check_port_connect_type(struct usb_device *hdev, | |||
112 | 121 | ||
113 | if (upc->package.elements[0].integer.value) | 122 | if (upc->package.elements[0].integer.value) |
114 | if (pld->user_visible) | 123 | if (pld->user_visible) |
115 | usb_set_hub_port_connect_type(hdev, port1, | 124 | connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG; |
116 | USB_PORT_CONNECT_TYPE_HOT_PLUG); | ||
117 | else | 125 | else |
118 | usb_set_hub_port_connect_type(hdev, port1, | 126 | connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED; |
119 | USB_PORT_CONNECT_TYPE_HARD_WIRED); | ||
120 | else if (!pld->user_visible) | 127 | else if (!pld->user_visible) |
121 | usb_set_hub_port_connect_type(hdev, port1, USB_PORT_NOT_USED); | 128 | connect_type = USB_PORT_NOT_USED; |
129 | hub->ports[port1 - 1]->connect_type = connect_type; | ||
122 | 130 | ||
123 | out: | 131 | out: |
124 | ACPI_FREE(pld); | 132 | ACPI_FREE(pld); |
@@ -128,9 +136,9 @@ out: | |||
128 | 136 | ||
129 | static struct acpi_device *usb_acpi_find_companion(struct device *dev) | 137 | static struct acpi_device *usb_acpi_find_companion(struct device *dev) |
130 | { | 138 | { |
139 | int port1; | ||
131 | struct usb_device *udev; | 140 | struct usb_device *udev; |
132 | acpi_handle *parent_handle; | 141 | acpi_handle *parent_handle; |
133 | int port_num; | ||
134 | 142 | ||
135 | /* | 143 | /* |
136 | * In the ACPI DSDT table, only usb root hub and usb ports are | 144 | * In the ACPI DSDT table, only usb root hub and usb ports are |
@@ -147,16 +155,16 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
147 | */ | 155 | */ |
148 | if (is_usb_device(dev)) { | 156 | if (is_usb_device(dev)) { |
149 | udev = to_usb_device(dev); | 157 | udev = to_usb_device(dev); |
158 | port1 = udev->portnum; | ||
150 | if (udev->parent) { | 159 | if (udev->parent) { |
151 | enum usb_port_connect_type type; | 160 | struct usb_hub *hub; |
152 | 161 | ||
162 | hub = usb_hub_to_struct_hub(udev->parent); | ||
153 | /* | 163 | /* |
154 | * According usb port's connect type to set usb device's | 164 | * According usb port's connect type to set usb device's |
155 | * removability. | 165 | * removability. |
156 | */ | 166 | */ |
157 | type = usb_get_hub_port_connect_type(udev->parent, | 167 | switch (hub->ports[port1 - 1]->connect_type) { |
158 | udev->portnum); | ||
159 | switch (type) { | ||
160 | case USB_PORT_CONNECT_TYPE_HOT_PLUG: | 168 | case USB_PORT_CONNECT_TYPE_HOT_PLUG: |
161 | udev->removable = USB_DEVICE_REMOVABLE; | 169 | udev->removable = USB_DEVICE_REMOVABLE; |
162 | break; | 170 | break; |
@@ -173,13 +181,14 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
173 | 181 | ||
174 | /* root hub's parent is the usb hcd. */ | 182 | /* root hub's parent is the usb hcd. */ |
175 | return acpi_find_child_device(ACPI_COMPANION(dev->parent), | 183 | return acpi_find_child_device(ACPI_COMPANION(dev->parent), |
176 | udev->portnum, false); | 184 | port1, false); |
177 | } else if (is_usb_port(dev)) { | 185 | } else if (is_usb_port(dev)) { |
186 | struct usb_port *port_dev = to_usb_port(dev); | ||
178 | struct acpi_device *adev = NULL; | 187 | struct acpi_device *adev = NULL; |
179 | 188 | ||
180 | sscanf(dev_name(dev), "port%d", &port_num); | ||
181 | /* Get the struct usb_device point of port's hub */ | 189 | /* Get the struct usb_device point of port's hub */ |
182 | udev = to_usb_device(dev->parent->parent); | 190 | udev = to_usb_device(dev->parent->parent); |
191 | port1 = port_dev->portnum; | ||
183 | 192 | ||
184 | /* | 193 | /* |
185 | * The root hub ports' parent is the root hub. The non-root-hub | 194 | * The root hub ports' parent is the root hub. The non-root-hub |
@@ -188,12 +197,11 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
188 | */ | 197 | */ |
189 | if (!udev->parent) { | 198 | if (!udev->parent) { |
190 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 199 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
191 | int raw_port_num; | 200 | int raw; |
192 | 201 | ||
193 | raw_port_num = usb_hcd_find_raw_port_number(hcd, | 202 | raw = usb_hcd_find_raw_port_number(hcd, port1); |
194 | port_num); | ||
195 | adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev), | 203 | adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev), |
196 | raw_port_num, false); | 204 | raw, false); |
197 | if (!adev) | 205 | if (!adev) |
198 | return NULL; | 206 | return NULL; |
199 | } else { | 207 | } else { |
@@ -204,11 +212,11 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
204 | return NULL; | 212 | return NULL; |
205 | 213 | ||
206 | acpi_bus_get_device(parent_handle, &adev); | 214 | acpi_bus_get_device(parent_handle, &adev); |
207 | adev = acpi_find_child_device(adev, port_num, false); | 215 | adev = acpi_find_child_device(adev, port1, false); |
208 | if (!adev) | 216 | if (!adev) |
209 | return NULL; | 217 | return NULL; |
210 | } | 218 | } |
211 | usb_acpi_check_port_connect_type(udev, adev->handle, port_num); | 219 | usb_acpi_check_port_connect_type(udev, adev->handle, port1); |
212 | return adev; | 220 | return adev; |
213 | } | 221 | } |
214 | 222 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 75bf649da82d..69bfc253a7b8 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -175,10 +175,6 @@ extern void usb_notify_add_device(struct usb_device *udev); | |||
175 | extern void usb_notify_remove_device(struct usb_device *udev); | 175 | extern void usb_notify_remove_device(struct usb_device *udev); |
176 | extern void usb_notify_add_bus(struct usb_bus *ubus); | 176 | extern void usb_notify_add_bus(struct usb_bus *ubus); |
177 | extern void usb_notify_remove_bus(struct usb_bus *ubus); | 177 | extern void usb_notify_remove_bus(struct usb_bus *ubus); |
178 | extern enum usb_port_connect_type | ||
179 | usb_get_hub_port_connect_type(struct usb_device *hdev, int port1); | ||
180 | extern void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, | ||
181 | enum usb_port_connect_type type); | ||
182 | extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | 178 | extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, |
183 | struct usb_hub_descriptor *desc); | 179 | struct usb_hub_descriptor *desc); |
184 | 180 | ||