Skip to contentSkip to conversation

Add support MediaTek USB3 DRD driver

PATCH Superseded Chunfeng Yun 1 participant 8 messages Jul 16, 2020

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

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Chunfeng Yun

author maintainer
#0 lore raw

v3 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.8-rc1

v3 changes:
1. add patch [5/7]
2. add udc_set_speed()
3. simplify some code flow

v2 changes:
1. simplify QMU operations

Chunfeng Yun (7):
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
usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller
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                       |  40 +-
 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/gadget/gadget_chips.h              |   8 +
 drivers/usb/mtu3/Kconfig                       |  45 ++
 drivers/usb/mtu3/Makefile                      |  11 +
 drivers/usb/mtu3/mtu3.h                        | 407 +++++++++++
 drivers/usb/mtu3/mtu3_core.c                   | 870 +++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_dr.h                     |  59 ++
 drivers/usb/mtu3/mtu3_gadget.c                 | 698 ++++++++++++++++++
 drivers/usb/mtu3/mtu3_gadget_ep0.c             | 933 +++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_host.c                   | 170 +++++
 drivers/usb/mtu3/mtu3_hw_regs.h                | 514 ++++++++++++++
 drivers/usb/mtu3/mtu3_plat.c                   | 248 +++++++
 drivers/usb/mtu3/mtu3_qmu.c                    | 504 +++++++++++++
 drivers/usb/mtu3/mtu3_qmu.h                    |  37 +
 include/linux/usb/ch9.h                        |   1 +
 21 files changed, 4681 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 v3 1/7 dt-binding: usb: add bindings for some common properties

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

---
v2~v3: no changes

---
 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 v3 2/7 dt-bindings: usb: mtu3: add bindings for MediaTek USB3 DRD

In reply to Chunfeng Yun

Add dt-binding for MediaTek USB3 DRD Driver

---
v2~v3: no changes

---
 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..eb14176
@@ -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 v3 3/7 usb: add USB_SPEED_SUPER_PLUS

In reply to Chunfeng Yun

Add enum USB_SPEED_SUPER_PLUS for USB3.1

---
v2~v3: no changes

---
 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 v3 4/7 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.

---
v3 changes
1. add ->udc_set_speed()
2. simplify some code flow

v2: simplify QMU operations

---
 Makefile                           |   1 +
 drivers/usb/Kconfig                |   2 +
 drivers/usb/mtu3/Kconfig           |  45 ++
 drivers/usb/mtu3/Makefile          |  11 +
 drivers/usb/mtu3/mtu3.h            | 407 ++++++++++++++++
 drivers/usb/mtu3/mtu3_core.c       | 870 ++++++++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_dr.h         |  59 +++
 drivers/usb/mtu3/mtu3_gadget.c     | 698 +++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 +++++++++++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_host.c       | 170 +++++++
 drivers/usb/mtu3/mtu3_hw_regs.h    | 514 ++++++++++++++++++++
 drivers/usb/mtu3/mtu3_plat.c       | 248 ++++++++++
 drivers/usb/mtu3/mtu3_qmu.c        | 504 ++++++++++++++++++++
 drivers/usb/mtu3/mtu3_qmu.h        |  37 ++
 14 files changed, 4499 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 f81e416..4434096 100644
@@ -793,6 +793,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 756a4ec..91d11f2 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 +407 -0

407 lines not on this page · raw message

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

870 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 +698 -0

698 lines not on this page · raw message

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

895 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 +514 -0

514 lines not on this page · raw message

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

248 lines not on this page · raw message

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

504 lines not on this page · raw message

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

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 v3 5/7 usb: gadget: Add bcdDevice for the MTU3 USB Gadget Controller

In reply to Chunfeng Yun

Add an entry in usb_gadget_controller_number() for the MTU3 gadget controller. It is used to bind the USB Ethernet driver.

---
v3: new patch

---
 drivers/usb/gadget/gadget_chips.h | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/gadget/gadget_chips.h +8 -0
index 91b0285..2dc4c47 100644
@@ -155,6 +155,12 @@
 #define gadget_is_cdns3(g)        0
 #endif
 
+#ifdef CONFIG_USB_MTU3_GADGET
+#define gadget_is_mtu3(g)        (!strcmp("mtu3-gadget", (g)->name))
+#else
+#define gadget_is_mtu3(g)        0
+#endif
+
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -216,5 +222,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
 		return 0x23;
 	else if (gadget_is_cdns3(gadget))
 		return 0x24;
+	else if (gadget_is_mtu3(gadget))
+		return 0x25;
 	return -ENOENT;
 }
Signature · 1 line
1.9.1
author maintainer
#6 lore raw

PATCH v3 6/7 arm: dts: mt8512: add usb related nodes

In reply to Chunfeng Yun

Add usb, usb phy nodes

---
v3: remove unused property mediatek,discth

v2: no changes

---
 arch/arm/dts/mt8512-bm1-emmc.dts | 10 ++++++++++
 arch/arm/dts/mt8512.dtsi         | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 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 +39 -1
index 01a02a7..730fec1 100644
@@ -9,6 +9,7 @@
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/phy/phy.h>
 
 / {
 	compatible = "mediatek,mt8512";
@@ -100,6 +101,43 @@
 		status = "disabled";
 	};
 
+	ssusb: usb at 11211000 {
+		compatible = "mediatek,mt8512-mtu3", "mediatek,mtu3";
+		reg = <0x11211000 0x2dff>,
+		      <0x11213e00 0x0100>;
+		reg-names = "mac", "ippc";
+		interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_LOW>;
+		phys = <&u2port0 PHY_TYPE_USB2>;
+		clocks = <&infracfg CLK_INFRA_USB_SYS>,
+			 <&topckgen CLK_TOP_SSUSB_TOP_CK_EN>,
+			 <&infracfg CLK_INFRA_ICUSB>;
+		clock-names = "sys_ck", "ref_ck", "mcu_ck";
+		status = "disabled";
+	};
+
+	u3phy: usb-phy at 11cc0000 {
+		compatible = "mediatek,mt8512-tphy",
+			     "mediatek,generic-tphy-v2";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+		status = "disabled";
+
+		u2port0: usb-phy at 11cc0000 {
+			reg = <0x11cc0000 0x400>;
+			clocks = <&topckgen CLK_TOP_USB20_48M_EN>;
+			clock-names = "ref";
+			#phy-cells = <1>;
+			status = "okay";
+		};
+
+		u2port1: usb-phy at 11c40000 {
+			reg = <0x11c40000 0x400>;
+			#phy-cells = <1>;
+			status = "okay";
+		};
+	};
+
 	mmc0: mmc at 11230000 {
 		compatible = "mediatek,mt8512-mmc";
 		reg = <0x11230000 0x1000>,
@@ -112,4 +150,4 @@
 		status = "disabled";
 	};
 
-};
\ No newline at end of file
+};
Signature · 1 line
1.9.1
author maintainer
#7 lore raw

PATCH v3 7/7 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.

---
v2~v3: no changes

---
 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