Skip to contentSkip to conversation

rk3328: add support of usb host and gadget

PATCH Superseded Meng Dongyang 3 participants 14 messages Jun 8, 2017 – Jun 10, 2017

Subsystems (4)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover rk3328: add support of usb host and gadget

Add support of usb host and gadget function for rk3328.

Changes in v4:
- Splite patch [U-boot,v3,04/10] into two patches
- Define set vbus as empty function if the macros aren't set
- Prepare a mask and set capabilities in GUSBCFG register once

Changes in v3:
- Revert change of macro definition in dwc2 driver
- Support host mode without HNP/SRP capability through DTS

Changes in v2:
- Add commit messages
- Split patch [U-boot,7/8] into two patches
- Use fixed regulator to control vbus instead of gpio

Meng Dongyang (11):
configs: rk3328: add support for usb and config ehci and ohci driver
rockchip: dts: rk3328: add ehci and ohci node and enable host0 port
configs: rk3328: config xhci controller
usb: host: xhci-rockchip: use fixed regulator to control vbus
usb: host: xhci-rockchip: add support for rk3328
rockchip: dts: rk3328: support and enable xhci
configs: rk3328: enable dwc2 driver and config for fastboot
usb: dwc2: force to host mode if not support HNP/SRP
rk3328: board: add support of dwc2 gadget
rockchip: dts: rk3328: support and enable dwc2
rockchip: dts: rk3399: control vbus of typec by fixed regulator

 arch/arm/dts/rk3328-evb.dts            | 36 ++++++++++++++++++++++++++++
 arch/arm/dts/rk3328.dtsi               | 35 +++++++++++++++++++++++++++
 arch/arm/dts/rk3399-evb.dts            | 16 +++++++++++--
 board/rockchip/evb_rk3328/evb-rk3328.c | 43 +++++++++++++++++++++++++++++++---
 configs/evb-rk3328_defconfig           | 25 ++++++++++++++++++++
 drivers/usb/host/dwc2.c                | 19 ++++++++++++---
 drivers/usb/host/xhci-rockchip.c       | 43 +++++++++++++++++++++++++++-------
 include/configs/rk3328_common.h        |  9 +++++++
 8 files changed, 209 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/11 configs: rk3328: add support for usb and config ehci and ohci driver

Add defconfig for usb and ehci and ohci controller, config maximal number of ports of the root hub for ohci driver.

---

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

 configs/evb-rk3328_defconfig    | 8 ++++++++
 include/configs/rk3328_common.h | 3 +++
 2 files changed, 11 insertions(+)
configs/evb-rk3328_defconfig +8 -0
index 96241f6..a4312b2 100644
@@ -31,3 +31,11 @@ CONFIG_SYS_NS16550=y
 CONFIG_SYSRESET=y
 CONFIG_USE_TINY_PRINTF=y
 CONFIG_ERRNO_STR=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
+CONFIG_CMD_USB=y
+CONFIG_USB_STORAGE=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_GENERIC=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB_OHCI_GENERIC=y
include/configs/rk3328_common.h +3 -0
index b0dcd48..96b71c3 100644
@@ -61,4 +61,7 @@
 
 #endif
 
+/* rockchip ohci host driver */
+#define CONFIG_USB_OHCI_NEW
+#define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS	1
 #endif
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/11 rockchip: dts: rk3328: add ehci and ohci node and enable host0 port

In reply to Meng Dongyang

Add dts node for ehci and ohci controller, enable the controllers.

---

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

 arch/arm/dts/rk3328-evb.dts |  8 ++++++++
 arch/arm/dts/rk3328.dtsi    | 14 ++++++++++++++
 2 files changed, 22 insertions(+)
arch/arm/dts/rk3328-evb.dts +8 -0
index 01794ed..9920935 100644
@@ -43,3 +43,11 @@
 	pinctrl-0 = <&emmc_clk &emmc_cmd &emmc_bus8>;
 	status = "okay";
 };
+
+&usb_host0_ehci {
+	status = "okay";
+};
+
+&usb_host0_ohci {
+	status = "okay";
+};
arch/arm/dts/rk3328.dtsi +14 -0
index 8a98ee3..e1219c3 100644
@@ -446,6 +446,20 @@
 		status = "disabled";
 	};
 
+	usb_host0_ehci: usb at ff5c0000 {
+		compatible = "generic-ehci";
+		reg = <0x0 0xff5c0000 0x0 0x10000>;
+		interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
+	usb_host0_ohci: usb at ff5d0000 {
+		compatible = "generic-ohci";
+		reg = <0x0 0xff5d0000 0x0 0x10000>;
+		interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
+		status = "disabled";
+	};
+
 	sdmmc_ext: rksdmmc at ff5f0000 {
 		compatible = "rockchip,rk3328-dw-mshc", "rockchip,rk3288-dw-mshc";
 		reg = <0x0 0xff5f0000 0x0 0x4000>;
Signature · 1 line
1.9.1
#3 lore raw

PATCH v4 3/11 configs: rk3328: config xhci controller

In reply to Meng Dongyang

Add config of max root ports and add config to enable xhci controller.

---

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

 configs/evb-rk3328_defconfig    | 3 +++
 include/configs/rk3328_common.h | 3 +++
 2 files changed, 6 insertions(+)
configs/evb-rk3328_defconfig +3 -0
index a4312b2..57aee02 100644
@@ -39,3 +39,6 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_GENERIC=y
+CONFIG_USB_XHCI_DWC3=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_RK=y
include/configs/rk3328_common.h +3 -0
index 96b71c3..cc6c890 100644
@@ -64,4 +64,7 @@
 /* rockchip ohci host driver */
 #define CONFIG_USB_OHCI_NEW
 #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS	1
+
+/* xhci host */
+#define CONFIG_SYS_USB_XHCI_MAX_ROOT_PORTS	2
 #endif
Signature · 1 line
1.9.1
#4 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

In reply to Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

 drivers/usb/host/xhci-rockchip.c | 41 +++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +32 -9
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
 #include <malloc.h>
 #include <usb.h>
 #include <watchdog.h>
-#include <asm/gpio.h>
 #include <linux/errno.h>
 #include <linux/compat.h>
 #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
 
 #include "xhci.h"
 
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct rockchip_xhci_platdata {
 	fdt_addr_t hcd_base;
 	fdt_addr_t phy_base;
-	struct gpio_desc vbus_gpio;
+	struct udevice *vbus_supply;
 };
 
 /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
 		return -ENXIO;
 	}
 
-	/* Vbus gpio */
-	ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-				   &plat->vbus_gpio, GPIOD_IS_OUT);
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+	/* Vbus regulator */
+	ret = device_get_supply_regulator(dev, "vbus-supply",
+					  &plat->vbus_supply);
 	if (ret)
-		debug("rockchip,vbus-gpio node missing!");
+		debug("Can't get vbus supply\n");
+#endif
 
 	return 0;
 }
 
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	int ret = 0;
+
+	ret = regulator_set_enable(plat->vbus_supply, value);
+	if (ret)
+		debug("XHCI: Failed to set vbus supply\n");
+
+	return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	return 0;
+}
+#endif
+
 /*
  * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3 Core
  * @dwc: Pointer to our controller context structure
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
 	hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
 			HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
 
-	/* setup the Vbus gpio here */
-	if (dm_gpio_is_valid(&plat->vbus_gpio))
-		dm_gpio_set_value(&plat->vbus_gpio, 1);
+	rockchip_xhci_set_vbus(plat, true);
 
 	ret = rockchip_xhci_core_init(ctx, dev);
 	if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
 
 static int xhci_usb_remove(struct udevice *dev)
 {
+	struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
 	struct rockchip_xhci *ctx = dev_get_priv(dev);
 	int ret;
 
@@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	rockchip_xhci_set_vbus(plat, false);
+
 	return 0;
 }
 
Signature · 1 line
1.9.1
#11 lore raw

v4 cover rk3328: add support of usb host and gadget

In reply to Meng Dongyang
Quoted 1 line · Meng Dongyang

Add support of usb host and gadget function for rk3328.

Why did I receive half of the series as a series (that is, cover letter and patches IRT to that) and half as separate emails ?

Quoted 37 lines

Changes in v4:
- Splite patch [U-boot,v3,04/10] into two patches
- Define set vbus as empty function if the macros aren't set
- Prepare a mask and set capabilities in GUSBCFG register once

Changes in v3:
- Revert change of macro definition in dwc2 driver
- Support host mode without HNP/SRP capability through DTS

Changes in v2:
- Add commit messages
- Split patch [U-boot,7/8] into two patches
- Use fixed regulator to control vbus instead of gpio

Meng Dongyang (11):
configs: rk3328: add support for usb and config ehci and ohci driver
rockchip: dts: rk3328: add ehci and ohci node and enable host0 port
configs: rk3328: config xhci controller
usb: host: xhci-rockchip: use fixed regulator to control vbus
usb: host: xhci-rockchip: add support for rk3328
rockchip: dts: rk3328: support and enable xhci
configs: rk3328: enable dwc2 driver and config for fastboot
usb: dwc2: force to host mode if not support HNP/SRP
rk3328: board: add support of dwc2 gadget
rockchip: dts: rk3328: support and enable dwc2
rockchip: dts: rk3399: control vbus of typec by fixed regulator

 arch/arm/dts/rk3328-evb.dts            | 36 ++++++++++++++++++++++++++++
 arch/arm/dts/rk3328.dtsi               | 35 +++++++++++++++++++++++++++
 arch/arm/dts/rk3399-evb.dts            | 16 +++++++++++--
 board/rockchip/evb_rk3328/evb-rk3328.c | 43 +++++++++++++++++++++++++++++++---
 configs/evb-rk3328_defconfig           | 25 ++++++++++++++++++++
 drivers/usb/host/dwc2.c                | 19 ++++++++++++---
 drivers/usb/host/xhci-rockchip.c       | 43 +++++++++++++++++++++++++++-------
 include/configs/rk3328_common.h        |  9 +++++++
 8 files changed, 209 insertions(+), 17 deletions(-)
Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

In reply to Meng Dongyang
Quoted 46 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

 drivers/usb/host/xhci-rockchip.c | 41 +++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +2 -2
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
 #include <malloc.h>
 #include <usb.h>
 #include <watchdog.h>
-#include <asm/gpio.h>
 #include <linux/errno.h>
 #include <linux/compat.h>
 #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
 
 #include "xhci.h"
 
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct rockchip_xhci_platdata {
 	fdt_addr_t hcd_base;
 	fdt_addr_t phy_base;
-	struct gpio_desc vbus_gpio;
+	struct udevice *vbus_supply;
 };
 
 /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
 		return -ENXIO;
 	}
 

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 74

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +5 -4
-	/* Vbus gpio */
-	ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-				   &plat->vbus_gpio, GPIOD_IS_OUT);
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+	/* Vbus regulator */
+	ret = device_get_supply_regulator(dev, "vbus-supply",
+					  &plat->vbus_supply);
 	if (ret)
-		debug("rockchip,vbus-gpio node missing!");
+		debug("Can't get vbus supply\n");

VBUS in caps

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +6 -0
+#endif
 
 	return 0;
 }
 
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	int ret = 0;

You don't need to init ret, it's always set right below.

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 88

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+	ret = regulator_set_enable(plat->vbus_supply, value);
+	if (ret)
+		debug("XHCI: Failed to set vbus supply\n");

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Quoted 14 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+	return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	return 0;
+}
+#endif
+
 /*
  * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3 Core
  * @dwc: Pointer to our controller context structure

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 7 lines
drivers/usb/host/xhci-rockchip.c +1 -3
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
 	hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
 			HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
 
-	/* setup the Vbus gpio here */
-	if (dm_gpio_is_valid(&plat->vbus_gpio))
-		dm_gpio_set_value(&plat->vbus_gpio, 1);
+	rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

Quoted 11 lines
drivers/usb/host/xhci-rockchip.c +1 -0
 	ret = rockchip_xhci_core_init(ctx, dev);
 	if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
 
 static int xhci_usb_remove(struct udevice *dev)
 {
+	struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
 	struct rockchip_xhci *ctx = dev_get_priv(dev);
 	int ret;
 

drivers/usb/host/xhci-rockchip.c static int xhci_usb_remove(struct udevice *dev) · line 202

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +1 -0
@@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	rockchip_xhci_set_vbus(plat, false);

Handle return value

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +0 -0
 	return 0;
 }
 
Signature · 2 lines
Best regards,
Marek Vasut
#12 lore raw

v4 cover rk3328: add support of usb host and gadget

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut
Quoted 1 line · Meng Dongyang

Add support of usb host and gadget function for rk3328.

Why did I receive half of the series as a series (that is, cover letter and patches IRT to that) and half as separate emails ?

Because there is a limit to the number of letter one time.

Quoted 39 lines
Quoted 38 lines

Changes in v4:
- Splite patch [U-boot,v3,04/10] into two patches
- Define set vbus as empty function if the macros aren't set
- Prepare a mask and set capabilities in GUSBCFG register once

Changes in v3:
- Revert change of macro definition in dwc2 driver
- Support host mode without HNP/SRP capability through DTS

Changes in v2:
- Add commit messages
- Split patch [U-boot,7/8] into two patches
- Use fixed regulator to control vbus instead of gpio

Meng Dongyang (11):
configs: rk3328: add support for usb and config ehci and ohci driver
rockchip: dts: rk3328: add ehci and ohci node and enable host0 port
configs: rk3328: config xhci controller
usb: host: xhci-rockchip: use fixed regulator to control vbus
usb: host: xhci-rockchip: add support for rk3328
rockchip: dts: rk3328: support and enable xhci
configs: rk3328: enable dwc2 driver and config for fastboot
usb: dwc2: force to host mode if not support HNP/SRP
rk3328: board: add support of dwc2 gadget
rockchip: dts: rk3328: support and enable dwc2
rockchip: dts: rk3399: control vbus of typec by fixed regulator

  arch/arm/dts/rk3328-evb.dts            | 36 ++++++++++++++++++++++++++++
  arch/arm/dts/rk3328.dtsi               | 35 +++++++++++++++++++++++++++
  arch/arm/dts/rk3399-evb.dts            | 16 +++++++++++--
  board/rockchip/evb_rk3328/evb-rk3328.c | 43 +++++++++++++++++++++++++++++++---
  configs/evb-rk3328_defconfig           | 25 ++++++++++++++++++++
  drivers/usb/host/dwc2.c                | 19 ++++++++++++---
  drivers/usb/host/xhci-rockchip.c       | 43 +++++++++++++++++++++++++++-------
  include/configs/rk3328_common.h        |  9 +++++++
  8 files changed, 209 insertions(+), 17 deletions(-)
#6 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

In reply to Marek Vasut
Quoted 71 lines · Marek Vasut
Quoted 46 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

  drivers/usb/host/xhci-rockchip.c | 41 +++++++++++++++++++++++++++++++---------
  1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +2 -2
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
  #include <malloc.h>
  #include <usb.h>
  #include <watchdog.h>
-#include <asm/gpio.h>
  #include <linux/errno.h>
  #include <linux/compat.h>
  #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
 
  #include "xhci.h"
 
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
  struct rockchip_xhci_platdata {
  	fdt_addr_t hcd_base;
  	fdt_addr_t phy_base;
-	struct gpio_desc vbus_gpio;
+	struct udevice *vbus_supply;
  };
 
  /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
  		return -ENXIO;
  	}
 

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 74

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +5 -4
-	/* Vbus gpio */
-	ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-				   &plat->vbus_gpio, GPIOD_IS_OUT);
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+	/* Vbus regulator */
+	ret = device_get_supply_regulator(dev, "vbus-supply",
+					  &plat->vbus_supply);
  	if (ret)
-		debug("rockchip,vbus-gpio node missing!");
+		debug("Can't get vbus supply\n");

VBUS in caps

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +6 -0
+#endif
 
  	return 0;
  }
 
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	int ret = 0;

You don't need to init ret, it's always set right below.

Quoted 6 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 88

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+	ret = regulator_set_enable(plat->vbus_supply, value);
+	if (ret)
+		debug("XHCI: Failed to set vbus supply\n");

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Considering the case vbus is always on, it is right with no vbus regulator. So maybe it's not an error actually.

Quoted 18 lines
Quoted 18 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+	return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+				  bool value)
+{
+	return 0;
+}
+#endif
+
  /*
   * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3 Core
   * @dwc: Pointer to our controller context structure
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
  	hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
  			HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
 
Quoted 5 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +1 -3
-	/* setup the Vbus gpio here */
-	if (dm_gpio_is_valid(&plat->vbus_gpio))
-		dm_gpio_set_value(&plat->vbus_gpio, 1);
+	rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

The return value can be ignored when vbus is always on. So is it enough just print message in
the rockchip_xhci_set_vbus function?

Quoted 23 lines
Quoted 12 lines
drivers/usb/host/xhci-rockchip.c +1 -0
  	ret = rockchip_xhci_core_init(ctx, dev);
  	if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
 
  static int xhci_usb_remove(struct udevice *dev)
  {
+	struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
  	struct rockchip_xhci *ctx = dev_get_priv(dev);
  	int ret;
 

drivers/usb/host/xhci-rockchip.c static int xhci_usb_remove(struct udevice *dev) · line 202

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +1 -0
@@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
  	if (ret)
  		return ret;
 
+	rockchip_xhci_set_vbus(plat, false);

Handle return value

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +0 -0
  	return 0;
  }
 
#7 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

Quoted 71 lines · rock-chips(daniel.meng)
Quoted 68 lines · Marek Vasut
Quoted 45 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

  drivers/usb/host/xhci-rockchip.c | 41
+++++++++++++++++++++++++++++++---------
  1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +1 -1
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
  #include <malloc.h>
  #include <usb.h>
  #include <watchdog.h>
-#include <asm/gpio.h>
  #include <linux/errno.h>
  #include <linux/compat.h>
  #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
    #include "xhci.h"
  @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
  struct rockchip_xhci_platdata {
      fdt_addr_t hcd_base;
      fdt_addr_t phy_base;
drivers/usb/host/xhci-rockchip.c +1 -1
-    struct gpio_desc vbus_gpio;
+    struct udevice *vbus_supply;
  };
    /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct
 udevice *dev)
          return -ENXIO;
      }

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct · line 75

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +5 -3
  -    /* Vbus gpio */
-    ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-                   &plat->vbus_gpio, GPIOD_IS_OUT);
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+    /* Vbus regulator */
+    ret = device_get_supply_regulator(dev, "vbus-supply",
+                      &plat->vbus_supply);
      if (ret)
-        debug("rockchip,vbus-gpio node missing!");
+        debug("Can't get vbus supply\n");

VBUS in caps

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 8 lines
drivers/usb/host/xhci-rockchip.c +5 -0
+#endif
        return 0;
  }
  +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    int ret = 0;

You don't need to init ret, it's always set right below.

Quoted 8 lines
Quoted 6 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 88

Quoted 4 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+    ret = regulator_set_enable(plat->vbus_supply, value);
+    if (ret)
+        debug("XHCI: Failed to set vbus supply\n");

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Considering the case vbus is always on, it is right with no vbus regulator. So maybe it's not an error actually.

Regulator failed to turn on, that's an error, right ?
Why would VBUS be always on ? You can just add a GPIO-regulator into the DT and then the VBUS is no longer always on.

Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+    return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    return 0;
+}
+#endif
+
  /*
   * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3

Core
* @dwc: Pointer to our controller context structure

Quoted 8 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 7 lines
drivers/usb/host/xhci-rockchip.c +1 -2
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
      hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
              HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
  -    /* setup the Vbus gpio here */
-    if (dm_gpio_is_valid(&plat->vbus_gpio))
-        dm_gpio_set_value(&plat->vbus_gpio, 1);
+    rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

Quoted 3 lines

The return value can be ignored when vbus is always on. So is it enough just print message in
the rockchip_xhci_set_vbus function?

See above, why is VBUS always on

Quoted 21 lines
Quoted 19 lines
Quoted 12 lines
drivers/usb/host/xhci-rockchip.c +1 -0
      ret = rockchip_xhci_core_init(ctx, dev);
      if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
    static int xhci_usb_remove(struct udevice *dev)
  {
+    struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
      struct rockchip_xhci *ctx = dev_get_priv(dev);
      int ret;
  @@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
      if (ret)
          return ret;
Quoted 1 line

+ rockchip_xhci_set_vbus(plat, false);

Handle return value

Quoted 3 lines
      return 0;

}

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

v4 cover rk3328: add support of usb host and gadget

In reply to rock-chips (daniel.meng)
Quoted 8 lines · rock-chips(daniel.meng)
Quoted 4 lines · Marek Vasut
Quoted 1 line · Meng Dongyang

Add support of usb host and gadget function for rk3328.

Why did I receive half of the series as a series (that is, cover letter and patches IRT to that) and half as separate emails ?

Because there is a limit to the number of letter one time.

You can use gmail to work that around if your corporate email is crap. You can also use foo.bar+rockchips at gmail.com with foo.bar at gmail.com to differentiate traffic.

Quoted 45 lines
Quoted 43 lines
Quoted 42 lines

Changes in v4:
- Splite patch [U-boot,v3,04/10] into two patches
- Define set vbus as empty function if the macros aren't set
- Prepare a mask and set capabilities in GUSBCFG register once

Changes in v3:
- Revert change of macro definition in dwc2 driver
- Support host mode without HNP/SRP capability through DTS

Changes in v2:
- Add commit messages
- Split patch [U-boot,7/8] into two patches
- Use fixed regulator to control vbus instead of gpio

Meng Dongyang (11):
configs: rk3328: add support for usb and config ehci and ohci driver
rockchip: dts: rk3328: add ehci and ohci node and enable host0 port
configs: rk3328: config xhci controller
usb: host: xhci-rockchip: use fixed regulator to control vbus
usb: host: xhci-rockchip: add support for rk3328
rockchip: dts: rk3328: support and enable xhci
configs: rk3328: enable dwc2 driver and config for fastboot
usb: dwc2: force to host mode if not support HNP/SRP
rk3328: board: add support of dwc2 gadget
rockchip: dts: rk3328: support and enable dwc2
rockchip: dts: rk3399: control vbus of typec by fixed regulator

  arch/arm/dts/rk3328-evb.dts            | 36
++++++++++++++++++++++++++++
  arch/arm/dts/rk3328.dtsi               | 35
+++++++++++++++++++++++++++
  arch/arm/dts/rk3399-evb.dts            | 16 +++++++++++--
  board/rockchip/evb_rk3328/evb-rk3328.c | 43
+++++++++++++++++++++++++++++++---
  configs/evb-rk3328_defconfig           | 25 ++++++++++++++++++++
  drivers/usb/host/dwc2.c                | 19 ++++++++++++---
  drivers/usb/host/xhci-rockchip.c       | 43
+++++++++++++++++++++++++++-------
  include/configs/rk3328_common.h        |  9 +++++++
  8 files changed, 209 insertions(+), 17 deletions(-)
Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

In reply to Marek Vasut
Quoted 52 lines · Marek Vasut
Quoted 51 lines · rock-chips(daniel.meng)
Quoted 49 lines · Marek Vasut
Quoted 48 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

   drivers/usb/host/xhci-rockchip.c | 41
+++++++++++++++++++++++++++++++---------
   1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +1 -1
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
   #include <malloc.h>
   #include <usb.h>
   #include <watchdog.h>
-#include <asm/gpio.h>
   #include <linux/errno.h>
   #include <linux/compat.h>
   #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
     #include "xhci.h"
   @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
   struct rockchip_xhci_platdata {
       fdt_addr_t hcd_base;
       fdt_addr_t phy_base;
drivers/usb/host/xhci-rockchip.c +1 -3
-    struct gpio_desc vbus_gpio;
+    struct udevice *vbus_supply;
   };
     /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct
 udevice *dev)
           return -ENXIO;
       }
   -    /* Vbus gpio */
-    ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-                   &plat->vbus_gpio, GPIOD_IS_OUT);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 74

Quoted 7 lines
drivers/usb/host/xhci-rockchip.c +5 -1
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+    /* Vbus regulator */
+    ret = device_get_supply_regulator(dev, "vbus-supply",
+                      &plat->vbus_supply);
       if (ret)
-        debug("rockchip,vbus-gpio node missing!");
+        debug("Can't get vbus supply\n");

VBUS in caps

change the print message?
debug("Can't get VBUS regulator\n") ?

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 9 lines
drivers/usb/host/xhci-rockchip.c +5 -0
+#endif
         return 0;
   }
   +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    int ret = 0;

You don't need to init ret, it's always set right below.

OK, I will correct

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+    ret = regulator_set_enable(plat->vbus_supply, value);
+    if (ret)
+        debug("XHCI: Failed to set vbus supply\n");
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Considering the case vbus is always on, it is right with no vbus regulator. So maybe it's not an error actually.

Regulator failed to turn on, that's an error, right ?
Why would VBUS be always on ? You can just add a GPIO-regulator into the DT and then the VBUS is no longer always on.

It's certainly right adding a GPIO-regulator into the DT. But when it's designed
as a host only port, the VBUS would be fixed to on by hardware and there is no
gpio for it. In this case, setting regulator will return fail, but it's also a right case.
So I think it can be treated as a debug or warning message.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+    return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    return 0;
+}
+#endif
+
   /*
    * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3

Core
* @dwc: Pointer to our controller context structure

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 6 lines
drivers/usb/host/xhci-rockchip.c +1 -2
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
       hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
               HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
   -    /* setup the Vbus gpio here */
-    if (dm_gpio_is_valid(&plat->vbus_gpio))
-        dm_gpio_set_value(&plat->vbus_gpio, 1);
+    rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

Quoted 4 lines
Quoted 3 lines

The return value can be ignored when vbus is always on. So is it enough just print message in
the rockchip_xhci_set_vbus function?

See above, why is VBUS always on

answer above

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
drivers/usb/host/xhci-rockchip.c +1 -0
       ret = rockchip_xhci_core_init(ctx, dev);
       if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
     static int xhci_usb_remove(struct udevice *dev)
   {
+    struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
       struct rockchip_xhci *ctx = dev_get_priv(dev);
       int ret;
   @@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
       if (ret)
           return ret;
Quoted 1 line

+ rockchip_xhci_set_vbus(plat, false);

Handle return value

I think print message may be is enough.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
       return 0;

}

#9 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

Quoted 88 lines · rock-chips(daniel.meng)
Quoted 52 lines · Marek Vasut
Quoted 51 lines · rock-chips(daniel.meng)
Quoted 49 lines · Marek Vasut
Quoted 48 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

  drivers/usb/host/xhci-rockchip.c | 41
+++++++++++++++++++++++++++++++---------
  1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +1 -1
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
  #include <malloc.h>
  #include <usb.h>
  #include <watchdog.h>
-#include <asm/gpio.h>
  #include <linux/errno.h>
  #include <linux/compat.h>
  #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
    #include "xhci.h"
  @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
  struct rockchip_xhci_platdata {
      fdt_addr_t hcd_base;
      fdt_addr_t phy_base;
drivers/usb/host/xhci-rockchip.c +1 -3
-    struct gpio_desc vbus_gpio;
+    struct udevice *vbus_supply;
  };
    /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct
 udevice *dev)
          return -ENXIO;
      }
  -    /* Vbus gpio */
-    ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-                   &plat->vbus_gpio, GPIOD_IS_OUT);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 74

Quoted 7 lines
drivers/usb/host/xhci-rockchip.c +5 -1
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+    /* Vbus regulator */
+    ret = device_get_supply_regulator(dev, "vbus-supply",
+                      &plat->vbus_supply);
      if (ret)
-        debug("rockchip,vbus-gpio node missing!");
+        debug("Can't get vbus supply\n");

VBUS in caps

change the print message?
debug("Can't get VBUS regulator\n") ?

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 9 lines
drivers/usb/host/xhci-rockchip.c +5 -0
+#endif
        return 0;
  }
  +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    int ret = 0;

You don't need to init ret, it's always set right below.

OK, I will correct

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 88

Quoted 5 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+    ret = regulator_set_enable(plat->vbus_supply, value);
+    if (ret)
+        debug("XHCI: Failed to set vbus supply\n");

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Considering the case vbus is always on, it is right with no vbus regulator. So maybe it's not an error actually.

Quoted 7 lines
Quoted 3 lines

Regulator failed to turn on, that's an error, right ?
Why would VBUS be always on ? You can just add a GPIO-regulator into the DT and then the VBUS is no longer always on.

It's certainly right adding a GPIO-regulator into the DT. But when it's designed as a host only port, the VBUS would be fixed to on by hardware and there is no gpio for it. In this case, setting regulator will return fail, but it's also a right case. So I think it can be treated as a debug or warning message.

Not necessarily: we sometimes put a USB hub on our modules and turn it on and off via the vbus_supply when enabling/disabling the USB controller.

In fact we do just that for the RK3399-Q7.
See https://patchwork.ozlabs.org/patch/769256/ <https://patchwork.ozlabs.org/patch/769256/>.

Quoted 55 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+    return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata *plat,
+                  bool value)
+{
+    return 0;
+}
+#endif
+
  /*
   * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3

Core
* @dwc: Pointer to our controller context structure

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 6 lines
drivers/usb/host/xhci-rockchip.c +1 -2
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
      hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
              HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
  -    /* setup the Vbus gpio here */
-    if (dm_gpio_is_valid(&plat->vbus_gpio))
-        dm_gpio_set_value(&plat->vbus_gpio, 1);
+    rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

Quoted 4 lines
Quoted 3 lines

The return value can be ignored when vbus is always on. So is it enough just print message in
the rockchip_xhci_set_vbus function?

See above, why is VBUS always on

answer above

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
drivers/usb/host/xhci-rockchip.c +1 -0
      ret = rockchip_xhci_core_init(ctx, dev);
      if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
    static int xhci_usb_remove(struct udevice *dev)
  {
+    struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
      struct rockchip_xhci *ctx = dev_get_priv(dev);
      int ret;
  @@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
      if (ret)
          return ret;
Quoted 1 line

+ rockchip_xhci_set_vbus(plat, false);

Handle return value

I think print message may be is enough.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
      return 0;

}

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de <mailto:[email protected]>
https://lists.denx.de/listinfo/u-boot <https://lists.denx.de/listinfo/u-boot>

#10 lore raw

PATCH v4 4/11 usb: host: xhci-rockchip: use fixed regulator to control vbus

In reply to rock-chips (daniel.meng)
Quoted 63 lines · rock-chips(daniel.meng)
Quoted 52 lines · Marek Vasut
Quoted 51 lines · rock-chips(daniel.meng)
Quoted 49 lines · Marek Vasut
Quoted 48 lines · Meng Dongyang

Use fixed regulator to control the voltage of vbus and turn off vbus when usb stop.

---

Changes in v4:
- Splited from patch [Uboot,v3,04/10]
- Define set vbus as empty function if the macros aren't set

Changes in v3: None
Changes in v2:
- Use fixed regulator to control vbus instead of gpio

   drivers/usb/host/xhci-rockchip.c | 41
+++++++++++++++++++++++++++++++---------
   1 file changed, 32 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-rockchip.c +1 -1
index f559830..dc9cd56 100644
@@ -11,10 +11,10 @@
   #include <malloc.h>
   #include <usb.h>
   #include <watchdog.h>
-#include <asm/gpio.h>
   #include <linux/errno.h>
   #include <linux/compat.h>
   #include <linux/usb/dwc3.h>
+#include <power/regulator.h>
     #include "xhci.h"
   @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;
   struct rockchip_xhci_platdata {
       fdt_addr_t hcd_base;
       fdt_addr_t phy_base;
drivers/usb/host/xhci-rockchip.c +1 -3
-    struct gpio_desc vbus_gpio;
+    struct udevice *vbus_supply;
   };
     /*
@@ -66,15 +66,37 @@ static int xhci_usb_ofdata_to_platdata(struct
 udevice *dev)
           return -ENXIO;
       }
   -    /* Vbus gpio */
-    ret = gpio_request_by_name(dev, "rockchip,vbus-gpio", 0,
-                   &plat->vbus_gpio, GPIOD_IS_OUT);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 74

Quoted 7 lines
drivers/usb/host/xhci-rockchip.c +5 -1
+#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+    /* Vbus regulator */
+    ret = device_get_supply_regulator(dev, "vbus-supply",
+                      &plat->vbus_supply);
       if (ret)
-        debug("rockchip,vbus-gpio node missing!");
+        debug("Can't get vbus supply\n");

VBUS in caps

Quoted 2 lines

change the print message?
debug("Can't get VBUS regulator\n") ?

Yes

Quoted 22 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 84

Quoted 10 lines
drivers/usb/host/xhci-rockchip.c +5 -0
+#endif
         return 0;
   }
   +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR)
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata
 *plat,
+                  bool value)
+{
+    int ret = 0;

You don't need to init ret, it's always set right below.

OK, I will correct

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

drivers/usb/host/xhci-rockchip.c static int xhci_usb_ofdata_to_platdata(struct udevice *dev) · line 88

Quoted 5 lines
drivers/usb/host/xhci-rockchip.c +4 -0
+
+    ret = regulator_set_enable(plat->vbus_supply, value);
+    if (ret)
+        debug("XHCI: Failed to set vbus supply\n");

That shouldn't be debug, that's a printf() because it's actually a failure. Or error() I guess ...

Considering the case vbus is always on, it is right with no vbus regulator.
So maybe it's not an error actually.

Quoted 8 lines
Quoted 3 lines

Regulator failed to turn on, that's an error, right ?
Why would VBUS be always on ? You can just add a GPIO-regulator into the DT and then the VBUS is no longer always on.

It's certainly right adding a GPIO-regulator into the DT. But when it's designed
as a host only port, the VBUS would be fixed to on by hardware and there is no
gpio for it.

Ugh, what ? You can certainly have a host port which does support switching VBUS on/off. In fact, that's the majority case. You can just toggle VBUS and reenumerate the whole bus, that's normal and majority of the USB controller driver(s) do it.

Quoted 2 lines

In this case, setting regulator will return fail, but it's also a right case.

No, if something fails, it's definitely not right. If you use dummy regulator on your hardware because your hardware doesn't support VBUS switching (because it's sub-par), that's fine, but setting the regulator on/off must not fail in that case.

Quoted 1 line

So I think it can be treated as a debug or warning message.

No, this is an error.

Quoted 42 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines
drivers/usb/host/xhci-rockchip.c +10 -0
+    return ret;
+}
+#else
+static int rockchip_xhci_set_vbus(struct rockchip_xhci_platdata
 *plat,
+                  bool value)
+{
+    return 0;
+}
+#endif
+
   /*
    * rockchip_dwc3_phy_setup() - Configure USB PHY Interface of DWC3

Core
* @dwc: Pointer to our controller context structure

drivers/usb/host/xhci-rockchip.c static int xhci_usb_probe(struct udevice *dev) · line 178

Quoted 6 lines
drivers/usb/host/xhci-rockchip.c +1 -2
@@ -153,9 +175,7 @@ static int xhci_usb_probe(struct udevice *dev)
       hcor = (struct xhci_hcor *)((uint64_t)ctx->hcd +
               HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
   -    /* setup the Vbus gpio here */
-    if (dm_gpio_is_valid(&plat->vbus_gpio))
-        dm_gpio_set_value(&plat->vbus_gpio, 1);
+    rockchip_xhci_set_vbus(plat, true);

What about handling the return value ?

Quoted 4 lines
Quoted 3 lines

The return value can be ignored when vbus is always on. So is it enough just print message in
the rockchip_xhci_set_vbus function?

See above, why is VBUS always on

answer above

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
drivers/usb/host/xhci-rockchip.c +1 -0
       ret = rockchip_xhci_core_init(ctx, dev);
       if (ret) {
@@ -168,6 +188,7 @@ static int xhci_usb_probe(struct udevice *dev)
     static int xhci_usb_remove(struct udevice *dev)
   {
+    struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
       struct rockchip_xhci *ctx = dev_get_priv(dev);
       int ret;
   @@ -178,6 +199,8 @@ static int xhci_usb_remove(struct udevice *dev)
       if (ret)
           return ret;
Quoted 1 line

+ rockchip_xhci_set_vbus(plat, false);

Handle return value

Quoted 1 line

I think print message may be is enough.

No, printing a message and ignoring error is NOT enough, the error must be propagated.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
       return 0;

}

Signature · 2 lines
Best regards,
Marek Vasut