Skip to contentSkip to conversation

rk3399: enable dwc3 gadget and fastboot

PATCH Superseded Kever Yang 2 participants 12 messages Aug 31, 2016 – Sep 2, 2016

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kever Yang

author
#0 lore raw

v3 cover rk3399: enable dwc3 gadget and fastboot

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

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         | 23 +++++++++++++++++++++++
 configs/evb-rk3399_defconfig                   | 17 +++++++++++++++++
 drivers/usb/dwc3/core.c                        | 18 ++++++++++++++++++
 drivers/usb/dwc3/core.h                        | 12 ++++++++++++
 5 files changed, 80 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-rockchip/sys_proto.h
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v3 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 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
author
#2 lore raw

PATCH v3 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 v3:
- remove utmi width DT parse from borad init

Changes in v2:
- parse dt for utmi width

 board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +23 -0
index d394276..0d39902 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,24 @@ 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 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = 0xfe800000,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+	.dis_u2_susphy_quirk = 1,
+};
+
+int usb_gadget_handle_interrupts(void)
+{
+	dwc3_uboot_handle_interrupt(0);
+	return 0;
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif
Signature · 1 line
1.9.1
author
#8 lore raw

PATCH v3 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 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 | 18 ++++++++++++++++++
 drivers/usb/dwc3/core.h | 12 ++++++++++++
 2 files changed, 30 insertions(+)
drivers/usb/dwc3/core.c +18 -0
index 85cc96a..b2c7eb1 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 == 16) {
+		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,14 @@ 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);
+
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
drivers/usb/dwc3/core.h +12 -0
index 72d2fcd..0c61c51 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:5;
 	int			index;
 	struct list_head        list;
 };
Signature · 1 line
1.9.1
author
#11 lore raw

PATCH v3 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 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
#3 lore raw

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

In reply to Kever Yang
Quoted 8 lines · Kever Yang

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

---

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

OK

Quoted 22 lines

Changes in v2:
- parse dt for utmi width

 board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..0d39902 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,24 @@ 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 void dram_init_banksize(void) · line 67

Quoted 10 lines
board/rockchip/evb_rk3399/evb-rk3399.c +9 -0
 }
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = 0xfe800000,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+	.dis_u2_susphy_quirk = 1,
+};

Uh, didn't I complain last time that this should come from DT and not platdata ?

Quoted 12 lines
board/rockchip/evb_rk3399/evb-rk3399.c +11 -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)
+{
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif
Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

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

In reply to Kever Yang
Quoted 60 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 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 | 18 ++++++++++++++++++
 drivers/usb/dwc3/core.h | 12 ++++++++++++
 2 files changed, 30 insertions(+)
drivers/usb/dwc3/core.c +10 -0
index 85cc96a..b2c7eb1 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 == 16) {
+		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)

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

Quoted 10 lines
drivers/usb/dwc3/core.c +7 -0
@@ -682,6 +692,14 @@ 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);

This is OK, thanks!

Quoted 34 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 +11 -0
index 72d2fcd..0c61c51 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)

drivers/usb/dwc3/core.h struct dwc3 { · line 827

Quoted 4 lines
drivers/usb/dwc3/core.h +1 -0
@@ -813,6 +824,7 @@ struct dwc3 {
 
 	unsigned		tx_de_emphasis_quirk:1;
 	unsigned		tx_de_emphasis:2;
+	unsigned		usb2_phyif_utmi_width:5;

Shouldn't this be :1 ? 0 for 8bit, 1 for 16bit ?

Quoted 4 lines
drivers/usb/dwc3/core.h +0 -0
 	int			index;
 	struct list_head        list;
 };
Signature · 2 lines
Best regards,
Marek Vasut
author
#4 lore raw

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

In reply to Marek Vasut

Hi Marek,

Quoted 30 lines · Marek Vasut
Quoted 8 lines · Kever Yang

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

---

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

OK

Quoted 19 lines

Changes in v2:
- parse dt for utmi width

  board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..0d39902 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;
 
Quoted 15 lines

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

Quoted 13 lines
board/rockchip/evb_rk3399/evb-rk3399.c +9 -0
@@ -54,3 +56,24 @@ 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 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = 0xfe800000,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+	.dis_u2_susphy_quirk = 1,
+};

Uh, didn't I complain last time that this should come from DT and not platdata ?

Since I'm not able to remove the platdata, I thought maybe I can init those features here, I will parse DT for maximum_speed, base, and dis_u2_susphy_quirk
in next version.

Thanks,
- Kever

Quoted 13 lines
Quoted 12 lines
board/rockchip/evb_rk3399/evb-rk3399.c +11 -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)
+{
+	return dwc3_uboot_init(&dwc3_device_data);
+}
+#endif
author
#10 lore raw

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

In reply to Marek Vasut
Quoted 104 lines · Marek Vasut
Quoted 60 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 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 | 18 ++++++++++++++++++
  drivers/usb/dwc3/core.h | 12 ++++++++++++
  2 files changed, 30 insertions(+)
drivers/usb/dwc3/core.c +10 -0
index 85cc96a..b2c7eb1 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 == 16) {
+		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)

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

Quoted 10 lines
drivers/usb/dwc3/core.c +7 -0
@@ -682,6 +692,14 @@ 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);

This is OK, thanks!

Quoted 31 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 +11 -0
index 72d2fcd..0c61c51 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)
 
Quoted 8 lines

drivers/usb/dwc3/core.h struct dwc3 { · line 827

Quoted 7 lines
drivers/usb/dwc3/core.h +1 -0
  /* 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:5;

Shouldn't this be :1 ? 0 for 8bit, 1 for 16bit ?

Well, using 1 bit in next version.

Thanks,
- Kever

Quoted 6 lines
Quoted 5 lines
drivers/usb/dwc3/core.h +0 -0
  	int			index;
  	struct list_head        list;
  };
#5 lore raw

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

In reply to Kever Yang
Quoted 48 lines · Kever Yang

Hi Marek,

Quoted 36 lines · Marek Vasut
Quoted 8 lines · Kever Yang

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

---

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

OK

Quoted 25 lines

Changes in v2:
- parse dt for utmi width

  board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..0d39902 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,24 @@ 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 +3 -0
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
Quoted 8 lines

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

Quoted 6 lines
board/rockchip/evb_rk3399/evb-rk3399.c +6 -0
+    .maximum_speed = USB_SPEED_HIGH,
+    .base = 0xfe800000,
+    .dr_mode = USB_DR_MODE_PERIPHERAL,
+    .index = 0,
+    .dis_u2_susphy_quirk = 1,
+};

Uh, didn't I complain last time that this should come from DT and not platdata ?

Quoted 4 lines

Since I'm not able to remove the platdata, I thought maybe I can init those features here, I will parse DT for maximum_speed, base, and dis_u2_susphy_quirk
in next version.

Why aren't you able to remove the platdata ?

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

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

Hi Marek,

Quoted 48 lines · Marek Vasut
Quoted 47 lines · Kever Yang

Hi Marek,

Quoted 44 lines · Marek Vasut
Quoted 8 lines · Kever Yang

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

---

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

OK

Quoted 22 lines

Changes in v2:
- parse dt for utmi width

   board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
   1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..0d39902 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,24 @@ 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 void dram_init_banksize(void) · line 67

Quoted 9 lines
board/rockchip/evb_rk3399/evb-rk3399.c +9 -0
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
+    .maximum_speed = USB_SPEED_HIGH,
+    .base = 0xfe800000,
+    .dr_mode = USB_DR_MODE_PERIPHERAL,
+    .index = 0,
+    .dis_u2_susphy_quirk = 1,
+};

Uh, didn't I complain last time that this should come from DT and not platdata ?

Quoted 5 lines
Quoted 4 lines

Since I'm not able to remove the platdata, I thought maybe I can init those features here, I will parse DT for maximum_speed, base, and dis_u2_susphy_quirk
in next version.

Why aren't you able to remove the platdata ?

Because this platdata is not only used by Rockchip SoC, but also used for many different SoC like
exynos5, zynqmp, and ti SoCs, and the dts node for dwc3 gadget in these SoCs are totally different.

Maybe maintainer like you are the one able to enable the DM for usb/dwc3 gadget, get the all
the information from DT and update for all the platforms?

I'm happy to test on rk3399-evb, but I don't have boards for other SoC.

Thanks,
- Kever

#7 lore raw

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

Quoted 1 line · Kever Yang

Hi Marek,

Hi!

Quoted 54 lines · Marek Vasut
Quoted 53 lines · Kever Yang
Quoted 52 lines

Hi Marek,

Quoted 36 lines · Marek Vasut
Quoted 8 lines · Kever Yang

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

---

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

OK

Quoted 25 lines

Changes in v2:
- parse dt for utmi width

   board/rockchip/evb_rk3399/evb-rk3399.c | 23 +++++++++++++++++++++++
   1 file changed, 23 insertions(+)
board/rockchip/evb_rk3399/evb-rk3399.c +2 -0
index d394276..0d39902 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,24 @@ 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 +3 -0
+
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device dwc3_device_data = {
Quoted 8 lines

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

Quoted 6 lines
board/rockchip/evb_rk3399/evb-rk3399.c +6 -0
+    .maximum_speed = USB_SPEED_HIGH,
+    .base = 0xfe800000,
+    .dr_mode = USB_DR_MODE_PERIPHERAL,
+    .index = 0,
+    .dis_u2_susphy_quirk = 1,
+};

Uh, didn't I complain last time that this should come from DT and not platdata ?

Since I'm not able to remove the platdata, I thought maybe I can init those
features here, I will parse DT for maximum_speed, base, and dis_u2_susphy_quirk
in next version.

Quoted 4 lines
Quoted 1 line

Why aren't you able to remove the platdata ?

Because this platdata is not only used by Rockchip SoC, but also used for many different SoC like
exynos5, zynqmp, and ti SoCs

No, these platdata are in your board file, so it's only used by your board. If what you mean is that dwc3_uboot_init() requires non-NULL $dwc3_dev parameter, that's pretty easy to fix:
- Check if dwc3_dev is NULL and if so, invoke (new) function, let's say dwc3_uboot_of_init()
- dwc3_uboot_of_init() would allocate the struct dwc3_device , fill it in from DT and return pointer to it (or null on failure)

This look like the least intrusive way to do things.

, and the dts node for dwc3 gadget in these

Quoted 1 line

SoCs are totally different.

How can the DT node for the exact same controller be different ? The DT is an ABI, STANDARD, it is documented how the node should look and what it should contain. If it deviates from that, it is invalid and needs fixing.

Quoted 5 lines

Maybe maintainer like you are the one able to enable the DM for usb/dwc3 gadget, get the all
the information from DT and update for all the platforms?

I'm happy to test on rk3399-evb, but I don't have boards for other SoC.

I don't have any dwc3 device (I think), so I depend purely on the contributors to do the right thing.

Quoted 3 lines

Thanks,
- Kever

Signature · 2 lines
Best regards,
Marek Vasut