Skip to contentSkip to conversation

usb: add MediaTek USB3 DRD driver

PATCH Superseded Chunfeng Yun 2 participants 7 messages Oct 14, 2020 – Oct 16, 2020

Subsystems (3)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Chunfeng Yun

author maintainer
#0 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

---
v9:
1. replace tab by space for macro in mtu3.h suggested by Marek
2. add Acked-by Bin

v8: Simplify Kconfig suggested by Bin

v7: use xhci quirk flag XHCI_MTK_HOST

v6: no changes

v5: change condition of readl_poll_timeout() when check clocks

v4:
1. remove unused member @busy and @wedged, use their flags instead
2. support force_vbus mode
3. add a glue driver using UCLASS_NOP
4. add host driver, and rebuild host flow

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           |  44 ++
 drivers/usb/mtu3/Makefile          |  11 +
 drivers/usb/mtu3/mtu3.h            | 423 +++++++++++++
 drivers/usb/mtu3/mtu3_core.c       | 838 ++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_dr.h         |  52 ++
 drivers/usb/mtu3/mtu3_gadget.c     | 686 +++++++++++++++++++++
 drivers/usb/mtu3/mtu3_gadget_ep0.c | 933 +++++++++++++++++++++++++++++
 drivers/usb/mtu3/mtu3_host.c       | 141 +++++
 drivers/usb/mtu3/mtu3_hw_regs.h    | 515 ++++++++++++++++
 drivers/usb/mtu3/mtu3_plat.c       | 368 ++++++++++++
 drivers/usb/mtu3/mtu3_qmu.c        | 504 ++++++++++++++++
 drivers/usb/mtu3/mtu3_qmu.h        |  37 ++
 14 files changed, 4555 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 5390c93f21..7379fb5db8 100644
@@ -795,6 +795,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 34881a12b8..fedc0134f5 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 +44 -0

44 lines not on this page · raw message

drivers/usb/mtu3/Makefile new file +11 -0
new file mode 100644
index 0000000000..234f3a380a
@@ -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 +423 -0

423 lines not on this page · raw message

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

838 lines not on this page · raw message

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

52 lines not on this page · raw message

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

686 lines not on this page · raw message

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

931 lines not on this page · raw message

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

141 lines not on this page · raw message

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

515 lines not on this page · raw message

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

368 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 0000000000..ba8a3aa309

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
2.18.0

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

#1 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Quoted 3 lines · Chunfeng Yun

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next , and also, u-boot-usb/next does not build:

https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/jobs/163995

author maintainer
#2 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Quoted 7 lines · Marek Vasut
Quoted 3 lines · Chunfeng Yun

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next , and also, u-boot-usb/next does not build:

There is error:
aarch64: + mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function `usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to `dm_usb_gadget_handle_interrupts'

It seems that the gadget of mtu3 is not enabled, but the default mode is gadget mode, not sure why not works.

I sent a patch to try to fix it:

https://patchwork.ozlabs.org/project/uboot/patch/1602678229-19372-1-git-send-email-chunfeng.yun at mediatek.com/
configs: mt8512: enable device mode of mtu3 explicitly

Sorry for inconvenience

Quoted 2 lines

https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/jobs/163995

#3 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Quoted 19 lines · Chunfeng Yun
Quoted 7 lines · Marek Vasut
Quoted 3 lines · Chunfeng Yun

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next , and also, u-boot-usb/next does not build:

There is error:
aarch64: + mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function `usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to `dm_usb_gadget_handle_interrupts'

It seems that the gadget of mtu3 is not enabled, but the default mode is gadget mode, not sure why not works.

Quoted 7 lines

I sent a patch to try to fix it:

https://patchwork.ozlabs.org/project/uboot/patch/1602678229-19372-1-git-send-email-chunfeng.yun at mediatek.com/
configs: mt8512: enable device mode of mtu3 explicitly

Sorry for inconvenience

That's fine, but can you please rebase this on usb/next and resend, so I can apply it ?

Also, you can use either of the travis/gitlab CI to build-test the patches before submitting them.

author maintainer
#4 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Hi Marek,

Quoted 8 lines · Marek Vasut
Quoted 7 lines · Chunfeng Yun
Quoted 6 lines · Marek Vasut
Quoted 3 lines · Chunfeng Yun

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next ,

This may cause u-boot-usb/next build error, due to no gadget driver is built, because I enabled the following configs in patch 764751784727 ("configs: mt8512: enable fastboot and USB host related configs"):
CONFIG_DM_USB_GADGET=y
CONFIG_USB_MTU3=y
CONFIG_USB_GADGET=y

but the mtu3 driver is not yet applied in u-boot-usb/next (although CONFIG_USB_MTU3 is enabled); and
CONFIG_DM_USB_GADGET requires a gadget driver to define dm_usb_gadget_handle_interrupts(), then the build error happened.

Quoted 10 lines

and also,

Quoted 9 lines
Quoted 1 line

u-boot-usb/next does not build:

There is error:
aarch64: + mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function `usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to `dm_usb_gadget_handle_interrupts'

Quoted 2 lines
Quoted 2 lines

It seems that the gadget of mtu3 is not enabled, but the default mode is gadget mode, not sure why not works.

I tested it again, and look at the CI pipeline 4997, the mtu3 driver is not applied into u-boot-usb/next, so will build error.

Please apply the following patch to u-boot-usb/next, it will build pass:
https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng.yun at mediatek.com/ [RESEND,v9] usb: add MediaTek USB3 DRD driver

The following patch is not needed anymore, please ignore it
https://patchwork.ozlabs.org/project/uboot/patch/1602680044-19794-1-git-send-email-chunfeng.yun at mediatek.com/ [v2] configs: mt8512: enable device mode of mtu3 explicitly

Thanks a lot

Quoted 14 lines
Quoted 8 lines

I sent a patch to try to fix it:

https://patchwork.ozlabs.org/project/uboot/patch/1602678229-19372-1-git-send-email-chunfeng.yun at mediatek.com/
configs: mt8512: enable device mode of mtu3 explicitly

Sorry for inconvenience

That's fine, but can you please rebase this on usb/next and resend, so I can apply it ?

Also, you can use either of the travis/gitlab CI to build-test the patches before submitting them.

#5 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Quoted 1 line · Chunfeng Yun

Hi Marek,

Hi,

Quoted 36 lines · Marek Vasut
Quoted 8 lines · Chunfeng Yun
Quoted 7 lines · Marek Vasut
Quoted 6 lines · Chunfeng Yun
Quoted 3 lines

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next ,

This may cause u-boot-usb/next build error, due to no gadget driver is built, because I enabled the following configs in patch 764751784727 ("configs: mt8512: enable fastboot and USB host related configs"):
CONFIG_DM_USB_GADGET=y
CONFIG_USB_MTU3=y
CONFIG_USB_GADGET=y

but the mtu3 driver is not yet applied in u-boot-usb/next (although CONFIG_USB_MTU3 is enabled); and
CONFIG_DM_USB_GADGET requires a gadget driver to define dm_usb_gadget_handle_interrupts(), then the build error happened.

Quoted 10 lines

and also,

Quoted 9 lines
Quoted 1 line

u-boot-usb/next does not build:

There is error:
aarch64: + mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function `usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to `dm_usb_gadget_handle_interrupts'

Quoted 2 lines
Quoted 2 lines

It seems that the gadget of mtu3 is not enabled, but the default mode is gadget mode, not sure why not works.

I tested it again, and look at the CI pipeline 4997, the mtu3 driver is not applied into u-boot-usb/next, so will build error.

Quoted 8 lines

Please apply the following patch to u-boot-usb/next, it will build pass:
https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng.yun at mediatek.com/ [RESEND,v9] usb: add MediaTek USB3 DRD driver

The following patch is not needed anymore, please ignore it
https://patchwork.ozlabs.org/project/uboot/patch/1602680044-19794-1-git-send-email-chunfeng.yun at mediatek.com/ [v2] configs: mt8512: enable device mode of mtu3 explicitly

OK, so, please rebase whatever is left on top of usb/next and resend. This patch does not apply on top of usb/next, sorry.

author maintainer
#6 lore raw

PATCH v9 1/1 usb: add MediaTek USB3 DRD driver

Quoted 46 lines · Marek Vasut
Quoted 1 line · Chunfeng Yun

Hi Marek,

Hi,

Quoted 41 lines · Marek Vasut
Quoted 8 lines · Chunfeng Yun
Quoted 7 lines · Marek Vasut
Quoted 6 lines · Chunfeng Yun
Quoted 3 lines

This patch adds support for the MediaTek USB3 DRD controller, its host side is based on xHCI, this driver supports device mode and host mode.

This patch doesn't seem to apply to u-boot-usb/next ,

This may cause u-boot-usb/next build error, due to no gadget driver is built, because I enabled the following configs in patch 764751784727 ("configs: mt8512: enable fastboot and USB host related configs"):
CONFIG_DM_USB_GADGET=y
CONFIG_USB_MTU3=y
CONFIG_USB_GADGET=y

but the mtu3 driver is not yet applied in u-boot-usb/next (although CONFIG_USB_MTU3 is enabled); and
CONFIG_DM_USB_GADGET requires a gadget driver to define dm_usb_gadget_handle_interrupts(), then the build error happened.

Quoted 10 lines

and also,

Quoted 9 lines
Quoted 1 line

u-boot-usb/next does not build:

There is error:
aarch64: + mt8512_bm1_emmc
+aarch64-linux-ld.bfd: drivers/usb/gadget/udc/built-in.o: in function `usb_gadget_handle_interrupts':
+drivers/usb/gadget/udc/udc-uclass.c:56: undefined reference to `dm_usb_gadget_handle_interrupts'

Quoted 2 lines
Quoted 2 lines

It seems that the gadget of mtu3 is not enabled, but the default mode is gadget mode, not sure why not works.

I tested it again, and look at the CI pipeline 4997, the mtu3 driver is not applied into u-boot-usb/next, so will build error.

Please apply the following patch to u-boot-usb/next, it will build pass:
https://patchwork.ozlabs.org/project/uboot/patch/1602681717-20850-1-git-send-email-chunfeng.yun at mediatek.com/ [RESEND,v9] usb: add MediaTek USB3 DRD driver

Quoted 5 lines
Quoted 3 lines

The following patch is not needed anymore, please ignore it
https://patchwork.ozlabs.org/project/uboot/patch/1602680044-19794-1-git-send-email-chunfeng.yun at mediatek.com/ [v2] configs: mt8512: enable device mode of mtu3 explicitly

OK, so, please rebase whatever is left on top of usb/next and resend.

Ok, thanks

Quoted 1 line

This patch does not apply on top of usb/next, sorry.