From c8b45d1c6edb4ffcd01850486673aed2317149d1 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:20 +0000 Subject: [PATCH 1/3] dt-bindings: usb: snps,dwc3: Describe Tensor G4 peripheral glue The Pixel 9 Pro Fold (Tensor G4) runs its USB 2.0 gadget through a glue driver that initialises the USB2 PHY before the DWC3 core's first register access. Add its google,zumapro-dwc3 compatible: peripheral only, high speed, three clocks (bus_early, ref, ctrl) and a single USB2 PHY. Existing snps,dwc3 users are unchanged. Assisted-by: LLM Signed-off-by: Nate Crawford --- .../devicetree/bindings/usb/snps,dwc3.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml index 4380bb6fa2..a04b2ddda4 100644 --- a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml @@ -16,12 +16,46 @@ description: allOf: - $ref: snps,dwc3-common.yaml# + - if: + properties: + compatible: + contains: + const: google,zumapro-dwc3 + then: + properties: + compatible: + const: google,zumapro-dwc3 + clocks: + minItems: 3 + maxItems: 3 + clock-names: + items: + - const: bus_early + - const: ref + - const: ctrl + phys: + maxItems: 1 + phy-names: + const: usb2-phy + dr_mode: + const: peripheral + maximum-speed: + const: high-speed + required: + - clocks + - clock-names + - phys + - phy-names + - dr_mode + - maximum-speed properties: compatible: contains: oneOf: - const: snps,dwc3 + - const: google,zumapro-dwc3 + description: Tensor G4 requires PHY initialization before core access. - const: synopsys,dwc3 deprecated: true From 8b89480f4045884bfcf5bcb97dd53cf4b0211335 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:20 +0000 Subject: [PATCH 2/3] usb: dwc3: Add Tensor G4 PHY-before-core glue The DWC3 core reads GSNPSID before it initialises its generic PHYs. On Tensor, a read of the link while the USB2 PHY is isolated or in reset can hang. Initialise the USB2 PHY under the three enabled clocks before handing over to dwc3_core_probe(), and hold that reference until removal; the core balances its own. Host and dual-role modes need their own power sequencing and are rejected. The probe structure follows dwc3-generic-plat. It gets its own Kconfig symbol, USB_DWC3_ZUMAPRO. The Pixel 9 Pro Fold (comet) brings up its USB gadget, and with it its only link during bring-up, through this glue on its daily v7.3-rc6 based kernel. The Pixel 9a, the same SoC, binds plain snps,dwc3; why comet needed the PHY first was not isolated: the bring-up boots that lost USB were fixed together with two unrelated changes. System sleep is added by the next patch. Assisted-by: LLM Signed-off-by: Nate Crawford --- MAINTAINERS | 1 + drivers/usb/dwc3/Kconfig | 10 +++ drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-zumapro.c | 120 ++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-zumapro.c diff --git a/MAINTAINERS b/MAINTAINERS index a44d4a1fbe..6a87970236 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11197,6 +11197,7 @@ F: drivers/phy/samsung/phy-zuma-pcie.c F: drivers/phy/samsung/phy-zumapro-ufs.c F: drivers/thermal/samsung/gs101_acpm_tmu.c F: drivers/usb/dwc3/dwc3-google.c +F: drivers/usb/dwc3/dwc3-zumapro.c F: include/dt-bindings/clock/google,gs101* F: include/dt-bindings/clock/google,gs201* F: include/dt-bindings/clock/google,zuma-acpm.h diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 18169727a4..37004f27be 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -234,4 +234,14 @@ config USB_DWC3_GOOGLE To compile this driver as a module, choose M here: the module will be called dwc3-google.ko. +config USB_DWC3_ZUMAPRO + tristate "DesignWare USB3 support on Tensor G4" + depends on ARCH_EXYNOS || COMPILE_TEST + depends on USB_DWC3_GADGET || USB_DWC3_DUAL_ROLE + help + Peripheral-only glue for Tensor G4. Initialize the USB2 PHY before + the DWC3 core reads registers, and retain its reference until removal. + Host and dual-role modes are not supported by this wrapper. + Select M to build dwc3-zumapro as a module. + endif diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile index f379711972..d34ead8831 100644 --- a/drivers/usb/dwc3/Makefile +++ b/drivers/usb/dwc3/Makefile @@ -61,3 +61,4 @@ obj-$(CONFIG_USB_DWC3_OCTEON) += dwc3-octeon.o obj-$(CONFIG_USB_DWC3_RTK) += dwc3-rtk.o obj-$(CONFIG_USB_DWC3_GENERIC_PLAT) += dwc3-generic-plat.o obj-$(CONFIG_USB_DWC3_GOOGLE) += dwc3-google.o +obj-$(CONFIG_USB_DWC3_ZUMAPRO) += dwc3-zumapro.o diff --git a/drivers/usb/dwc3/dwc3-zumapro.c b/drivers/usb/dwc3/dwc3-zumapro.c new file mode 100644 index 0000000000..e01fe324da --- /dev/null +++ b/drivers/usb/dwc3/dwc3-zumapro.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Tensor G4 peripheral USB: initialize the PHY before the first core read. + * Probe structure based on dwc3-generic-plat.c: + * Copyright (C) 2025 Ze Huang + */ +#include +#include +#include +#include +#include +#include +#include + +#include "glue.h" + +struct dwc3_zumapro { + struct dwc3 dwc; + struct phy *usb2_phy; + struct clk_bulk_data *clks; +}; + +static void dwc3_zumapro_phy_exit(void *data) +{ + struct dwc3_zumapro *zumapro = data; + int ret; + + ret = phy_exit(zumapro->usb2_phy); + if (ret) + dev_warn(zumapro->dwc.dev, "Failed to exit USB2 PHY: %d\n", ret); +} + +static int dwc3_zumapro_probe(struct platform_device *pdev) +{ + struct dwc3_probe_data probe_data = { + .ignore_clocks_and_resets = true, + .properties = DWC3_DEFAULT_PROPERTIES, + }; + struct device *dev = &pdev->dev; + struct dwc3_zumapro *zumapro; + struct resource *res; + int ret; + + /* Host/dual-role and suspend need their own power sequencing. */ + if (usb_get_dr_mode(dev) != USB_DR_MODE_PERIPHERAL) + return dev_err_probe(dev, -EINVAL, "Only peripheral mode is supported\n"); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + zumapro = devm_kzalloc(dev, sizeof(*zumapro), GFP_KERNEL); + if (!zumapro) + return -ENOMEM; + zumapro->dwc.dev = dev; + + /* Check and enable all three clocks before accessing the PHY. */ + ret = devm_clk_bulk_get_all_enabled(dev, &zumapro->clks); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to check inherited USB clocks\n"); + if (ret != 3) + return dev_err_probe(dev, -EINVAL, "Three USB clocks are required\n"); + + zumapro->usb2_phy = devm_phy_get(dev, "usb2-phy"); + if (IS_ERR(zumapro->usb2_phy)) + return dev_err_probe(dev, PTR_ERR(zumapro->usb2_phy), "Failed to get USB2 PHY\n"); + + /* + * DWC3 reads GSNPSID before its own generic PHY initialization. On + * Tensor, an isolated or reset link can hang that read. Initialize + * under checked clocks first and hold this reference until removal; + * core probe/remove balances its additional generic PHY reference. + */ + ret = phy_init(zumapro->usb2_phy); + if (ret) + return dev_err_probe(dev, ret, "Failed to prepare USB link before core access\n"); + + ret = devm_add_action_or_reset(dev, dwc3_zumapro_phy_exit, zumapro); + if (ret) + return ret; + + probe_data.dwc = &zumapro->dwc; + probe_data.res = res; + return dwc3_core_probe(&probe_data); +} + +static void dwc3_zumapro_remove(struct platform_device *pdev) +{ + dwc3_core_remove(platform_get_drvdata(pdev)); +} + +static int dwc3_zumapro_suspend(struct device *dev) +{ + /* This staged path deliberately retains the firmware power state. */ + return -EBUSY; +} + +static const struct dev_pm_ops dwc3_zumapro_pm_ops = { + SYSTEM_SLEEP_PM_OPS(dwc3_zumapro_suspend, NULL) +}; + +static const struct of_device_id dwc3_zumapro_match[] = { + { .compatible = "google,zumapro-dwc3" }, + { } +}; +MODULE_DEVICE_TABLE(of, dwc3_zumapro_match); + +static struct platform_driver dwc3_zumapro_driver = { + .probe = dwc3_zumapro_probe, + .remove = dwc3_zumapro_remove, + .driver = { + .name = "dwc3-zumapro", + .of_match_table = dwc3_zumapro_match, + .pm = pm_sleep_ptr(&dwc3_zumapro_pm_ops), + }, +}; +module_platform_driver(dwc3_zumapro_driver); + +MODULE_DESCRIPTION("Tensor G4 peripheral USB with PHY-before-core ordering"); +MODULE_LICENSE("GPL"); From babd9035307ac89235dfb97edfd7bed6e8d1b1f4 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:21 +0000 Subject: [PATCH 3/3] usb: dwc3: zumapro: Suspend and resume through the DWC3 core The glue refused system sleep with -EBUSY, so every suspend attempt on the Pixel 9 Pro Fold failed at 11210000.usb ("failed to suspend: error -16"), even at the PM core's "devices" test level. Use the generic DWC3 system sleep path, as dwc3-generic-plat does, but keep the inherited clocks on and hold an extra PHY power reference over the sleep. The usbdrd PHY's last power_off isolates the link, and dwc3_core_init() reads core registers (dwc3_phy_setup()) before it powers the PHY again; the probe comment already records that such a read can hang on Tensor. With the extra reference the core is re-inited against the same initialised, powered PHY that it found at probe. In peripheral mode the core soft-disconnects the gadget on suspend and reconnects on resume. Tested on a Pixel 9 Pro Fold with a v7.3-rc6 based kernel: pm_test "devices" passes, every device suspends and resumes, the USB gadget comes back and the host reconnects, with no storage or ACPM errors. Before this change the same test failed at 11210000.usb with -EBUSY. Three real suspend-to-idle cycles on a 30 s RTC alarm and one power-key wake then passed, with SSH over the gadget back after each. Assisted-by: LLM Signed-off-by: Nate Crawford --- drivers/usb/dwc3/dwc3-zumapro.c | 54 ++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-zumapro.c b/drivers/usb/dwc3/dwc3-zumapro.c index e01fe324da..c346fe077e 100644 --- a/drivers/usb/dwc3/dwc3-zumapro.c +++ b/drivers/usb/dwc3/dwc3-zumapro.c @@ -20,6 +20,8 @@ struct dwc3_zumapro { struct clk_bulk_data *clks; }; +#define to_dwc3_zumapro(d) container_of((d), struct dwc3_zumapro, dwc) + static void dwc3_zumapro_phy_exit(void *data) { struct dwc3_zumapro *zumapro = data; @@ -41,7 +43,7 @@ static int dwc3_zumapro_probe(struct platform_device *pdev) struct resource *res; int ret; - /* Host/dual-role and suspend need their own power sequencing. */ + /* Host and dual-role need their own power sequencing. */ if (usb_get_dr_mode(dev) != USB_DR_MODE_PERIPHERAL) return dev_err_probe(dev, -EINVAL, "Only peripheral mode is supported\n"); @@ -91,12 +93,56 @@ static void dwc3_zumapro_remove(struct platform_device *pdev) static int dwc3_zumapro_suspend(struct device *dev) { - /* This staged path deliberately retains the firmware power state. */ - return -EBUSY; + struct dwc3_zumapro *zumapro = to_dwc3_zumapro(dev_get_drvdata(dev)); + int ret; + + /* + * Keep the PHY powered across the core's exit and re-init. Its last + * power_off isolates the link, and dwc3_core_init() reads core + * registers before it powers the PHY again; on Tensor such a read can + * hang. With this reference the core resumes against the same powered, + * initialized PHY it found at probe. The inherited clocks stay on. + */ + ret = phy_power_on(zumapro->usb2_phy); + if (ret) + return ret; + + ret = dwc3_pm_suspend(&zumapro->dwc); + if (ret) + phy_power_off(zumapro->usb2_phy); + + return ret; +} + +static int dwc3_zumapro_resume(struct device *dev) +{ + struct dwc3_zumapro *zumapro = to_dwc3_zumapro(dev_get_drvdata(dev)); + int ret; + + ret = dwc3_pm_resume(&zumapro->dwc); + phy_power_off(zumapro->usb2_phy); + + return ret; +} + +static int dwc3_zumapro_prepare(struct device *dev) +{ + struct dwc3_zumapro *zumapro = to_dwc3_zumapro(dev_get_drvdata(dev)); + + return dwc3_pm_prepare(&zumapro->dwc); +} + +static void dwc3_zumapro_complete(struct device *dev) +{ + struct dwc3_zumapro *zumapro = to_dwc3_zumapro(dev_get_drvdata(dev)); + + dwc3_pm_complete(&zumapro->dwc); } static const struct dev_pm_ops dwc3_zumapro_pm_ops = { - SYSTEM_SLEEP_PM_OPS(dwc3_zumapro_suspend, NULL) + SYSTEM_SLEEP_PM_OPS(dwc3_zumapro_suspend, dwc3_zumapro_resume) + .prepare = pm_sleep_ptr(dwc3_zumapro_prepare), + .complete = pm_sleep_ptr(dwc3_zumapro_complete), }; static const struct of_device_id dwc3_zumapro_match[] = {