From dcf1c627cf436191919c5a3b153d1033245b54b7 Mon Sep 17 00:00:00 2001 From: Michael Ferolito Date: Mon, 27 Jan 2025 21:09:45 -0600 Subject: usb: gadget: g_dnl: Fix NULLPTR dereference when serial# is unset The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash. In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal. This simple check is enough to fix it Signed-off-by: Michael Ferolito Cc: Marek Vasut Cc: Heiko Schocher Cc: Kyungmin Park Reviewed-by: Heiko Schocher Reviewed-by: Mattijs Korpershoek Reviewed-by: Marek Vasut Link: https://lore.kernel.org/r/20250128030945.1219589-1-michaelsunn101@gmail.com Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/g_dnl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 631969b3405..f2540eb6ded 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -207,7 +207,8 @@ void g_dnl_clear_detach(void) static int on_serialno(const char *name, const char *value, enum env_op op, int flags) { - g_dnl_set_serialnumber((char *)value); + if (value) + g_dnl_set_serialnumber((char *)value); return 0; } U_BOOT_ENV_CALLBACK(serialno, on_serialno); -- cgit From aa817a2f1fb66067fc3c6dc7d9d1a84bbaa99df9 Mon Sep 17 00:00:00 2001 From: Sam Day Date: Thu, 23 Jan 2025 14:35:01 +0000 Subject: boot: android: handle boot images with missing DTB 607b07554e2 removed the check on the return status of the android_image_get_dtb_img_addr call from android_image_get_dtb_by_index, which results in null pointer accesses shortly after when trying to check the header of a nonexistent DTB. Fixes: 607b07554e2 ("android: boot: move to andr_image_data structure") Signed-off-by: Sam Day Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20250123-android-handle-no-dtb-v1-1-1cb7373247da@samcday.com Signed-off-by: Mattijs Korpershoek --- boot/image-android.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boot/image-android.c b/boot/image-android.c index fa4e14ca469..1746b018900 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -696,7 +696,10 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img, ulong dtb_addr; /* address of DTB blob with specified index */ u32 i; /* index iterator */ - android_image_get_dtb_img_addr(hdr_addr, vendor_boot_img, &dtb_img_addr); + if (!android_image_get_dtb_img_addr(hdr_addr, vendor_boot_img, + &dtb_img_addr)) + return false; + /* Check if DTB area of boot image is in DTBO format */ if (android_dt_check_header(dtb_img_addr)) { return android_dt_get_fdt_by_index(dtb_img_addr, index, addr, -- cgit From 4b6a3e860878de5198f5561a0d8c602a9c296f0a Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Mon, 2 Dec 2024 08:46:44 +0100 Subject: usb: gadget: f_mass_storage: Add schedule() in sleep_thread() In case "ums" command is used on platforms which don't implement g_dnl_board_usb_cable_connected() and USB cable is not connected, we stay inside sleep_thread() forever and watchdog is triggered. Add schedule() call to avoid this issue. Signed-off-by: Patrice Chotard Reviewed-by: Marek Vasut Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20241202074644.5380-1-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/f_mass_storage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index ffe1ae6eb73..d3fc4acb401 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -682,6 +682,7 @@ static int sleep_thread(struct fsg_common *common) k = 0; } + schedule(); dm_usb_gadget_handle_interrupts(udcdev); } common->thread_wakeup_needed = 0; -- cgit From 3810cd52cbf42727ebe22cf2a7929045d5ab01fd Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:39 +0100 Subject: ARM: dts: sti: Add fixed clock for ehci and ohci nodes in stih410-b2260.dtsi 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 Cc: Marek Vasut Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-2-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- 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>; }; }; }; -- cgit From 0f688eb0d69e2f8f65532908d8575113b4bd3427 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:40 +0100 Subject: configs: stih410-b2260: Enable DM_REGULATOR flag 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 Cc: Marek Vasut Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-3-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- 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 -- cgit From 15cd35cb3f1a128f1f4da8a3e5b8d93316125330 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:41 +0100 Subject: usb: dwc3: Remove dwc3 glue driver support for STi STi will migrate to dwc3-generic driver, dwc3-sti-glue driver can be removed. Signed-off-by: Patrice Chotard Cc: Marek Vasut Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20250130163547.512990-4-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- MAINTAINERS | 2 - board/st/stih410-b2260/board.c | 1 - drivers/usb/host/Kconfig | 9 -- drivers/usb/host/Makefile | 1 - drivers/usb/host/dwc3-sti-glue.c | 253 --------------------------------------- include/dwc3-sti-glue.h | 41 ------- 6 files changed, 307 deletions(-) delete mode 100644 drivers/usb/host/dwc3-sti-glue.c delete mode 100644 include/dwc3-sti-glue.h diff --git a/MAINTAINERS b/MAINTAINERS index 10f7f1fd180..8834737ebf9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -671,8 +671,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/board/st/stih410-b2260/board.c b/board/st/stih410-b2260/board.c index a912712c9dd..3a495eb5089 100644 --- a/board/st/stih410-b2260/board.c +++ b/board/st/stih410-b2260/board.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index a656265890e..3dc79770eeb 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, for STMicroelectronics. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -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, -}; diff --git a/include/dwc3-sti-glue.h b/include/dwc3-sti-glue.h deleted file mode 100644 index 546ffbaf7b4..00000000000 --- a/include/dwc3-sti-glue.h +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2017, STMicroelectronics - All Rights Reserved - * Author(s): Patrice Chotard, for STMicroelectronics. - */ - -#ifndef __DWC3_STI_UBOOT_H_ -#define __DWC3_STI_UBOOT_H_ - -/* glue registers */ -#include -#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) - -int sti_dwc3_init(enum usb_dr_mode mode); - -#endif /* __DWC3_STI_UBOOT_H_ */ -- cgit From 9de4b7e0a4c93128f28b19ad8a3a82421275418f Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:42 +0100 Subject: usb: dwc3-generic: Reorder include Reorder include following rules available here : https://docs.u-boot.org/en/latest/develop/codingstyle.html#include-files Remove useless include files. Signed-off-by: Patrice Chotard Cc: Marek Vasut Reviewed-by: Mattijs Korpershoek Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-5-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- drivers/usb/dwc3/dwc3-generic.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 55e62b35c61..21452ad1569 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -7,29 +7,17 @@ * Based on dwc3-omap.c. */ -#include -#include #include -#include +#include +#include #include -#include -#include -#include #include -#include -#include #include -#include #include -#include -#include "core.h" -#include "gadget.h" -#include -#include #include -#include - +#include "core.h" #include "dwc3-generic.h" +#include "gadget.h" struct dwc3_generic_plat { fdt_addr_t base; -- cgit From 23542078ec9a49cfb35cc00a6715106afbf65627 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:43 +0100 Subject: usb: dwc3-generic: Add STih407 support 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 Cc: Marek Vasut Reviewed-by: Mattijs Korpershoek Link: https://lore.kernel.org/r/20250130163547.512990-6-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- MAINTAINERS | 1 + drivers/usb/dwc3/Kconfig | 8 +++ drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-generic-sti.c | 134 ++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-generic-sti.c diff --git a/MAINTAINERS b/MAINTAINERS index 8834737ebf9..c1851280e6e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -671,6 +671,7 @@ 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.c 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/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 0100723a68b..682a6910655 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -87,6 +87,14 @@ config USB_DWC3_LAYERSCAPE Host and Peripheral operation modes are supported. OTG is not supported. +config USB_DWC3_STI + bool "STi USB wrapper" + depends on DM_USB && USB_DWC3_GENERIC && SYSCON + 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. + menu "PHY Subsystem" config USB_DWC3_PHY_OMAP diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile index a085c9d4628..985206eafe4 100644 --- a/drivers/usb/dwc3/Makefile +++ b/drivers/usb/dwc3/Makefile @@ -15,3 +15,4 @@ obj-$(CONFIG_USB_DWC3_UNIPHIER) += dwc3-uniphier.o obj-$(CONFIG_USB_DWC3_LAYERSCAPE) += dwc3-layerscape.o obj-$(CONFIG_USB_DWC3_PHY_OMAP) += ti_usb_phy.o obj-$(CONFIG_USB_DWC3_PHY_SAMSUNG) += samsung_usb_phy.o +obj-$(CONFIG_USB_DWC3_STI) += dwc3-generic-sti.o diff --git a/drivers/usb/dwc3/dwc3-generic-sti.c b/drivers/usb/dwc3/dwc3-generic-sti.c new file mode 100644 index 00000000000..b34f5ceceac --- /dev/null +++ b/drivers/usb/dwc3/dwc3-generic-sti.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause +/* + * STi specific glue layer for DWC3 + * + * Copyright (C) 2025, STMicroelectronics - All Rights Reserved + */ + +#define LOG_CATEGORY UCLASS_NOP + +#include +#include +#include +#include +#include +#include +#include +#include +#include "dwc3-generic.h" + +/* 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) + +static void dwc3_stih407_glue_configure(struct udevice *dev, int index, + enum usb_dr_mode mode) +{ + struct dwc3_glue_data *glue = dev_get_plat(dev); + struct regmap *regmap; + ulong syscfg_base; + ulong syscfg_offset; + ulong glue_base; + int ret; + + /* deassert both powerdown and softreset */ + ret = reset_deassert_bulk(&glue->resets); + if (ret) { + dev_err(dev, "reset_deassert_bulk error: %d\n", ret); + return; + } + + regmap = syscon_regmap_lookup_by_phandle(dev, "st,syscfg"); + if (IS_ERR(regmap)) { + dev_err(dev, "unable to get st,syscfg, dev %s\n", dev->name); + return; + } + + syscfg_base = regmap->ranges[0].start; + glue_base = dev_read_addr_index(dev, 0); + syscfg_offset = dev_read_addr_index(dev, 1); + + clrbits_le32(syscfg_base + syscfg_offset, USB3_CONTROL_MASK); + + /* glue drd init */ + switch (mode) { + case USB_DR_MODE_PERIPHERAL: + clrbits_le32(syscfg_base + syscfg_offset, + 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); + + setbits_le32(syscfg_base + syscfg_offset, + USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID); + break; + + case USB_DR_MODE_HOST: + clrbits_le32(syscfg_base + syscfg_offset, + 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); + + setbits_le32(syscfg_base + syscfg_offset, USB3_DELAY_VBUSVALID); + break; + + default: + dev_err(dev, "Unsupported mode of operation %d\n", mode); + return; + } + + /* glue init */ + setbits_le32(glue_base + CLKRST_CTRL, AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION); + clrbits_le32(glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); + + /* configure mux for vbus, powerpresent and bvalid signals */ + setbits_le32(glue_base + USB2_VBUS_MNGMNT_SEL1, + SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | + SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG)); + setbits_le32(glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); +}; + +struct dwc3_glue_ops stih407_ops = { + .glue_configure = dwc3_stih407_glue_configure, +}; + +static const struct udevice_id dwc3_sti_match[] = { + { .compatible = "st,stih407-dwc3", .data = (ulong)&stih407_ops}, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(dwc3_sti_wrapper) = { + .name = "dwc3-sti", + .id = UCLASS_NOP, + .of_match = dwc3_sti_match, + .bind = dwc3_glue_bind, + .probe = dwc3_glue_probe, + .remove = dwc3_glue_remove, + .plat_auto = sizeof(struct dwc3_glue_data), +}; -- cgit From 08fec26a67643fac05e2a076d19c54bca6f6e427 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:44 +0100 Subject: configs: stih410-b2260: Enable USB_DWC3_GENERIC and USB_DWC3_STI flags Enable USB_DWC3_GENERIC and USB_DWC3_STI flags. Signed-off-by: Patrice Chotard Cc: Marek Vasut Link: https://lore.kernel.org/r/20250130163547.512990-7-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- configs/stih410-b2260_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index e312ca492d2..4fcbf75548b 100644 --- a/configs/stih410-b2260_defconfig +++ b/configs/stih410-b2260_defconfig @@ -61,6 +61,8 @@ 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_DWC3_STI=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_MCS7830=y -- cgit From d0ff527f6237a78fb289b02e5dab63a23478565b Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:45 +0100 Subject: configs: stih410-b2260: Enable DM_USB_GADGET flag Enable DM_USB_GADGET flag. Signed-off-by: Patrice Chotard Cc: Marek Vasut Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-8-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index 4fcbf75548b..5641fd1d8d7 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 -- cgit From 0b96214cb32ebc54e92442a96eb9dc1e1f7e9175 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:46 +0100 Subject: board: stih410-b2260: Remove board_usb_init/cleanup() Since DM_USB_GADGET is enable for this board, board_usb_init() and board_usb_cleanup() can be removed. Signed-off-by: Patrice Chotard Reviewed-by: Mattijs Korpershoek Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-9-patrice.chotard@foss.st.com Signed-off-by: Mattijs Korpershoek --- board/st/stih410-b2260/board.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/board/st/stih410-b2260/board.c b/board/st/stih410-b2260/board.c index 3a495eb5089..8ad593cccdd 100644 --- a/board/st/stih410-b2260/board.c +++ b/board/st/stih410-b2260/board.c @@ -7,10 +7,6 @@ #include #include #include -#include -#include -#include -#include DECLARE_GLOBAL_DATA_PTR; @@ -42,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; -- cgit From 4096d28ec80f982454ef0dc7d42a4d4eaead5d56 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Jan 2025 17:35:47 +0100 Subject: configs: stih410-b2260: Enable CMD_USB_MASS_STORAGE flag Enable CMD_USB_MASS_STORAGE flag. Signed-off-by: Patrice Chotard Cc: Marek Vasut Reviewed-by: Patrick Delaunay Link: https://lore.kernel.org/r/20250130163547.512990-10-patrice.chotard@foss.st.com [mkorpershoek: fixed up commit footer] Signed-off-by: Mattijs Korpershoek --- configs/stih410-b2260_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig index 5641fd1d8d7..1e5190dc828 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 -- cgit