Skip to contentSkip to conversation

Add support MediaTek USB3 DRD driver

PATCH Superseded Chunfeng Yun 1 participant 7 messages Jun 5, 2020

Subsystems (5)
Arm (32-bit) USB Kbuild Arm MediaTek +1 more subsystems

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Chunfeng Yun

author maintainer
#0 lore raw

cover Add support MediaTek USB3 DRD driver

These patches introduce the MediaTek USB3 Dual-Role Controller driver.
The driver can be configured as Dual-Role Device, Peripheral only and Host only(xHCI) modes, and it's ported from Linux Kernel 5.7-rc1

Chunfeng Yun (6):
dt-binding: usb: add bindings for some common properties
dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD
usb: add USB_SPEED_SUPER_PLUS
usb: add MediaTek USB3 DRD driver
arm: dts: mt8512: add usb related nodes
configs: mt8512: enable fastboot

 Makefile                                       |   1 +
 arch/arm/dts/mt8512-bm1-emmc.dts               |  10 +
 arch/arm/dts/mt8512.dtsi                       |  41 +-
 configs/mt8512_bm1_emmc_defconfig              |  19 +
 doc/device-tree-bindings/usb/generic.txt       |  31 +
 doc/device-tree-bindings/usb/mediatek,mtu3.txt |  74 ++
 drivers/usb/Kconfig                            |   2 +
 drivers/usb/mtu3/Kconfig                       |  45 ++
 drivers/usb/mtu3/Makefile                      |  11 +
 drivers/usb/mtu3/mtu3.h                        | 405 +++++++++++
 drivers/usb/mtu3/mtu3_core.c                   | 867 +++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_dr.h                     |  59 ++
 drivers/usb/mtu3/mtu3_gadget.c                 | 707 +++++++++++++++++++
 drivers/usb/mtu3/mtu3_gadget_ep0.c             | 933 +++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_host.c                   | 170 +++++
 drivers/usb/mtu3/mtu3_hw_regs.h                | 524 ++++++++++++++
 drivers/usb/mtu3/mtu3_plat.c                   | 251 +++++++
 drivers/usb/mtu3/mtu3_qmu.c                    | 602 ++++++++++++++++
 drivers/usb/mtu3/mtu3_qmu.h                    |  38 +
 include/linux/usb/ch9.h                        |   1 +
 20 files changed, 4790 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
 create mode 100644 drivers/usb/mtu3/Kconfig
 create mode 100644 drivers/usb/mtu3/Makefile
 create mode 100644 drivers/usb/mtu3/mtu3.h
 create mode 100644 drivers/usb/mtu3/mtu3_core.c
 create mode 100644 drivers/usb/mtu3/mtu3_dr.h
 create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
 create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
 create mode 100644 drivers/usb/mtu3/mtu3_host.c
 create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
 create mode 100644 drivers/usb/mtu3/mtu3_plat.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH 1/6 dt-binding: usb: add bindings for some common properties

Add bindings for common properties, include maximum-speed, dr_mode and phy_type

---
 doc/device-tree-bindings/usb/generic.txt | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/generic.txt
doc/device-tree-bindings/usb/generic.txt new file +31 -0
new file mode 100644
index 0000000..a02a198
@@ -0,0 +1,31 @@
+Generic USB Properties
+
+Optional properties:
+ - maximum-speed: tells USB controllers we want to work up to a certain
+			speed. Valid arguments are "super-speed-plus",
+			"super-speed", "high-speed", "full-speed" and
+			"low-speed". In case this isn't passed via DT, USB
+			controllers should default to their maximum HW
+			capability.
+ - dr_mode: tells Dual-Role USB controllers that we want to work on a
+			particular mode. Valid arguments are "host",
+			"peripheral" and "otg". In case this attribute isn't
+			passed via DT, USB DRD controllers should default to
+			OTG.
+ - phy_type: tells USB controllers that we want to configure the core to support
+			a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+			selected. Valid arguments are "utmi" and "utmi_wide".
+			In case this isn't passed via DT, USB controllers should
+			default to HW capability.
+
+This is an attribute to a USB controller such as:
+
+dwc3 at 4a030000 {
+	compatible = "synopsys,dwc3";
+	reg = <0x4a030000 0xcfff>;
+	interrupts = <0 92 4>
+	usb-phy = <&usb2_phy>, <&usb3,phy>;
+	maximum-speed = "super-speed";
+	dr_mode = "otg";
+	phy_type = "utmi_wide";
+};
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

PATCH 2/6 dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

In reply to Chunfeng Yun

Add dt-binding for MediaTek USB3 DRD Driver

---
 doc/device-tree-bindings/usb/mediatek,mtu3.txt | 74 ++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtu3.txt
doc/device-tree-bindings/usb/mediatek,mtu3.txt new file +74 -0
new file mode 100644
index 0000000..75a6785
@@ -0,0 +1,74 @@
+The device node for Mediatek USB3.0 DRD controller
+
+Required properties:
+ - compatible : should be "mediatek,<soc-model>-mtu3", "mediatek,mtu3",
+	soc-model is the name of SoC, such as mt8512 etc,
+	when using "mediatek,mtu3" compatible string, you need SoC specific
+	ones in addition, one of:
+	- "mediatek,mt8512-mtu3"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be
+ 	- "mac" : device IP,
+	- "ippc" : IP port control
+ - interrupts : interrupt used by the device IP
+ - 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 controller,
+	the following clocks are optional:
+	"ref_ck", "mcu_ck" and "dma_ck";
+ - phys : list of all the USB PHYs on this HCD
+ - dr_mode : should be one of "host", "peripheral" or "otg",
+	see : usb/generic.txt
+
+Optional properties:
+ - #address-cells, #size-cells : should be '2' if the device has sub-nodes
+	with 'reg' property
+ - ranges : allows valid 1:1 translation between child's address space and
+	parent's address space
+ - vbus-supply : reference to the VBUS regulator, needed when supports
+	dual-role mode.
+ - pinctrl-names : a pinctrl state named "default" is optional
+ - pinctrl-0 : pin control group
+	See: pinctrl/pinctrl-bindings.txt
+
+ - maximum-speed : valid arguments are "full-speed", "high-speed",
+	"super-speed" and "super-speed-plus",
+	see: usb/generic.txt.
+
+Sub-nodes:
+The xhci should be added as subnode to mtu3 as shown in the following example
+if host mode is enabled. The DT binding details of xhci can be found in:
+	- usb/mediatek,mtk-xhci.txt
+
+Example:
+ssusb: usb at 11271000 {
+	compatible = "mediatek,mt8173-mtu3", "mediatek,mtu3";
+	reg = <0 0x11271000 0 0x3000>,
+	      <0 0x11280700 0 0x0100>;
+	reg-names = "mac", "ippc";
+	interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_LOW>;
+	phys = <&phy_port0 PHY_TYPE_USB3>,
+	       <&phy_port1 PHY_TYPE_USB2>;
+	power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>;
+	clocks = <&topckgen CLK_TOP_USB30_SEL>, <&clk26m>;
+	clock-names = "sys_ck", "ref_ck";
+	vusb33-supply = <&mt6397_vusb_reg>;
+	vbus-supply = <&usb_p0_vbus>;
+	dr_mode = "otg";
+	#address-cells = <2>;
+	#size-cells = <2>;
+	ranges;
+
+	usb_host: xhci at 11270000 {
+		compatible = "mediatek,mt8173-xhci", "mediatek,mtk-xhci";
+		reg = <0 0x11270000 0 0x1000>;
+		reg-names = "mac";
+		interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>;
+		power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>;
+		clocks = <&topckgen CLK_TOP_USB30_SEL>, <&clk26m>;
+		clock-names = "sys_ck", "ref_ck";
+		vusb33-supply = <&mt6397_vusb_reg>;
+	};
+};
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH 3/6 usb: add USB_SPEED_SUPER_PLUS

In reply to Chunfeng Yun

Add enum USB_SPEED_SUPER_PLUS for USB3.1

---
 include/linux/usb/ch9.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/usb/ch9.h +1 -0
index 989a5fc..7d225ee 100644
@@ -956,6 +956,7 @@ enum usb_device_speed {
 	USB_SPEED_HIGH,				/* usb 2.0 */
 	USB_SPEED_WIRELESS,			/* wireless (usb 2.5) */
 	USB_SPEED_SUPER,			/* usb 3.0 */
+	USB_SPEED_SUPER_PLUS,			/* usb 3.1 */
 };
 
 #ifdef __KERNEL__
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

PATCH 4/6 usb: add MediaTek USB3 DRD driver

In reply to Chunfeng Yun

This patch adds support for the MediaTek USB3 DRD controller, its host side is based ont xHCI, but currently only device mode is supported.
Dual-Role Device and Host Only (xHCI) modes will be added when needed.

---
 Makefile                           |   1 +
 drivers/usb/Kconfig                |   2 +
 drivers/usb/mtu3/Kconfig           |  45 ++
 drivers/usb/mtu3/Makefile          |  11 +
 drivers/usb/mtu3/mtu3.h            | 405 ++++++++++++++++
 drivers/usb/mtu3/mtu3_core.c       | 867 ++++++++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_dr.h         |  59 +++
 drivers/usb/mtu3/mtu3_gadget.c     | 707 ++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 +++++++++++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_host.c       | 170 +++++++
 drivers/usb/mtu3/mtu3_hw_regs.h    | 524 +++++++++++++++++++++
 drivers/usb/mtu3/mtu3_plat.c       | 251 ++++++++++
 drivers/usb/mtu3/mtu3_qmu.c        | 602 ++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_qmu.h        |  38 ++
 14 files changed, 4615 insertions(+)
 create mode 100644 drivers/usb/mtu3/Kconfig
 create mode 100644 drivers/usb/mtu3/Makefile
 create mode 100644 drivers/usb/mtu3/mtu3.h
 create mode 100644 drivers/usb/mtu3/mtu3_core.c
 create mode 100644 drivers/usb/mtu3/mtu3_dr.h
 create mode 100644 drivers/usb/mtu3/mtu3_gadget.c
 create mode 100644 drivers/usb/mtu3/mtu3_gadget_ep0.c
 create mode 100644 drivers/usb/mtu3/mtu3_host.c
 create mode 100644 drivers/usb/mtu3/mtu3_hw_regs.h
 create mode 100644 drivers/usb/mtu3/mtu3_plat.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.c
 create mode 100644 drivers/usb/mtu3/mtu3_qmu.h
Makefile +1 -0
index bf4b983..b8c52cc 100644
@@ -797,6 +797,7 @@ libs-y += drivers/usb/eth/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
 libs-y += drivers/usb/host/
+libs-y += drivers/usb/mtu3/
 libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
 libs-y += drivers/usb/phy/
drivers/usb/Kconfig +2 -0
index 928a891..270306b 100644
@@ -72,6 +72,8 @@ source "drivers/usb/cdns3/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/mtu3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
drivers/usb/mtu3/Kconfig new file +45 -0

45 lines not on this page · raw message

drivers/usb/mtu3/Makefile new file +11 -0
new file mode 100644
index 0000000..234f3a3
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-$(CONFIG_USB_MTU3_DEBUG)	+= -DDEBUG
+
+obj-$(CONFIG_USB_MTU3)	+= mtu3.o
+
+mtu3-y	:= mtu3_plat.o
+
+obj-$(CONFIG_USB_MTU3_GADGET)	+= mtu3_core.o mtu3_gadget_ep0.o mtu3_gadget.o
+obj-$(CONFIG_USB_MTU3_GADGET)	+= mtu3_qmu.o
+obj-$(CONFIG_USB_MTU3_HOST)	+= mtu3_host.o
drivers/usb/mtu3/mtu3.h new file +405 -0

405 lines not on this page · raw message

drivers/usb/mtu3/mtu3_core.c new file +867 -0

867 lines not on this page · raw message

drivers/usb/mtu3/mtu3_dr.h new file +59 -0

59 lines not on this page · raw message

drivers/usb/mtu3/mtu3_gadget.c new file +707 -0

707 lines not on this page · raw message

drivers/usb/mtu3/mtu3_gadget_ep0.c new file +933 -0

891 lines not on this page · raw message

drivers/usb/mtu3/mtu3_host.c new file +170 -0

170 lines not on this page · raw message

drivers/usb/mtu3/mtu3_hw_regs.h new file +524 -0

524 lines not on this page · raw message

drivers/usb/mtu3/mtu3_plat.c new file +251 -0

251 lines not on this page · raw message

drivers/usb/mtu3/mtu3_qmu.c new file +602 -0

602 lines not on this page · raw message

drivers/usb/mtu3/mtu3_qmu.h new file +38 -0
new file mode 100644
index 0000000..d341efc

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.1

Part of the diff is not shown here. View the raw message.

author maintainer
#5 lore raw

PATCH 5/6 arm: dts: mt8512: add usb related nodes

In reply to Chunfeng Yun

Add usb, usb phy nodes

---
 arch/arm/dts/mt8512-bm1-emmc.dts | 10 ++++++++++
 arch/arm/dts/mt8512.dtsi         | 41 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)
arch/arm/dts/mt8512-bm1-emmc.dts +10 -0
index 296ed93..0788e05 100644
@@ -95,6 +95,16 @@
 		};
 };
 
+&ssusb {
+	dr_mode = "peripheral";
+	maximum-speed = "high-speed";
+	status = "okay";
+};
+
+&u3phy {
+	status = "okay";
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_pins>;
arch/arm/dts/mt8512.dtsi +40 -1

57 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#6 lore raw

PATCH 6/6 configs: mt8512: enable fastboot

In reply to Chunfeng Yun

Enable fastboot to support download image from usb, also enable usb related drivers, such as usb phy etc.

---
 configs/mt8512_bm1_emmc_defconfig | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
configs/mt8512_bm1_emmc_defconfig +19 -0
index e7659d7..bdcd06a 100644
@@ -13,6 +13,7 @@ CONFIG_DEFAULT_FDT_FILE="mt8512-bm1-emmc.dtb"
 CONFIG_SYS_PROMPT="MT8512> "
 CONFIG_CMD_BOOTMENU=y
 CONFIG_CMD_MMC=y
+CONFIG_EFI_PARTITION=y
 CONFIG_DEFAULT_DEVICE_TREE="mt8512-bm1-emmc"
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
@@ -25,6 +26,15 @@ CONFIG_PINCONF=y
 CONFIG_PINCTRL_MT8512=y
 CONFIG_RAM=y
 CONFIG_BAUDRATE=921600
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x56000000
+CONFIG_FASTBOOT_BUF_SIZE=0x1e00000
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT=y
+CONFIG_PHY=y
+CONFIG_PHY_MTK_TPHY=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_SERIAL=y
 CONFIG_MTK_SERIAL=y
 CONFIG_TIMER=y
@@ -32,3 +42,12 @@ CONFIG_MTK_TIMER=y
 CONFIG_WDT=y
 CONFIG_WDT_MTK=y
 CONFIG_LZO=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_DM_USB_GADGET=y
+CONFIG_USB_MTU3=y
+CONFIG_USB_MTU3_GADGET=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="MediaTek"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0e8d
+CONFIG_USB_GADGET_PRODUCT_NUM=0x201c
Signature · 1 line
1.9.1