usb: hub: Change USB hub descriptor to match USB 3.0 hubs
[platform/kernel/u-boot.git] / drivers / usb / host / xhci.c
index 0b09643..d5a1b34 100644 (file)
@@ -28,7 +28,7 @@
 #include <watchdog.h>
 #include <asm/cache.h>
 #include <asm/unaligned.h>
-#include <asm-generic/errno.h>
+#include <linux/errno.h>
 #include "xhci.h"
 
 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
@@ -50,8 +50,8 @@ static struct descriptor {
                cpu_to_le16(0x8), /* wHubCharacteristics */
                10,             /* bPwrOn2PwrGood */
                0,              /* bHubCntrCurrent */
-               {},             /* Device removable */
-               {}              /* at most 7 ports! XXX */
+               {               /* Device removable */
+                             /* at most 7 ports! XXX */
        },
        {
                0x12,           /* bLength */
@@ -192,14 +192,14 @@ static int xhci_start(struct xhci_hcor *hcor)
  * @param hcor pointer to host controller operation registers
  * @return -EBUSY if XHCI Controller is not halted else status of handshake
  */
-int xhci_reset(struct xhci_hcor *hcor)
+static int xhci_reset(struct xhci_hcor *hcor)
 {
        u32 cmd;
        u32 state;
        int ret;
 
        /* Halting the Host first */
-       debug("// Halt the HC\n");
+       debug("// Halt the HC: %p\n", hcor);
        state = xhci_readl(&hcor->or_usbsts) & STS_HALT;
        if (!state) {
                cmd = xhci_readl(&hcor->or_usbcmd);
@@ -332,8 +332,8 @@ static int xhci_set_configuration(struct usb_device *udev)
        ifdesc = &udev->config.if_desc[0];
 
        ctrl_ctx = xhci_get_input_control_ctx(in_ctx);
-       /* Zero the input context control */
-       ctrl_ctx->add_flags = 0;
+       /* Initialize the input context control */
+       ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG);
        ctrl_ctx->drop_flags = 0;
 
        /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */
@@ -481,7 +481,7 @@ static int xhci_address_device(struct usb_device *udev, int root_portnr)
  * @param udev pointer to the Device Data Structure
  * @return Returns 0 on succes else return error code on failure
  */
-int _xhci_alloc_device(struct usb_device *udev)
+static int _xhci_alloc_device(struct usb_device *udev)
 {
        struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
        union xhci_trb *event;
@@ -727,6 +727,7 @@ static int xhci_submit_root(struct usb_device *udev, unsigned long pipe,
        case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8):
                switch (le16_to_cpu(req->value) >> 8) {
                case USB_DT_HUB:
+               case USB_DT_SS_HUB:
                        debug("USB_DT_HUB config\n");
                        srcptr = &descriptor.hub;
                        srclen = 0x8;
@@ -941,10 +942,12 @@ static int _xhci_submit_control_msg(struct usb_device *udev, unsigned long pipe,
        if (usb_pipedevice(pipe) == ctrl->rootdev)
                return xhci_submit_root(udev, pipe, buffer, setup);
 
-       if (setup->request == USB_REQ_SET_ADDRESS)
+       if (setup->request == USB_REQ_SET_ADDRESS &&
+          (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD)
                return xhci_address_device(udev, root_portnr);
 
-       if (setup->request == USB_REQ_SET_CONFIGURATION) {
+       if (setup->request == USB_REQ_SET_CONFIGURATION &&
+          (setup->requesttype & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
                ret = xhci_set_configuration(udev);
                if (ret) {
                        puts("Failed to configure xHCI endpoint\n");
@@ -1064,6 +1067,8 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
        struct xhci_ctrl *ctrl;
        int ret;
 
+       *controller = NULL;
+
        if (xhci_hcd_init(index, &hccr, (struct xhci_hcor **)&hcor) != 0)
                return -ENODEV;
 
@@ -1077,7 +1082,12 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
 
        ret = xhci_lowlevel_init(ctrl);
 
-       *controller = &xhcic[index];
+       if (ret) {
+               ctrl->hccr = NULL;
+               ctrl->hcor = NULL;
+       } else {
+               *controller = &xhcic[index];
+       }
 
        return ret;
 }
@@ -1093,9 +1103,11 @@ int usb_lowlevel_stop(int index)
 {
        struct xhci_ctrl *ctrl = (xhcic + index);
 
-       xhci_lowlevel_stop(ctrl);
-       xhci_hcd_stop(index);
-       xhci_cleanup(ctrl);
+       if (ctrl->hcor) {
+               xhci_lowlevel_stop(ctrl);
+               xhci_hcd_stop(index);
+               xhci_cleanup(ctrl);
+       }
 
        return 0;
 }
@@ -1110,7 +1122,7 @@ static struct usb_device *get_usb_device(struct udevice *dev)
        if (device_get_uclass_id(dev) == UCLASS_USB)
                udev = dev_get_uclass_priv(dev);
        else
-               udev = dev_get_parentdata(dev);
+               udev = dev_get_parent_priv(dev);
 
        return udev;
 }
@@ -1141,7 +1153,7 @@ static int xhci_submit_control_msg(struct udevice *dev, struct usb_device *udev,
                } else {
                        while (!is_root_hub(hub->parent))
                                hub = hub->parent;
-                       uhop = dev_get_parentdata(hub);
+                       uhop = dev_get_parent_priv(hub);
                        root_portnr = uhop->portnr;
                }
        }