Since a_alt_hnp_support is obsolete in OTG 2.0, HNP capable host should
send this set feature request only if the otg device is connecting to a
non-HNP port and it's compliant with OTG 1.x revision. This is done by
checking its otg descriptor length, OTG 2.0 uses usb_otg20_descriptor
which has different length than OTG 1.x using usb_otg_descriptor.

Signed-off-by: Li Jun <[email protected]>
---
 drivers/usb/core/hub.c | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 917c27c..47dca78 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2254,23 +2254,36 @@ static int usb_enumerate_device_otg(struct usb_device 
*udev)
                                                ? "" : "non-");
 
                                /* enable HNP before suspend, it's simpler */
-                               if (port1 == bus->otg_port)
+                               if (port1 == bus->otg_port) {
                                        bus->b_hnp_enable = 1;
-                               err = usb_control_msg(udev,
-                                       usb_sndctrlpipe(udev, 0),
-                                       USB_REQ_SET_FEATURE, 0,
-                                       bus->b_hnp_enable
-                                               ? USB_DEVICE_B_HNP_ENABLE
-                                               : USB_DEVICE_A_ALT_HNP_SUPPORT,
-                                       0, NULL, 0, USB_CTRL_SET_TIMEOUT);
-                               if (err < 0) {
-                                       /* OTG MESSAGE: report errors here,
-                                        * customize to match your product.
-                                        */
-                                       dev_info(&udev->dev,
-                                               "can't set HNP mode: %d\n",
-                                               err);
-                                       bus->b_hnp_enable = 0;
+                                       err = usb_control_msg(udev,
+                                               usb_sndctrlpipe(udev, 0),
+                                               USB_REQ_SET_FEATURE, 0,
+                                               USB_DEVICE_B_HNP_ENABLE,
+                                               0, NULL, 0,
+                                               USB_CTRL_SET_TIMEOUT);
+                                       if (err < 0) {
+                                               /* OTG MESSAGE: report errors
+                                                * here, customize to match your
+                                                * product.
+                                                */
+                                               dev_info(&udev->dev,
+                                                       "can't set HNP mode: 
%d\n",
+                                                       err);
+                                               bus->b_hnp_enable = 0;
+                                       }
+                               } else if (desc->bLength == sizeof
+                                               (struct usb_otg_descriptor)) {
+                                       err = usb_control_msg(udev,
+                                               usb_sndctrlpipe(udev, 0),
+                                               USB_REQ_SET_FEATURE, 0,
+                                               USB_DEVICE_A_ALT_HNP_SUPPORT,
+                                               0, NULL, 0,
+                                               USB_CTRL_SET_TIMEOUT);
+                                       if (err < 0)
+                                               dev_info(&udev->dev,
+                                                       "set a_alt_hnp_support 
failed: %d\n",
+                                                       err);
                                }
                        }
                }
-- 
1.9.1

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

Reply via email to