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: 19162 Return-Path: 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 + 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 ); 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 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: 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?= 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;