1 Index: linux-3.10.26/drivers/usb/core/hub.c
2 ===================================================================
3 --- linux-3.10.26.orig/drivers/usb/core/hub.c 2014-01-09 20:25:15.000000000 +0000
4 +++ linux-3.10.26/drivers/usb/core/hub.c 2014-01-19 16:29:18.548615960 +0000
6 if (type != HUB_SUSPEND) {
7 /* Disconnect all the children */
8 for (i = 0; i < hdev->maxchild; ++i) {
9 - if (hub->ports[i]->child)
10 + if (hub->ports[i] && hub->ports[i]->child)
11 usb_disconnect(&hub->ports[i]->child);
14 Index: linux-3.10.26/drivers/usb/core/port.c
15 ===================================================================
16 --- linux-3.10.26.orig/drivers/usb/core/port.c 2014-01-09 20:25:15.000000000 +0000
17 +++ linux-3.10.26/drivers/usb/core/port.c 2014-01-19 16:29:18.548615960 +0000
19 void usb_hub_remove_port_device(struct usb_hub *hub,
22 - device_unregister(&hub->ports[port1 - 1]->dev);
23 + if (hub->ports[port1 - 1])
24 + device_unregister(&hub->ports[port1 - 1]->dev);
27 Index: linux-3.10.26/drivers/usb/host/Kconfig
28 ===================================================================
29 --- linux-3.10.26.orig/drivers/usb/host/Kconfig 2014-01-09 20:25:15.000000000 +0000
30 +++ linux-3.10.26/drivers/usb/host/Kconfig 2014-01-19 16:29:18.548615960 +0000
34 config USB_XHCI_PLATFORM
36 + bool "xHCI platform"
38 +config USB_MT7621_XHCI_PLATFORM
39 + bool "MTK MT7621 xHCI"
40 + depends on USB_XHCI_PLATFORM
42 config USB_XHCI_HCD_DEBUGGING
43 bool "Debugging for the xHCI host controller"
44 Index: linux-3.10.26/drivers/usb/host/Makefile
45 ===================================================================
46 --- linux-3.10.26.orig/drivers/usb/host/Makefile 2014-01-09 20:25:15.000000000 +0000
47 +++ linux-3.10.26/drivers/usb/host/Makefile 2014-01-19 16:30:54.964617843 +0000
50 xhci-hcd-y := xhci.o xhci-mem.o
51 xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o
52 +ifndef CONFIG_USB_MT7621_XHCI_PLATFORM
53 xhci-hcd-$(CONFIG_PCI) += xhci-pci.o
56 +ifdef CONFIG_USB_MT7621_XHCI_PLATFORM
57 +xhci-hcd-y += mtk-phy.o xhci-mtk-scheduler.o xhci-mtk-power.o xhci-mtk.o mtk-phy-7621.o mtk-phy-ahb.o
60 ifneq ($(CONFIG_USB_XHCI_PLATFORM), )
61 - xhci-hcd-y += xhci-plat.o
62 +xhci-hcd-y += xhci-plat.o
65 obj-$(CONFIG_USB_WHCI_HCD) += whci/
67 +ifndef CONFIG_USB_MT7621_XHCI_PLATFORM
68 obj-$(CONFIG_PCI) += pci-quirks.o
71 obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
72 obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
73 Index: linux-3.10.26/drivers/usb/host/pci-quirks.h
74 ===================================================================
75 --- linux-3.10.26.orig/drivers/usb/host/pci-quirks.h 2014-01-19 16:29:17.392615927 +0000
76 +++ linux-3.10.26/drivers/usb/host/pci-quirks.h 2014-01-19 16:29:18.548615960 +0000
78 #ifndef __LINUX_USB_PCI_QUIRKS_H
79 #define __LINUX_USB_PCI_QUIRKS_H
82 +#if defined (CONFIG_PCI) && !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
83 void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
84 int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
85 bool usb_is_intel_switchable_xhci(struct pci_dev *pdev);
86 Index: linux-3.10.26/drivers/usb/host/xhci.c
87 ===================================================================
88 --- linux-3.10.26.orig/drivers/usb/host/xhci.c 2014-01-09 20:25:15.000000000 +0000
89 +++ linux-3.10.26/drivers/usb/host/xhci.c 2014-01-19 16:29:18.548615960 +0000
94 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
95 +#include <asm/uaccess.h>
96 +#include <linux/dma-mapping.h>
97 +#include <linux/platform_device.h>
99 +#include "xhci-mtk-scheduler.h"
100 +#include "xhci-mtk-power.h"
101 +#include "xhci-mtk.h"
104 #define DRIVER_AUTHOR "Sarah Sharp"
105 #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
108 module_param(link_quirk, int, S_IRUGO | S_IWUSR);
109 MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB");
111 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
112 +long xhci_mtk_test_unlock_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
113 +static struct file_operations xhci_mtk_test_fops = {
114 + .owner = THIS_MODULE,
115 + .read = xhci_mtk_test_read,
116 + .write = xhci_mtk_test_write,
117 + .unlocked_ioctl = xhci_mtk_test_unlock_ioctl,
118 + .open = xhci_mtk_test_open,
119 + .release = xhci_mtk_test_release,
123 /* TODO: copied from ehci-hcd.c - can this be refactored? */
125 * xhci_handshake - spin reading hc until handshake completes or fails
131 +#if defined (CONFIG_PCI) && !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
132 static int xhci_free_msi(struct xhci_hcd *xhci)
138 hcd->irq = pdev->irq;
144 xhci_dbg(xhci, "Attempting compliance mode recovery\n");
145 hcd = xhci->shared_hcd;
147 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
149 + xhci_writel(xhci, temp, xhci->usb3_ports[i]);
152 if (hcd->state == HC_STATE_SUSPENDED)
153 usb_hcd_resume_root_hub(hcd);
157 const char *dmi_product_name, *dmi_sys_vendor;
159 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
162 dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
163 dmi_sys_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
164 if (!dmi_product_name || !dmi_sys_vendor)
167 xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n");
170 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
171 + mtk_xhci_scheduler_init();
173 retval = xhci_mem_init(xhci, GFP_KERNEL);
174 xhci_dbg(xhci, "Finished xhci_init\n");
177 xhci_dbg(xhci, "// Set the interrupt modulation register\n");
178 temp = xhci_readl(xhci, &xhci->ir_set->irq_control);
179 temp &= ~ER_IRQ_INTERVAL_MASK;
180 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
185 xhci_writel(xhci, temp, &xhci->ir_set->irq_control);
187 /* Set the HCD state before we enable the irqs */
189 xhci_queue_vendor_command(xhci, 0, 0, 0,
190 TRB_TYPE(TRB_NEC_GET_FW));
192 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
193 + enableXhciAllPortPower(xhci);
195 xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n");
200 /* If restore operation fails, re-initialize the HC during resume */
201 if ((temp & STS_SRE) || hibernated) {
203 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
204 !(xhci_all_ports_seen_u0(xhci))) {
205 del_timer_sync(&xhci->comp_mode_recovery_timer);
206 @@ -1583,6 +1624,13 @@
208 u32 new_add_flags, new_drop_flags, new_slot_info;
210 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
212 + struct sch_ep *sch_ep = NULL;
218 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
220 @@ -1634,6 +1682,40 @@
222 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
224 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
226 + slot_ctx = xhci_get_slot_ctx(xhci, xhci->devs[udev->slot_id]->out_ctx);
227 + if ((slot_ctx->tt_info & 0xff) > 0) {
233 + if (usb_endpoint_xfer_int(&ep->desc)) {
234 + ep_type = USB_EP_INT;
236 + else if (usb_endpoint_xfer_isoc(&ep->desc)) {
237 + ep_type = USB_EP_ISOC;
239 + else if (usb_endpoint_xfer_bulk(&ep->desc)) {
240 + ep_type = USB_EP_BULK;
243 + ep_type = USB_EP_CONTROL;
245 + sch_ep = mtk_xhci_scheduler_remove_ep(udev->speed, usb_endpoint_dir_in(&ep->desc)
246 + , isTT, ep_type, (mtk_u32 *)ep);
247 + if (sch_ep != NULL) {
251 + xhci_dbg(xhci, "[MTK]Doesn't find ep_sch instance when removing endpoint\n");
254 + mtk_xhci_scheduler_remove_ep(xhci, udev, ep);
258 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n",
259 (unsigned int) ep->desc.bEndpointAddress,
261 @@ -1669,6 +1751,18 @@
262 u32 new_add_flags, new_drop_flags, new_slot_info;
263 struct xhci_virt_device *virt_dev;
265 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
266 + struct xhci_ep_ctx *in_ep_ctx;
268 + struct sch_ep *sch_ep;
278 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
280 @@ -1731,6 +1825,56 @@
284 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
285 + in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
287 + slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
288 + if ((slot_ctx->tt_info & 0xff) > 0) {
294 + if (usb_endpoint_xfer_int(&ep->desc)) {
295 + ep_type = USB_EP_INT;
297 + else if (usb_endpoint_xfer_isoc(&ep->desc)) {
298 + ep_type = USB_EP_ISOC;
300 + else if (usb_endpoint_xfer_bulk(&ep->desc)) {
301 + ep_type = USB_EP_BULK;
304 + ep_type = USB_EP_CONTROL;
306 + if (udev->speed == USB_SPEED_FULL || udev->speed == USB_SPEED_HIGH
307 + || udev->speed == USB_SPEED_LOW) {
308 + maxp = ep->desc.wMaxPacketSize & 0x7FF;
309 + burst = ep->desc.wMaxPacketSize >> 11;
312 + else if (udev->speed == USB_SPEED_SUPER) {
313 + maxp = ep->desc.wMaxPacketSize & 0x7FF;
314 + burst = ep->ss_ep_comp.bMaxBurst;
315 + mult = ep->ss_ep_comp.bmAttributes & 0x3;
317 + interval = (1 << ((in_ep_ctx->ep_info >> 16) & 0xff));
318 + sch_ep = kmalloc(sizeof(struct sch_ep), GFP_KERNEL);
319 + if (mtk_xhci_scheduler_add_ep(udev->speed, usb_endpoint_dir_in(&ep->desc),
320 + isTT, ep_type, maxp, interval, burst, mult, (mtk_u32 *)ep
321 + , (mtk_u32 *)in_ep_ctx, sch_ep) != SCH_SUCCESS) {
322 + xhci_err(xhci, "[MTK] not enough bandwidth\n");
327 + if (mtk_xhci_scheduler_add_ep(xhci, udev, ep, in_ep_ctx) != SCH_SUCCESS) {
328 + xhci_err(xhci, "[MTK] not enough bandwidth\n");
334 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs);
335 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
337 @@ -2694,7 +2838,7 @@
338 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) &&
339 ctrl_ctx->drop_flags == 0)
343 xhci_dbg(xhci, "New Input Control Context:\n");
344 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
345 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
346 @@ -4230,10 +4374,14 @@
349 if (state == USB3_LPM_U1) {
350 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
351 if (xhci->quirks & XHCI_INTEL_HOST)
353 return xhci_calculate_intel_u1_timeout(udev, desc);
355 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
356 if (xhci->quirks & XHCI_INTEL_HOST)
358 return xhci_calculate_intel_u2_timeout(udev, desc);
361 @@ -4659,7 +4807,9 @@
362 /* Accept arbitrarily long scatter-gather lists */
363 hcd->self.sg_tablesize = ~0;
364 /* XHCI controllers don't stop the ep queue on short packets :| */
365 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
366 hcd->self.no_stop_on_short = 1;
369 if (usb_hcd_is_primary_hcd(hcd)) {
370 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);
371 @@ -4728,6 +4878,10 @@
373 xhci_dbg(xhci, "Reset complete\n");
375 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
379 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
380 if (HCC_64BIT_ADDR(temp)) {
381 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
382 @@ -4752,8 +4906,21 @@
383 MODULE_AUTHOR(DRIVER_AUTHOR);
384 MODULE_LICENSE("GPL");
386 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
387 +static struct platform_device xhci_platform_dev = {
388 + .name = "xhci-hcd",
391 + .coherent_dma_mask = 0xffffffff,
396 static int __init xhci_hcd_init(void)
398 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
399 + struct platform_device *pPlatformDev;
403 retval = xhci_register_pci();
404 @@ -4766,6 +4933,33 @@
405 printk(KERN_DEBUG "Problem registering platform driver.");
409 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
410 + retval = register_chrdev(XHCI_MTK_TEST_MAJOR, DEVICE_NAME, &xhci_mtk_test_fops);
413 + if (u3phy_ops->u2_slew_rate_calibration) {
414 + u3phy_ops->u2_slew_rate_calibration(u3phy);
415 + u3phy_ops->u2_slew_rate_calibration(u3phy_p1);
418 + printk(KERN_ERR "WARN: PHY doesn't implement u2 slew rate calibration function\n");
420 + u3phy_ops->init(u3phy);
423 + pPlatformDev = &xhci_platform_dev;
424 + memset(pPlatformDev, 0, sizeof(struct platform_device));
425 + pPlatformDev->name = "xhci-hcd";
426 + pPlatformDev->id = -1;
427 + pPlatformDev->dev.coherent_dma_mask = 0xffffffff;
428 + pPlatformDev->dev.dma_mask = &pPlatformDev->dev.coherent_dma_mask;
430 + retval = platform_device_register(&xhci_platform_dev);
432 + xhci_unregister_plat();
436 * Check the compiler generated sizes of structures that must be laid
437 * out in specific ways for hardware access.
438 @@ -4783,6 +4977,7 @@
439 BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8);
440 /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */
441 BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8);
445 xhci_unregister_pci();
446 Index: linux-3.10.26/drivers/usb/host/xhci-dbg.c
447 ===================================================================
448 --- linux-3.10.26.orig/drivers/usb/host/xhci-dbg.c 2014-01-09 20:25:15.000000000 +0000
449 +++ linux-3.10.26/drivers/usb/host/xhci-dbg.c 2014-01-19 16:29:18.548615960 +0000
454 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
455 +#include "xhci-mtk.h"
458 #define XHCI_INIT_VALUE 0x0
460 Index: linux-3.10.26/drivers/usb/host/xhci.h
461 ===================================================================
462 --- linux-3.10.26.orig/drivers/usb/host/xhci.h 2014-01-09 20:25:15.000000000 +0000
463 +++ linux-3.10.26/drivers/usb/host/xhci.h 2014-01-19 16:29:18.548615960 +0000
465 #include <linux/usb/hcd.h>
467 /* Code sharing between pci-quirks and xhci hcd */
468 -#include "xhci-ext-caps.h"
469 +#include "xhci-ext-caps.h"
470 #include "pci-quirks.h"
472 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
473 +#define XHC_IRQ (22 + 8)
474 +#define XHC_IO_START 0x1E1C0000
475 +#define XHC_IO_LENGTH 0x10000
476 +/* mtk scheduler bitmasks */
477 +#define BPKTS(p) ((p) & 0x3f)
478 +#define BCSCOUNT(p) (((p) & 0x7) << 8)
479 +#define BBM(p) ((p) << 11)
480 +#define BOFFSET(p) ((p) & 0x3fff)
481 +#define BREPEAT(p) (((p) & 0x7fff) << 16)
487 /* xHCI PCI Configuration Registers */
488 #define XHCI_SBRN_OFFSET (0x60)
490 @@ -1536,8 +1551,12 @@
491 /* Compliance Mode Recovery Data */
492 struct timer_list comp_mode_recovery_timer;
494 +#ifdef CONFIG_USB_MT7621_XHCI_PLATFORM
495 +#define COMP_MODE_RCVRY_MSECS 5000
497 /* Compliance Mode Timer Triggered every 2 seconds */
498 #define COMP_MODE_RCVRY_MSECS 2000
502 /* convert between an HCD pointer and the corresponding EHCI_HCD */
503 @@ -1703,7 +1722,7 @@
504 void xhci_free_command(struct xhci_hcd *xhci,
505 struct xhci_command *command);
508 +#if defined (CONFIG_PCI) && !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
510 int xhci_register_pci(void);
511 void xhci_unregister_pci(void);
512 Index: linux-3.10.26/drivers/usb/host/xhci-mem.c
513 ===================================================================
514 --- linux-3.10.26.orig/drivers/usb/host/xhci-mem.c 2014-01-09 20:25:15.000000000 +0000
515 +++ linux-3.10.26/drivers/usb/host/xhci-mem.c 2014-01-19 16:29:18.548615960 +0000
518 static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
524 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma);
526 @@ -1446,9 +1449,17 @@
527 max_burst = (usb_endpoint_maxp(&ep->desc)
530 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
531 + if ((max_packet % 4 == 2) && (max_packet % 16 != 14) && (max_burst == 0) && usb_endpoint_dir_in(&ep->desc))
537 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
538 + if ((max_packet % 4 == 2) && (max_packet % 16 != 14) && (max_burst == 0) && usb_endpoint_dir_in(&ep->desc))
544 Index: linux-3.10.26/drivers/usb/host/xhci-plat.c
545 ===================================================================
546 --- linux-3.10.26.orig/drivers/usb/host/xhci-plat.c 2014-01-09 20:25:15.000000000 +0000
547 +++ linux-3.10.26/drivers/usb/host/xhci-plat.c 2014-01-19 16:29:18.548615960 +0000
549 * dev struct in order to setup MSI
551 xhci->quirks |= XHCI_PLAT;
552 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
553 + /* MTK host controller gives a spurious successful event after a
554 + * short transfer. Ignore it.
556 + xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
557 + xhci->quirks |= XHCI_LPM_SUPPORT;
561 /* called during probe() after chip reset completes */
564 driver = &xhci_plat_xhci_driver;
566 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
569 irq = platform_get_irq(pdev, 0);
575 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
576 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
581 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
585 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
586 + hcd->rsrc_start = (uint32_t)XHC_IO_START;
587 + hcd->rsrc_len = XHC_IO_LENGTH;
589 hcd->rsrc_start = res->start;
590 hcd->rsrc_len = resource_size(res);
593 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
594 driver->description)) {
595 Index: linux-3.10.26/drivers/usb/host/xhci-ring.c
596 ===================================================================
597 --- linux-3.10.26.orig/drivers/usb/host/xhci-ring.c 2014-01-09 20:25:15.000000000 +0000
598 +++ linux-3.10.26/drivers/usb/host/xhci-ring.c 2014-01-19 16:29:18.548615960 +0000
601 if (!chain && !more_trbs_coming)
604 /* If we're not dealing with 0.95 hardware or
605 * isoc rings on AMD 0.96 host,
606 * carry over the chain bit of the previous TRB
607 @@ -273,16 +272,20 @@
608 static inline int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
609 unsigned int num_trbs)
611 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
612 int num_trbs_in_deq_seg;
615 if (ring->num_trbs_free < num_trbs)
618 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
619 if (ring->type != TYPE_COMMAND && ring->type != TYPE_EVENT) {
620 num_trbs_in_deq_seg = ring->dequeue - ring->deq_seg->trbs;
621 if (ring->num_trbs_free < num_trbs + num_trbs_in_deq_seg)
628 @@ -2910,6 +2913,7 @@
629 next = ring->enqueue;
631 while (last_trb(xhci, ring, ring->enq_seg, next)) {
632 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
633 /* If we're not dealing with 0.95 hardware or isoc rings
634 * on AMD 0.96 host, clear the chain bit.
636 @@ -2919,7 +2923,9 @@
637 next->link.control &= cpu_to_le32(~TRB_CHAIN);
639 next->link.control |= cpu_to_le32(TRB_CHAIN);
642 + next->link.control &= cpu_to_le32(~TRB_CHAIN);
645 next->link.control ^= cpu_to_le32(TRB_CYCLE);
647 @@ -3049,6 +3055,9 @@
648 start_trb->field[3] |= cpu_to_le32(start_cycle);
650 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE);
651 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
654 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
657 @@ -3108,6 +3117,29 @@
658 return (remainder >> 10) << 17;
661 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
662 +static u32 mtk_xhci_td_remainder(unsigned int td_transfer_size, unsigned int td_running_total, unsigned int maxp, unsigned trb_buffer_length)
665 + int remainder, td_packet_count, packet_transferred;
667 + //0 for the last TRB
668 + //FIXME: need to workaround if there is ZLP in this TD
669 + if (td_running_total + trb_buffer_length == td_transfer_size)
672 + //FIXME: need to take care of high-bandwidth (MAX_ESIT)
673 + packet_transferred = (td_running_total /*+ trb_buffer_length*/) / maxp;
674 + td_packet_count = DIV_ROUND_UP(td_transfer_size, maxp);
675 + remainder = td_packet_count - packet_transferred;
677 + if (remainder > max)
680 + return remainder << 17;
685 * For xHCI 1.0 host controllers, TD size is the number of max packet sized
686 * packets remaining in the TD (*not* including this TRB).
687 @@ -3245,6 +3277,7 @@
690 /* Set the TRB length, TD size, and interrupter fields. */
691 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
692 if (xhci->hci_version < 0x100) {
693 remainder = xhci_td_remainder(
694 urb->transfer_buffer_length -
695 @@ -3254,6 +3287,13 @@
696 trb_buff_len, total_packet_count, urb,
701 + remainder = mtk_xhci_td_remainder(urb->transfer_buffer_length,
702 + running_total, urb->ep->desc.wMaxPacketSize, trb_buff_len);
706 length_field = TRB_LEN(trb_buff_len) |
709 @@ -3316,6 +3356,9 @@
710 int running_total, trb_buff_len, ret;
711 unsigned int total_packet_count;
713 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
718 return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index);
719 @@ -3341,6 +3384,25 @@
720 running_total += TRB_MAX_BUFF_SIZE;
722 /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */
723 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
724 + switch(urb->dev->speed){
725 + case USB_SPEED_SUPER:
726 + max_packet = urb->ep->desc.wMaxPacketSize;
728 + case USB_SPEED_HIGH:
729 + case USB_SPEED_FULL:
730 + case USB_SPEED_LOW:
731 + case USB_SPEED_WIRELESS:
732 + case USB_SPEED_UNKNOWN:
734 + max_packet = urb->ep->desc.wMaxPacketSize & 0x7ff;
737 + if((urb->transfer_flags & URB_ZERO_PACKET)
738 + && ((urb->transfer_buffer_length % max_packet) == 0)){
743 ret = prepare_transfer(xhci, xhci->devs[slot_id],
744 ep_index, urb->stream_id,
745 @@ -3400,6 +3462,7 @@
748 /* Set the TRB length, TD size, and interrupter fields. */
749 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
750 if (xhci->hci_version < 0x100) {
751 remainder = xhci_td_remainder(
752 urb->transfer_buffer_length -
753 @@ -3409,6 +3472,10 @@
754 trb_buff_len, total_packet_count, urb,
758 + remainder = mtk_xhci_td_remainder(urb->transfer_buffer_length, running_total, max_packet, trb_buff_len);
761 length_field = TRB_LEN(trb_buff_len) |
764 @@ -3498,7 +3565,11 @@
767 /* xHCI 1.0 6.4.1.2.1: Transfer Type field */
768 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
771 if (xhci->hci_version == 0x100) {
773 if (urb->transfer_buffer_length > 0) {
774 if (setup->bRequestType & USB_DIR_IN)
775 field |= TRB_TX_TYPE(TRB_DATA_IN);
776 @@ -3522,7 +3593,12 @@
777 field = TRB_TYPE(TRB_DATA);
779 length_field = TRB_LEN(urb->transfer_buffer_length) |
780 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
781 xhci_td_remainder(urb->transfer_buffer_length) |
783 + //CC: MTK style, no scatter-gather for control transfer
787 if (urb->transfer_buffer_length > 0) {
788 if (setup->bRequestType & USB_DIR_IN)
789 @@ -3533,7 +3609,7 @@
791 field | ep_ring->cycle_state);
795 /* Save the DMA address of the last TRB in the TD */
796 td->last_trb = ep_ring->enqueue;
798 @@ -3645,6 +3721,9 @@
799 u64 start_addr, addr;
801 bool more_trbs_coming;
802 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
806 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
808 @@ -3658,6 +3737,21 @@
809 start_trb = &ep_ring->enqueue->generic;
810 start_cycle = ep_ring->cycle_state;
812 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
813 + switch(urb->dev->speed){
814 + case USB_SPEED_SUPER:
815 + max_packet = urb->ep->desc.wMaxPacketSize;
817 + case USB_SPEED_HIGH:
818 + case USB_SPEED_FULL:
819 + case USB_SPEED_LOW:
820 + case USB_SPEED_WIRELESS:
821 + case USB_SPEED_UNKNOWN:
822 + max_packet = urb->ep->desc.wMaxPacketSize & 0x7ff;
827 urb_priv = urb->hcpriv;
828 /* Queue the first TRB, even if it's zero-length */
829 for (i = 0; i < num_tds; i++) {
830 @@ -3729,9 +3823,13 @@
832 td->last_trb = ep_ring->enqueue;
834 +#if defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
835 + if (!(xhci->quirks & XHCI_AVOID_BEI)) {
837 if (xhci->hci_version == 0x100 &&
841 /* Set BEI bit except for the last td */
844 @@ -3746,6 +3844,7 @@
845 trb_buff_len = td_remain_len;
847 /* Set the TRB length, TD size, & interrupter fields. */
848 +#if !defined (CONFIG_USB_MT7621_XHCI_PLATFORM)
849 if (xhci->hci_version < 0x100) {
850 remainder = xhci_td_remainder(
851 td_len - running_total);
852 @@ -3755,6 +3854,10 @@
853 total_packet_count, urb,
854 (trbs_per_td - j - 1));
857 + remainder = mtk_xhci_td_remainder(urb->transfer_buffer_length, running_total, max_packet, trb_buff_len);
860 length_field = TRB_LEN(trb_buff_len) |