Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v4 6/6] usb: dwc2: platform: fix stm32mp15 detection logic power management
Date: Fri, 13 Nov 2026 20:41:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-213670@kernel.org> (raw)
In-Reply-To: <20261113-dwc2-low-power-fixes-stm32-v4-6-08a8c962a09e@foss.st.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc2: missing forced mode restore in
  dwc2_stm32_hw_enable()
--

commit faf6843d2e18eaa77a4b2f6b54f7e23489971e73
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

usb: dwc2: platform: fix stm32mp15 detection logic power management

This commit moves the STM32 ID/VBUS detection enable and disable logic into
dedicated helpers called from the low-level hardware enable/disable paths,
and tracks its state in stm32_id_vb_detection_enabled.

> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 968b4ba6d8141..7aa8d7c58e75f 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -91,6 +91,95 @@ static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg)
>  	return 0;
>  }
>  
> +static void dwc2_stm32_hw_activate_id_vb_detection(struct dwc2_hsotg *hsotg)
> +{
> +	unsigned long flags;
> +	u32 ggpio, gotgctl;
> +
> +	ggpio = dwc2_readl(hsotg, GGPIO);
> +	ggpio |= GGPIO_STM32_OTG_GCCFG_IDEN;
> +	ggpio |= GGPIO_STM32_OTG_GCCFG_VBDEN;
> +	dwc2_writel(hsotg, ggpio, GGPIO);
> +
> +	/* ID/VBUS detection startup time */
> +	usleep_range(5000, 7000);
> +
> +	spin_lock_irqsave(&hsotg->lock, flags);
> +	/* Remove overrides when resuming from the disable */
> +	gotgctl = dwc2_readl(hsotg, GOTGCTL);
> +	gotgctl &= ~GOTGCTL_DBNCE_FLTR_BYPASS;
> +	gotgctl &= ~(GOTGCTL_BVALOEN | GOTGCTL_AVALOEN |
> +		     GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL);
> +	dwc2_writel(hsotg, gotgctl, GOTGCTL);
> +	spin_unlock_irqrestore(&hsotg->lock, flags);
> +}
> +
> +static int dwc2_stm32_hw_enable(struct dwc2_hsotg *hsotg)
> +{
> +	int ret;
> +
> +	/* params are only known, once dwc2_init_params() has been probed */
> +	if (!hsotg->params.activate_stm_id_vb_detection)
> +		return 0;
> +
> +	if (hsotg->stm32_id_vb_detection_enabled)
> +		return 0;
> +
> +	ret = regulator_enable(hsotg->usb33d);
> +	if (ret)
> +		return ret;
> +
> +	dwc2_stm32_hw_activate_id_vb_detection(hsotg);
> +	hsotg->stm32_id_vb_detection_enabled = true;
> +
> +	return 0;
> +}

[Severity: Medium]
Does dwc2_stm32_hw_enable() leave GUSBCFG_FORCEDEVMODE cleared when a gadget
driver is bound after resuming from standby in peripheral mode?

When the system enters standby in USB_DR_MODE_PERIPHERAL with no gadget
driver bound, ll_hw_enabled is false, so dwc2_resume() returns early without
calling dwc2_force_dr_mode() and the controller registers reset during
standby.  When a gadget driver is later bound, dwc2_hsotg_udc_start() ->
dwc2_lowlevel_hw_enable() -> dwc2_stm32_hw_enable() enables
GGPIO_STM32_OTG_GCCFG_IDEN and clears the GOTGCTL overrides without
restoring GUSBCFG_FORCEDEVMODE.

If the ID pin is low, the OTG controller switches into host mode instead of
staying forced into device mode, breaking peripheral operation and hitting
WARN_ON(host && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in
dwc2_force_mode() on the next dwc2_stm32_hw_disable() call.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-dwc2-low-power-fixes-stm32-v4-0-08a8c962a09e@foss.st.com?part=6

      reply	other threads:[~2026-11-13 20:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 18:47 [PATCH v4 0/6] usb: dwc2: fix low power issues found on stm32mp1 Fabrice Gasnier
2026-11-13 18:47 ` [PATCH v4 1/6] usb: dwc2: fix recovery after PM domain off Fabrice Gasnier
2026-11-13 19:30   ` sashiko-bot
2026-11-13 18:47 ` [PATCH v4 2/6] usb: dwc2: fix a possible interrupt storm in hcd resume Fabrice Gasnier
2026-11-13 19:34   ` sashiko-bot
2026-11-13 18:48 ` [PATCH v4 3/6] usb: dwc2: fix a possible interrupt storm on stm32mp1 Fabrice Gasnier
2026-11-13 19:43   ` sashiko-bot
2026-11-13 18:48 ` [PATCH v4 4/6] usb: dwc2: hcd: fix possible successive vbus supply enables Fabrice Gasnier
2026-11-13 19:49   ` sashiko-bot
2026-11-13 18:48 ` [PATCH v4 5/6] usb: dwc2: hcd: don't disable external vbus in system suspend Fabrice Gasnier
2026-11-13 20:00   ` sashiko-bot
2026-11-13 18:48 ` [PATCH v4 6/6] usb: dwc2: platform: fix stm32mp15 detection logic power management Fabrice Gasnier
2026-11-13 20:41   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-213670@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox