Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp613742rdf; Fri, 3 Nov 2023 09:43:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZScefRaI9+tkO7dTUPBKcdYs+iT4jIVy6SI2k8OgCKGXCfrZXdUgtPuvuleech8Wh3Rws X-Received: by 2002:a05:6870:10d1:b0:1f0:811a:4027 with SMTP id 17-20020a05687010d100b001f0811a4027mr1414101oar.8.1699029832490; 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=h0jBk2PicF9WNra2+Kk5rrMKUwZkXOowDYMyY3Ai8gXlsj7N05ESrQayIp9zu2Yx1d kuIAIN5mbrACa1m5WrHP1TDzQq7oV91+b6M/ukLCcvD6R369DLnUGdfcovlCTiWStCBt 9jhNEOPNlwTOzvRogN7T9VRpGUZVgUQvje8Q22ze4fNpWpkcSdo67KNUxDYyVkeqmxuW 2b33oBluAk+W2tKf7FhB8iPvk3fJMEYP4F+uXZqBlekBkELtLPGbVDKUKfNW1gP6SZ3B XipbuvVjc+A3/uoB4VBOdcC2PkvWV96EdejXuzJAmDhTbyLBqN6vmvcaNzu1g2DXLfKz X09g== 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 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q17-20020a056a00085100b0068a85532963si1791830pfk.160.2023.11.03.09.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 09:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; 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 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 8628D830F562; Fri, 3 Nov 2023 09:43:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345473AbjKCQni (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 03 Nov 2023 09:43:49 -0700 (PDT) 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 --- 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; -- 2.41.0