Mediatek xHCI support
Subsystems (5)
Chunfeng Yun
maintainerv11 cover Mediatek xHCI support
Quoted 1 line
From
1c6e0dd39074297ebb0714c1d44a3e0dc9af466cMon Sep 17 00:00:00 2001
From: Chunfeng Yun <[email protected]>
Date: Mon, 19 Oct 2015 14:13:45 +0800
Subject: [PATCH v11 0/3] Mediatek xHCI support
The patch supports MediaTek's xHCI controller.
There are some differences from xHCI spec:
1. The interval is specified in 250 * 8ns increments for Interrupt Moderation Interval(IMODI) of the Interrupter Moderation(IMOD) register, it is 8 times as much as that defined in xHCI spec.
2. For the value of TD Size in Normal TRB, MTK's xHCI controller defines a number of packets that remain to be transferred for a TD after processing all Max packets in all previous TRBs,that means don't include the current TRB's, but in xHCI spec it includes the current ones.
3. To minimize the scheduling effort for synchronous endpoints in xHC, the MTK architecture defines some extra SW scheduling parameters for HW. According to these parameters provided by SW, the xHC can easily decide whether a synchronous endpoint should be scheduled in a specific uFrame. The extra SW scheduling parameters are put into reserved DWs in Slot and Endpoint Context. And a bandwidth scheduler algorithm is added to support such feature.
A usb3.0 phy driver is also added which used by mt65xx SoCs platform, it supports two usb2.0 ports and one usb3.0 port.
depend on the patch for TDS calculation:
https://patchwork.kernel.org/patch/7140041/
change in v11:
1. remove some dummy header files
2. call xhci_mtk_sch_exit() when primary hcd register fail
3. use false instead of 0 for the second parameter of device_init_wakeup();
Change in v10:
1. simplify clock stability checks
2. put MTK xHCI configuration from xhci_mtk_probe() to xhci_mtk_setup()
Change in v9:
1. fix up issue of FS out-iso when use single-TT hub
2. improve RX sensitivity
3. remove udelay(800) called by phy_instance_power_on/off
Change in v8:
1. use struct overlay for ippc register
2. change usb wakeup as optional feature
3. add TDS quirk into unified TDS calculation function
Change in v7:
1. remove xHCI timing setting which only for FPGA
2. revise xHCI scheduler algorithms
3. replace "usb" by "USB" in xHCI binding file
Change in v6:
1. get register base address of port in probe instead of of_xlate
2. enable clock in phy_init instead of probe
Change in v5:
1. descripte more exactly for each specifiers in xHCI binding
2. make use of new multi-phy feature for phy driver
Change in v4:
1. descripte more exactly for each specifiers in binding file
2. use BIT() to define a bit mask macro
Change in v3:
1. implement generic phy
2. move opperations of IPPC and wakeup from phy driver to xHCI driver
3. seperate quirk functions into a single C file to fix up dependence issue
Change in v2:
1. Rebase to 4.2-rc1
2. Remove probe phy before add usb_hcd patch from this series due to 4.2-rc1 already fix this issue
3. add xhci mac clocks
4. add suspend/resume
5. support remote wakeup
Chunfeng Yun (3):
dt-bindings: Add a binding for Mediatek xHCI host controller
xhci: mediatek: support MTK xHCI host controller
arm64: dts: mediatek: add xHCI & usb phy for mt8173
.../devicetree/bindings/usb/mt8173-xhci.txt | 51 ++ arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 16 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 42 ++ drivers/usb/host/Kconfig | 9 + drivers/usb/host/Makefile | 4 + drivers/usb/host/xhci-mtk-sch.c | 415 +++++++++++ drivers/usb/host/xhci-mtk.c | 762 +++++++++++++++++++++ drivers/usb/host/xhci-mtk.h | 162 +++++ drivers/usb/host/xhci-ring.c | 16 +- drivers/usb/host/xhci.c | 19 +- drivers/usb/host/xhci.h | 1 + 11 files changed, 1491 insertions(+), 6 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt create mode 100644 drivers/usb/host/xhci-mtk-sch.c create mode 100644 drivers/usb/host/xhci-mtk.c create mode 100644 drivers/usb/host/xhci-mtk.h
--
1.8.1.1.dirty
Chunfeng Yun
maintainerPATCH v11 1/3 dt-bindings: Add a binding for Mediatek xHCI host controller
add a DT binding documentation of xHCI host controller for the MT8173 SoC from Mediatek.
--- .../devicetree/bindings/usb/mt8173-xhci.txt | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mt8173-xhci.txt
Documentation/devicetree/bindings/usb/mt8173-xhci.txt new file +51 -0
@@ -0,0 +1,51 @@ +MT8173 xHCI + +The device node for Mediatek SOC USB3.0 host controller + +Required properties: + - compatible : should contain "mediatek,mt8173-xhci" + - reg : specifies physical base address and size of the registers, + the first one for MAC, the second for IPPC + - interrupts : interrupt used by the controller + - power-domains : a phandle to USB power domain node to control USB's + mtcmos + - vusb33-supply : regulator of USB avdd3.3v + + - clocks : a list of phandle + clock-specifier pairs, one for each + entry in clock-names + - clock-names : must contain + "sys_ck": for clock of xHCI MAC + "wakeup_deb_p0": for USB wakeup debounce clock of port0 + "wakeup_deb_p0": for USB wakeup debounce clock of port1 + + - phys : a list of phandle + phy specifier pairs + - usb3-lpm-capable : supports USB3.0 LPM + +Optional properties: + - mediatek,wakeup-src : 1: ip sleep wakeup mode; 2: line state wakeup + mode; + - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup + control register, it depends on "mediatek,wakeup-src". + - vbus-supply : reference to the VBUS regulator; + +Example: +usb30: usb at 11270000 { + compatible = "mediatek,mt8173-xhci"; + reg = <0 0x11270000 0 0x1000>, + <0 0x11280700 0 0x0100>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, + <&pericfg CLK_PERI_USB0>, + <&pericfg CLK_PERI_USB1>; + clock-names = "sys_ck", + "wakeup_deb_p0", + "wakeup_deb_p1"; + phys = <&phy_port0 PHY_TYPE_USB3>, + <&phy_port1 PHY_TYPE_USB2>; + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; + usb3-lpm-capable; + mediatek,syscon-wakeup = <&pericfg>; + mediatek,wakeup-src = <1>; +};
Signature · 1 line
1.8.1.1.dirty
Chunfeng Yun
maintainerPATCH v11 2/3 xhci: mediatek: support MTK xHCI host controller
In reply to Chunfeng YunThere some vendor quirks for MTK xhci host controller:
1. It defines some extra SW scheduling parameters for HW to minimize the scheduling effort for synchronous and interrupt endpoints. The parameters are put into reseved DWs of slot context and endpoint context.
2. Its IMODI unit for Interrupter Moderation register is 8 times as much as that defined in xHCI spec.
3. Its TDS in Normal TRB defines a number of packets that remains to be transferred for a TD after processing all Max packets in all previous TRBs.
--- drivers/usb/host/Kconfig | 9 + drivers/usb/host/Makefile | 4 + drivers/usb/host/xhci-mtk-sch.c | 415 ++++++++++++++++++++++ drivers/usb/host/xhci-mtk.c | 762 ++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci-mtk.h | 162 +++++++++ drivers/usb/host/xhci-ring.c | 16 +- drivers/usb/host/xhci.c | 19 +- drivers/usb/host/xhci.h | 1 + 8 files changed, 1382 insertions(+), 6 deletions(-) create mode 100644 drivers/usb/host/xhci-mtk-sch.c create mode 100644 drivers/usb/host/xhci-mtk.c create mode 100644 drivers/usb/host/xhci-mtk.h
drivers/usb/host/Kconfig +9 -0
@@ -41,6 +41,15 @@ config USB_XHCI_PLATFORM If unsure, say N. +config USB_XHCI_MTK + tristate "xHCI support for Mediatek MT65xx" + select MFD_SYSCON + depends on ARCH_MEDIATEK || COMPILE_TEST + ---help--- + Say 'Y' to enable the support for the xHCI host controller + found in Mediatek MT65xx SoCs. + If unsure, say N. + config USB_XHCI_MVEBU tristate "xHCI support for Marvell Armada 375/38x" select USB_XHCI_PLATFORM
drivers/usb/host/Makefile +4 -0
@@ -13,6 +13,9 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o xhci-hcd-y := xhci.o xhci-mem.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o xhci-hcd-y += xhci-trace.o +ifneq ($(CONFIG_USB_XHCI_MTK), ) + xhci-hcd-y += xhci-mtk-sch.o +endif xhci-plat-hcd-y := xhci-plat.o ifneq ($(CONFIG_USB_XHCI_MVEBU), )
@@ -30,6 +33,7 @@ endif obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o +obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
drivers/usb/host/xhci-mtk-sch.c new file +415 -0
415 lines not on this page · raw message
drivers/usb/host/xhci-mtk.c new file +762 -0
762 lines not on this page · raw message
drivers/usb/host/xhci-mtk.h new file +162 -0
162 lines not on this page · raw message
drivers/usb/host/xhci-ring.c +11 -5
@@ -68,6 +68,7 @@#include <linux/slab.h> #include "xhci.h" #include "xhci-trace.h" +#include "xhci-mtk.h" /* * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA
@@ -3045,17 +3046,22 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, {u32 maxp, total_packet_count; -if (xhci->hci_version <0x100 ) +/* MTK xHCI is mostly 0.97 but contains some features from 1.0 */ +if (xhci->hci_version <0x100 && !(xhci->quirks &XHCI_MTK_HOST ))return ((td_total_len - transferred) >>10 ); - maxp =GET_MAX_PACKET (usb_endpoint_maxp (&urb->ep->desc)); - total_packet_count =DIV_ROUND_UP (td_total_len, maxp); -/* One TRB with a zero-length data packet. */ if (num_trbs_left ==0 || (transferred ==0 && trb_buff_len ==0 ) || trb_buff_len == td_total_len)return 0 ; +/* for MTK xHCI, TD size doesn't include this TRB */ +if (xhci->quirks &XHCI_MTK_HOST ) + trb_buff_len =0 ; + + maxp =GET_MAX_PACKET (usb_endpoint_maxp (&urb->ep->desc)); + total_packet_count =DIV_ROUND_UP (td_total_len, maxp); +/* Queueing functions don't count the current TRB into transferred */ return (total_packet_count - ((transferred + trb_buff_len) / maxp)); }
@@ -3443,7 +3449,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field |=0x1 ;/* xHCI 1.0 6.4.1.2.1: Transfer Type field */ -if (xhci->hci_version ==0x100 ) { +if ((xhci->hci_version ==0x100 ) || (xhci->quirks &XHCI_MTK_HOST )) {if (urb->transfer_buffer_length >0 ) {if (setup->bRequestType &USB_DIR_IN ) field |=TRB_TX_TYPE (TRB_DATA_IN );
drivers/usb/host/xhci.c +18 -1
@@ -31,6 +31,7 @@#include "xhci.h" #include "xhci-trace.h" +#include "xhci-mtk.h" #define DRIVER_AUTHOR "Sarah Sharp"#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
@@ -623,7 +624,11 @@ int xhci_run(struct usb_hcd *hcd) "// Set the interrupt modulation register"); temp =readl (&xhci->ir_set->irq_control); temp &= ~ER_IRQ_INTERVAL_MASK ; - temp |= (u32 )160 ; +/* +* the increment interval is 8 times as much as that defined +* in xHCI spec on MTK's controller +*/ + temp |= (u32) ((xhci->quirks &XHCI_MTK_HOST ) ?20 :160 );writel (temp, &xhci->ir_set->irq_control);/* Set the HCD state before we enable the irqs */
@@ -1693,6 +1698,9 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,xhci_endpoint_zero (xhci, xhci->devs[udev->slot_id], ep); +if (xhci->quirks &XHCI_MTK_HOST ) +xhci_mtk_drop_ep_quirk (hcd, udev, ep); + xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", (unsigned int) ep->desc.bEndpointAddress, udev->slot_id,
@@ -1788,6 +1796,15 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,return -ENOMEM ; } +if (xhci->quirks &XHCI_MTK_HOST ) { + ret =xhci_mtk_add_ep_quirk (hcd, udev, ep); +if (ret <0 ) { +xhci_free_or_cache_endpoint_ring (xhci, + virt_dev, ep_index); +return ret; + } + } + ctrl_ctx->add_flags |=cpu_to_le32 (added_ctxs); new_add_flags =le32_to_cpu (ctrl_ctx->add_flags);
drivers/usb/host/xhci.h +1 -0
@@ -1577,6 +1577,7 @@ struct xhci_hcd {/* For controllers with a broken beyond repair streams implementation */ #define XHCI_BROKEN_STREAMS (1 << 19)#define XHCI_PME_STUCK_QUIRK (1 << 20) +#define XHCI_MTK_HOST (1 << 21)unsigned int num_active_eps;unsigned int limit_active_eps;/* There are two roothubs to keep track of bus suspend info for */
Signature · 1 line
1.8.1.1.dirty
Chunfeng Yun
maintainerPATCH v11 3/3 arm64: dts: mediatek: add xHCI & usb phy for mt8173
In reply to Chunfeng Yunadd xHCI and phy drivers for MT8173-EVB
--- arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 16 +++++++++++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 42 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173-evb.dts +16 -0
@@ -13,6 +13,7 @@ */ /dts-v1/; +#include <dt-bindings/gpio/gpio.h> #include "mt8173.dtsi" / {
@@ -32,6 +33,15 @@ }; chosen { }; + + usb_p1_vbus: regulator at 0 { + compatible = "regulator-fixed"; + regulator-name = "usb_vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + gpio = <&pio 130 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; }; &i2c1 {
@@ -390,3 +400,9 @@ &uart0 { status = "okay"; }; + +&usb30 { + vusb33-supply = <&mt6397_vusb_reg>; + vbus-supply = <&usb_p1_vbus>; + mediatek,wakeup-src = <1>; +};
arch/arm64/boot/dts/mediatek/mt8173.dtsi +42 -0
54 lines not on this page · raw message
Signature · 1 line
1.8.1.1.dirty