Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3881077rwb; Sat, 12 Nov 2022 15:30:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf5bIz/c4VJbFYB4r7ePY/ONv6vOkmFZMCplfqS4v9TAEZpTIIWigeFVAsICaKaK/BOTwUjh X-Received: by 2002:a17:906:a1c6:b0:7ad:d250:b907 with SMTP id bx6-20020a170906a1c600b007add250b907mr6034646ejb.737.1668295844335; Sat, 12 Nov 2022 15:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668295844; cv=none; d=google.com; s=arc-20160816; b=onyz34HBcJHIdyEovr4Au2fTubAikGL6K5nJWC9WqZAjSjYpCt1UjPtBzQhiwY93bx yT2juXYSCbAOOJP5ndnLHpk0FfmzDUZ0+drpv72l/9DV7h2ifkAPHwSWWDe2qDHh/yhV hwkLVRpWnZYaQKJnL3KiSyoEBh+fOBhaHvxpsAIeSpUAJewtvl5qP0Za2o1vPLd//YQk TNnKRGz/dq1znErrvmayF+AvQSYfzW0gwdOVQhWNcgQWdm3OuhxbbII+3KGYZt61Rfuz X2RvErSoqJyKT/nDwMoXc0W5518HGZqHR2mWmIAvwAfvO2nlm8KEDV3Y+XjYa3R8VeF0 zPTw== 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=UR6IZENSs9Hhv2gtReWHrfdfYMNRxyX0JgKvZaNESMM=; b=FjtUcizB60CklFJBfxLHtu9HQAKSfAm73OXImUo7ZYfcbe35+WaZpVhThAkhcmEnT3 DWtw3yybDTnjvS4U5/j/u8DkMZZ/YPBrpbYq8hQvusTn4ETEcM89LqU09qHteqDklNl+ 6ZaINWlOBZOvivozSmClQrH2P9jaWHbtuSUxq6vK6qmaQ47iga2ejZA8fWjDo/WVuiz+ +7RYq7+hTlOJLlZ+FeK2xZl/mRj6I51EIKnv/yz13/K8c8C8j9kZaeLIzG2f1TU/FH6d IQysd0TqynlsUg3LzT197JGnU+/RH5SwBQSwa6iB23FilIwowUBw66Ei5+b/K5+wgvVq cJug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=gqmiTzPV; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=QZ2bB0r3; 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 by12-20020a0564021b0c00b00461d8ee1316si4535141edb.21.2022.11.12.15.30.06; Sat, 12 Nov 2022 15:30:44 -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=gqmiTzPV; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=QZ2bB0r3; 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 S234867AbiKLWqs (ORCPT + 91 others); Sat, 12 Nov 2022 17:46:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbiKLWqq (ORCPT ); Sat, 12 Nov 2022 17:46:46 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE54D15A3C; Sat, 12 Nov 2022 14:46:44 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C949D32002D8; Sat, 12 Nov 2022 17:46:41 -0500 (EST) Received: from imap47 ([10.202.2.97]) by compute2.internal (MEProxy); Sat, 12 Nov 2022 17:46:42 -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=1668293201; x=1668379601; bh=UR 6IZENSs9Hhv2gtReWHrfdfYMNRxyX0JgKvZaNESMM=; b=gqmiTzPVUIKICbV0rT mYa/C3SOcK3X4P0ZSAxIYw5XX/9zm+iy3FRh02ISej1X6QSUGFnDkf5MJgq42UXG 7dsRMfcpvZoTo5s7cYmi4SHoRKzgUjVZ869jm2hUPbgG9GoCj+LDNSmYtTYfSe+F UKQ2bj8VPaZTXZ2gl23zSnwtEGPg/i9DvlG3NMCzTAvUYZ0YpL1RZq347QH79ux8 br3Q+kzL/ufOhEV2AYUFpnTkmVGe0omDxzdfPPTgE6uPqu5DNQxZPJpLXEX+3ICA zYnC+ERsPHlD6iq5Yne2ba4eAcrzuh+1FZRtd5/kMOPjYK1oQniVCLK4amVrdH5Q g37Q== 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=1668293201; x=1668379601; bh=UR6IZENSs9Hhv2gtReWHrfdfYMNR xyX0JgKvZaNESMM=; b=QZ2bB0r3zIF4kBQgSYHmtzqd0hii9X91zrRLeLrmb/Fl ro8qPsKnJ44OcHKgh+PkrSbd5je148LiMQU2dCgUIQ2W0l8gzf8GG6qo5rWde9U2 G4tLUH5Jd84sfniPiruyPntl7YERjnfTtfhREGVAGFzaFJ8+vnb7/mYYl5fPeXgk QnulMaIi4ARTpKZnEfZGVdg7tRm2osNwGBicEt7hE6RNf5B//lhsb3k4JcRTBmRX MCB66rXHgKZ9uTyFla470S5xwvDm8FCCweD6lPRk8fbKihOf7br7ts5qz1mckMdY qnDV1qBqLGcjFXeEhhi118i8QwPUx/0qEjH7geZE8w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeelgddtudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdfuvhgv nhcurfgvthgvrhdfuceoshhvvghnsehsvhgvnhhpvghtvghrrdguvghvqeenucggtffrrg htthgvrhhnpeelvefggeffheevtdeivefhkeehfeettdejteduveeiheevveeilefghfei veeiueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Feedback-ID: i51094778:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D94A7A60084; Sat, 12 Nov 2022 17:46:40 -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: <1800f8ea-2dde-a420-3e99-56237bde1bb0@gmail.com> References: <20221112102506.34990-1-sven@svenpeter.dev> <1800f8ea-2dde-a420-3e99-56237bde1bb0@gmail.com> Date: Sat, 12 Nov 2022 23:46:19 +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 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. Best, Sven