Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3889609rwb; Sat, 12 Nov 2022 15:45:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf487pddx9B3SQliFBm6wPCk2zanKBGEYEmaCrsa3C9d5H8L3peBfrRSexm7HQR04DmWATey X-Received: by 2002:a17:90a:d511:b0:20a:e469:dc7d with SMTP id t17-20020a17090ad51100b0020ae469dc7dmr7722899pju.97.1668296724740; Sat, 12 Nov 2022 15:45:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296724; cv=none; d=google.com; s=arc-20160816; b=yYPU4C0byqsZiw2AxC98RteNppGbhLRh8aKjN3f4nyG/gwPIYFnnUICDeEB/Xs4CD9 Yvn1/mCDx5r2PYttrMORsuYov93RFPiYF/zssfJRXVaMYxdc0PF1Tr5jdeK0Z1DSjoa+ BvgNPQRGeDtFlg0uFaU+8QrvK5dGWGm9asZthPiZcctwN66TG5wUKSRonirZImLoFz0s +a2oJx/jb4AMiEXltAbsgrjRyu4vvnx3RFYLH5b41aGChDywPpskfv2Sw/6nDY2VRLmY WHSlcNOBJUkkqH8dJd8rjOx7KcRfmc+zG0FbywjDQtdNxXaaMjCMtQT0ES6eITQThJTa VaOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=khnIpPk/qP1/uxcosccEQAXtAdWlBTJFtbAinjXeAQE=; b=W/FvnYH/Kmz3mC21eqNq/Y94KvNP72JdrvPK5yJbiqws2K1o/JDY12Ioca3HmyPPp/ zPrOWSpDfDFpMcHagF91ZHt4qabRZVi5h/6TDkL3CxQyDl95BhiIhqWVMAE73NvvHX3h kAChvOdMkobi8LM8qQ40AYyyC6aunmVB4g0vsUx8J/4zfDANHrcnA1EAWHyuBoBNVkmQ agDgJtXLqr70XN5IZPA2l2bJLWYxgHKaZmQLmSelW992FqP3au4hsvW6bjg770Rp1g+v 6KW80Vo+2G+zInwuADa/SRvefudpTWqjoFnpsUGL2/Vf5YcpFqiWLYxsgffrS2N9ksEU Z5hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=CPlqXEvF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=uIxYBQr4; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a654145000000b004599da2b2b6si5242825pgp.716.2022.11.12.15.45.12; Sat, 12 Nov 2022 15:45:24 -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=CPlqXEvF; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=uIxYBQr4; 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 S235130AbiKLXLs (ORCPT + 90 others); Sat, 12 Nov 2022 18:11:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbiKLXLr (ORCPT ); Sat, 12 Nov 2022 18:11:47 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F56DF77; Sat, 12 Nov 2022 15:11:46 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 6422432001C6; Sat, 12 Nov 2022 18:11:45 -0500 (EST) Received: from imap47 ([10.202.2.97]) by compute2.internal (MEProxy); Sat, 12 Nov 2022 18:11:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1668294705; x=1668381105; bh=kh nIpPk/qP1/uxcosccEQAXtAdWlBTJFtbAinjXeAQE=; b=CPlqXEvFN6Dm/Ovo6M u9Ql888+flCL/ICarV+LeiEaazDrAASvwMlsx8aIG8UsgpIwPaP8jZbiwjH20G+J d5woO11fp13L0kPW1Roybx+2UsXjW5dWltffGrAf13vv5OMLFJm+XbXeixDyRQCG zctKDoDXtKIrycAedMMObGaO3yyTyiRXTt3uJRlA66ahv4qrB/6TS2NI2qRS8kSV eUotVCg3QYD4FwMKMxMiDVM/VaBsPo4RJDdIseHb8oFAGowSA9wveQ+dnWb8Apci mP1ndbtBDZ0gINXHvrlK16EAsSZEI6kNv+7/0Uo4EyEFMCdRlJB0O20LBE1NlPpD fMdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references: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=1668294705; x=1668381105; bh=khnIpPk/qP1/uxcosccEQAXtAdWl BTJFtbAinjXeAQE=; b=uIxYBQr48dhxBYloxVhdiGpxeIeXQTfvjOBnRqRsL4Lp FIxE6JZs+HfpjlT3anwQ3Abdaz75mCqZTvjhXav62rN7l4Byomvo06Y2aHkhPf+B Ygjt2iftlKT75o2SEeHOWCzcmXv/OpuY1u+u4KsgPgYRHUZU+NEpycQyL1ww4WD+ i3/6dE+/Yo5XS0UKgfuEta7SNuVIYrCdLIIetPGuxf6oUvo5eEgNeaxAdjCmXdKb A629jN9cz9q9ymo9i9/9b9AwwDKDW7tlGBLGp5ZWFk0QXt0PfY+rS1q2ccugbMaz YEvhv0w7bzFTd2Oq/WMVDpJXcdcsYVE7MDrkdupx/w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeelgddtiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdfuvhgv nhcurfgvthgvrhdfuceoshhvvghnsehsvhgvnhhpvghtvghrrdguvghvqeenucggtffrrg htthgvrhhnpeelvefggeffheevtdeivefhkeehfeettdejteduveeiheevveeilefghfei veeiueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Feedback-ID: i51094778:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6016DA60084; Sat, 12 Nov 2022 18:11:44 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20221112102506.34990-1-sven@svenpeter.dev> <1800f8ea-2dde-a420-3e99-56237bde1bb0@gmail.com> Date: Sun, 13 Nov 2022 00:11:24 +0100 From: "Sven Peter" To: "Ferry Toth" Cc: "Felipe Balbi" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Andy Shevchenko" , "Thinh Nguyen" , "Greg Kroah-Hartman" Subject: Re: [PATCH] usb: dwc3: core: configure PHY before initializing host in dwc3_set_mode Content-Type: text/plain 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, RCVD_IN_MSPIKE_H2,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: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>>> --- >>>> 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