Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp353272imp; Thu, 21 Feb 2019 02:50:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IaMpxvELJpOWWCLJfho7GkQ7Cyx4yo+jqNLF68SJHLsSTz6Y/iS3G9Zu3YKWcwbCMgrEI5o X-Received: by 2002:a17:902:7293:: with SMTP id d19mr40229984pll.29.1550746221981; Thu, 21 Feb 2019 02:50:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550746221; cv=none; d=google.com; s=arc-20160816; b=BdfYC37cVDxPv/Fkzh4o0wp0L64e3kw6zDutRjWHNYiLEXh66/BC1HXfvo4TOTd9aP A1uACkyM1h0228rqQfZxAPdkJWZ9UUFtKsqq2wHUXhBB28lCxzDbSfvWeLwEmPVlbL+7 AvGgVPzZ8K8Wob+izfIDf7pS4SYgiquc1kfzkMQ9zGaW3DqoWu9VEqZP81Qwq4/LKkXF wBzWkTmXv+wL7OV057mIdD/Pn3UDbJ97BJSVaiW/uFZ28OMaF7uweB1Q3tQBg0sK9ydd SVl+ebMVXfGyT9kXmL09olBjooOeDm3p7cUMKDTKBBEkAuXyVjSlv1S77JeqRZLSy5A+ 4Uqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=t/fxeMbPA6ndCIxOlmNPRnhZ1ItRlprgQI65Eva47e0=; b=vBkQGjVBzOxQFmpJMfrDrTDxEDa6EFsMgaBXWtFlVrqmPcsPFvLrI6nXu00Fx1Mpf7 L/1h/qyC4Bq+mDZbBrndbwcYWshDy8lSgrE0h2mlOF/2kGssYXvyBh6cyXCSTV+v0zkt 752uKFY5h1ltas1Hv2I12Cx6ZcjP00XNo+jaaM89xBGTYEZXNaJC/884mjSqrOaFXU9z TOVn+p8PT8rNS6P2sxaoQmu5MduFonA36fcsn6Mu3AkGKPJoGOqItcKfqaHfyZP8iiZ5 iBd+rB1zF9UDkvgTMQbLCU9pHzHXKKk0RcT3zT2ywcZTqSxNxehpjzS7rfyYrq2ULgOD RZCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si21975091pla.89.2019.02.21.02.50.06; Thu, 21 Feb 2019 02:50:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727545AbfBUKtl (ORCPT + 99 others); Thu, 21 Feb 2019 05:49:41 -0500 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:60269 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbfBUKth (ORCPT ); Thu, 21 Feb 2019 05:49:37 -0500 X-Originating-IP: 90.88.23.190 Received: from localhost.localdomain (aaubervilliers-681-1-81-190.w90-88.abo.wanadoo.fr [90.88.23.190]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id F240E40013; Thu, 21 Feb 2019 10:49:34 +0000 (UTC) From: Paul Kocialkowski To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Chen , Greg Kroah-Hartman , Thomas Petazzoni , Paul Kocialkowski Subject: [PATCH v4 2/2] usb: chipidea: Refactor USB PHY selection and keep a single PHY Date: Thu, 21 Feb 2019 11:49:14 +0100 Message-Id: <20190221104914.32031-2-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221104914.32031-1-paul.kocialkowski@bootlin.com> References: <20190221104914.32031-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor the code in charge of looking up the USB PHY when no platdata is provided. Attempt to get a generic USB PHY first, then look for a legacy USB PHY through device-tree and finally get any registered PHY with the correct type. This way, only a single USB PHY is obtained and the flow is easier to understand and follow. All error pointers (except for EPROBE_DEFER) are considered as PHY not found. Signed-off-by: Paul Kocialkowski --- drivers/usb/chipidea/core.c | 49 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 016e4004fe9d..27749ace2d93 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -954,32 +954,47 @@ static int ci_hdrc_probe(struct platform_device *pdev) } else if (ci->platdata->usb_phy) { ci->usb_phy = ci->platdata->usb_phy; } else { - ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, "phys", - 0); + /* Look for a generic PHY first */ ci->phy = devm_phy_get(dev->parent, "usb-phy"); - /* Fallback to grabbing any registered USB2 PHY */ - if (IS_ERR(ci->usb_phy) && - PTR_ERR(ci->usb_phy) != -EPROBE_DEFER) + if (PTR_ERR(ci->phy) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto ulpi_exit; + } else if (IS_ERR(ci->phy)) { + ci->phy = NULL; + } + + /* Look for a legacy USB PHY from device-tree next */ + if (!ci->phy) { + ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, + "phys", 0); + + if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto ulpi_exit; + } else if (IS_ERR(ci->usb_phy)) { + ci->usb_phy = NULL; + } + } + + /* Look for any registered legacy USB PHY as last resort */ + if (!ci->phy && !ci->usb_phy) { ci->usb_phy = devm_usb_get_phy(dev->parent, USB_PHY_TYPE_USB2); - /* if both generic PHY and USB PHY layers aren't enabled */ - if (PTR_ERR(ci->phy) == -ENOSYS && - PTR_ERR(ci->usb_phy) == -ENXIO) { - ret = -ENXIO; - goto ulpi_exit; + if (PTR_ERR(ci->usb_phy) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto ulpi_exit; + } else if (IS_ERR(ci->usb_phy)) { + ci->usb_phy = NULL; + } } - if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) { - ret = -EPROBE_DEFER; + /* No USB PHY was found in the end */ + if (!ci->phy && !ci->usb_phy) { + ret = -ENXIO; goto ulpi_exit; } - - if (IS_ERR(ci->phy)) - ci->phy = NULL; - else if (IS_ERR(ci->usb_phy)) - ci->usb_phy = NULL; } ret = ci_usb_phy_init(ci); -- 2.20.1