Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp105932pxf; Wed, 10 Mar 2021 22:24:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvTZ8jP25yGYkpINXaHjXE5X6i5fQX4lSH5PDhKBeJf7Xt0VvI/2uOu67e2AZ36Wr8mzje X-Received: by 2002:a17:907:6005:: with SMTP id fs5mr1520951ejc.184.1615443896565; Wed, 10 Mar 2021 22:24:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1615443896; cv=pass; d=google.com; s=arc-20160816; b=dNlc7AR0/aBCEKTPKSIdOddEo+yrp6Uwot24mF/ibK2jMxBAESj23Zvy975bQpaAJ9 89v/FlpQIuDyUNlyQC+uPdjPDR0RWSYdyb8b3lvp2hCaLsrySDJ7znw1AGqqBf08j71I vnwHyI8rMItqiimw8oRAStH00Z+dHxUh/5SO1zfPc49viWo/FYHjyvGF3WVgMzxNtBme zz67nQtKtc/wcaK6Z4X7KBvhyS6WkbQ8tbRjYaJmoMsSNpjDa5pkX+JLtbt+yn8onZm9 OOLn9WMjE62kQ6NbIMaHr/Xv7iHFXjp1HJCHGzzTkYJ8s1qfOUzi6caniSc561Qaxodl FwDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mA9n+CzKw760mthl8WNU1R68T0UjsjxA9RAup/kG3oA=; b=YTGRSUzdTvdt07w8rFQGR5Fz1okdEI7hEaiDXoSpaPV7BDG1D20RDJ1r6U3Mou/PvK i/Pp7eah8BSMaFYNnv5qYauLcMZTBNKyVyK4B8dFcip9/y5rDLGUjTG2BN0iCA+PKD/p qPH7VFiI/0F6nDgerbGXmIbkOfQTNWX+dz+ogC7pi/wdnyo+B0Acs51XiTZ9NUmrCT6q XIPwScKBWdrQwQdTj96wVNY0kivUQdAJRoGTfEEnqE36F6rZDqJUe9+YENX0SZiHi87N yBodxlAf6Lb1gi1EEpMelAcPl28cEwv7vyBjx40zmxtUesjt1KBmRGXJXrTz4h5CMst0 hpWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=ajtF3AfE; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si1179205edd.473.2021.03.10.22.24.34; Wed, 10 Mar 2021 22:24:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=ajtF3AfE; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbhCKGVl (ORCPT + 99 others); Thu, 11 Mar 2021 01:21:41 -0500 Received: from mail-eopbgr70083.outbound.protection.outlook.com ([40.107.7.83]:51643 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230263AbhCKGVN (ORCPT ); Thu, 11 Mar 2021 01:21:13 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LQqqjhju7fKa9s+p7pHULV2ZcEuXVRtUMJ/DU52hv/S8vnyBOUtSGGPmQeHAzvhr6LD4t0SeaUkPZZnYodVkL0/hKbtsTh+ukI5/NuSIU22YxAwZVxuSVebE1HBI4BzpE2kFEWq4rucil4Fzn3ndewK4hThuKTxkKwoKZIWtv+nDKnH8CIq72gRWfsg620ToOG/2V2vkIMhCOK1XIAMdtE5DfEe2PEisKpLjN/RnmwGCMzOyM5/WMHGYGjIeLuYGzAahXYeQ2aFeG8eLsOWLrhEg+lxbXNi/CkQIT6D0x8zdz905Rd1FLHsv/IzLPujTdldng0XwYwIlrnoYsBwFQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mA9n+CzKw760mthl8WNU1R68T0UjsjxA9RAup/kG3oA=; b=dhMPNEo+3JsGML04p1gD0kr+qZiJQ6+gHJIW4rmxm2g7GMyaPT5eWx41tKpVIZYfk+tAGBkbbPjWYydk0XHy+B2m4YuJZUmSsq4/LWivnQdqZTd8xiKL/sLCfl1U1vke6KHedhJWZhzNwmf8jgj8RhB1Z5CVdDJlDMKuNiqMBPMBxMwucEiwB/7NkyfXgblUUF/2lDGZN1aYM4cysNxi9/51ityYf/XuvhLHdoN84S2K/UBvwCubshm2mHA4ocZ09IX537GGVzF91nAVioPWiy642JF5ydkshlKBRkvfR8ygszK3e9oKrjhEj3RJhD/nPk39oDF0lBEyCvnKbsrG4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mA9n+CzKw760mthl8WNU1R68T0UjsjxA9RAup/kG3oA=; b=ajtF3AfERgli5ZT2zcRHRFo7IfQEUILqRz1+oHLWw6zePht3H0ycptJLhdiZWzDSMy57wCupfEeMCxcPBaIUdJt16NvoEDXgtqf4gUZwNLxwlnA7JPYmZD6KwaX2HS3tTMEcBezMGqSgxdi/TFNuOkJoz5c8/+Rkkq5g8lDvg/A= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=oss.nxp.com; Received: from AM0PR04MB5636.eurprd04.prod.outlook.com (2603:10a6:208:130::22) by AM0PR04MB5473.eurprd04.prod.outlook.com (2603:10a6:208:112::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26; Thu, 11 Mar 2021 06:21:10 +0000 Received: from AM0PR04MB5636.eurprd04.prod.outlook.com ([fe80::1cd:7101:5570:cd79]) by AM0PR04MB5636.eurprd04.prod.outlook.com ([fe80::1cd:7101:5570:cd79%7]) with mapi id 15.20.3912.027; Thu, 11 Mar 2021 06:21:10 +0000 From: Calvin Johnson To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Cristi Sovaiala , Florin Laurentiu Chiculita , Ioana Ciornei , Madalin Bucur , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap Cc: linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Calvin Johnson , "David S. Miller" , Heiner Kallweit , Jakub Kicinski Subject: [net-next PATCH v7 03/16] net: phy: Introduce phy related fwnode functions Date: Thu, 11 Mar 2021 11:49:58 +0530 Message-Id: <20210311062011.8054-4-calvin.johnson@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210311062011.8054-1-calvin.johnson@oss.nxp.com> References: <20210311062011.8054-1-calvin.johnson@oss.nxp.com> Content-Type: text/plain X-Originating-IP: [14.142.151.118] X-ClientProxiedBy: HKAPR03CA0026.apcprd03.prod.outlook.com (2603:1096:203:c9::13) To AM0PR04MB5636.eurprd04.prod.outlook.com (2603:10a6:208:130::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv03152.swis.in-blr01.nxp.com (14.142.151.118) by HKAPR03CA0026.apcprd03.prod.outlook.com (2603:1096:203:c9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.9 via Frontend Transport; Thu, 11 Mar 2021 06:21:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 68579370-079b-4f20-0954-08d8e455dc8c X-MS-TrafficTypeDiagnostic: AM0PR04MB5473: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KusriLlBx09LknlqRkefMSzLNTqiFdsFCahkdpC1RT9sF/Jb4GVliZsgFlKjM5kXXxvB0pCbcu6uhPfzRDeDQZ+/2jHpa9Q2c+OFX2psdn4PjbM3Xaj2K1pKxoKOKsikHWRJOSROoShCfW2HPD4/oqFZ19ORvh/SD2X+yLZYnPeZYK1/VcjvQtN31vHWFb3wi+ld0U84WtiQ0t5+hgOBl8nsxcWUG67o7yC+/z+CEhX6MVZyMHX0q8FUWvb8mpbff46tbu0k2ymxh7m9x3Q//Fa2GMC7jECDruiPZMLpCwtg31VW23uwn/1okNJM0qVoaVZwUqqW9GfRjwdzhW96P/tuasczhMsm5bxG6XsV0sKhZ7tyKxZ9jRlFiCqBoX+F3WOfVDP3jrEmgxdJ2fK7pXDmTrb7G92GNkqSNYjBCBmbaAwlUwcZNnHBKOd3rY9Kdh3/5UhMgjbywZ4r7yAIC5lveDk8I0AbdMzrEGHUo2A5etMbstXSMspYG2tWX3lsMKYJfGU8a1JiHlhAAFQt+yfRPlQXbZ1l2tmo6/1roz0pAQ/kHAsFYhwd/s4SU8WjccjcA726GZqrMy3+LT0QSGopYVevEXyH1hlInxMA70o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5636.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(136003)(346002)(376002)(396003)(44832011)(186003)(54906003)(66476007)(52116002)(5660300002)(110136005)(1076003)(66946007)(2906002)(316002)(16526019)(6666004)(6486002)(921005)(4326008)(478600001)(83380400001)(6506007)(26005)(2616005)(6512007)(8936002)(7416002)(55236004)(1006002)(8676002)(86362001)(66556008)(956004)(110426009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?6slTvZb6krx/5RrFzdiiPnkwGXLieDRoUZuLUYRciKp5PiOKAKPAvgZdph2q?= =?us-ascii?Q?tMG8NmF2Q5JxW+5Ry1jf8gnB3HbdopiZmUwGdGtQ6BRO8rpBBGEZVf+tHWon?= =?us-ascii?Q?kQ8uqQq47Vcd1gxm3ufqKftX34NAW8tdHESL3amzO1MLppQG9G4SCHnUgTOP?= =?us-ascii?Q?U3x/qbLTqmkVFGmFp/QtyXcrlpm3lctBk5XcUb04GjeJJQ8iRTu6lvMUGXYG?= =?us-ascii?Q?tCPGPzKweK58POUo+U/RPtKvh3jgOp0nNRJ3xz10rr5L6juo64muCq7ntKS7?= =?us-ascii?Q?AdgMbQTjZY+tz78jgC50h2muNBLDvW2tPLxv2bli8kTvCzI9mJI6zFYlY0qJ?= =?us-ascii?Q?WQe2A1dS6YS4RDuT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ascii?Q?lHx0Sjl5q+wZLrhu3ZWlpNyrXBJyJkbDV4dng8quub0sh5ajFlZVi+z5KULS?= =?us-ascii?Q?gBZlRr4IFTTcTbj0Ej4gN3IN?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68579370-079b-4f20-0954-08d8e455dc8c X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5636.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2021 06:21:09.9231 (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: zl9HWstuk+OKCkViod3XtmZsQieqBojqwxM5VKQSTYUNaXKbfVQPm5eLWndDNYy6xGEynrZgquHPuCq8lXuyqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5473 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define fwnode_phy_find_device() to iterate an mdiobus and find the phy device of the provided phy fwnode. Additionally define device_phy_find_device() to find phy device of provided device. Define fwnode_get_phy_node() to get phy_node using named reference. Signed-off-by: Calvin Johnson --- Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: - Add more info on legacy DT properties "phy" and "phy-device" - Redefine fwnode_phy_find_device() to follow of_phy_find_device() Changes in v2: - use reverse christmas tree ordering for local variables drivers/net/phy/phy_device.c | 62 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 20 ++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index daabb17bba00..aec8dadf5d8b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -9,6 +9,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -2842,6 +2843,67 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) } EXPORT_SYMBOL(fwnode_mdio_find_device); +/** + * fwnode_phy_find_device - For provided phy_fwnode, find phy_device. + * + * @phy_fwnode: Pointer to the phy's fwnode. + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + struct mdio_device *mdiodev; + + mdiodev = fwnode_mdio_find_device(phy_fwnode); + if (!mdiodev) + return NULL; + + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + return to_phy_device(&mdiodev->dev); + + put_device(&mdiodev->dev); + + return NULL; +} +EXPORT_SYMBOL(fwnode_phy_find_device); + +/** + * device_phy_find_device - For the given device, get the phy_device + * @dev: Pointer to the given device + * + * Refer return conditions of fwnode_phy_find_device(). + */ +struct phy_device *device_phy_find_device(struct device *dev) +{ + return fwnode_phy_find_device(dev_fwnode(dev)); +} +EXPORT_SYMBOL_GPL(device_phy_find_device); + +/** + * fwnode_get_phy_node - Get the phy_node using the named reference. + * @fwnode: Pointer to fwnode from which phy_node has to be obtained. + * + * Refer return conditions of fwnode_find_reference(). + * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy" + * and "phy-device" are not supported in ACPI. DT supports all the three + * named references to the phy node. + */ +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *phy_node; + + /* Only phy-handle is used for ACPI */ + phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); + if (is_acpi_node(fwnode) || !IS_ERR(phy_node)) + return phy_node; + phy_node = fwnode_find_reference(fwnode, "phy", 0); + if (IS_ERR(phy_node)) + phy_node = fwnode_find_reference(fwnode, "phy-device", 0); + return phy_node; +} +EXPORT_SYMBOL_GPL(fwnode_get_phy_node); + /** * phy_probe - probe and init a PHY device * @dev: device to probe and init diff --git a/include/linux/phy.h b/include/linux/phy.h index f5eb1e3981a1..720a2a8cf355 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1367,6 +1367,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, struct phy_c45_device_ids *c45_ids); #if IS_ENABLED(CONFIG_PHYLIB) struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); +struct phy_device *device_phy_find_device(struct device *dev); +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode); struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); int phy_device_register(struct phy_device *phy); void phy_device_free(struct phy_device *phydev); @@ -1376,6 +1379,23 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) { return 0; } +static inline +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + return NULL; +} + +static inline struct phy_device *device_phy_find_device(struct device *dev) +{ + return NULL; +} + +static inline +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) +{ + return NULL; +} + static inline struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) { -- 2.17.1