[PATCH 00/10] Restore USB and add UMS support for STiH407-B2260

This series is : _ restoring USB on STiH410-B2260 which hasn't been tested since a while. _ migrating STi DWC3 glue from proprietary driver to dwc3-generic driver. _ adding UMS support for STiH410-B2260.
Patrice Chotard (10): ARM: dts: sti: Add fixed clock for ehci and ohci nodes in stih410-b2260.dtsi configs: stih410-b2260: Enable DM_REGULATOR flag usb: dwc3-generic: Reorder include usb: dwc3-generic: Add STih407 support configs: stih410-b2260: Enable USB_DWC3_GENERIC flag dw3-generic: Add dependencies whith SYSCON and REGMAP usb: dwc3: Remove dwc3 glue driver support for STi configs: stih410-b2260: Enable DM_USB_GADGET flag board: stih410-b2260: Remove board_usb_init/cleanup() configs: stih410-b2260: Enable CMD_USB_MASS_STORAGE flag
MAINTAINERS | 2 - arch/arm/dts/stih410-b2260-u-boot.dtsi | 10 + board/st/stih410-b2260/board.c | 30 --- configs/stih410-b2260_defconfig | 4 + drivers/usb/dwc3/Kconfig | 4 + drivers/usb/dwc3/dwc3-generic.c | 129 +++++++++++-- drivers/usb/host/Kconfig | 9 - drivers/usb/host/Makefile | 1 - drivers/usb/host/dwc3-sti-glue.c | 253 ------------------------- 9 files changed, 136 insertions(+), 306 deletions(-) delete mode 100644 drivers/usb/host/dwc3-sti-glue.c

On STi platforms, all clocks are enabled by BOOTROM, so CONFIG_CLK is not set as no clock driver for STI exists.
As ehci-generic and ohci-generic drivers are used on platforms where CONFIG_CLK is set, clk_get_bulk() returns-ENOSYS in case of stih410-b2260. To avoid this error, add fixed clocks for ehci and ohci nodes for stih410-b2260 to fix the following errors:
Bus usb@9a03c00: ohci_generic usb@9a03c00: Failed to get clocks (ret=-19) Port not available. Bus usb@9a03e00: ehci_generic usb@9a03e00: Failed to get clocks (ret=-19) Port not available. Bus usb@9a83c00: ohci_generic usb@9a83c00: Failed to get clocks (ret=-19) Port not available. Bus usb@9a83e00: ehci_generic usb@9a83e00: Failed to get clocks (ret=-19) Port not available. scanning bus dwc3@9900000 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
arch/arm/dts/stih410-b2260-u-boot.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/arch/arm/dts/stih410-b2260-u-boot.dtsi b/arch/arm/dts/stih410-b2260-u-boot.dtsi index 3b080ac7a1b..e9d7ec92281 100644 --- a/arch/arm/dts/stih410-b2260-u-boot.dtsi +++ b/arch/arm/dts/stih410-b2260-u-boot.dtsi @@ -14,20 +14,30 @@ }; };
+ clk_usb: clk-usb { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <100000000>; + }; + ohci0: usb@9a03c00 { compatible = "generic-ohci"; + clocks = <&clk_usb>; };
ehci0: usb@9a03e00 { compatible = "generic-ehci"; + clocks = <&clk_usb>; };
ohci1: usb@9a83c00 { compatible = "generic-ohci"; + clocks = <&clk_usb>; };
ehci1: usb@9a83e00 { compatible = "generic-ehci"; + clocks = <&clk_usb>; }; }; };

Since commit 6aa8bde8786d ("usb: host: ehci-generic: Remove DM_REGULATOR flag") device_get_supply_regulator() returns -ENOSYS which is not handle by ehci_enable_vbus_supply() and thus, ehci_usb_probe() return an error.
By enabling DM_REGULATOR flag, device_get_supply_regulator() return -ENOENT which is handle and ehci_usb_probe() return 0.
This fixed the following issue: stih410-b2260 =>usb start starting USB... Bus dwc3@9900000: Register 2000240 NbrPorts 2 Starting the controller USB XHCI 1.00 Bus usb@9a03c00: USB OHCI 1.0 Bus usb@9a03e00: probe failed, error -38 Bus usb@9a83c00: USB OHCI 1.0 Bus usb@9a83e00: probe failed, error -38 scanning bus dwc3@9900000 for devices... 1 USB Device(s) found scanning bus usb@9a03c00 for devices... data abort pc : [<7df929b4>] lr : [<7df92918>] reloc pc : [<7d6409b4>] lr : [<7d640918>] sp : 7c73b848 ip : 9cf13c5c fp : 7c879d08 r10: 7c85d040 r9 : 7c74ded0 r8 : 09a03c00 r7 : 00000002 r6 : 7c85d080 r5 : 7c86a040 r4 : 00000000 r3 : 00000000 r2 : 00000000 r1 : 7c85d080 r0 : 7c85d040 Flags: nzCv IRQs off FIQs off Mode SVC_32 Code: 05853ae4 0affffe2 e59a2010 e59a300c (e5832010) Resetting CPU ...
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index 815f7557d69..e312ca492d2 100644 --- a/configs/stih410-b2260_defconfig +++ b/configs/stih410-b2260_defconfig @@ -48,6 +48,7 @@ CONFIG_MMC_SDHCI_STI=y CONFIG_PHY=y CONFIG_STI_USB_PHY=y CONFIG_PINCTRL=y +CONFIG_DM_REGULATOR=y CONFIG_STI_RESET=y CONFIG_STI_ASC_SERIAL=y CONFIG_SYSRESET=y

Reorder include following rules available here : https://docs.u-boot.org/en/latest/develop/codingstyle.html#include-files
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
drivers/usb/dwc3/dwc3-generic.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 2ab41cbae45..cb96e1f344f 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -7,29 +7,28 @@ * Based on dwc3-omap.c. */
+#include <clk.h> #include <cpu_func.h> -#include <log.h> #include <dm.h> -#include <dm/device-internal.h> -#include <dm/lists.h> #include <dwc3-uboot.h> #include <generic-phy.h> +#include <log.h> +#include <malloc.h> +#include <reset.h> +#include <usb.h> +#include <asm/gpio.h> +#include <dm/device-internal.h> +#include <dm/lists.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/printk.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> -#include <malloc.h> #include <power/regulator.h> -#include <usb.h> -#include "core.h" -#include "gadget.h" -#include <reset.h> -#include <clk.h> #include <usb/xhci.h> -#include <asm/gpio.h> - +#include "core.h" #include "dwc3-generic.h" +#include "gadget.h"
struct dwc3_generic_plat { fdt_addr_t base;

On 1/14/25 3:45 PM, Patrice Chotard wrote:
Reorder include following rules available here : https://docs.u-boot.org/en/latest/develop/codingstyle.html#include-files
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/dwc3-generic.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 2ab41cbae45..cb96e1f344f 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -7,29 +7,28 @@
- Based on dwc3-omap.c.
*/
+#include <clk.h> #include <cpu_func.h> -#include <log.h> #include <dm.h> -#include <dm/device-internal.h> -#include <dm/lists.h> #include <dwc3-uboot.h> #include <generic-phy.h> +#include <log.h> +#include <malloc.h> +#include <reset.h> +#include <usb.h> +#include <asm/gpio.h> +#include <dm/device-internal.h> +#include <dm/lists.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/printk.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> -#include <malloc.h> #include <power/regulator.h> -#include <usb.h> -#include "core.h" -#include "gadget.h" -#include <reset.h> -#include <clk.h> #include <usb/xhci.h> -#include <asm/gpio.h>
Can you remove some of them too ?

On 1/14/25 15:51, Marek Vasut wrote:
On 1/14/25 3:45 PM, Patrice Chotard wrote:
Reorder include following rules available here : https://docs.u-boot.org/en/latest/develop/codingstyle.html#include-files
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/dwc3-generic.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 2ab41cbae45..cb96e1f344f 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -7,29 +7,28 @@ * Based on dwc3-omap.c. */ +#include <clk.h> #include <cpu_func.h> -#include <log.h> #include <dm.h> -#include <dm/device-internal.h> -#include <dm/lists.h> #include <dwc3-uboot.h> #include <generic-phy.h> +#include <log.h> +#include <malloc.h> +#include <reset.h> +#include <usb.h> +#include <asm/gpio.h> +#include <dm/device-internal.h> +#include <dm/lists.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/printk.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> -#include <malloc.h> #include <power/regulator.h> -#include <usb.h> -#include "core.h" -#include "gadget.h" -#include <reset.h> -#include <clk.h> #include <usb/xhci.h> -#include <asm/gpio.h>
Can you remove some of them too ?
Hi Marek
Effectively, some seems useless, i will fix this in v2
Thanks Patrice

Add STi glue logic to manage the DWC3 HC on STiH407 SoC family. It configures the internal glue logic and syscfg registers.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
drivers/usb/dwc3/dwc3-generic.c | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index cb96e1f344f..0cd03bf0787 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -14,7 +14,9 @@ #include <generic-phy.h> #include <log.h> #include <malloc.h> +#include <regmap.h> #include <reset.h> +#include <syscon.h> #include <usb.h> #include <asm/gpio.h> #include <dm/device-internal.h> @@ -511,6 +513,111 @@ struct dwc3_glue_ops rk_ops = { .glue_get_ctrl_dev = dwc3_rk_glue_get_ctrl_dev, };
+void dwc3_stih407_glue_configure(struct udevice *dev, int index, + enum usb_dr_mode mode) +{ +/* glue registers */ +#define CLKRST_CTRL 0x00 +#define AUX_CLK_EN BIT(0) +#define SW_PIPEW_RESET_N BIT(4) +#define EXT_CFG_RESET_N BIT(8) + +#define XHCI_REVISION BIT(12) + +#define USB2_VBUS_MNGMNT_SEL1 0x2C +#define USB2_VBUS_UTMIOTG 0x1 + +#define SEL_OVERRIDE_VBUSVALID(n) ((n) << 0) +#define SEL_OVERRIDE_POWERPRESENT(n) ((n) << 4) +#define SEL_OVERRIDE_BVALID(n) ((n) << 8) + +/* Static DRD configuration */ +#define USB3_CONTROL_MASK 0xf77 + +#define USB3_DEVICE_NOT_HOST BIT(0) +#define USB3_FORCE_VBUSVALID BIT(1) +#define USB3_DELAY_VBUSVALID BIT(2) +#define USB3_SEL_FORCE_OPMODE BIT(4) +#define USB3_FORCE_OPMODE(n) ((n) << 5) +#define USB3_SEL_FORCE_DPPULLDOWN2 BIT(8) +#define USB3_FORCE_DPPULLDOWN2 BIT(9) +#define USB3_SEL_FORCE_DMPULLDOWN2 BIT(10) +#define USB3_FORCE_DMPULLDOWN2 BIT(11) + + struct dwc3_glue_data *glue = dev_get_plat(dev); + struct regmap *regmap; + ulong syscfg_base; + ulong syscfg_offset; + ulong glue_base; + u32 reg; + int ret; + + /* deassert both powerdown and softreset */ + ret = reset_deassert_bulk(&glue->resets); + if (ret) { + debug("reset_deassert_bulk error: %d\n", ret); + return; + } + + regmap = syscon_regmap_lookup_by_phandle(dev, "st,syscfg"); + + syscfg_base = regmap->ranges[0].start; + glue_base = dev_read_addr_index(dev, 0); + syscfg_offset = dev_read_addr_index(dev, 1); + + reg = readl(syscfg_base + syscfg_offset); + reg &= USB3_CONTROL_MASK; + + /* glue drd init */ + switch (mode) { + case USB_DR_MODE_PERIPHERAL: + reg &= ~(USB3_DELAY_VBUSVALID + | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) + | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 + | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); + + reg |= USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID; + break; + + case USB_DR_MODE_HOST: + reg &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID + | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) + | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 + | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); + + reg |= USB3_DELAY_VBUSVALID; + break; + + default: + debug("Unsupported mode of operation %d\n", mode); + return; + } + writel(reg, syscfg_base + syscfg_offset); + + /* glue init */ + reg = readl(glue_base + CLKRST_CTRL); + + reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION; + reg &= ~SW_PIPEW_RESET_N; + + writel(reg, glue_base + CLKRST_CTRL); + + /* configure mux for vbus, powerpresent and bvalid signals */ + reg = readl(glue_base + USB2_VBUS_MNGMNT_SEL1); + + reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG); + + writel(reg, glue_base + USB2_VBUS_MNGMNT_SEL1); + + setbits_le32(glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); +}; + +struct dwc3_glue_ops stih407_ops = { + .glue_configure = dwc3_stih407_glue_configure, +}; + static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) { const char *name = ofnode_get_name(node); @@ -714,6 +821,7 @@ static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops }, { .compatible = "fsl,imx8mq-dwc3" }, { .compatible = "intel,tangier-dwc3" }, + { .compatible = "st,stih407-dwc3", .data = (ulong)&stih407_ops}, { } };

On 1/14/25 3:45 PM, Patrice Chotard wrote:
- /* glue init */
- reg = readl(glue_base + CLKRST_CTRL);
- reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION;
- reg &= ~SW_PIPEW_RESET_N;
- writel(reg, glue_base + CLKRST_CTRL);
- /* configure mux for vbus, powerpresent and bvalid signals */
- reg = readl(glue_base + USB2_VBUS_MNGMNT_SEL1);
- reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) |
SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) |
SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
- writel(reg, glue_base + USB2_VBUS_MNGMNT_SEL1);
setbits_le32() , please fix globally.
Also, I am wondering if we're not overstuffing the dwc3-generic.c with too many disparate glue code shreds, and whether it isn't just about time to split the glue code parts out of it, into separate .c files. Thoughts ?

On 1/14/25 15:53, Marek Vasut wrote:
On 1/14/25 3:45 PM, Patrice Chotard wrote:
+ /* glue init */ + reg = readl(glue_base + CLKRST_CTRL);
+ reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION; + reg &= ~SW_PIPEW_RESET_N;
+ writel(reg, glue_base + CLKRST_CTRL);
+ /* configure mux for vbus, powerpresent and bvalid signals */ + reg = readl(glue_base + USB2_VBUS_MNGMNT_SEL1);
+ reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
+ writel(reg, glue_base + USB2_VBUS_MNGMNT_SEL1);
setbits_le32() , please fix globally.
Ok
Also, I am wondering if we're not overstuffing the dwc3-generic.c with too many disparate glue code shreds, and whether it isn't just about time to split the glue code parts out of it, into separate .c files. Thoughts ?
OK i will introduce a specific dwc3-sti.c glue wrapper. I just notice that dwc3-am62.c or dwc3-uniphier.c are typically what i have to do. By the same occasion, it removes the need of patch 06/10 with REGMAP/SYSCON dependencies
Thanks Patrice

Enable USB_DWC3_GENERIC flag.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index e312ca492d2..c1092bdde29 100644 --- a/configs/stih410-b2260_defconfig +++ b/configs/stih410-b2260_defconfig @@ -61,6 +61,7 @@ CONFIG_USB_EHCI_GENERIC=y CONFIG_USB_OHCI_HCD=y CONFIG_USB_OHCI_GENERIC=y CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_MCS7830=y

Since addition of STiH407 support in dwc3-generic, SYSCON and REGMAP support are needed.
Add dependencies with SPL_REGMAP and SPL_SYSCON for: qcm6490, imx8mp_evk, phycore-imx8mp, librem5, qcom, xilinx_versal_net_virt, amd_versal2_virt, xilinx_zynqmp_kria xilinx_zynqmp_virt.
Add dependencies with SPL_REGMAP and SPL_SYSCON for am57xx_hs_evm_usb.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
drivers/usb/dwc3/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..ef82a3e9626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -26,6 +26,10 @@ config USB_DWC3_OMAP config USB_DWC3_GENERIC bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" depends on DM_USB && USB_DWC3 && MISC + select SPL_REGMAP if SPL + select SPL_SYSCON if SPL + select REGMAP + select SYSCON help Select this for Xilinx ZynqMP and similar Platforms. This wrapper supports Host and Peripheral operation modes.

On 1/14/25 3:45 PM, Patrice Chotard wrote:
Since addition of STiH407 support in dwc3-generic, SYSCON and REGMAP support are needed.
Add dependencies with SPL_REGMAP and SPL_SYSCON for: qcm6490, imx8mp_evk, phycore-imx8mp, librem5, qcom, xilinx_versal_net_virt, amd_versal2_virt, xilinx_zynqmp_kria xilinx_zynqmp_virt.
Add dependencies with SPL_REGMAP and SPL_SYSCON for am57xx_hs_evm_usb.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..ef82a3e9626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -26,6 +26,10 @@ config USB_DWC3_OMAP config USB_DWC3_GENERIC bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" depends on DM_USB && USB_DWC3 && MISC
- select SPL_REGMAP if SPL
- select SPL_SYSCON if SPL
- select REGMAP
- select SYSCON
Why was this not needed so far ? Or is this a bugfix ?

On 1/14/25 15:54, Marek Vasut wrote:
On 1/14/25 3:45 PM, Patrice Chotard wrote:
Since addition of STiH407 support in dwc3-generic, SYSCON and REGMAP support are needed.
Add dependencies with SPL_REGMAP and SPL_SYSCON for: qcm6490, imx8mp_evk, phycore-imx8mp, librem5, qcom, xilinx_versal_net_virt, amd_versal2_virt, xilinx_zynqmp_kria xilinx_zynqmp_virt.
Add dependencies with SPL_REGMAP and SPL_SYSCON for am57xx_hs_evm_usb.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..ef82a3e9626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -26,6 +26,10 @@ config USB_DWC3_OMAP config USB_DWC3_GENERIC bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" depends on DM_USB && USB_DWC3 && MISC + select SPL_REGMAP if SPL + select SPL_SYSCON if SPL + select REGMAP + select SYSCON
Why was this not needed so far ? Or is this a bugfix ?
My comment lacks of detail. By adding stih407 support, i am using syscon_regmap_lookup_by_phandle() which need that REGMAP and SYSCOn support are enabled.
Thanks Patrice

On 1/15/25 11:43 AM, Patrice CHOTARD wrote:
On 1/14/25 15:54, Marek Vasut wrote:
On 1/14/25 3:45 PM, Patrice Chotard wrote:
Since addition of STiH407 support in dwc3-generic, SYSCON and REGMAP support are needed.
Add dependencies with SPL_REGMAP and SPL_SYSCON for: qcm6490, imx8mp_evk, phycore-imx8mp, librem5, qcom, xilinx_versal_net_virt, amd_versal2_virt, xilinx_zynqmp_kria xilinx_zynqmp_virt.
Add dependencies with SPL_REGMAP and SPL_SYSCON for am57xx_hs_evm_usb.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..ef82a3e9626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -26,6 +26,10 @@ config USB_DWC3_OMAP config USB_DWC3_GENERIC bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" depends on DM_USB && USB_DWC3 && MISC + select SPL_REGMAP if SPL + select SPL_SYSCON if SPL + select REGMAP + select SYSCON
Why was this not needed so far ? Or is this a bugfix ?
My comment lacks of detail. By adding stih407 support, i am using syscon_regmap_lookup_by_phandle() which need that REGMAP and SYSCOn support are enabled.
I suspect this will now be specific to the stih glue driver , right?

On 1/15/25 20:29, Marek Vasut wrote:
On 1/15/25 11:43 AM, Patrice CHOTARD wrote:
On 1/14/25 15:54, Marek Vasut wrote:
On 1/14/25 3:45 PM, Patrice Chotard wrote:
Since addition of STiH407 support in dwc3-generic, SYSCON and REGMAP support are needed.
Add dependencies with SPL_REGMAP and SPL_SYSCON for: qcm6490, imx8mp_evk, phycore-imx8mp, librem5, qcom, xilinx_versal_net_virt, amd_versal2_virt, xilinx_zynqmp_kria xilinx_zynqmp_virt.
Add dependencies with SPL_REGMAP and SPL_SYSCON for am57xx_hs_evm_usb.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de
drivers/usb/dwc3/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..ef82a3e9626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -26,6 +26,10 @@ config USB_DWC3_OMAP config USB_DWC3_GENERIC bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" depends on DM_USB && USB_DWC3 && MISC + select SPL_REGMAP if SPL + select SPL_SYSCON if SPL + select REGMAP + select SYSCON
Why was this not needed so far ? Or is this a bugfix ?
My comment lacks of detail. By adding stih407 support, i am using syscon_regmap_lookup_by_phandle() which need that REGMAP and SYSCOn support are enabled.
I suspect this will now be specific to the stih glue driver , right?
Right it's specific to STi glue driver. But as i said in my reply of patch 04/10, the rework of patch 04/10 will remove the need of patch 06/10.
Thanks Patrice

STi is now using the dwc3-generic driver, dwc3-sti-glue driver can be removed.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
MAINTAINERS | 2 - drivers/usb/host/Kconfig | 9 -- drivers/usb/host/Makefile | 1 - drivers/usb/host/dwc3-sti-glue.c | 253 ------------------------------- 4 files changed, 265 deletions(-) delete mode 100644 drivers/usb/host/dwc3-sti-glue.c
diff --git a/MAINTAINERS b/MAINTAINERS index 8c6c0c2a4bc..0e93f88c2aa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -657,8 +657,6 @@ F: drivers/reset/sti-reset.c F: drivers/serial/serial_sti_asc.c F: drivers/sysreset/sysreset_sti.c F: drivers/timer/arm_global_timer.c -F: drivers/usb/host/dwc3-sti-glue.c -F: include/dwc3-sti-glue.h F: include/dt-bindings/clock/stih407-clks.h F: include/dt-bindings/clock/stih410-clks.h F: include/dt-bindings/reset/stih407-resets.h diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 24786a2bc91..cd1c03f10d7 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -110,15 +110,6 @@ config USB_XHCI_RCAR Choose this option to add support for USB 3.0 driver on Renesas R-Car Gen3 SoCs.
-config USB_XHCI_STI - bool "Support for STMicroelectronics STiH407 family on-chip xHCI USB controller" - depends on ARCH_STI - default y - help - Enables support for the on-chip xHCI controller on STMicroelectronics - STiH407 family SoCs. This is a driver for the dwc3 to provide the glue logic - to configure the controller. - config USB_XHCI_DRA7XX_INDEX int "DRA7XX xHCI USB index" range 0 1 diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 301bb9fdee1..902d68d0378 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -54,7 +54,6 @@ obj-$(CONFIG_USB_XHCI_GENERIC) += xhci-generic.o obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o -obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o obj-$(CONFIG_USB_XHCI_OCTEON) += dwc3-octeon-glue.o
# designware diff --git a/drivers/usb/host/dwc3-sti-glue.c b/drivers/usb/host/dwc3-sti-glue.c deleted file mode 100644 index 3e6834e38e3..00000000000 --- a/drivers/usb/host/dwc3-sti-glue.c +++ /dev/null @@ -1,253 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * STiH407 family DWC3 specific Glue layer - * - * Copyright (C) 2017, STMicroelectronics - All Rights Reserved - * Author(s): Patrice Chotard, patrice.chotard@foss.st.com for STMicroelectronics. - */ - -#include <log.h> -#include <asm/global_data.h> -#include <asm/io.h> -#include <dm.h> -#include <errno.h> -#include <dm/lists.h> -#include <regmap.h> -#include <reset-uclass.h> -#include <syscon.h> -#include <usb.h> -#include <linux/printk.h> - -#include <linux/usb/dwc3.h> -#include <linux/usb/otg.h> -#include <dwc3-sti-glue.h> - -DECLARE_GLOBAL_DATA_PTR; - -/* - * struct sti_dwc3_glue_plat - dwc3 STi glue driver private structure - * @syscfg_base: addr for the glue syscfg - * @glue_base: addr for the glue registers - * @syscfg_offset: usb syscfg control offset - * @powerdown_ctl: rest controller for powerdown signal - * @softreset_ctl: reset controller for softreset signal - * @mode: drd static host/device config - */ -struct sti_dwc3_glue_plat { - phys_addr_t syscfg_base; - phys_addr_t glue_base; - phys_addr_t syscfg_offset; - struct reset_ctl powerdown_ctl; - struct reset_ctl softreset_ctl; - enum usb_dr_mode mode; -}; - -static int sti_dwc3_glue_drd_init(struct sti_dwc3_glue_plat *plat) -{ - unsigned long val; - - val = readl(plat->syscfg_base + plat->syscfg_offset); - - val &= USB3_CONTROL_MASK; - - switch (plat->mode) { - case USB_DR_MODE_PERIPHERAL: - val &= ~(USB3_DELAY_VBUSVALID - | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) - | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 - | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); - - val |= USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID; - break; - - case USB_DR_MODE_HOST: - val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID - | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) - | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 - | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); - - val |= USB3_DELAY_VBUSVALID; - break; - - default: - pr_err("Unsupported mode of operation %d\n", plat->mode); - return -EINVAL; - } - writel(val, plat->syscfg_base + plat->syscfg_offset); - - return 0; -} - -static void sti_dwc3_glue_init(struct sti_dwc3_glue_plat *plat) -{ - unsigned long reg; - - reg = readl(plat->glue_base + CLKRST_CTRL); - - reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION; - reg &= ~SW_PIPEW_RESET_N; - - writel(reg, plat->glue_base + CLKRST_CTRL); - - /* configure mux for vbus, powerpresent and bvalid signals */ - reg = readl(plat->glue_base + USB2_VBUS_MNGMNT_SEL1); - - reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | - SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | - SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG); - - writel(reg, plat->glue_base + USB2_VBUS_MNGMNT_SEL1); - - setbits_le32(plat->glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); -} - -static int sti_dwc3_glue_of_to_plat(struct udevice *dev) -{ - struct sti_dwc3_glue_plat *plat = dev_get_plat(dev); - struct udevice *syscon; - struct regmap *regmap; - int ret; - u32 reg[4]; - - ret = ofnode_read_u32_array(dev_ofnode(dev), "reg", reg, - ARRAY_SIZE(reg)); - if (ret) { - pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret); - return ret; - } - - plat->glue_base = reg[0]; - plat->syscfg_offset = reg[2]; - - /* get corresponding syscon phandle */ - ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "st,syscfg", - &syscon); - if (ret) { - pr_err("unable to find syscon device (%d)\n", ret); - return ret; - } - - /* get syscfg-reg base address */ - regmap = syscon_get_regmap(syscon); - if (!regmap) { - pr_err("unable to find regmap\n"); - return -ENODEV; - } - plat->syscfg_base = regmap->ranges[0].start; - - /* get powerdown reset */ - ret = reset_get_by_name(dev, "powerdown", &plat->powerdown_ctl); - if (ret) { - pr_err("can't get powerdown reset for %s (%d)", dev->name, ret); - return ret; - } - - /* get softreset reset */ - ret = reset_get_by_name(dev, "softreset", &plat->softreset_ctl); - if (ret) - pr_err("can't get soft reset for %s (%d)", dev->name, ret); - - return ret; -}; - -static int sti_dwc3_glue_bind(struct udevice *dev) -{ - struct sti_dwc3_glue_plat *plat = dev_get_plat(dev); - ofnode node, dwc3_node; - - /* Find snps,dwc3 node from subnode */ - ofnode_for_each_subnode(node, dev_ofnode(dev)) { - if (ofnode_device_is_compatible(node, "snps,dwc3")) - dwc3_node = node; - } - - if (!ofnode_valid(dwc3_node)) { - pr_err("Can't find dwc3 subnode for %s\n", dev->name); - return -ENODEV; - } - - /* retrieve the DWC3 dual role mode */ - plat->mode = usb_get_dr_mode(dwc3_node); - if (plat->mode == USB_DR_MODE_UNKNOWN) - /* by default set dual role mode to HOST */ - plat->mode = USB_DR_MODE_HOST; - - return dm_scan_fdt_dev(dev); -} - -static int sti_dwc3_glue_probe(struct udevice *dev) -{ - struct sti_dwc3_glue_plat *plat = dev_get_plat(dev); - int ret; - - /* deassert both powerdown and softreset */ - ret = reset_deassert(&plat->powerdown_ctl); - if (ret < 0) { - pr_err("DWC3 powerdown reset deassert failed: %d", ret); - return ret; - } - - ret = reset_deassert(&plat->softreset_ctl); - if (ret < 0) { - pr_err("DWC3 soft reset deassert failed: %d", ret); - goto softreset_err; - } - - ret = sti_dwc3_glue_drd_init(plat); - if (ret) - goto init_err; - - sti_dwc3_glue_init(plat); - - return 0; - -init_err: - ret = reset_assert(&plat->softreset_ctl); - if (ret < 0) { - pr_err("DWC3 soft reset deassert failed: %d", ret); - return ret; - } - -softreset_err: - ret = reset_assert(&plat->powerdown_ctl); - if (ret < 0) - pr_err("DWC3 powerdown reset deassert failed: %d", ret); - - return ret; -} - -static int sti_dwc3_glue_remove(struct udevice *dev) -{ - struct sti_dwc3_glue_plat *plat = dev_get_plat(dev); - int ret; - - /* assert both powerdown and softreset */ - ret = reset_assert(&plat->powerdown_ctl); - if (ret < 0) { - pr_err("DWC3 powerdown reset deassert failed: %d", ret); - return ret; - } - - ret = reset_assert(&plat->softreset_ctl); - if (ret < 0) - pr_err("DWC3 soft reset deassert failed: %d", ret); - - return ret; -} - -static const struct udevice_id sti_dwc3_glue_ids[] = { - { .compatible = "st,stih407-dwc3" }, - { } -}; - -U_BOOT_DRIVER(dwc3_sti_glue) = { - .name = "dwc3_sti_glue", - .id = UCLASS_NOP, - .of_match = sti_dwc3_glue_ids, - .of_to_plat = sti_dwc3_glue_of_to_plat, - .probe = sti_dwc3_glue_probe, - .remove = sti_dwc3_glue_remove, - .bind = sti_dwc3_glue_bind, - .plat_auto = sizeof(struct sti_dwc3_glue_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, -};

Enable DM_USB_GADGET flag.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Marek Vasut marex@denx.de ---
configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index c1092bdde29..6fa28c11546 100644 --- a/configs/stih410-b2260_defconfig +++ b/configs/stih410-b2260_defconfig @@ -54,6 +54,7 @@ CONFIG_STI_ASC_SERIAL=y CONFIG_SYSRESET=y CONFIG_TIMER=y CONFIG_USB=y +CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y

Since DM_USB_GADGET is enable for this board, board_usb_init() and board_usb_cleanup() can be removed.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com ---
board/st/stih410-b2260/board.c | 30 ------------------------------ 1 file changed, 30 deletions(-)
diff --git a/board/st/stih410-b2260/board.c b/board/st/stih410-b2260/board.c index a912712c9dd..8ad593cccdd 100644 --- a/board/st/stih410-b2260/board.c +++ b/board/st/stih410-b2260/board.c @@ -7,11 +7,6 @@ #include <cpu_func.h> #include <init.h> #include <asm/cache.h> -#include <asm/global_data.h> -#include <linux/usb/otg.h> -#include <dwc3-sti-glue.h> -#include <dwc3-uboot.h> -#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -43,31 +38,6 @@ int board_init(void) }
#ifdef CONFIG_USB_DWC3 -static struct dwc3_device dwc3_device_data = { - .maximum_speed = USB_SPEED_HIGH, - .dr_mode = USB_DR_MODE_PERIPHERAL, - .index = 0, -}; - -int board_usb_init(int index, enum usb_init_type init) -{ - int node; - const void *blob = gd->fdt_blob; - - /* find the snps,dwc3 node */ - node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3"); - - dwc3_device_data.base = fdtdec_get_addr(blob, node, "reg"); - - return dwc3_uboot_init(&dwc3_device_data); -} - -int board_usb_cleanup(int index, enum usb_init_type init) -{ - dwc3_uboot_exit(index); - return 0; -} - int g_dnl_board_usb_cable_connected(void) { return 1;

Enable CMD_USB_MASS_STORAGE flag.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
Cc: Marek Vasut marex@denx.de
---
configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index 6fa28c11546..cc77d03d473 100644 --- a/configs/stih410-b2260_defconfig +++ b/configs/stih410-b2260_defconfig @@ -25,6 +25,7 @@ CONFIG_CMD_ASKENV=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_USB_MASS_STORAGE=y CONFIG_CMD_TIME=y CONFIG_CMD_TIMER=y CONFIG_CMD_EXT4_WRITE=y
participants (3)
-
Marek Vasut
-
Patrice CHOTARD
-
Patrice Chotard