From patchwork Sat Nov 12 10:25:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 624417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CD7C433FE for ; Sat, 12 Nov 2022 10:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234787AbiKLKZY (ORCPT ); Sat, 12 Nov 2022 05:25:24 -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 ); 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: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrfeekgdduiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcurfgv thgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvghrnh epleduffeiheeuvedtffevtdeuleeljeduudfgtedtvefhfeffvdfghfejhefgleelnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvghnse hsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Feedback-ID: i51094778:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 12 Nov 2022 05:25:14 -0500 (EST) From: Sven Peter To: Thinh Nguyen , Greg Kroah-Hartman Cc: Sven Peter , Felipe Balbi , 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 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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;