Merge tag 'ti-v2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/u-boot.git] / drivers / usb / host / xhci-mem.c
index 84982a92d6030efbdab5437a94199b3c4c60ab90..2d968aafb03eddb1948ec3308d87df146a98fdf7 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * USB HOST XHCI Controller stack
  *
  * Copyright (C) 2013 Samsung Electronics Co.Ltd
  * Authors: Vivek Gautam <gautam.vivek@samsung.com>
  *         Vikas Sajjan <vikas.sajjan@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <cpu_func.h>
 #include <dm.h>
+#include <log.h>
 #include <asm/byteorder.h>
 #include <usb.h>
 #include <malloc.h>
 #include <asm/cache.h>
+#include <linux/bug.h>
 #include <linux/errno.h>
 
-#include "xhci.h"
+#include <usb/xhci.h>
 
 #define CACHELINE_SIZE         CONFIG_SYS_CACHELINE_SIZE
 /**
@@ -370,6 +372,9 @@ static int xhci_scratchpad_alloc(struct xhci_ctrl *ctrl)
        ctrl->dcbaa->dev_context_ptrs[0] =
                cpu_to_le64((uintptr_t)scratchpad->sp_array);
 
+       xhci_flush_cache((uintptr_t)&ctrl->dcbaa->dev_context_ptrs[0],
+               sizeof(ctrl->dcbaa->dev_context_ptrs[0]));
+
        page_size = xhci_readl(&hcor->or_pagesize) & 0xffff;
        for (i = 0; i < 16; i++) {
                if ((0x1 & page_size) != 0)
@@ -724,7 +729,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
        int slot_id = udev->slot_id;
        int speed = udev->speed;
        int route = 0;
-#ifdef CONFIG_DM_USB
+#if CONFIG_IS_ENABLED(DM_USB)
        struct usb_device *dev = udev;
        struct usb_hub_device *hub;
 #endif
@@ -740,7 +745,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
        /* Only the control endpoint is valid - one endpoint context */
        slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1));
 
-#ifdef CONFIG_DM_USB
+#if CONFIG_IS_ENABLED(DM_USB)
        /* Calculate the route string for this device */
        port_num = dev->portnr;
        while (!usb_hub_is_root_hub(dev->dev)) {
@@ -783,7 +788,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
                BUG();
        }
 
-#ifdef CONFIG_DM_USB
+#if CONFIG_IS_ENABLED(DM_USB)
        /* Set up TT fields to support FS/LS devices */
        if (speed == USB_SPEED_LOW || speed == USB_SPEED_FULL) {
                struct udevice *parent = udev->dev;
@@ -850,6 +855,12 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
        trb_64 = (uintptr_t)virt_dev->eps[0].ring->first_seg->trbs;
        ep0_ctx->deq = cpu_to_le64(trb_64 | virt_dev->eps[0].ring->cycle_state);
 
+       /*
+        * xHCI spec 6.2.3:
+        * software shall set 'Average TRB Length' to 8 for control endpoints.
+        */
+       ep0_ctx->tx_info = cpu_to_le32(EP_AVG_TRB_LENGTH(8));
+
        /* Steps 7 and 8 were done in xhci_alloc_virt_device() */
 
        xhci_flush_cache((uintptr_t)ep0_ctx, sizeof(struct xhci_ep_ctx));