rk3328: add support of usb host and gadget
Subsystems (4)
v6 cover rk3328: add support of usb host and gadget
Add support of usb host and gadget function for rk3328.
Changed in v6:
- Rebase on the newest code of master branch
- Make xhci-rockchip driver depend on DM_REGULATOR and DM_USB
- Remove #ifdef DM_RERULATOR and DM_USB in xhci-rockchip driver
- Use dev_read_boot() instead of fdt_getprop() in dwc2 driver
Changes in v5:
- Propagate return value and print error message when failed
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 (8):
usb: Kconfig: add depends on feature for xhci-rockchip driver
usb: host: xhci-rockchip: use fixed regulator to control vbus
rockchip: dts: rk3328: support and enable xhci
rockchip: configs: rk3328: enable dwc2 driver and config fastboot
usb: dwc2: use dev_read_bool() instead of fdt_getprop()
rockchip: 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 | 25 +++++++++++++++++++- arch/arm/dts/rk3328.dtsi | 10 ++++++++ arch/arm/dts/rk3399-evb.dts | 16 +++++++++++-- board/rockchip/evb_rk3328/evb-rk3328.c | 42 ++++++++++++++++++++++++++++++++++ configs/evb-rk3328_defconfig | 19 +++++++++++++-- drivers/usb/host/Kconfig | 2 ++ drivers/usb/host/dwc2.c | 15 +++++------- drivers/usb/host/xhci-rockchip.c | 36 ++++++++++++++--------------- include/configs/rk3328_common.h | 3 +++ 9 files changed, 136 insertions(+), 32 deletions(-)
Signature · 1 line
1.9.1
PATCH v6 1/8 usb: Kconfig: add depends on features for xhci-rockchip driver
The xhci-rockchip driver depends on DM_REGULATOR and DM_USB. So add depends on features in Kconfig to make the driver explicitly depend on DM_REGULATOR and DM_USB.
---
Changes in v6:
- New patch, add depends on features for xhci-rockchip in Kconfig
drivers/usb/host/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/host/Kconfig +2 -0
@@ -34,6 +34,8 @@ config USB_XHCI_MVEBU config USB_XHCI_ROCKCHIP bool "Support for Rockchip on-chip xHCI USB controller" depends on ARCH_ROCKCHIP + depends on DM_REGULATOR + depends on DM_USB default y help Enables support for the on-chip xHCI controller on Rockchip SoCs.
Signature · 1 line
1.9.1
PATCH v6 2/8 usb: host: xhci-rockchip: use fixed regulator to control vbus
In reply to Meng DongyangUse fixed regulator to control the voltage of vbus and turn off vbus when usb stop.
---
Changes in v6:
- Remove #ifdef DM_REGULATOR and DM_USB due to the addition in Kconfig
Changes in v5:
- Propagate the return value of setting VBus and print error when failed
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 | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/usb/host/xhci-rockchip.c +18 -18
@@ -48,7 +48,7 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev)*/ plat->hcd_base =devfdt_get_addr (dev);if (plat->hcd_base ==FDT_ADDR_T_NONE ) { -debug ("Can't get the XHCI register base address\n" ); +error ("Can't get the XHCI register base address\n" );return -ENXIO ; }
@@ -62,17 +62,15 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev) }if (plat->phy_base ==FDT_ADDR_T_NONE ) { -debug ("Can't get the usbphy register address\n" ); +error ("Can't get the usbphy register address\n" );return -ENXIO ; } -#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 ("Can't get vbus supply\n" ); -#endif +debug ("Can't get VBus regulator!\n" );return 0 ; }
@@ -126,7 +124,7 @@ static int rockchip_xhci_core_init(struct rockchip_xhci *rkxhci, ret =dwc3_core_init (rkxhci->dwc3_reg);if (ret) { -debug ("failed to initialize core\n" ); +error ("failed to initialize core\n" );return ret; }
@@ -155,15 +153,17 @@ static int xhci_usb_probe(struct udevice *dev) hcor = (struct xhci_hcor *)((uint64_t )ctx->hcd +HC_LENGTH (xhci_readl (&ctx->hcd->cr_capbase))); -#if defined(CONFIG_DM_USB ) && defined(CONFIG_DM_REGULATOR ) - ret =regulator_set_enable (plat->vbus_supply, true); -if (ret) -debug ("XHCI: Failed to enable vbus supply\n" ); -#endif +if (plat->vbus_supply) { + ret =regulator_set_enable (plat->vbus_supply, true); +if (ret) { +error ("XHCI: failed to set VBus supply\n" ); +return ret; + } + } ret =rockchip_xhci_core_init (ctx, dev);if (ret) { -debug ("XHCI: failed to initialize controller\n" ); +error ("XHCI: failed to initialize controller\n" );return ret; }
@@ -183,13 +183,13 @@ static int xhci_usb_remove(struct udevice *dev)if (ret)return ret; -#if defined(CONFIG_DM_USB ) && defined(CONFIG_DM_REGULATOR ) - ret =regulator_set_enable (plat->vbus_supply, false); -if (ret) -debug ("XHCI: Failed to disable vbus supply\n" ); -#endif +if (plat->vbus_supply) { + ret =regulator_set_enable (plat->vbus_supply, false); +if (ret) +error ("XHCI: failed to set VBus supply\n" ); + } -return 0 ; +return ret; }static const struct udevice_id xhci_usb_ids[] = {
Signature · 1 line
1.9.1
PATCH v6 3/8 rockchip: dts: rk3328: add fix-regulator node for xhci
In reply to Meng DongyangThe driver changes gpio to fix-regulator to control vbus, so add fix-regulator node in DTS for xhci driver.
---
Changes in v6:
- New patch, splited from [PATCH,v5,06/11]
arch/arm/dts/rk3328-evb.dts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm/dts/rk3328-evb.dts +10 -1
@@ -14,6 +14,15 @@ chosen { stdout-path = &uart2; }; + + vcc5v0_host_xhci: vcc5v0-host-xhci-drv { + compatible = "regulator-fixed"; + enable-active-high; + regulator-name = "vcc5v0_host_xhci"; + gpio = <&gpio0 0 GPIO_ACTIVE_HIGH>; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + }; }; &uart2 {
@@ -53,6 +62,6 @@ }; &usb_host0_xhci { - rockchip,vbus-gpio = <&gpio0 0 GPIO_ACTIVE_HIGH>; + vbus-supply = <&vcc5v0_host_xhci>; status = "okay"; };
Signature · 1 line
1.9.1
PATCH v6 4/8 rockchip: configs: rk3328: enable dwc2 driver and config fastboot
In reply to Meng DongyangConfig dwc2 driver support host and gadget function. Add support of fastboot function.
---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
configs/evb-rk3328_defconfig | 19 +++++++++++++++++-- include/configs/rk3328_common.h | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-)
configs/evb-rk3328_defconfig +17 -2
@@ -31,12 +31,27 @@ CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYS_NS16550=y CONFIG_SYSRESET=y CONFIG_USB=y -CONFIG_USB_XHCI_HCD=y -CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y CONFIG_USB_OHCI_HCD=y CONFIG_USB_OHCI_GENERIC=y CONFIG_USB_STORAGE=y +CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_XHCI_HCD=y +CONFIG_USB_XHCI_RK=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_USB_GADGET_DUALSPEED=y +CONFIG_USB_GADGET_DWC2_OTG=y +CONFIG_USB_FUNCTION_FASTBOOT=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_FASTBOOT_FLASH=y +CONFIG_FASTBOOT_FLASH_MMC_DEV=1 +CONFIG_FASTBOOT_BUF_ADDR=0x00800800 +CONFIG_FASTBOOT_BUF_SIZE=0x08000000 CONFIG_USE_TINY_PRINTF=y CONFIG_ERRNO_STR=y
include/configs/rk3328_common.h +3 -0
@@ -59,6 +59,9 @@#endif +/* dwc2 otg */ +#define CONFIG_USB_DWC2 +/* rockchip ohci host driver */ #define CONFIG_USB_OHCI_NEW #define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 1
Signature · 1 line
1.9.1
PATCH v6 5/8 usb: dwc2: use dev_read_bool() instead of fdt_getprop()
In reply to Meng DongyangUse dev_read_bool() instead of fdt_getprop() to get the property from DTS. And add a comment for "hnp-srp-disable" property to fully describe its effect.
---
Changes in v6:
- New patch
- Use dev_read_bool() instead of fdt_getprop()
- Add a comment for "hnp-srp-disable" feature
drivers/usb/host/dwc2.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/usb/host/dwc2.c +6 -9
@@ -43,6 +43,10 @@ struct dwc2_priv {struct dwc2_core_regs *regs;int root_hub_devnum;bool ext_vbus; +/* +* The hnp/srp capability must be disabled if the platform +* does't support hnp/srp. Otherwise the force mode can't work. +*/ bool hnp_srp_disable;bool oc_disable; };
@@ -1247,15 +1251,8 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)return -EINVAL ; priv->regs = (struct dwc2_core_regs *)addr; - prop =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), -"disable-over-current" ,NULL ); -if (prop) - priv->oc_disable = true; - - prop =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), -"hnp-srp-disable" ,NULL ); -if (prop) - priv->hnp_srp_disable = true; + priv->oc_disable =dev_read_bool (dev,"disable-over-current" ); + priv->hnp_srp_disable =dev_read_bool (dev,"hnp-srp-disable" );return 0 ; }
Signature · 1 line
1.9.1
Heiko Stuebner
maintainerPATCH v6 5/8 usb: dwc2: use dev_read_bool() instead of fdt_getprop()
Hi,
Am Mittwoch, 21. Juni 2017, 11:58:24 CEST schrieb Meng Dongyang:
Quoted 35 lines
Use
dev_read_bool()instead offdt_getprop()to get the property from DTS. And add a comment for "hnp-srp-disable" property to fully describe its effect.Signed-off-by Meng Dongyang <[email protected]>---
Changes in v6:
- New patch
- Usedev_read_bool()instead offdt_getprop()
- Add a comment for "hnp-srp-disable" featuredrivers/usb/host/dwc2.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)drivers/usb/host/dwc2.c +4
-1@@ -43,6 +43,10 @@ struct dwc2_priv {struct dwc2_core_regs *regs;int root_hub_devnum;bool ext_vbus; +/* +* The hnp/srp capability must be disabled if the platform +* does't support hnp/srp. Otherwise the force mode can't work. +*/ bool hnp_srp_disable;bool oc_disable; };@@ -1247,15 +1251,8 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)return -EINVAL ; priv->regs = (struct dwc2_core_regs *)addr; - prop = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
drivers/usb/host/dwc2.c static int dwc2_usb_ofdata_to_platdata(struct udevice *dev) · line 1255
Quoted 10 lines
drivers/usb/host/dwc2.c +2
-8- "disable-over-current", NULL); -if (prop) - priv->oc_disable = true; - - prop =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), -"hnp-srp-disable" ,NULL ); -if (prop) - priv->hnp_srp_disable = true; + priv->oc_disable =dev_read_bool (dev,"disable-over-current" ); + priv->hnp_srp_disable =dev_read_bool (dev,"hnp-srp-disable" );
with this patch applied, I get
drivers/usb/host/dwc2.c: In function ‘dwc2_usb_ofdata_to_platdata’:drivers/usb/host/dwc2.c:1246:14: warning: unused variable ‘prop’ [-Wunused-variable]
const void *prop;
^~~~so you might want to remove the prop var as well?
PATCH v6 5/8 usb: dwc2: use dev_read_bool() instead of fdt_getprop()
Quoted 50 lines · Heiko Stuebner
Hi,
Am Mittwoch, 21. Juni 2017, 11:58:24 CEST schrieb Meng Dongyang:
Quoted 35 lines
Use
dev_read_bool()instead offdt_getprop()to get the property from DTS. And add a comment for "hnp-srp-disable" property to fully describe its effect.Signed-off-by Meng Dongyang <[email protected]>---
Changes in v6:
- New patch
- Usedev_read_bool()instead offdt_getprop()
- Add a comment for "hnp-srp-disable" featuredrivers/usb/host/dwc2.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)drivers/usb/host/dwc2.c +4
-1@@ -43,6 +43,10 @@ struct dwc2_priv {struct dwc2_core_regs *regs;int root_hub_devnum;bool ext_vbus; +/* +* The hnp/srp capability must be disabled if the platform +* does't support hnp/srp. Otherwise the force mode can't work. +*/ bool hnp_srp_disable;bool oc_disable; };@@ -1247,15 +1251,8 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)return -EINVAL ; priv->regs = (struct dwc2_core_regs *)addr; - prop = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),drivers/usb/host/dwc2.c static int dwc2_usb_ofdata_to_platdata(struct udevice *dev) · line 1255
Quoted 10 lines
drivers/usb/host/dwc2.c +2
-8- "disable-over-current", NULL); -if (prop) - priv->oc_disable = true; - - prop =fdt_getprop (gd->fdt_blob,dev_of_offset (dev), -"hnp-srp-disable" ,NULL ); -if (prop) - priv->hnp_srp_disable = true; + priv->oc_disable =dev_read_bool (dev,"disable-over-current" ); + priv->hnp_srp_disable =dev_read_bool (dev,"hnp-srp-disable" );with this patch applied, I get
Quoted 6 lines
drivers/usb/host/dwc2.c: In function ‘dwc2_usb_ofdata_to_platdata’:drivers/usb/host/dwc2.c:1246:14: warning: unused variable ‘prop’ [-Wunused-variable]const void *prop; ^~~~so you might want to remove the prop var as well?
Yes, I forgot this.
Quoted 2 lines
PATCH v6 6/8 rockchip: rk3328: board: add support of dwc2 gadget
In reply to Meng DongyangProbe dwc2 udc in the function of board_usb_start to enable usb gadget function.
---
Changes in v6: None
Chagnes in v5: None
Changes in v4: None
Changes in v3: None
board/rockchip/evb_rk3328/evb-rk3328.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
board/rockchip/evb_rk3328/evb-rk3328.c +42 -0
@@ -31,7 +31,49 @@ int dram_init_banksize(void)return 0 ; } +#if defined(CONFIG_USB_GADGET ) && defined(CONFIG_USB_GADGET_DWC2_OTG ) +#include <usb.h> +#include <usb/dwc2_udc.h> + +static struct dwc2_plat_otg_data rk3328_otg_data = { + .rx_fifo_sz =512 , + .np_tx_fifo_sz =16 , + .tx_fifo_sz =128 , +}; +int board_usb_init (int index,enum usb_init_type init) { +int node; +const char *mode; +bool matched = false; +const void *blob = gd->fdt_blob; + +/* find the usb_otg node */ + node =fdt_node_offset_by_compatible (blob,-1 , +"rockchip,rk3328-usb" ); + +while (node >0 ) { + mode =fdt_getprop (blob, node,"dr_mode" ,NULL ); +if (mode &&strcmp (mode,"otg" ) ==0 ) { + matched = true; +break ; + } + + node =fdt_node_offset_by_compatible (blob, node, +"rockchip,rk3328-usb" ); + } +if (!matched) { +debug ("Not found usb_otg device\n" ); +return -ENODEV ; + } + + rk3328_otg_data.regs_otg =fdtdec_get_addr (blob, node,"reg" ); + +return dwc2_udc_probe (&rk3328_otg_data); +} + +int board_usb_cleanup (int index,enum usb_init_type init) +{return 0 ; } +#endif
Signature · 1 line
1.9.1
PATCH v6 7/8 rockchip: dts: rk3328: support and enable dwc2
In reply to Meng DongyangEnable dwc2 controller and add fixed regulator for dwc2 controller to control vbus.
---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- add hnp-srp-disable property
arch/arm/dts/rk3328-evb.dts | 14 ++++++++++++++ arch/arm/dts/rk3328.dtsi | 10 ++++++++++ 2 files changed, 24 insertions(+)
arch/arm/dts/rk3328-evb.dts +14 -0
@@ -15,6 +15,15 @@ stdout-path = &uart2; }; + vcc5v0_otg: vcc5v0-otg-drv { + compatible = "regulator-fixed"; + enable-active-high; + regulator-name = "vcc5v0_otg"; + gpio = <&gpio0 27 GPIO_ACTIVE_HIGH>; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + }; + vcc5v0_host_xhci: vcc5v0-host-xhci-drv { compatible = "regulator-fixed"; enable-active-high;
@@ -61,6 +70,11 @@ status = "okay"; }; +&usb20_otg { + vbus-supply = <&vcc5v0_otg>; + status = "okay"; +}; + &usb_host0_xhci { vbus-supply = <&vcc5v0_host_xhci>; status = "okay";
arch/arm/dts/rk3328.dtsi +10 -0
@@ -460,6 +460,16 @@ status = "disabled"; }; + usb20_otg: usb at ff580000 { + compatible = "rockchip,rk3328-usb", "rockchip,rk3066-usb", + "snps,dwc2"; + reg = <0x0 0xff580000 0x0 0x40000>; + interrupts = <GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>; + hnp-srp-disable; + dr_mode = "otg"; + 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
PATCH v6 8/8 rockchip: dts: rk3399: control vbus of typec by fixed regulator
In reply to Meng DongyangAdd fixed regulator for the port of typec0 and typec1 to control vbus instead of gpio.
---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
arch/arm/dts/rk3399-evb.dts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
arch/arm/dts/rk3399-evb.dts +14 -2
@@ -60,6 +60,18 @@ gpio = <&gpio4 25 GPIO_ACTIVE_HIGH>; }; + vcc5v0_typec0: vcc5v0-typec0-en { + compatible = "regulator-fixed"; + regulator-name = "vcc5v0_typec0"; + gpio = <&gpio1 3 GPIO_ACTIVE_HIGH>; + }; + + vcc5v0_typec1: vcc5v0-typec1-en { + compatible = "regulator-fixed"; + regulator-name = "vcc5v0_typec1"; + gpio = <&gpio1 4 GPIO_ACTIVE_HIGH>; + }; + clkin_gmac: external-gmac-clock { compatible = "fixed-clock"; clock-frequency = <125000000>;
@@ -163,7 +175,7 @@ }; &dwc3_typec0 { - rockchip,vbus-gpio = <&gpio1 3 GPIO_ACTIVE_HIGH>; + vbus-supply = <&vcc5v0_typec0>; status = "okay"; };
@@ -176,7 +188,7 @@ }; &dwc3_typec1 { - rockchip,vbus-gpio = <&gpio1 4 GPIO_ACTIVE_HIGH>; + vbus-supply = <&vcc5v0_typec1>; status = "okay"; };
Signature · 1 line
1.9.1