From patchwork Fri Nov 3 16:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 161370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1171790vqu; Fri, 3 Nov 2023 09:43:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9MFy0TcdyMK8w2cGFs4FxAt8/RA4K/8fFvDc7sDL0sRhUCZFOQrfRr2Ux5dU5qWsjnv6T X-Received: by 2002:a17:90a:f0d8:b0:27d:12e1:94e0 with SMTP id fa24-20020a17090af0d800b0027d12e194e0mr18577048pjb.36.1699029832020; Fri, 03 Nov 2023 09:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699029832; cv=none; d=google.com; s=arc-20160816; b=ao40cUB0WFPAY5XPV1NgRSDAYz/AHz2YXarI16VOMoLHAjr3hSyDiFHn63QVB3rabv CHGnWhJFmUYluIJ+2DeMqCiQY+mILJK89IRVBAbByEoDM+q8k82C80nmLoDl/yAR4Kyi 5faa2Wpuy6n+OGCiQy/d7fT2TAbFEWXVLZYiUtNtUVuvUCrXBTStKNr7cnZgVOrWdQwG 6VujAaTukm3kI+6uL5r9f+JMKz1XalMbfxq2a3x+MQX46sGxXxIf74olDjx8oDFrqisy qxfV6f2a+sj+hbu/DYht7OXg4BxSfKVgIynkYJlKlA462Pb3fpgX/lLYyLOZqwPUHxSh BtnQ== 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:dkim-signature; bh=aF8E+KQGHyFoAvrp45WgBfI9gi7R9oNA/daxDJda+Xs=; fh=oTT6vpJ6BNdYh47kEGKw75PvxT5u4FWn86hNE+lzjIw=; b=mF4Yrbi9Pcpy56S8TS3Rxd8dRTbpkSSv5lhpnn+KAmtuIF341m6CgMS5o/wem6NxMA w77FBlCxSQdALnzTpOH+KJERYui8iu6G+F2pqtV1FO9Yu8IIFEPT6j2SycKU9S+8/UnL ofKzrILuhdHVssTOUMYel8zd+ObLQDCD/8xmkiU1fScvJH9jU8oa58kxVlo/B4zkhn7t ypYenYt1lQusCju+3YTXCV7ahUgjMXjd6PTa8YPsL093zCipc5GAagjifXHE3EngrVOA S8LhjjLXPQSrEUWXVhRUewA4sjO4mjCDcoD/9Cp+nGNjxJc1CrYVyDl64nasMyJl13mY JCYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m3wVna0k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d2-20020a17090a114200b00262ff3a4545si1897559pje.169.2023.11.03.09.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 09:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m3wVna0k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4EA1A829B8BB; Fri, 3 Nov 2023 09:43:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345543AbjKCQni (ORCPT + 35 others); Fri, 3 Nov 2023 12:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345287AbjKCQnh (ORCPT ); Fri, 3 Nov 2023 12:43:37 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B42D44; Fri, 3 Nov 2023 09:43:34 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45509C433C8; Fri, 3 Nov 2023 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699029814; bh=AKJI6ud2/gqzwSf2vyoKUTsXLPjddX84FQGpHNeQVNE=; h=From:To:Cc:Subject:Date:From; b=m3wVna0kVxQ6v441O/jKbp5N8irWGgjATWudGzxUK9bGqx/kDunXmxDDUwWpf5w/m EkolboyL9WxzhbBo63r5HnTRMYoFGP7tcSO2kRxj4WD7N/tkmA1DgM6V/VU5mxVvOk RS2OAqremX9mWjsQrThv4EBpVQGsdN+wAgXcuNPapmOFNzFs4aeelXlGU9aGxAqgpC 1rEZkl3Fen+LUVE9PtED1vw78RQldn0eHx68lL44l98PetaUubtEqQ+0CF1MUGguae 4Ncu9HFwshrKHf9CJwxZy2b47KCIjC2o/OT0f47rUyZkVkfnH4nS7r7FuxdITIOWC+ ZxjpcmDGUJluA== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qyxHH-0003j7-05; Fri, 03 Nov 2023 17:44:11 +0100 From: Johan Hovold To: Mathias Nyman Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Maxime Ripard , Stanley Chang Subject: [PATCH] USB: xhci-plat: fix legacy PHY double init Date: Fri, 3 Nov 2023 17:43:23 +0100 Message-ID: <20231103164323.14294-1-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 03 Nov 2023 09:43:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781561904918777920 X-GMAIL-MSGID: 1781561904918777920 Commits 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support") and 9134c1fd0503 ("usb: xhci: plat: Add USB 3.0 phy support") added support for looking up legacy PHYs from the sysdev devicetree node and initialising them. This broke drivers such as dwc3 which manages PHYs themself as the PHYs would now be initialised twice, something which specifically can lead to resources being left enabled during suspend (e.g. with the usb_phy_generic PHY driver). As the dwc3 driver uses driver-name matching for the xhci platform device, fix this by only looking up and initialising PHYs for devices that have been matched using OF. Note that checking that the platform device has a devicetree node would currently be sufficient, but that could lead to subtle breakages in case anyone ever tries to reuse an ancestor's node. Fixes: 7b8ef22ea547 ("usb: xhci: plat: Add USB phy support") Fixes: 9134c1fd0503 ("usb: xhci: plat: Add USB 3.0 phy support") Cc: stable@vger.kernel.org # 4.1 Cc: Maxime Ripard Cc: Stanley Chang Signed-off-by: Johan Hovold Tested-by: Stefan Eichenberger Tested-by: Stanley Chang --- drivers/usb/host/xhci-plat.c | 50 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 28218c8f1837..01d19d17153b 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -148,7 +149,7 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s int ret; int irq; struct xhci_plat_priv *priv = NULL; - + bool of_match; if (usb_disabled()) return -ENODEV; @@ -253,16 +254,23 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s &xhci->imod_interval); } - hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0); - if (IS_ERR(hcd->usb_phy)) { - ret = PTR_ERR(hcd->usb_phy); - if (ret == -EPROBE_DEFER) - goto disable_clk; - hcd->usb_phy = NULL; - } else { - ret = usb_phy_init(hcd->usb_phy); - if (ret) - goto disable_clk; + /* + * Drivers such as dwc3 manages PHYs themself (and rely on driver name + * matching for the xhci platform device). + */ + of_match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev); + if (of_match) { + hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, "usb-phy", 0); + if (IS_ERR(hcd->usb_phy)) { + ret = PTR_ERR(hcd->usb_phy); + if (ret == -EPROBE_DEFER) + goto disable_clk; + hcd->usb_phy = NULL; + } else { + ret = usb_phy_init(hcd->usb_phy); + if (ret) + goto disable_clk; + } } hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node); @@ -285,15 +293,17 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s goto dealloc_usb2_hcd; } - xhci->shared_hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, - "usb-phy", 1); - if (IS_ERR(xhci->shared_hcd->usb_phy)) { - xhci->shared_hcd->usb_phy = NULL; - } else { - ret = usb_phy_init(xhci->shared_hcd->usb_phy); - if (ret) - dev_err(sysdev, "%s init usb3phy fail (ret=%d)\n", - __func__, ret); + if (of_match) { + xhci->shared_hcd->usb_phy = devm_usb_get_phy_by_phandle(sysdev, + "usb-phy", 1); + if (IS_ERR(xhci->shared_hcd->usb_phy)) { + xhci->shared_hcd->usb_phy = NULL; + } else { + ret = usb_phy_init(xhci->shared_hcd->usb_phy); + if (ret) + dev_err(sysdev, "%s init usb3phy fail (ret=%d)\n", + __func__, ret); + } } xhci->shared_hcd->tpl_support = hcd->tpl_support;