From patchwork Wed Feb 27 06:51:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 10831291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21E2B1669 for ; Wed, 27 Feb 2019 06:52:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CF9D2CFA3 for ; Wed, 27 Feb 2019 06:52:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 016B12CFBB; Wed, 27 Feb 2019 06:51:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8690A2CFA3 for ; Wed, 27 Feb 2019 06:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729479AbfB0Gv7 (ORCPT ); Wed, 27 Feb 2019 01:51:59 -0500 Received: from mail-eopbgr70081.outbound.protection.outlook.com ([40.107.7.81]:60384 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729412AbfB0Gv6 (ORCPT ); Wed, 27 Feb 2019 01:51:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XrU4P4IhfdnErOn4BTFdrftuImsGA/1Jse5vhxE0PWI=; b=PEdBQ4TWvozvbOstqQBTYDuoHukMHXeZS5qMquUvC1lSWw3dQgwRfVWX1IQYplKS6qR+MLkNJREVkSdLibqFqzLiHGfZ9Wta3qtseiHKK2vtLybUcBa2Tc/C/L3GL3lbiqsS8+qlswSkxXkV2D09ylPhjh+4EPVoCMKWHyHR5Ck= Received: from VI1PR04MB5327.eurprd04.prod.outlook.com (20.177.52.16) by VI1PR04MB6271.eurprd04.prod.outlook.com (20.179.26.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.15; Wed, 27 Feb 2019 06:51:38 +0000 Received: from VI1PR04MB5327.eurprd04.prod.outlook.com ([fe80::790f:a219:bcbd:6fd2]) by VI1PR04MB5327.eurprd04.prod.outlook.com ([fe80::790f:a219:bcbd:6fd2%3]) with mapi id 15.20.1643.022; Wed, 27 Feb 2019 06:51:38 +0000 From: Peter Chen To: "gregkh@linuxfoundation.org" CC: "linux-usb@vger.kernel.org" , Paul Kocialkowski , Peter Chen Subject: [PATCH 5/5] usb: chipidea: Refactor USB PHY selection and keep a single PHY Thread-Topic: [PATCH 5/5] usb: chipidea: Refactor USB PHY selection and keep a single PHY Thread-Index: AQHUzmjjrb8FaVuwv0q25WsLU8rI+A== Date: Wed, 27 Feb 2019 06:51:38 +0000 Message-ID: <20190227064908.17731-6-peter.chen@nxp.com> References: <20190227064908.17731-1-peter.chen@nxp.com> In-Reply-To: <20190227064908.17731-1-peter.chen@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.14.1 x-clientproxiedby: HK0PR03CA0034.apcprd03.prod.outlook.com (2603:1096:203:2f::22) To VI1PR04MB5327.eurprd04.prod.outlook.com (2603:10a6:803:60::16) authentication-results: spf=none (sender IP is ) smtp.mailfrom=peter.chen@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b4f281da-bba3-424d-3df1-08d69c800585 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:VI1PR04MB6271; x-ms-traffictypediagnostic: VI1PR04MB6271: x-microsoft-exchange-diagnostics: =?iso-8859-1?q?1=3BVI1PR04MB6271=3B23=3AQA?= =?iso-8859-1?q?lwqk4NrXvgev6W2mfm1j3fDPGBrW6cvwLUQw8qw1UScOzyFWkFciL3JGtC9c?= =?iso-8859-1?q?SjY7vqLEJSTKAH7TH3YoMJ8To9nxdRiwoaxeVOKlppjsXXiA4ovh7AjvH4HH?= =?iso-8859-1?q?P5hOfDN+P2waGcjdEsuYeLbdh1xO0J421TAdAM+T70UBQJhfvKNZlBhLI4Sj?= =?iso-8859-1?q?va4uFx0iXmm4ycAZpcUWMdryC5dUh8/6Qe1CGSH91ojBe8txFnXRO3tSbv/6?= =?iso-8859-1?q?6+Sv9flmGH15tYXLEnrWqotEi+yUO30Zlr7+INTFlWlcqJfUof4SsUNPHV7V?= =?iso-8859-1?q?vH0KgVKZS1OAPo/l36jYCIU0bD1tNr/USbNMOurvyHU0KdtpyxYjdJyBDSdU?= =?iso-8859-1?q?PdZ8SYntk2ZsU8zD2rSxb+yBOVMlzkijK9yXJ27g0mAo87fs+lxI0txR7Dbs?= =?iso-8859-1?q?huWLeykitOx370dtpZJXphxtxVgXM05mVLHINTSrgP2GHtSNXFGDeh0NGX1u?= =?iso-8859-1?q?QsC9oFe8WieIwJDBYThjULm1QUpIauuXBbYeudDr06l2CoIXx2iECnqZtC7G?= =?iso-8859-1?q?HQ/QBQMPSr0bB+oSOTn7idiVOdnh/yjLbauR+o9LnXbzi1vO0KH8koEAGSUG?= =?iso-8859-1?q?iZyAAdbN9MpyxW9gdWrsBimx50a5O/nWPhmNfy67vubcdDS6jOTOV5w/XhLP?= =?iso-8859-1?q?ec2iuv5nG7rGYtr5TQgjKSUbEaxCBdP4wRaGi5pPOh0eRaB1e3pTz3w0jtAK?= =?iso-8859-1?q?YZpzHn0uysputbTlFXht/cRLXKC1FoiE6B5x938g/tyMrlpUwZ/h1HNWbLZU?= =?iso-8859-1?q?UfNU1WP+8qQgzGc0J946ZInS2BGZ0JvLuIpJfQxqj5UjvZvuKJa7EzfHg81p?= =?iso-8859-1?q?sNy7YAytF2w6m0KMqvvC3swFcINZ1MfbDh8S3A0Ez+X539gafNJDQeaCrgW/?= =?iso-8859-1?q?04Lrd5LBR2qU0rVQzMoOAjHYpIXm6Q9RNQX3EQcPVmB7EKgT29d2o4fmbreR?= =?iso-8859-1?q?NMpzNrgRQaMkHwgDCeh28JuyTq2CAf18zcLIyFMJTHsj0mns+MIaZZt5dkHf?= =?iso-8859-1?q?ewwEP1k7xSR4fdklQ4Gosaz6YBbgg1zud7dyYN0zJExs1Yo7vz5/m9virt13?= =?iso-8859-1?q?wseuGwvjvsnt0nSrOA92s7pLEgj6L3x0FfW8V7A0cPJ/UM+rXOmZBA2LNMLM?= =?iso-8859-1?q?ZUZcixt9Gvn8r+xGMN/3aupXMMXw2W29Ae9YgCwpjFoH9nfVVpKkVRv+Q3Kv?= =?iso-8859-1?q?eLVyCczD+szgR9roaEBwH1/IvrO+/nmuFqS7uJqi1USCu5rL7XV6b1PObq6I?= =?iso-8859-1?q?y2DJgN+91bS1kp4D1DcD6W0oOj9sfaRAB6UEq+2hLtIGraLnA2zQkTmPbyvm?= =?iso-8859-1?q?M=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 0961DF5286 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(376002)(396003)(366004)(346002)(39860400002)(189003)(199004)(446003)(6486002)(6916009)(478600001)(1076003)(5660300002)(36756003)(2351001)(26005)(6512007)(106356001)(386003)(186003)(6506007)(68736007)(486006)(102836004)(5640700003)(6436002)(44832011)(105586002)(81166006)(81156014)(1730700003)(97736004)(8676002)(14454004)(54906003)(76176011)(53936002)(71200400001)(66066001)(6116002)(71190400001)(3846002)(8936002)(2501003)(2906002)(50226002)(316002)(476003)(2616005)(99286004)(25786009)(256004)(52116002)(11346002)(7736002)(86362001)(305945005)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB6271;H:VI1PR04MB5327.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Xs6MUO0FQ1CkGJxYzpId2yuhi47Ods25V9M28TwVutCXvVORgLfm0XYTdWxKdy5Rfk9FX5abPfrDIFIUh/zM0vLDVwBwIoM1+x9qy+xbWGcRkUls1E+JPgiqw+Ip4Flz4+e5J3KYxGO9cdB87pMWjsbqZJMXaGWecNBUieqxPcnwxXOdrIWYfmCU6ejkYqcbATXQuEwK2s/432MSpuyjHf589K/SVPfl5JY8f1o7S2/bSqR6aHqE920BdmI5NS/3s1E/kPGgvq2rVkqx2/jcrNoMfPprFwNH7h6KN0jM4MrbdKMtcC4MdZjXRgzMrivSP3cKUlG5QayoHLcG385JrC4n0kEMtHew0QDWFWKEQfe0LO48V24LH1LOLq4zxkL59gVtir2Y+DHT4/RQeWJOJd1V9BRhO5OuAo/r0SEuIHc= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4f281da-bba3-424d-3df1-08d69c800585 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Feb 2019 06:51:36.5317 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Kocialkowski 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 Signed-off-by: Peter Chen --- 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);