Message ID | 20221112102506.34990-1-sven@svenpeter.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1206190wru; Sat, 12 Nov 2022 02:27:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf52hM/QQtpRyRMf27U56eBTeKh/ndYJzpUdHDApGVCGGSe8eXvGc0vi6/qUM9SnVTsdpYoE X-Received: by 2002:a50:fd91:0:b0:463:ff10:4ff with SMTP id o17-20020a50fd91000000b00463ff1004ffmr5011030edt.290.1668248866435; Sat, 12 Nov 2022 02:27:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668248866; cv=none; d=google.com; s=arc-20160816; b=Cszbs+HKpZv/UjBYnxbPfc0GKVjgrkTkmzNBhoyoR2MEr0GBz5oC3f5IhUx5cMl6bU S9jzrwGCuk3S/ZTlNbpZU2lc6KMqY1AZ7eipYzSHabIF0AynbecnaNSL+8i3va2pi0p6 ngN2yJ3qnOLK1q203+kxXC35ntIZyfb0wG8t/3j2PiOVsdZVyW8/Q6U3xpz69Utxfqm8 Fp8MspzVjtXVBmdEq8L0xPbfkuGZ6cy0sSjTTbTQbKcgEe9qpWMTUS7UZOjpTBE6zFKY 4ZfKqDvpkXp4C8Vd0XaqoaNCMIvzJwsPaAcK02CsYQnHxtBB6tYF2050Vx1lh4shQFj5 nQgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=qJfGBhZiTWulvBK64Qdm+CqQnbSC354FNmkmvzVs8Q8=; b=S+BuETEyLrpR1ox4RqQ+2CJS7rO9Ndh1G69ijqJlGxEttdJtHPLIHv862s2kvv3gWa O3I/u88jRnWk54fYztsji0rYOINnR4W71dn47dxW9JKxx4T7S3PZ05YGePPSDyhzz1y4 lr1ROL+SX2hxtHTvC9ubrYzo7T3vJjQuqb+q+3sL6NqaI8Gp+LNNWcLjQVXgqkyPIxr8 6MuMk07WPHH7lRO3sGYqprwbCmrDoQejsXe1r2NX3eBuu8OT7KPj1OWMdsnpbW4DbWwf O4sPlbJ+lXvufW7XTLEwn5P1q7N663mpAqyeKhNl5SxX+HHt+xcmi4OAi75Ybyv9ma3f NO5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=P4bRPkGF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=SojtWf0s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svenpeter.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a1709064fca00b007707c67f523si4543653ejw.335.2022.11.12.02.27.21; Sat, 12 Nov 2022 02:27:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=P4bRPkGF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=SojtWf0s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234820AbiKLKZZ (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Sat, 12 Nov 2022 05:25:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234809AbiKLKZW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 12 Nov 2022 05:25:22 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDB22FC12; Sat, 12 Nov 2022 02:25:18 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 922435C00EE; Sat, 12 Nov 2022 05:25:16 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 12 Nov 2022 05:25:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to; s=fm1; t=1668248716; x=1668335116; bh=qJfGBhZiTW ulvBK64Qdm+CqQnbSC354FNmkmvzVs8Q8=; b=P4bRPkGFH8dx3o+518cE2uqVKj GP0y7JWPhLiaF6TkrxidvwSXZXwljCNaDzsn/jQ02gnyvmM31F2riZoObuzHJ0cf Bvg2O1nW2oHvU9n/rzkPNtolYUoFDqVanDOtZ9XZsNKsuJ2d5d8Gb6joVHKu/JYk dX7Cw07yUp/2qBWwrJaLYuWZ4d3Sun+tRULVEi6JJp6x/S4y0NTly6HN1RGRddHZ m0ZwPzodW6FbGegU15axtHC912ujxvZbNCVVpsRLlwrVDXbyYsyhuFIUPmSt2Et/ p8/zhw2mt5Q108rjXCCWJ3jN/QZw1xGLl9nxaix5gPTaIFNNBZkk7c5FbdBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1668248716; x=1668335116; bh=qJfGBhZiTWulvBK64Qdm+CqQnbSC354FNmk mvzVs8Q8=; b=SojtWf0siDBsuZmgt8IC+2ZQY+72PRBIRZVDkCoGYx5gcBpqHN0 cAoRrMZDdEi5nuRem71ptZp6lvxY64czborDZejTcFjv+uUuR+FgzRYZ2YAVjTRv 09rUekkVIdRMfdLWBoOa49wCy7c+hRKWdkyeJqaSMTZ55RcrwMyvqg5GrK/UUbDD 0GN+pg8SdG+X1Dxywu3dzpS/pq/6LYF4PFJJHgjhgLOmXWDn7+DIGOFiXpr5Nl68 vdliMXeg+EGr+xNWVlS8LuvAO112v4CTDDytGv2ORPav9Au2Bo3vUjJT17oE75rE GZLUC3UsQkg7bwa9pV/VI578EDCZc2A+3cQ== X-ME-Sender: <xms:i3RvY-S93xrXhrw6sTqeWJ78rtoXwjMbywMSrMXsJWTvZbeyH2Gyhg> <xme:i3RvYzzOBIS8tSaDMltAh2Xw5q8dMW9O6mvP4az4WxaCpsmztxfS5M1a5BvxtRcgK 90zobE9V0o27Trf3qc> X-ME-Received: <xmr:i3RvY70PBqa_vqhRCqPpIfOauRnYgx3hhZArb26PbH35fUEEyjxgnc4E9p6n_69VGJ9ZaPe4kRr_EeRFTu1vgNPCPOR9nlSTEY50i9l3QMgEgPb3dh51S6aTZucj9Q> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeekgdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcurfgv thgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvghrnh epleduffeiheeuvedtffevtdeuleeljeduudfgtedtvefhfeffvdfghfejhefgleelnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvghnse hsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: <xmx:i3RvY6Dt18-ddLR4gyLnKN_BKdvVLE7fu8cPv95EKgSZB1alxa-L0Q> <xmx:i3RvY3ixMYqN0irLUMIrHLRTx3AUmYe1r4xA3XAEcgucv5aRrJ6fyA> <xmx:i3RvY2r8IKiC4OWVsj9ybMfMtsky9ENL2mj6voIs5j6O95GuAfdsnQ> <xmx:jHRvY3cCTVWoiB_yqsRXSMq9oE8n3gKALIA_4rlLvfHN8Bk0l6Hj0Q> Feedback-ID: i51094778:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 12 Nov 2022 05:25:14 -0500 (EST) From: Sven Peter <sven@svenpeter.dev> To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Sven Peter <sven@svenpeter.dev>, Felipe Balbi <felipe.balbi@linux.intel.com>, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: dwc3: core: configure PHY before initializing host in dwc3_set_mode Date: Sat, 12 Nov 2022 11:25:06 +0100 Message-Id: <20221112102506.34990-1-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749285723545773592?= X-GMAIL-MSGID: =?utf-8?q?1749285723545773592?= |
Series |
usb: dwc3: core: configure PHY before initializing host in dwc3_set_mode
|
|
Commit Message
Sven Peter
Nov. 12, 2022, 10:25 a.m. UTC
Usually, first the PHY is set to the correct mode and then the host or
device side of the controller is initialized afterwards. Otherwise a PHY
that's already used has to be reconfigured.
dwc3_core_init_mode() does this correctly for both host and device and
__dwc3_set_mode() does it correctly when switching to device mode.
When setting up host mode however it first initializes xhci and only
then changes the PHY's mode. Let's also do the operations in the correct
order here.
Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
drivers/usb/dwc3/core.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
Comments
Hi Sven, Op 12-11-2022 om 11:25 schreef Sven Peter: > Usually, first the PHY is set to the correct mode and then the host or > device side of the controller is initialized afterwards. Otherwise a PHY > that's already used has to be reconfigured. > dwc3_core_init_mode() does this correctly for both host and device and > __dwc3_set_mode() does it correctly when switching to device mode. > When setting up host mode however it first initializes xhci and only > then changes the PHY's mode. Let's also do the operations in the correct > order here. > > Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes") > Signed-off-by: Sven Peter <sven@svenpeter.dev> > --- > drivers/usb/dwc3/core.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index ad4d644e21a4..759d23d908fa 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work) > > switch (dwc->desired_dr_role) { > case DWC3_GCTL_PRTCAP_HOST: > + if (dwc->usb2_phy) > + otg_set_vbus(dwc->usb2_phy->otg, true); > + phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); > + phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); > + > ret = dwc3_host_init(dwc); > if (ret) { > dev_err(dwc->dev, "failed to initialize host\n"); > } else { > - if (dwc->usb2_phy) > - otg_set_vbus(dwc->usb2_phy->otg, true); > - phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); > - phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); > if (dwc->dis_split_quirk) { > reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); > reg |= DWC3_GUCTL3_SPLITDISABLE; This patch breaks usb host mode on Intel Merrifield platform. I am testing this on top of v6.0 + * my 2 "usb: dwc3: core: defer probe on ulpi_read_id timeout" patches (otherwise tusb1210 will not be probed on this platform) * Revert "usb: dwc3: disable USB core PHY management" (with/without this patch makes no difference) * usb: dwc3: Do not get extcon device when usb-role-switch is used (with/without this patch makes no difference) ftrace shows tusb1210 is indeed still probed, nevertheless in host mode it seems vbus is not powered as my connected smsc95xx based hub is not active (seems not plugged). Flipping the switch to device mode gadgets work fine. Could it be dwc3_host_init() needs to be called prior to otg_set_vbus()?
Hi Ferry, On Sat, Nov 12, 2022, at 23:15, Ferry Toth wrote: > Hi Sven, > > Op 12-11-2022 om 11:25 schreef Sven Peter: >> Usually, first the PHY is set to the correct mode and then the host or >> device side of the controller is initialized afterwards. Otherwise a PHY >> that's already used has to be reconfigured. >> dwc3_core_init_mode() does this correctly for both host and device and >> __dwc3_set_mode() does it correctly when switching to device mode. >> When setting up host mode however it first initializes xhci and only >> then changes the PHY's mode. Let's also do the operations in the correct >> order here. >> >> Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes") >> Signed-off-by: Sven Peter <sven@svenpeter.dev> >> --- >> drivers/usb/dwc3/core.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >> index ad4d644e21a4..759d23d908fa 100644 >> --- a/drivers/usb/dwc3/core.c >> +++ b/drivers/usb/dwc3/core.c >> @@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work) >> >> switch (dwc->desired_dr_role) { >> case DWC3_GCTL_PRTCAP_HOST: >> + if (dwc->usb2_phy) >> + otg_set_vbus(dwc->usb2_phy->otg, true); >> + phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >> + phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >> + >> ret = dwc3_host_init(dwc); >> if (ret) { >> dev_err(dwc->dev, "failed to initialize host\n"); >> } else { >> - if (dwc->usb2_phy) >> - otg_set_vbus(dwc->usb2_phy->otg, true); >> - phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >> - phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >> if (dwc->dis_split_quirk) { >> reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); >> reg |= DWC3_GUCTL3_SPLITDISABLE; > This patch breaks usb host mode on Intel Merrifield platform. I am > testing this on top of v6.0 + > * my 2 "usb: dwc3: core: defer probe on ulpi_read_id timeout" patches > (otherwise tusb1210 will not be probed on this platform) > * Revert "usb: dwc3: disable USB core PHY management" (with/without this > patch makes no difference) > * usb: dwc3: Do not get extcon device when usb-role-switch is used > (with/without this patch makes no difference) > > ftrace shows tusb1210 is indeed still probed, nevertheless in host mode > it seems vbus is not powered as my connected smsc95xx based hub is not > active (seems not plugged). > > Flipping the switch to device mode gadgets work fine. > > Could it be dwc3_host_init() needs to be called prior to otg_set_vbus()? Huh, thanks for testing! For the platform I'm working on I need to set the phy mode before dwc3_host_init() and then found the same code further below in dwc3_core_init_mode, static int dwc3_core_init_mode(struct dwc3 *dwc) { [...] case USB_DR_MODE_HOST: dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); if (dwc->usb2_phy) otg_set_vbus(dwc->usb2_phy->otg, true); phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); ret = dwc3_host_init(dwc); if (ret) return dev_err_probe(dev, ret, "failed to initialize host\n"); break; [...] } so I'm quite surprised it causes issue in __dwc3_set_mode now. If otg_set_vbus indeed needs to happen after dwc3_host_init it should probably also be called afterwards in dwc3_core_init_mode as well. Best, Sven
Hi, Op 12-11-2022 om 23:46 schreef Sven Peter: > Hi Ferry, > > On Sat, Nov 12, 2022, at 23:15, Ferry Toth wrote: >> Hi Sven, >> >> Op 12-11-2022 om 11:25 schreef Sven Peter: >>> Usually, first the PHY is set to the correct mode and then the host or >>> device side of the controller is initialized afterwards. Otherwise a PHY >>> that's already used has to be reconfigured. >>> dwc3_core_init_mode() does this correctly for both host and device and >>> __dwc3_set_mode() does it correctly when switching to device mode. >>> When setting up host mode however it first initializes xhci and only >>> then changes the PHY's mode. Let's also do the operations in the correct >>> order here. >>> >>> Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes") >>> Signed-off-by: Sven Peter <sven@svenpeter.dev> >>> --- >>> drivers/usb/dwc3/core.c | 9 +++++---- >>> 1 file changed, 5 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >>> index ad4d644e21a4..759d23d908fa 100644 >>> --- a/drivers/usb/dwc3/core.c >>> +++ b/drivers/usb/dwc3/core.c >>> @@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work) >>> >>> switch (dwc->desired_dr_role) { >>> case DWC3_GCTL_PRTCAP_HOST: >>> + if (dwc->usb2_phy) >>> + otg_set_vbus(dwc->usb2_phy->otg, true); >>> + phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >>> + phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >>> + >>> ret = dwc3_host_init(dwc); >>> if (ret) { >>> dev_err(dwc->dev, "failed to initialize host\n"); >>> } else { >>> - if (dwc->usb2_phy) >>> - otg_set_vbus(dwc->usb2_phy->otg, true); >>> - phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >>> - phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >>> if (dwc->dis_split_quirk) { >>> reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); >>> reg |= DWC3_GUCTL3_SPLITDISABLE; >> This patch breaks usb host mode on Intel Merrifield platform. I am >> testing this on top of v6.0 + >> * my 2 "usb: dwc3: core: defer probe on ulpi_read_id timeout" patches >> (otherwise tusb1210 will not be probed on this platform) >> * Revert "usb: dwc3: disable USB core PHY management" (with/without this >> patch makes no difference) >> * usb: dwc3: Do not get extcon device when usb-role-switch is used >> (with/without this patch makes no difference) >> >> ftrace shows tusb1210 is indeed still probed, nevertheless in host mode >> it seems vbus is not powered as my connected smsc95xx based hub is not >> active (seems not plugged). >> >> Flipping the switch to device mode gadgets work fine. >> >> Could it be dwc3_host_init() needs to be called prior to otg_set_vbus()? > > Huh, thanks for testing! > > For the platform I'm working on I need to set the phy mode before dwc3_host_init() > and then found the same code further below in dwc3_core_init_mode, > > static int dwc3_core_init_mode(struct dwc3 *dwc) > { > [...] > case USB_DR_MODE_HOST: > dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); > > if (dwc->usb2_phy) > otg_set_vbus(dwc->usb2_phy->otg, true); > phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); > phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); > > ret = dwc3_host_init(dwc); > if (ret) > return dev_err_probe(dev, ret, "failed to initialize host\n"); > break; > [...] > } > > so I'm quite surprised it causes issue in __dwc3_set_mode now. > If otg_set_vbus indeed needs to happen after dwc3_host_init it should probably > also be called afterwards in dwc3_core_init_mode as well. Maybe there is a difference between the case USB_DR_MODE_HOST above and case USB_DR_MODE_OTG touched by this patch? > > Best, > > > Sven
On Sun, Nov 13, 2022, at 00:07, Ferry Toth wrote: > Hi, > > Op 12-11-2022 om 23:46 schreef Sven Peter: >> Hi Ferry, >> >> On Sat, Nov 12, 2022, at 23:15, Ferry Toth wrote: >>> Hi Sven, >>> >>> Op 12-11-2022 om 11:25 schreef Sven Peter: >>>> Usually, first the PHY is set to the correct mode and then the host or >>>> device side of the controller is initialized afterwards. Otherwise a PHY >>>> that's already used has to be reconfigured. >>>> dwc3_core_init_mode() does this correctly for both host and device and >>>> __dwc3_set_mode() does it correctly when switching to device mode. >>>> When setting up host mode however it first initializes xhci and only >>>> then changes the PHY's mode. Let's also do the operations in the correct >>>> order here. >>>> >>>> Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes") >>>> Signed-off-by: Sven Peter <sven@svenpeter.dev> >>>> --- >>>> drivers/usb/dwc3/core.c | 9 +++++---- >>>> 1 file changed, 5 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >>>> index ad4d644e21a4..759d23d908fa 100644 >>>> --- a/drivers/usb/dwc3/core.c >>>> +++ b/drivers/usb/dwc3/core.c >>>> @@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work) >>>> >>>> switch (dwc->desired_dr_role) { >>>> case DWC3_GCTL_PRTCAP_HOST: >>>> + if (dwc->usb2_phy) >>>> + otg_set_vbus(dwc->usb2_phy->otg, true); >>>> + phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >>>> + phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >>>> + >>>> ret = dwc3_host_init(dwc); >>>> if (ret) { >>>> dev_err(dwc->dev, "failed to initialize host\n"); >>>> } else { >>>> - if (dwc->usb2_phy) >>>> - otg_set_vbus(dwc->usb2_phy->otg, true); >>>> - phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >>>> - phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >>>> if (dwc->dis_split_quirk) { >>>> reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); >>>> reg |= DWC3_GUCTL3_SPLITDISABLE; >>> This patch breaks usb host mode on Intel Merrifield platform. I am >>> testing this on top of v6.0 + >>> * my 2 "usb: dwc3: core: defer probe on ulpi_read_id timeout" patches >>> (otherwise tusb1210 will not be probed on this platform) >>> * Revert "usb: dwc3: disable USB core PHY management" (with/without this >>> patch makes no difference) >>> * usb: dwc3: Do not get extcon device when usb-role-switch is used >>> (with/without this patch makes no difference) >>> >>> ftrace shows tusb1210 is indeed still probed, nevertheless in host mode >>> it seems vbus is not powered as my connected smsc95xx based hub is not >>> active (seems not plugged). >>> >>> Flipping the switch to device mode gadgets work fine. >>> >>> Could it be dwc3_host_init() needs to be called prior to otg_set_vbus()? >> >> Huh, thanks for testing! >> >> For the platform I'm working on I need to set the phy mode before dwc3_host_init() >> and then found the same code further below in dwc3_core_init_mode, >> >> static int dwc3_core_init_mode(struct dwc3 *dwc) >> { >> [...] >> case USB_DR_MODE_HOST: >> dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST); >> >> if (dwc->usb2_phy) >> otg_set_vbus(dwc->usb2_phy->otg, true); >> phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); >> phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); >> >> ret = dwc3_host_init(dwc); >> if (ret) >> return dev_err_probe(dev, ret, "failed to initialize host\n"); >> break; >> [...] >> } >> >> so I'm quite surprised it causes issue in __dwc3_set_mode now. >> If otg_set_vbus indeed needs to happen after dwc3_host_init it should probably >> also be called afterwards in dwc3_core_init_mode as well. > > Maybe there is a difference between the case USB_DR_MODE_HOST above and > case USB_DR_MODE_OTG touched by this patch? Would be surprising but who knows. I'll see if I can move more of the PHY initialization on my platform to the power_on callback so that it'll also work there with the current code. I just thought this was going to fix a bug but if it breaks things it's better to just drop this patch. Thanks, Sven
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index ad4d644e21a4..759d23d908fa 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work) switch (dwc->desired_dr_role) { case DWC3_GCTL_PRTCAP_HOST: + if (dwc->usb2_phy) + otg_set_vbus(dwc->usb2_phy->otg, true); + phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); + phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); + ret = dwc3_host_init(dwc); if (ret) { dev_err(dwc->dev, "failed to initialize host\n"); } else { - if (dwc->usb2_phy) - otg_set_vbus(dwc->usb2_phy->otg, true); - phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); - phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); if (dwc->dis_split_quirk) { reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); reg |= DWC3_GUCTL3_SPLITDISABLE;