Skip to contentSkip to conversation

rk3399: enable dwc3 gadget and fastboot

PATCH New Kever Yang 4 participants 16 messages Sep 1, 2016 – Sep 12, 2017

Subsystems (4)
lore
Share & tools
lore

Kever Yang

author
#0 lore raw

v4 cover rk3399: enable dwc3 gadget and fastboot

This patch set enable rk3399 dwc3 controller and gadget driver for fastboot.

Changes in v4:
- parse DT for quirk, base address and maximum speed
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- remove utmi width DT parse from borad init
- Parse the DT for utmi+ interface width in dwc3 driver
- move the config into Kconfig file.

Changes in v2:
- parse dt for utmi width
- use a variable to identify utmi+ bus width instead of CONFIG MACRO
- remove config for USB2PHY UTMI BITS

Kever Yang (4):
rk3399: add a empty "sys_proto.h" header file
board: evb-rk3399: add api to support dwc3 gadget
usb: dwc3: add support for 16 bit UTMI+ interface
config: rk3399: add support for dwc3 gadget

 arch/arm/include/asm/arch-rockchip/sys_proto.h | 10 +++++
 board/rockchip/evb_rk3399/evb-rk3399.c         | 51 ++++++++++++++++++++++++++
 configs/evb-rk3399_defconfig                   | 17 +++++++++
 drivers/usb/dwc3/core.c                        | 19 ++++++++++
 drivers/usb/dwc3/core.h                        | 12 ++++++
 5 files changed, 109 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sys_proto.h
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v4 1/4 rk3399: add a empty "sys_proto.h" header file

driver/usb/dwc3/gadget.c need a "sys_proto.h" header file, add a empty one to make compile success.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-rockchip/sys_proto.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sys_proto.h
arch/arm/include/asm/arch-rockchip/sys_proto.h new file +10 -0
new file mode 100644
index 0000000..35423e1
@@ -0,0 +1,10 @@
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co.,Ltd
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _ASM_ARCH_SYS_PROTO_H
+#define _ASM_ARCH_SYS_PROTO_H
+
+#endif /* _ASM_ARCH_SYS_PROTO_H */
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 1/4 rk3399: add a empty "sys_proto.h" header file

Quoted 7 lines · Kever Yang

driver/usb/dwc3/gadget.c need a "sys_proto.h" header file, add a empty one to make compile success.

---

Quoted 7 lines

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-rockchip/sys_proto.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sys_proto.h

Applied to u-boot-rockchip/next, thanks!

author
#3 lore raw

PATCH v4 2/4 board: evb-rk3399: add api to support dwc3 gadget

In reply to Kever Yang

This patch add board_usb_init() and interrupt callback for dwc3 gadget.

---

Changes in v4:
- parse DT for quirk, base address and maximum speed

Changes in v3:
- remove utmi width DT parse from borad init

Changes in v2:
- parse dt for utmi width

 board/rockchip/evb_rk3399/evb-rk3399.c | 51 ++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +51 -0
index d394276..58bfa78 100644
@@ -7,6 +7,8 @@
 #include <dm.h>
 #include <dm/pinctrl.h>
 #include <asm/arch/periph.h>
+#include <usb.h>
+#include <dwc3-uboot.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -54,3 +56,52 @@ void dram_init_banksize(void)
 	gd->bd->bi_dram[0].start = 0x200000;
 	gd->bd->bi_dram[0].size = 0x80000000;
 }
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+	.index = 0,
+};
+
+int usb_gadget_handle_interrupts(void)
+{
+	dwc3_uboot_handle_interrupt(0);
+	return 0;
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+	const char *string;
+
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0) {
+		debug("%s dwc3 node not found\n", __func__);
+	} else {
+		dwc3_device_data.base = fdtdec_get_addr(blob, node, "reg");
+		dwc3_device_data.dis_u2_susphy_quirk =
+			fdtdec_get_int(blob, node,
+				       "snps,dis-u2-susphy-quirk", -1);
+
+		string = fdt_getprop(blob, node, "maximum-speed", NULL);
+		if (string) {
+			if (0 == strcmp(string, "super-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_SUPER;
+			else if (0 == strcmp(string, "high-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+			else if (0 == strcmp(string, "full-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_FULL;
+			else
+				debug("%s: Cannot decode speed'%s'\n", __func__,
+				      string);
+		} else {
+			dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+		}
+		/* Hardcode controller in peripheral mode */
+		dwc3_device_data.dr_mode = USB_DR_MODE_PERIPHERAL;
+	}
+
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif
Signature · 1 line
1.9.1
#4 lore raw

PATCH v4 2/4 board: evb-rk3399: add api to support dwc3 gadget

Quoted 75 lines · Kever Yang

This patch add board_usb_init() and interrupt callback for dwc3 gadget.

---

Changes in v4:
- parse DT for quirk, base address and maximum speed

Changes in v3:
- remove utmi width DT parse from borad init

Changes in v2:
- parse dt for utmi width

 board/rockchip/evb_rk3399/evb-rk3399.c | 51 ++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +41 -0
index d394276..58bfa78 100644
@@ -7,6 +7,8 @@
 #include <dm.h>
 #include <dm/pinctrl.h>
 #include <asm/arch/periph.h>
+#include <usb.h>
+#include <dwc3-uboot.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -54,3 +56,52 @@ void dram_init_banksize(void)
 	gd->bd->bi_dram[0].start = 0x200000;
 	gd->bd->bi_dram[0].size = 0x80000000;
 }
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+	.index = 0,
+};
+
+int usb_gadget_handle_interrupts(void)
+{
+	dwc3_uboot_handle_interrupt(0);
+	return 0;
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+	const char *string;
+
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0) {
+		debug("%s dwc3 node not found\n", __func__);
+	} else {
+		dwc3_device_data.base = fdtdec_get_addr(blob, node, "reg");
+		dwc3_device_data.dis_u2_susphy_quirk =
+			fdtdec_get_int(blob, node,
+				       "snps,dis-u2-susphy-quirk", -1);
+
+		string = fdt_getprop(blob, node, "maximum-speed", NULL);
+		if (string) {
+			if (0 == strcmp(string, "super-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_SUPER;
+			else if (0 == strcmp(string, "high-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+			else if (0 == strcmp(string, "full-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_FULL;
+			else
+				debug("%s: Cannot decode speed'%s'\n", __func__,
+				      string);

board/rockchip/evb_rk3399/evb-rk3399.c void dram_init_banksize(void) · line 107

Quoted 10 lines
board/rockchip/evb_rk3399/evb-rk3399.c +10 -0
+		} else {
+			dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+		}
+		/* Hardcode controller in peripheral mode */
+		dwc3_device_data.dr_mode = USB_DR_MODE_PERIPHERAL;
+	}
+
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif

So will every board have a copy of this exact code, verbatim ?

Signature · 2 lines
Best regards,
Marek Vasut
author
#5 lore raw

PATCH v4 2/4 board: evb-rk3399: add api to support dwc3 gadget

Hi Marek,

Quoted 79 lines · Marek Vasut
Quoted 78 lines · Kever Yang

This patch add board_usb_init() and interrupt callback for dwc3 gadget.

---

Changes in v4:
- parse DT for quirk, base address and maximum speed

Changes in v3:
- remove utmi width DT parse from borad init

Changes in v2:
- parse dt for utmi width

  board/rockchip/evb_rk3399/evb-rk3399.c | 51 ++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +45 -0
index d394276..58bfa78 100644
@@ -7,6 +7,8 @@
  #include <dm.h>
  #include <dm/pinctrl.h>
  #include <asm/arch/periph.h>
+#include <usb.h>
+#include <dwc3-uboot.h>
 
  DECLARE_GLOBAL_DATA_PTR;
 
@@ -54,3 +56,52 @@ void dram_init_banksize(void)
  	gd->bd->bi_dram[0].start = 0x200000;
  	gd->bd->bi_dram[0].size = 0x80000000;
  }
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+	.index = 0,
+};
+
+int usb_gadget_handle_interrupts(void)
+{
+	dwc3_uboot_handle_interrupt(0);
+	return 0;
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+	const char *string;
+
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0) {
+		debug("%s dwc3 node not found\n", __func__);
+	} else {
+		dwc3_device_data.base = fdtdec_get_addr(blob, node, "reg");
+		dwc3_device_data.dis_u2_susphy_quirk =
+			fdtdec_get_int(blob, node,
+				       "snps,dis-u2-susphy-quirk", -1);
+
+		string = fdt_getprop(blob, node, "maximum-speed", NULL);
+		if (string) {
+			if (0 == strcmp(string, "super-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_SUPER;
+			else if (0 == strcmp(string, "high-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+			else if (0 == strcmp(string, "full-speed"))
+				dwc3_device_data.maximum_speed = USB_SPEED_FULL;
+			else
+				debug("%s: Cannot decode speed'%s'\n", __func__,
+				      string);
+		} else {
+			dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+		}
+		/* Hardcode controller in peripheral mode */
Quoted 9 lines

board/rockchip/evb_rk3399/evb-rk3399.c void dram_init_banksize(void) · line 107

Quoted 7 lines
board/rockchip/evb_rk3399/evb-rk3399.c +6 -0
+		dwc3_device_data.dr_mode = USB_DR_MODE_PERIPHERAL;
+	}
+
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif

So will every board have a copy of this exact code, verbatim ?

Yes for rk3399 based board.
Not sure why you ask this question, but I guess you still want these parse happen in driver instead of board_init()?
I didn't make these code in dwc3 driver because other SoC dts are different now, they are init in platdata data structure.

To be honest, I want to make the upstream code to support rk3399 dwc3, but I don't want to touch too much code in other SoC.

Thanks,
- Kever

#6 lore raw

PATCH v4 2/4 board: evb-rk3399: add api to support dwc3 gadget

Quoted 91 lines · Kever Yang

Hi Marek,

Quoted 79 lines · Marek Vasut
Quoted 78 lines · Kever Yang

This patch add board_usb_init() and interrupt callback for dwc3 gadget.

---

Changes in v4:
- parse DT for quirk, base address and maximum speed

Changes in v3:
- remove utmi width DT parse from borad init

Changes in v2:
- parse dt for utmi width

  board/rockchip/evb_rk3399/evb-rk3399.c | 51
++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..58bfa78 100644
@@ -7,6 +7,8 @@
  #include <dm.h>
  #include <dm/pinctrl.h>
  #include <asm/arch/periph.h>
+#include <usb.h>
+#include <dwc3-uboot.h>
    DECLARE_GLOBAL_DATA_PTR;
  @@ -54,3 +56,52 @@ void dram_init_banksize(void)
      gd->bd->bi_dram[0].start = 0x200000;
      gd->bd->bi_dram[0].size = 0x80000000;

}

board/rockchip/evb_rk3399/evb-rk3399.c +43 -0
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+    .index = 0,
+};
+
+int usb_gadget_handle_interrupts(void)
+{
+    dwc3_uboot_handle_interrupt(0);
+    return 0;
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+    const void *blob = gd->fdt_blob;
+    int node;
+    const char *string;
+
+    node = fdt_node_offset_by_compatible(blob, -1,
+            "rockchip,rk3399-xhci");
+    if (node < 0) {
+        debug("%s dwc3 node not found\n", __func__);
+    } else {
+        dwc3_device_data.base = fdtdec_get_addr(blob, node, "reg");
+        dwc3_device_data.dis_u2_susphy_quirk =
+            fdtdec_get_int(blob, node,
+                       "snps,dis-u2-susphy-quirk", -1);
+
+        string = fdt_getprop(blob, node, "maximum-speed", NULL);
+        if (string) {
+            if (0 == strcmp(string, "super-speed"))
+                dwc3_device_data.maximum_speed = USB_SPEED_SUPER;
+            else if (0 == strcmp(string, "high-speed"))
+                dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+            else if (0 == strcmp(string, "full-speed"))
+                dwc3_device_data.maximum_speed = USB_SPEED_FULL;
+            else
+                debug("%s: Cannot decode speed'%s'\n", __func__,
+                      string);
+        } else {
+            dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
+        }
+        /* Hardcode controller in peripheral mode */
Quoted 9 lines

board/rockchip/evb_rk3399/evb-rk3399.c void dram_init_banksize(void) · line 107

Quoted 7 lines
board/rockchip/evb_rk3399/evb-rk3399.c +6 -0
+        dwc3_device_data.dr_mode = USB_DR_MODE_PERIPHERAL;
+    }
+
+    return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif

So will every board have a copy of this exact code, verbatim ?

Quoted 3 lines

Yes for rk3399 based board.
Not sure why you ask this question, but I guess you still want these parse happen in driver instead of board_init()?

Of course.

Quoted 2 lines

I didn't make these code in dwc3 driver because other SoC dts are different now, they are init in platdata data structure.

You can retain this behavior while adding the support for OF probing, see my reply to your v3 patchset.

Quoted 2 lines

To be honest, I want to make the upstream code to support rk3399 dwc3, but I don't want to touch too much code in other SoC.

This would result in having many various vendor hacks in board files, which would be almost identical but only slightly broken and nightmare to maintain. We have been there are we're glad we are getting out of there. So no, I will not allow this. Instead, do changes to common code and let others review/test them for you, this is perfectly fine.

btw the way of parsing DT in the driver I outlined in the reply to v3 should be pretty unintrusive.

Quoted 3 lines

Thanks,
- Kever

Signature · 2 lines
Best regards,
Marek Vasut
author
#7 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

In reply to Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

 drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
 drivers/usb/dwc3/core.h | 12 ++++++++++++
 2 files changed, 31 insertions(+)
drivers/usb/dwc3/core.c +19 -0
index 85cc96a..8792f99 100644
@@ -16,6 +16,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <fdtdec.h>
 #include <dwc3-uboot.h>
 #include <asm/dma-mapping.h>
 #include <linux/ioport.h>
@@ -29,6 +30,8 @@
 
 #include "linux-compat.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static LIST_HEAD(dwc3_list);
 /* -------------------------------------------------------------------------- */
 
@@ -388,6 +391,11 @@ static void dwc3_phy_setup(struct dwc3 *dwc)
 	if (dwc->dis_u2_susphy_quirk)
 		reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
 
+	if (dwc->usb2_phyif_utmi_width == 1) {
+		reg &= ~DWC3_GUSB2PHYCFG_USBTRDTIM_MASK;
+		reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT;
+		reg |= DWC3_GUSB2PHYCFG_PHYIF_16BIT;
+	}
 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
 	mdelay(100);
@@ -621,6 +629,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 	int			ret;
 
 	void			*mem;
+	const void *blob = gd->fdt_blob;
+	int node;
 
 	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
 	if (!mem)
@@ -682,6 +692,15 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 
 	dwc->index = dwc3_dev->index;
 
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0)
+		debug("%s dwc3 node not found\n", __func__);
+	else
+		dwc->usb2_phyif_utmi_width =
+			(fdtdec_get_int(blob, node, "snps,phyif-utmi-bits", -1)
+			 == 16) ? 1 : 0;
+
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
drivers/usb/dwc3/core.h +12 -0
index 72d2fcd..7484d5f 100644
@@ -74,6 +74,7 @@
 #define DWC3_GCTL		0xc110
 #define DWC3_GEVTEN		0xc114
 #define DWC3_GSTS		0xc118
+#define DWC3_GUCTL1		0xc11c
 #define DWC3_GSNPSID		0xc120
 #define DWC3_GGPIO		0xc124
 #define DWC3_GUID		0xc128
@@ -162,7 +163,17 @@
 
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
+#define DWC3_GUSB2PHYCFG_ENBLSLPM   (1 << 8)
 #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
+#define DWC3_GUSB2PHYCFG_PHYIF_8BIT	(0 << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_16BIT	(1 << 3)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT	(10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK	(0xf << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT (0x5 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT (0x9 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
 
 /* Global USB3 PIPE Control Register */
 #define DWC3_GUSB3PIPECTL_PHYSOFTRST	(1 << 31)
@@ -813,6 +824,7 @@ struct dwc3 {
 
 	unsigned		tx_de_emphasis_quirk:1;
 	unsigned		tx_de_emphasis:2;
+	unsigned		usb2_phyif_utmi_width:1;
 	int			index;
 	struct list_head        list;
 };
Signature · 1 line
1.9.1
#8 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Quoted 64 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

 drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
 drivers/usb/dwc3/core.h | 12 ++++++++++++
 2 files changed, 31 insertions(+)
drivers/usb/dwc3/core.c +10 -0
index 85cc96a..8792f99 100644
@@ -16,6 +16,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <fdtdec.h>
 #include <dwc3-uboot.h>
 #include <asm/dma-mapping.h>
 #include <linux/ioport.h>
@@ -29,6 +30,8 @@
 
 #include "linux-compat.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static LIST_HEAD(dwc3_list);
 /* -------------------------------------------------------------------------- */
 
@@ -388,6 +391,11 @@ static void dwc3_phy_setup(struct dwc3 *dwc)
 	if (dwc->dis_u2_susphy_quirk)
 		reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
 
+	if (dwc->usb2_phyif_utmi_width == 1) {
+		reg &= ~DWC3_GUSB2PHYCFG_USBTRDTIM_MASK;
+		reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT;
+		reg |= DWC3_GUSB2PHYCFG_PHYIF_16BIT;
+	}
 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
 	mdelay(100);
@@ -621,6 +629,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 	int			ret;
 
 	void			*mem;
+	const void *blob = gd->fdt_blob;
+	int node;
 
 	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
 	if (!mem)
@@ -682,6 +692,15 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 702

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -0
 	dwc->index = dwc3_dev->index;
 
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0)
+		debug("%s dwc3 node not found\n", __func__);
+	else
+		dwc->usb2_phyif_utmi_width =
+			(fdtdec_get_int(blob, node, "snps,phyif-utmi-bits", -1)
+			 == 16) ? 1 : 0;

What happens if fdtdec_get_int() returns -1 here ? Is that an error?

I just took a look into Linux and they use "phy_type" property to describe the PHY bus, with possible values being "utmi" "utmi_wide" "ulpi" etc . Do we need to invent new vendor-specific property ? See Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt in Linux for example.

Quoted 42 lines
drivers/usb/dwc3/core.c +0 -0
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
drivers/usb/dwc3/core.h +12 -0
index 72d2fcd..7484d5f 100644
@@ -74,6 +74,7 @@
 #define DWC3_GCTL		0xc110
 #define DWC3_GEVTEN		0xc114
 #define DWC3_GSTS		0xc118
+#define DWC3_GUCTL1		0xc11c
 #define DWC3_GSNPSID		0xc120
 #define DWC3_GGPIO		0xc124
 #define DWC3_GUID		0xc128
@@ -162,7 +163,17 @@
 
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
+#define DWC3_GUSB2PHYCFG_ENBLSLPM   (1 << 8)
 #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
+#define DWC3_GUSB2PHYCFG_PHYIF_8BIT	(0 << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_16BIT	(1 << 3)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT	(10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK	(0xf << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT (0x5 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT (0x9 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
 
 /* Global USB3 PIPE Control Register */
 #define DWC3_GUSB3PIPECTL_PHYSOFTRST	(1 << 31)
@@ -813,6 +824,7 @@ struct dwc3 {
 
 	unsigned		tx_de_emphasis_quirk:1;
 	unsigned		tx_de_emphasis:2;
+	unsigned		usb2_phyif_utmi_width:1;
 	int			index;
 	struct list_head        list;
 };
Signature · 2 lines
Best regards,
Marek Vasut
author
#9 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Hi Marek,

Quoted 67 lines · Marek Vasut
Quoted 66 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

  drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
  drivers/usb/dwc3/core.h | 12 ++++++++++++
  2 files changed, 31 insertions(+)
drivers/usb/dwc3/core.c +10 -0
index 85cc96a..8792f99 100644
@@ -16,6 +16,7 @@
 
  #include <common.h>
  #include <malloc.h>
+#include <fdtdec.h>
  #include <dwc3-uboot.h>
  #include <asm/dma-mapping.h>
  #include <linux/ioport.h>
@@ -29,6 +30,8 @@
 
  #include "linux-compat.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
  static LIST_HEAD(dwc3_list);
  /* -------------------------------------------------------------------------- */
 
@@ -388,6 +391,11 @@ static void dwc3_phy_setup(struct dwc3 *dwc)
  	if (dwc->dis_u2_susphy_quirk)
  		reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
 
+	if (dwc->usb2_phyif_utmi_width == 1) {
+		reg &= ~DWC3_GUSB2PHYCFG_USBTRDTIM_MASK;
+		reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT;
+		reg |= DWC3_GUSB2PHYCFG_PHYIF_16BIT;
+	}
  	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
  	mdelay(100);
@@ -621,6 +629,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
  	int			ret;
 
  	void			*mem;
+	const void *blob = gd->fdt_blob;
+	int node;
 
  	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
  	if (!mem)
@@ -682,6 +692,15 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 
  	dwc->index = dwc3_dev->index;
 
Quoted 9 lines

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 702

Quoted 8 lines
drivers/usb/dwc3/core.c +8 -0
+	node = fdt_node_offset_by_compatible(blob, -1,
+			"rockchip,rk3399-xhci");
+	if (node < 0)
+		debug("%s dwc3 node not found\n", __func__);
+	else
+		dwc->usb2_phyif_utmi_width =
+			(fdtdec_get_int(blob, node, "snps,phyif-utmi-bits", -1)
+			 == 16) ? 1 : 0;

What happens if fdtdec_get_int() returns -1 here ? Is that an error?

It may happen when the node is not defined, then we use 8bit as default, and we don't break any of origin source code.

Quoted 6 lines

I just took a look into Linux and they use "phy_type" property to describe the PHY bus, with possible values being "utmi" "utmi_wide" "ulpi" etc . Do we need to invent new vendor-specific property ? See Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt in Linux for example.

Well, I will parse "phy_type" for utmi width instead in next patch version.

Thanks,
- Kever

Quoted 44 lines
Quoted 43 lines
drivers/usb/dwc3/core.c +0 -0
  	dwc3_cache_hwparams(dwc);
 
  	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
drivers/usb/dwc3/core.h +12 -0
index 72d2fcd..7484d5f 100644
@@ -74,6 +74,7 @@
  #define DWC3_GCTL		0xc110
  #define DWC3_GEVTEN		0xc114
  #define DWC3_GSTS		0xc118
+#define DWC3_GUCTL1		0xc11c
  #define DWC3_GSNPSID		0xc120
  #define DWC3_GGPIO		0xc124
  #define DWC3_GUID		0xc128
@@ -162,7 +163,17 @@
 
  /* Global USB2 PHY Configuration Register */
  #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
+#define DWC3_GUSB2PHYCFG_ENBLSLPM   (1 << 8)
  #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
+#define DWC3_GUSB2PHYCFG_PHYIF_8BIT	(0 << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_16BIT	(1 << 3)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT	(10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK	(0xf << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT (0x5 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT (0x9 << \
+		DWC3_GUSB2PHYCFG_USBTRDTIM_SHIFT)
 
  /* Global USB3 PIPE Control Register */
  #define DWC3_GUSB3PIPECTL_PHYSOFTRST	(1 << 31)
@@ -813,6 +824,7 @@ struct dwc3 {
 
  	unsigned		tx_de_emphasis_quirk:1;
  	unsigned		tx_de_emphasis:2;
+	unsigned		usb2_phyif_utmi_width:1;
  	int			index;
  	struct list_head        list;
  };
#10 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

In reply to Kever Yang

Kever,

What is the status on this patch (and the encapsulating series)? This seems to be stuck in 'changes requested' for about a year now...

Thanks,
Philipp.

Quoted 20 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
drivers/usb/dwc3/core.h | 12 ++++++++++++

2 files changed, 31 insertions(+)
author
#11 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Philipp,

I believe there are some request I think is not reasonable which
stop me from update new patch sets.

The usb/dwc3 is mess up now, separate in host mode and gadget mode, one need init in board init

while another use DM. When I want to add a new feature like use 16bit UTMI+ instead of 8bit(which suppose to be very very simple),

I don't think the maintainer have an idea where it should go and how it should be, and the driver now

it's far away from upstream kernel.

I have send 4 patch set for this, everything should be clear, but...

Thanks,
- Kever

Quoted 32 lines · Philipp Tomsich

Kever,

What is the status on this patch (and the encapsulating series)? This seems to be stuck in 'changes requested' for about a year now...

Thanks,
Philipp.

Quoted 20 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
drivers/usb/dwc3/core.h | 12 ++++++++++++

2 files changed, 31 insertions(+)
#12 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Marek,

do you know whether there's an update of the DWC3 driver planned to get us back in sync with the kernel driver?

Thanks,
Philipp.

Quoted 55 lines · Kever Yang

Philipp,

I believe there are some request I think is not reasonable which stop me from update new patch sets.

The usb/dwc3 is mess up now, separate in host mode and gadget mode, one need init in board init

while another use DM. When I want to add a new feature like use 16bit UTMI+ instead of 8bit(which suppose to be very very simple),

I don't think the maintainer have an idea where it should go and how it should be, and the driver now

it's far away from upstream kernel.

I have send 4 patch set for this, everything should be clear, but...

Thanks,
- Kever

Quoted 32 lines · Philipp Tomsich

Kever,

What is the status on this patch (and the encapsulating series)? This seems to be stuck in 'changes requested' for about a year now...

Thanks,
Philipp.

Quoted 20 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
drivers/usb/dwc3/core.h | 12 ++++++++++++

2 files changed, 31 insertions(+)
#13 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Quoted 3 lines · Dr. Philipp Tomsich

Marek,

do you know whether there's an update of the DWC3 driver planned to get us back in sync with the kernel driver?

To my knowledge, no. Patches welcome.

btw please stop top-posting

Quoted 60 lines

Thanks,
Philipp.

Quoted 55 lines · Kever Yang

Philipp,

I believe there are some request I think is not reasonable which stop me from update new patch sets.

The usb/dwc3 is mess up now, separate in host mode and gadget mode, one need init in board init

while another use DM. When I want to add a new feature like use 16bit UTMI+ instead of 8bit(which suppose to be very very simple),

I don't think the maintainer have an idea where it should go and how it should be, and the driver now

it's far away from upstream kernel.

I have send 4 patch set for this, everything should be clear, but...

Thanks,
- Kever

Quoted 32 lines · Philipp Tomsich

Kever,

What is the status on this patch (and the encapsulating series)? This seems to be stuck in 'changes requested' for about a year now...

Thanks,
Philipp.

Quoted 20 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
drivers/usb/dwc3/core.h | 12 ++++++++++++

2 files changed, 31 insertions(+)
Signature · 2 lines
Best regards,
Marek Vasut
#14 lore raw

PATCH v4 3/4 usb: dwc3: add support for 16 bit UTMI+ interface

Kever,

Quoted 8 lines · Marek Vasut
Quoted 3 lines · Dr. Philipp Tomsich

Marek,

do you know whether there's an update of the DWC3 driver planned to get us back in sync with the kernel driver?

To my knowledge, no. Patches welcome.

Could you summarise (for everyone involved) what the impact of this series not being merged is in terms of functionality?

Once everyone is aware of what the objectives are, we can then try to revive the discussion and agree on a specific set of changes (to the series) to move forward...

Cheers,
Philipp.

Quoted 66 lines
Quoted 61 lines

Thanks,
Philipp.

Quoted 55 lines · Kever Yang

Philipp,

I believe there are some request I think is not reasonable which stop me from update new patch sets.

The usb/dwc3 is mess up now, separate in host mode and gadget mode, one need init in board init

while another use DM. When I want to add a new feature like use 16bit UTMI+ instead of 8bit(which suppose to be very very simple),

I don't think the maintainer have an idea where it should go and how it should be, and the driver now

it's far away from upstream kernel.

I have send 4 patch set for this, everything should be clear, but...

Thanks,
- Kever

Quoted 32 lines · Philipp Tomsich

Kever,

What is the status on this patch (and the encapsulating series)? This seems to be stuck in 'changes requested' for about a year now...

Thanks,
Philipp.

Quoted 20 lines · Kever Yang

The dwc3 controller is using 8 bit UTMI+ interface for USB2.0 PHY, add one variable in dwc3/dwc3_device struct to support 16 bit UTMI+ interface on some SoCs like Rockchip rk3399.

---

Changes in v4:
- use 1 bit for usb2_phyif_utmi_width instead of 5bit

Changes in v3:
- Parse the DT for utmi+ interface width in dwc3 driver

Changes in v2:
- use a variable to identify utmi+ bus width instead of CONFIG MACRO

drivers/usb/dwc3/core.c | 19 +++++++++++++++++++
drivers/usb/dwc3/core.h | 12 ++++++++++++

2 files changed, 31 insertions(+)
Signature · 2 lines
Best regards,
Marek Vasut
author
#15 lore raw

PATCH v4 4/4 config: rk3399: add support for dwc3 gadget

In reply to Kever Yang

To support fastboot, we need to enable the controller first. rk3399 is using dwc3 as usb device controller, this patch enable the configs for dwc3 gadget.

---

Changes in v4: None
Changes in v3:
- move the config into Kconfig file.

Changes in v2:
- remove config for USB2PHY UTMI BITS

 configs/evb-rk3399_defconfig | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
configs/evb-rk3399_defconfig +17 -0
index 2951678..72f2224 100644
@@ -36,3 +36,20 @@ CONFIG_DEBUG_UART_CLOCK=24000000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_USE_TINY_PRINTF=y
 CONFIG_ERRNO_STR=y
+CONFIG_USB=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_DUALSPEED=y
+CONFIG_USB_GADGET_VBUS_DRAW=0
+CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GADGET=y
+CONFIG_USB_GADGET_DOWNLOAD=y
+CONFIG_G_DNL_MANUFACTURER="Rockchip"
+CONFIG_G_DNL_VENDOR_NUM=0x2207
+CONFIG_G_DNL_PRODUCT_NUM=0x330a
+CONFIG_FASTBOOT=y
+CONFIG_CMD_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_BUF_ADDR=0x00800800
+CONFIG_FASTBOOT_BUF_SIZE=0x08000000
Signature · 1 line
1.9.1