[v7,phy-next,14/27] usb: gadget: tegra-xudc: avoid direct dereference of phy->dev.of_node
| Message ID | 20260430110652.558622-15-vladimir.oltean@nxp.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-23018-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 190DD1C00DB for <noreply@patchwork.local>; Thu, 30 Apr 2026 13:18:05 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=nxp.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-23018-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-23018-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 18ED130B0494 for <noreply@patchwork.local>; Thu, 30 Apr 2026 11:11:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50E8E426ED0; Thu, 30 Apr 2026 11:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="UMBFweKF" X-Original-To: linux-sunxi@lists.linux.dev Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010066.outbound.protection.outlook.com [52.101.69.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EBE53F9F2A; Thu, 30 Apr 2026 11:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777547253; cv=fail; b=cgr0lQayttD1bdWakS0QR0OfwExQPx4zDLCUqUMGEY69sUN5Jqgn2poveCO9xlwQiib4FsSq/koDtC2YG4/qA1tvA481OsAjRAIO6zAr7mfB/YAKO7hby3LohCUcgFkZ6XnLcumaB3NAR+QBEtcJQI0v+kL5jJvkOkQNmzKj0ls= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777547253; c=relaxed/simple; bh=1jbR8ctvdwfWn2+V0Am+qBM8BmtJ5xZ5CM0TNSwx3yY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=cnSKEhEI5YrWZQi5/6b6eui4bstgzMPZMnt0tke5Lg4R6zXppqx7tVBJ4UdX50km2zPl2uFUsbUOgiVVfS52ASyWgbAdTlHEIQh6JnjJzI7uleHVilQ5owPjp0yPfPeSmEWa9GMVVt2tKcomMsuvhIlY9BZgxWOZgfXL8prOVw8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=UMBFweKF; arc=fail smtp.client-ip=52.101.69.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O3BKgWGHAHAbStytQpD473qHz9JsCtp3LgHcdFFPWgIfLUruFhAbBFa/gOU5eFsKM0hQSvc8IXFLRvZ/7HTSIiz3nSp/UUhw3cac2Lf9KEEfur3Db07w92FJ07ojwsYnI5YeqDYMlRjWx+Y+7brDOP3QYFLlDTI46/5ol0IOMSWDT0kk63EnYZL5ETk91qv1e9+HjkWnjw4q057wOmD/2W4g0Py7QAlqG257zX1JTfV0+77EPFQvaiihQMP6ni/CJHqBQuW/umWmvlrRqoFSRxpWV54LdCGcWbGeVlPNZ0qWzUybW5LeIyYEPzCd6MH4Rt0cjc83G/io496lhe+qVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G5FCjmEG1XDGz3sCPq9VXRXcsutJAgvtv8mVJdpgqgo=; b=tQg2osPf6RWRe7vuaKRvc6QOMphBhilDAqEnzWzCyXPIYcEb6nhxSQAOgj1vK8Ir0yTM+l1vZsXww/mnilPnJLkovXEZaU1pTN0JBOw4Cyhbb9LzKckos/IK5qXhXwGOF7eIxEfDVgWFMNsITtW1HlZHB4m1gsfY1BVVKdXaLGqhqYpoI0Gveap2hmqHO+gWTvkOQWSMvwvmhL4LEdilono11RMEg+Xp6hbjrdbp7g3IQrjh5Xci3TZbWBD6ho2Cs2ksG2WTQPQH+QLAK5F7fIwTcdaUUrYY1vHgH+CrNuN/MywPVGOEXpi1I8ejYKDc5PrdEQ1oadstaVhHVK9Qng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none 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=G5FCjmEG1XDGz3sCPq9VXRXcsutJAgvtv8mVJdpgqgo=; b=UMBFweKFxaHFLRqnCq42ai/dLrol9kBw8noQVypRevSjvZ53U5fMdcExa+J9z4Yl+9yiTlrUtTZRbsCDU99bmSO+d9y/hVwMI1AJGlx/Ou51j4dRbeV37+3itK7iWGx9yKpjlp/TNEL12ryRU2OVNAYvOy/2U7Unp+kJxYE9S7GJhp4GOMNH9rY3K9oVX3D2OE3gzSGNJa4rhiuJB0aKoWMrgGeAe0yPNxj+VeCC5WYJCa+8aqnxpYO3pUXn6aKMJpL5WTmgsK5M7vG7Zpq0s1TN5op4VbFxhmv9vo4LGfWGH+HCf5DJ5x2ltgMH6pTecXOiR+AyZwi2a0NAEtXdNA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 11:07:21 +0000 Received: from AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4]) by AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4%4]) with mapi id 15.20.9846.025; Thu, 30 Apr 2026 11:07:21 +0000 From: Vladimir Oltean <vladimir.oltean@nxp.com> To: linux-phy@lists.infradead.org Cc: Vinod Koul <vkoul@kernel.org>, Neil Armstrong <neil.armstrong@linaro.org>, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-gpio@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, spacemit@lists.linux.dev, UNGLinuxDriver@microchip.com, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, JC Kuo <jckuo@nvidia.com>, Johan Hovold <johan+linaro@kernel.org>, Jonathan Hunter <jonathanh@nvidia.com>, Mathias Nyman <mathias.nyman@intel.com>, Thierry Reding <thierry.reding@gmail.com> Subject: [PATCH v7 phy-next 14/27] usb: gadget: tegra-xudc: avoid direct dereference of phy->dev.of_node Date: Thu, 30 Apr 2026 14:06:39 +0300 Message-Id: <20260430110652.558622-15-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260430110652.558622-1-vladimir.oltean@nxp.com> References: <20260430110652.558622-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM0PR10CA0004.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:17c::14) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8585:EE_|VI1PR04MB7182:EE_ X-MS-Office365-Filtering-Correlation-Id: e5e892bb-aad7-4e75-7375-08dea6a8a650 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|7416014|376014|366016|19092799006|1800799024|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: Vjxm4dT4YyrAAns68Zk2tH54RuyQO39C91uPBT8f0gJz7f95Yzt1H6bSZNDv7S3jrD64N/liAlRMnr7uqw3MZ0/COe0b2WYOp9i90bRAKOmsTG/KLPHJLZ/7M8BLp0vITL2MtwHExZEeY2Ho7ramZ4fYFNotfW/nMU55bbQP8NZLhoz624hOtsdXFZfgLwYjOEU1zfcNssoXnzfL+r92LOKoPQyJ89iRstr+Ky9reM1s6Z+gerU166pZCirWYw5j+/iMWIYKyxAfmPjPhBm0T6NYju+wqJOnvH05JTkadM+rAB2zlsBIYQ0k2//7Q1jkgpdW5CCskUNOZ3LBm1D9rUXlr2nXLf9OsIgr4I0pAUTzTCY+/SM3GSYcy9TUGmi/ZzlJxFO6eOZo+6gWzoyaWrBfCg3NLZmJI5NjrBOgz3lprgjrvxu69xl174+NeSJ07zo3EL7lldE3dWyF19eDcKy500c2QPH9G3B8u6GYYpKfZoZ3D569Phh3/KtONs17WOmzkZp6lZ4x8x3GMRwzf4IuWnfvkIkv1JekjvMSTGDoSkL3BlwhBN+3MnumZCmZ+BUKysVDg6z5qZPjAaAPTqV8tA7nCYcRws0u5xpcTn9p03wnRWnCXRgaLZ5VvsAJVqRAZ5TzMUBWOIB3SNUGu6MbHMlgzEPwvN3gQ18BGP0NQ41lnWbLCmPLQoLwOhqA4r5foqI5UyQTVqcW1A9xFnQO76dm9cEXGaNqtx8sBn4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8585.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(7416014)(376014)(366016)(19092799006)(1800799024)(18002099003)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GOSUmq02vXVyKIg667nUdJkomAM/j9xzmmGgg8x27Ib0TX/e/NZZwFpRGKaDLnGpoEx0dx/Rjj1R7/nl5/L5cKm//bCGBdGpLX2jmYW/pGN/pj0pND+PjiIXEZ5iE+oS6cmiFApOfQOEbIDLL+FFMABMGSxOUx7Zjg/XP2pvAza4807AhbxCKk+75if+2ZJGtLssJkirIXRzzltnUth/nOoBH/kz3IK3McRdLMnzjFLB0QqiVQsVrmD7nEdfeqbELtdtHcxV7BiYbzinqvCaai92jxfFz4X0kizIrkCjR83GSpAHMDo/mGPP3dNOFKMSkMaaZ7cGrlG11rnMHsePPOsGIZJfNDmKq//nJt3PRl5s+qwEnfgbRFdQE3ihmiebOpM+edkMxf4XvbZrWptsTg/czVtCPnIH7qMEQ7HCQX378DhOmz7QgR6YtD5A2/EfpRNnn8AsWbfNZfouMBsXpRzQWboC2BAj+VRe7mvTOXbvjXqCabH3mGVfHVzz7ilO83LuGaB3QamNa1sWXIIREZvScW7Q5A2RK/nLZx9STapnctZBszcXsD4+VmVMI0sOnbUAVfud4A64GkLxkXgPkB252DocKWCsl7aIVQXOBa2hMDe11iTuE3aOwmbAKaLB0v7QP5oJEZFDJ6wCSMdlF/EO5hI0ebnb94ZVFXrRY98Kk8D6USVaA45670JAYlrrIQl71yVeXK77BFfNpdLewn28V97mNCXPpJEOcsOsGsByBG4wnCYdgp+er4s4WQjx5EnBOnLUylEM+EnYOqvn1Qc6DO0oA9CpYhgJxZ5N+K/+FcOMXIgUKKxqdp+kGJoQzMOI26y05Y/+M0Jtwd0MoO6DE7OnCz2/CEjv9XsVkfOPteovcEn4Vh6dQegIr2+56dbRNamwHwJgTZOYIhIhFU+W0z0pnR7LRZQV1JHFp16INzL4BiTeW1WJfF7kXYYUQqzNh+Yatc8P5RUlerLYIK9bj13tvzBRvs+uHOk3EDnRL6M5pSaAjkf9zWik7VdBXP8sfONe39Nt8WDXSYgaNpB6/J/m5xrIW2TXYWaAE/jCgNjhZAWMSKTRdH/y5wWjTf36uP4bKYHA+XBeM/6CmoXQpPg15kJe99OZnmdMPsZ2KnRt6jSTS3hU7pHGsnRQXD9l8g5pdVuU5NqKKiEJQ8B2seRcIBDyLpPSQ4bXPrdTRhBPlAlRlZMKwFdkvyyav2StpSd6T7jdYJbtxuvT8IFiHEls1fwOwTArYEtsdCn/jF2E8W8Mc48K289K4J3kGEwMkM1xIhhcjAhVdayMoIyxRpsXfiPZcFZjxvzfI1Kj5BoQs3osUdp7tMjRLgVYdJjyPYUW3yV3AhaCU+RJ7rGDjBlTLbyQvxgiRHnfaxynMnUKQXnkkRZKXHE7cjff5HbXHff8wptB9l0nSIbjJpaxCy5R9dbs8qkRst8PKUtxj340aI2SZpm88NP8xqxCTZpMXwKRg+jonSZmfIqVVhscInv0+XEb+RWp9k0Yz+hgiAvWqDt0Nyy4dcJ+LvOGjZyF2S1/VNC/PnQJW2kgk0ghHaeljTyDUgv09qOKXoBo5uF65FjY9AvaAb5If/6il5ziARCXlgIxiKGCHf2JQKqXnGxTjrgaqbD/ii7VG4noq/sf4CAVqDJIalnPO1S434AjYIOTGFVzRKV4G8MbzT0VanE/QZ9MoJ7SCTg/5R3iIk+iMKcLpiypTi1oFBHlOWpTx04bjVNxgr8/hd9eiMwV/G2TrFjjJ/AVvHp0IKrSvBiwalYjIEGcknozCUiX X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5e892bb-aad7-4e75-7375-08dea6a8a650 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8585.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 11:07:20.9807 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: x8EGf2P8v4K0XOZvRQI+9IBdZ+H+sDVngmOBs60CmjT9R1w/swBSVhiNG+zSanxsx5FpWwSMaByuhI+6CXtAOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
Split Generic PHY consumer and provider
|
|
Commit Message
Vladimir Oltean
April 30, 2026, 11:06 a.m. UTC
In a somewhat similar situation as the Tegra USB host controller driver,
the Tegra XUDC driver for USB gadget mode needs to get to a struct
usb_phy that sits behind the same OF node as the Generic PHY. It does
that directly, which will no longer be possible. The PHY provider is
also the xusb padctl driver.
The rework here is also to implement a parallel OF node lookup path
based on the "phys" phandle and the #phy-cells of the padctl provider.
Some further notes:
- create a local "usbphy" variable to hold the devm_usb_get_phy_by_node()
output. This makes the error checks more obvious (avoids keeping an
error-encoded pointer in xudc->usbphy[i] even temporarily).
- the "if (IS_ERR(utmi_phy)) .. else if (utmi_phy) .. else if (!utmi_phy)"
pattern can be simplified, considering that neither the IS_ERR() nor
the NULL case continue execution in the current block. Therefore, we
can move the case where the "utmi_phy" is a valid pointer outside the
"if" checks, and this reduces the code indentation level.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: JC Kuo <jckuo@nvidia.com>
Cc: Johan Hovold <johan+linaro@kernel.org>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
v5->v7: none
v4->v5: patch is new
---
drivers/usb/gadget/udc/tegra-xudc.c | 35 ++++++++++++++++++++---------
1 file changed, 24 insertions(+), 11 deletions(-)
Comments
Sashiko says: > commit 1ca88ec2e954b3a331eb5afb8081406d9200c8f6 > Author: Vladimir Oltean <vladimir.oltean@nxp.com> > usb: gadget: tegra-xudc: avoid direct dereference of phy->dev.of_node > > This commit replaces direct dereferences of the device tree node with a > parallel lookup using the phys phandle and the padctl provider. It also > introduces a local usbphy variable to hold the output and simplify error > checks. > > > diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c > > index e9d33be028664..cf4e6c87e44da 100644 > > --- a/drivers/usb/gadget/udc/tegra-xudc.c > > +++ b/drivers/usb/gadget/udc/tegra-xudc.c > [ ... ] > > @@ -3515,7 +3516,10 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) > > xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notify; > > > > for (i = 0; i < xudc->soc->num_phys; i++) { > > + struct of_phandle_args args; > > char phy_name[] = "usb.-."; > > + struct usb_phy *usbphy; > > + int index, err; > > This declares a local err variable inside the loop, shadowing the outer > err variable from the function scope. > Later in this loop, if devm_phy_optional_get() or devm_usb_get_phy_by_node() > fails, the code assigns the error code to this inner err and uses goto > clean_up. > Since the inner err is destroyed when leaving the loop block, will the > function incorrectly return the outer err which is still 0? This is correct, I've removed the duplicated "err" variable declaration for v8. > > > > /* Get USB2 phy */ > > snprintf(phy_name, sizeof(phy_name), "usb2-%d", i); > [ ... ] > > @@ -3525,22 +3529,31 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) > > dev_err_probe(xudc->dev, err, > > "failed to get PHY for phy-name usb2-%d\n", i); > > goto clean_up; > > - } else if (xudc->utmi_phy[i]) { > [ ... ] > > } else if (!xudc->utmi_phy[i]) { > > /* if utmi phy is not available, ignore USB3 phy get */ > > continue; > > } > > > > + index = of_property_match_string(np, "phy-names", phy_name); > > + if (index < 0) > > + continue; > > + > > + err = of_parse_phandle_with_args(np, "phys", "#phy-cells", > > + index, &args); > > + if (err) > > + continue; > > If either of these device tree parsing steps fail, the code uses continue > to skip to the next iteration. > Does this unintentionally skip the entire USB3 PHY initialization block > that follows later in this loop for the current port? This is correct, although theoretically of_property_match_string() and of_parse_phandle_with_args() should not fail as long as devm_phy_optional_get() succeeded for that very same phy_name starting from the very same OF node. But nonetheless, if this happens due to bugs, I've instead treated the condition as fatal and printed error messages for v8. > > + > > + /* Get usb-phy, if utmi phy is available */ > > + usbphy = devm_usb_get_phy_by_node(xudc->dev, args.np, NULL); > > + of_node_put(args.np); > [ ... ]
diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index e9d33be02866..cf4e6c87e44d 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -3494,6 +3494,7 @@ static void tegra_xudc_device_params_init(struct tegra_xudc *xudc) static int tegra_xudc_phy_get(struct tegra_xudc *xudc) { + struct device_node *np = dev_of_node(xudc->dev); int err = 0, usb3_companion_port; unsigned int i, j; @@ -3515,7 +3516,10 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notify; for (i = 0; i < xudc->soc->num_phys; i++) { + struct of_phandle_args args; char phy_name[] = "usb.-."; + struct usb_phy *usbphy; + int index, err; /* Get USB2 phy */ snprintf(phy_name, sizeof(phy_name), "usb2-%d", i); @@ -3525,22 +3529,31 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) dev_err_probe(xudc->dev, err, "failed to get PHY for phy-name usb2-%d\n", i); goto clean_up; - } else if (xudc->utmi_phy[i]) { - /* Get usb-phy, if utmi phy is available */ - xudc->usbphy[i] = devm_usb_get_phy_by_node(xudc->dev, - xudc->utmi_phy[i]->dev.of_node, - NULL); - if (IS_ERR(xudc->usbphy[i])) { - err = PTR_ERR(xudc->usbphy[i]); - dev_err_probe(xudc->dev, err, - "failed to get usbphy-%d\n", i); - goto clean_up; - } } else if (!xudc->utmi_phy[i]) { /* if utmi phy is not available, ignore USB3 phy get */ continue; } + index = of_property_match_string(np, "phy-names", phy_name); + if (index < 0) + continue; + + err = of_parse_phandle_with_args(np, "phys", "#phy-cells", + index, &args); + if (err) + continue; + + /* Get usb-phy, if utmi phy is available */ + usbphy = devm_usb_get_phy_by_node(xudc->dev, args.np, NULL); + of_node_put(args.np); + if (IS_ERR(usbphy)) { + err = PTR_ERR(usbphy); + dev_err_probe(xudc->dev, err, + "failed to get usbphy-%d\n", i); + goto clean_up; + } + xudc->usbphy[i] = usbphy; + /* Get USB3 phy */ usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); if (usb3_companion_port < 0)