Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7007265pxb; Wed, 17 Feb 2021 21:33:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzPDAvjK16BJjYFpZQblR8w+S65DQKzczPyj6gvQyuA/gDHbivkhY/tN4EIMKTOQUarCzF X-Received: by 2002:aa7:d8da:: with SMTP id k26mr2313678eds.364.1613626439071; Wed, 17 Feb 2021 21:33:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1613626439; cv=pass; d=google.com; s=arc-20160816; b=x6K2fO/ZRHJa2UzvLB1v5GKvVLTWhVPs3IGDIMKeNOZQi5i06QordEs2xxpblUiUxc h7MR76iTOOZVRPXWDmRaaLzNuqxaX7H7coK8adnsjqO+pgWQgkY5xm6O045F58QHGDRY HnxovBFC8qIeH2j8zy4VlzxSUw0WHAqfB6ZemZtWJyTnX/VXS+GMLeaByg/qeGYVMtYy EaH2V1ipsDICTdXVc+GBqn5eviRpmIolX5NK4wTBzNj6E+vgtVjHIAOFnbWLn4ueQ09/ q0LWcS6dFSZ6eTbir+3JPLTOoC45xmQKdsGKjpxsxtS+j1k7+glI2KpXijTTGHvWmXQu 9hWA== 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=5ZOYecOt4RSVmkzwuwUIQWBC6q5eTkoxJIpLnAA0Np4=; b=H0CU7iWdPQiKWJ3g74OnCIuM0heDtet+UesRi6L4u6wWgSsxiXCqqozC4KIthK+Jok wyCdLCwSxPLnGW2vUEW0qfxs5I0g228NlZOLuulCR5W5mzmbeQ1fX6m32/y9aY9varPr pN3FfVDbSJAtUJDK3ba084SFkuhKZIW7N8+4/FU5UxRwrkopllRy4MrBrK3L4xJbsaH4 1FmrJ6k9vRWC7VEkkWZHZK3PNQC1oc2qQAWR1LfKFDYxy1gWnbJ45pXz/OMhscc8oGn4 sJX88drkKwoSCDhiVwc6KP0Gsp0RKCSnVZvQACDqX0vXZdItO/lpsIKdFcdv4q/K20O7 JihA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b="Wca/z+hK"; 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 f17si2861455ejd.597.2021.02.17.21.33.36; Wed, 17 Feb 2021 21:33:59 -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="Wca/z+hK"; 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 S230486AbhBRFb2 (ORCPT + 99 others); Thu, 18 Feb 2021 00:31:28 -0500 Received: from mail-am6eur05on2076.outbound.protection.outlook.com ([40.107.22.76]:48096 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230282AbhBRF3K (ORCPT ); Thu, 18 Feb 2021 00:29:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HF90btY+P2NKF3HgXpLuCJlCOXl4fZ5HApg+NgKf7V49zp+k5iC+hjmW8MFwr23xJOIEA+CJv0O2SZwZZz1ytjR49sV+ti63Bz9jdmGI6Hi7Ce3+v3m4aIIKc9bqbLOMA7Hx77yCz8gr1C7wtJhJT9Ro2ssC39PDrFO8BqJUONsIa1UPiKXiMeNrHHUhP7LUA5RyAInhuQqEwBmYDdwm1na+FRYSt7ewj63aROKwFW9gmh+MO+RN78TfwLr9NvrL1JqF4IoLdwpentqA7PNhHths/F2Ps/qrgYomCZyMzHA7+bKNsqtVqcLVceUmvT90dDiDldnxW9l+EdIkWcVGfQ== 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=5ZOYecOt4RSVmkzwuwUIQWBC6q5eTkoxJIpLnAA0Np4=; b=BtCRW2rKLNkxNzoeKI5uz1i1ompqMCv//OktXw7kMpDU8L39Gh9Av1QVWbCL0rd7uXQmSqQg/QhTfEvnHQzCr+3c3DQXEwJY3aVgBAkA56lLhta8Rus7RZG11ybU4NeKq0lmwRzlka3sremubA7modIHYGqHbES7aGxxd8BUD8R0D1cj+DSH+JZ4gHLFDRoLnz3cW3LZ9fGmSTPBCZTkbKiLK+zWXssqyS0Xmh1H69DKv+wEuKyANdiQEXFylipGbeQZLcogxgB3YcraoSMahJgY8mifAxGtFJBBjT+fSYPmdFfYhYFK+L0e4hIc9Uh7D7R4IRxUXOEEjJtes+y3ww== 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=5ZOYecOt4RSVmkzwuwUIQWBC6q5eTkoxJIpLnAA0Np4=; b=Wca/z+hKq8lS7dlCgRAB+g8xpKKVOb9mb9++JmbgqR51C/QZA9XYzpTU2hfBMuCuSUvj79cLvhDl+d/gz9B/19s3TFyVkfivbBWHYpvdreVdKr8g0PnEpErvl4ZvswH+TTveHy30Nx4a3Q9eC7tEG6GRYqitscfNHCb39DJpl9U= 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 AM0PR0402MB3442.eurprd04.prod.outlook.com (2603:10a6:208:21::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.42; Thu, 18 Feb 2021 05:27:46 +0000 Received: from AM0PR04MB5636.eurprd04.prod.outlook.com ([fe80::e90e:b1d6:18a2:2d42]) by AM0PR04MB5636.eurprd04.prod.outlook.com ([fe80::e90e:b1d6:18a2:2d42%6]) with mapi id 15.20.3846.042; Thu, 18 Feb 2021 05:27:46 +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-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, Laurentiu Tudor , Diana Madalina Craciun , linux-arm-kernel@lists.infradead.org, linux.cj@gmail.com, Calvin Johnson , "David S. Miller" , Heiner Kallweit , Jakub Kicinski Subject: [net-next PATCH v6 03/15] net: phy: Introduce phy related fwnode functions Date: Thu, 18 Feb 2021 10:56:42 +0530 Message-Id: <20210218052654.28995-4-calvin.johnson@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210218052654.28995-1-calvin.johnson@oss.nxp.com> References: <20210218052654.28995-1-calvin.johnson@oss.nxp.com> Content-Type: text/plain X-Originating-IP: [14.142.151.118] X-ClientProxiedBy: SG2PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:54::15) 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 SG2PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Thu, 18 Feb 2021 05:27:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e3b72d66-ceaf-42f3-4537-08d8d3cdec9f X-MS-TrafficTypeDiagnostic: AM0PR0402MB3442: 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: nRBe+aawi4jvYREZ2kxxYWhfmFDhADjSgKIfRNBTypNexAV2anugX3hzagZTwuKT3NVqvvE4mefqsv2RUhi47v0D3O1r8siN+wjhafBPjBQXwNqzLRi652ICV/wzw88jiPfbGekLqHUnJ8DlwVpIgP2Cnh0O7AD1sn7Bli2TnmDhZub1mmS6L+ivNZq03sy7uj0PJQHBCZVMbpQXBWMltHhCsSpmA6n+bgUxTVVuAsPcuMv6aNnB0BEtPGeR5rn6TqFYtYFASy48VtcJfsrAa613neeMXv7AKftpmgk9fYNWkwoK6rfGKFtVZ/GSvQtb14X0QyZ7YOnAL2bfQtPhK/C2zq8zH223d4u1WOnOorYuLqNzqemLGsGjYKuFa0YAv28+FljxALA4WdGKeGp2PnoEyw6hmF8TGc1HV8SieQm82SM6lZn8tR9SgTNE5oQG0JlSEZilGLiYHhjIATwtaqgx5spCc1503xQqyjuqxOj41lPhGTEvwa6L2V1QfWu/FEsk95LOubtbTraWAFo5OfRU1qsyB5ek6bDADwUKxNUQmNKwBW92qlmeMY9IGxMT08FxFpUYOfaqckPp4EHf7cOqXVdfygQ+7a7LMZpNDg4= 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)(346002)(136003)(39860400002)(376002)(396003)(44832011)(6486002)(26005)(7416002)(16526019)(110136005)(956004)(2616005)(186003)(55236004)(83380400001)(1076003)(4326008)(316002)(1006002)(54906003)(8936002)(5660300002)(921005)(2906002)(52116002)(478600001)(86362001)(8676002)(6512007)(66946007)(6506007)(66476007)(66556008)(110426009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?5OKDYrqSaHTBbIzuZFQGCNlPRIrZ96EQoTI7THPDXMFgrxMJ97UbJqx/FgUj?= =?us-ascii?Q?V1neR1mZlU+mCZKDSykb6p+YwGWuUiqPRm1oNFTGRfejfK0dK7J7GKKGrqhl?= =?us-ascii?Q?6zTXu/9w66g4o6+xFXylrIzIf74bVFhS6EtMWbjbFLWpFefCMDv2d5nAFJvu?= =?us-ascii?Q?7GsvkXx91TH02GjR+Okznua1LDlibH6zzu2+RsQpWg5xpE1cr27pHpXYCaot?= =?us-ascii?Q?PMBVPT5cboTttASSn7AMZ2scVO4GjrGk9Lbgz0bz1cjWc5dP1+BfXQlRpQhU?= =?us-ascii?Q?UTF45HdUnI28pXLozmQNtXwQDH0UxkLLaulEMHZCjUr5+dL7ZHu2FnTv26T3?= =?us-ascii?Q?djiQU+mIZAKBLaCXXsflgv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Q?ngUw2izo28WHNVoirCgWK2DiQG64P9SdTIgNHvNGBNbowQeFgosWmszlqw35?= =?us-ascii?Q?ve15MlsQQxHRZEtarSe+cYKz?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3b72d66-ceaf-42f3-4537-08d8d3cdec9f X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5636.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2021 05:27:46.6621 (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: QDBFf9JZ6SBkwHbKphGnaVJcE3VRtfkP0Ae1bwfSraMXze8nvaJ7wvrV+mjkuvq470er2AR8vVrYJMX9sdY6Ag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3442 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 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 e673912e8938..537a25b9ee94 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 @@ -2844,6 +2845,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