From patchwork Mon Feb 8 15:12:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Johnson X-Patchwork-Id: 12075839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BD3EC433E0 for ; Mon, 8 Feb 2021 15:15:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7E7464F1F for ; Mon, 8 Feb 2021 15:15:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7E7464F1F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oss.nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ou9nISc7598ACGBO2Q4sS5SXLmexgLLvOa5wbMmG6ik=; b=VhdFjOTboAa8i7RB6tkT516Zg R+X2pzJNKU7J9n/fh6JDTZy/Pl7plwsdWZQPUiHVXVmeppmqFmyIvfP0RrxZenJFoAPeQMbfZMubS MwFn5hQsf5s7AuoIJBBMkeugG9IZemAErqFm1cs7WwGJ3TkllotpW0CNuMlkD2t5DQfg2K48YoFyH dsgf77uiV+V25VH5BIv0YE8upja3MM88UdYUCKHCkEhLcp+AagPmPQiBic8588bK1Wy3m6vCJTgwM N00QZ/j8Ny84jBlxg9kBplQR25MDMSQC/CmVkEo4vmk3mj65zwjGFg+nywyqDb5kLj0I3A3eFc7zZ n6KfDcaTA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l98En-0005H4-N2; Mon, 08 Feb 2021 15:14:05 +0000 Received: from mail-db8eur05on2057.outbound.protection.outlook.com ([40.107.20.57] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l98EZ-00058A-Hq for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 15:13:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=huCRt6RRNW96v3gl4gvsLxnvKfEinuMKAUU6EkIuN3jP1NbVO1ELDceD8yPeiKUYNvZCI60b9UvLQP0uEADemcjiHtYulHPeRoGOwfGxWKM1zFQgIMubqbOM14Bzr7vPwtsm2PTdUpkan6aXXWG3/vOagDu8NnGshFCRlaCSQoLGKE64Lq9qU+y+lBjrCmagaq4vf0WxB2A/ClY/rxbIpF5mKHsgiK3THskmUHsYNWpuV7XJAbFwjdhlQx4VEs8Lc/yORflKg6hvWPaSYzd6QwjV+zVKW21QeTd5L+/hhl/678G1Lf1wTYogTvJ3u+QPLe3flfi5fuEKipobhc7XhA== 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=YRvgSQHKAJvU9aFJfRrrx4h4veKkWYBtZnfpXrLrwQ8=; b=CYugh7Kq/wrLhmURdOFZx3p0QQdXBSN4nZOpBevXteD5gqHxcnmMhnDa1aDkoAQDN1Stnrun+2rYkig+73KBFOSP7kuaSzQhuwgMbn2XvwzVz5g2Q7ujaxy9B8D+ovyuz7321GckbRoOL69ADrz1DObIbDTJAa/fSZumTxPxgfRc6PQKx/xO2cF5CVX1GeEBZgqTVCGMBmyKgrHikVEkI4BZFOHbdTvV8gi13ccbBTHV9tYx3S+sQgWY4yTAP4SHVauYE3Eh55W6eaX+IcMyqF91z6zBZj7HLcTuTcL+R4d+NAzrDBmApewF0UZjlc73dDSng7Ae5DfXNHCOReGhaA== 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=YRvgSQHKAJvU9aFJfRrrx4h4veKkWYBtZnfpXrLrwQ8=; b=HSuOAWKQjnbJoV8G474zTb5ZLHykgJcjPVHAruDCO80zmkOoQ7hph6Azf0m07bH/T4jOi/TL8yQagQnhi/bqniw6oLOGnSewKcrGPeKt53w/TtGqs69VbYEnC1ovzjU0znmou173riJrb4+8EmoF6P6ZwPZgGLhpsU2f136DBj8= 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 AM0PR04MB6435.eurprd04.prod.outlook.com (2603:10a6:208:176::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.23; Mon, 8 Feb 2021 15:13:38 +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.3825.030; Mon, 8 Feb 2021 15:13:38 +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 Subject: [net-next PATCH v5 03/15] net: phy: Introduce phy related fwnode functions Date: Mon, 8 Feb 2021 20:42:32 +0530 Message-Id: <20210208151244.16338-4-calvin.johnson@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210208151244.16338-1-calvin.johnson@oss.nxp.com> References: <20210208151244.16338-1-calvin.johnson@oss.nxp.com> X-Originating-IP: [14.142.151.118] X-ClientProxiedBy: SG2PR04CA0176.apcprd04.prod.outlook.com (2603:1096:4:14::14) 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 SG2PR04CA0176.apcprd04.prod.outlook.com (2603:1096:4:14::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.19 via Frontend Transport; Mon, 8 Feb 2021 15:13:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 598d6afb-5e6c-4712-5cb7-08d8cc441c90 X-MS-TrafficTypeDiagnostic: AM0PR04MB6435: 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: Dz/Zh7fZSvwdZCF9ReltYRrT+yuHj5P63wenw63BqmENPiwTHEpxxbvgSf6dSgghYY6xEWbpacBZSuYJs48ltuN8rg+2BSu/Hexqrlfn7ePdm80iYEMpmrMaZLwr++yaiB6ouGxmAEKiTtK8bSqTs62/aNKoqZhjgR+BEzoadUuxwfLOyE4ffuhXtKp8rIKF7Ka8SKwW0tRM6D4Z6aKpTx0Ez6zk4IzhDj4U46vr2LEqbZVEWlUnbeY2gBuUPmY5UoBOPjE9j0BPunnzwDsAdGRvrCgAcHCSZnNbki+cRfBuaHaMv/NR7ip4YXlkkJWoM9WQajOMsDwnu6Z/3oWO1YupIpNSxBfg/YNMlU8qE6csrr95UjG9yhEOmRUc0qtDXn13xcDvnhZTJDQtwZWBr2830BaW7aotUtUWe5BCkHSvHsLayZQG9lx1fLxakZhKq8uuBDzZQiZbXALbPoAUTp9YnqphmZH3h6He9WJdNnmX9f5ZoGL8QRdJ1nW++WJLhLrdDxdW9yfWCv5Cfi2vvjLG2gOCQeWXVm3ltbjOr0A2p48BF+BRuLUzUG8vbhtoeGyWN4JRGQkjHBZUXnwmaH8PM97p1MnPfqglLtQeCkg= 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)(376002)(346002)(396003)(8936002)(54906003)(7416002)(52116002)(110136005)(186003)(16526019)(316002)(55236004)(956004)(6486002)(1006002)(4326008)(2906002)(478600001)(6512007)(1076003)(6506007)(5660300002)(921005)(44832011)(83380400001)(86362001)(66556008)(26005)(2616005)(66476007)(66946007)(8676002)(110426009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: x7AvCnidtJZTOTrk7hv7xr8aFJOO3x5K08yAYdk62m3SfOzhNOP/TUPrU9dO/pLlZ7kXJVTj7CHHGkgNCH6CPe6AdsOgK77tRyjWWZn5cYbcK7jOKaI0gkVXTF6fMIyRKvI9O3iOve69n1wF15AllTZvKpqqPM03QQ1gY+b3aWKIxDxWNHpltTiy7JYpmnBtxHQ/tPhNA4Brk6u50A+PEfTvLjIO56WSuRT5Q//IQgIBpxUWcNvx00SjVW3/iWG5psWdpZ6pQCujYYk2gS+8jH5IqH/H7a8VLLvdr3jFgCKDAKBs3d3mH5D1GmYR6cHTbW904h+QQlFr+RAZK93lcKClqbjAEn17hSt+VC4fVvzVO6+5JEqymyW8A8eUD9XX+usk9nPFh67Na3s/oT1dQjLSfIWzCWtqJSSnr51kF73MxFK4gKtnC4bzq9uYplQWMucr0543UTcmQSI+tglbNlHJ24dvyNP9FVteStMdtfJ8rclfL0eWG9IxUJjAwkSBSPSfOJgjCBSPG5sD5Wgj/9ohON82+h80h1y1q2LdWaI5xuccB2QfIH5v7/WTOUd+BqNV+NibPltgCXd1UBXufrzVegxAD5av6UJV+FE5Cn1csNxjWRAxK+Ro82VrvMZBoTipbBiO7AbjJQD9F0y4hAf3yAp0wr4JSCkGM0Ms13uxFXxSUdzirpLImPJrk6gRosY0POKiuOvj+HnbB0WimUy/FdEQTUM1WXmY8KyICq3rfd3D0iPcIBSqnnJvgc5AWuhbcGafV3E+jWzzEl/yovygTw4xVIL2iGrCILk7cFwcy0mYOoTzFR+D41yxtel1E3Li1s9+loHTNWTnM0vwP347amOHEimlFi4NcnGeTdE9koSmHWwZ+QakE/F0nVKSEjM3YkbKM0+W/do/ZcqQGRT3dsOwf9J5mORtxx003BM/0OFQC8VHpfDYW0PH2xSgmj3va9253nhVEOHt7rl0bIYuxqcgtqacCcP5tr+EUfdoC7dSQjKLWmtBPzlRTDOz7+oU+FKYN71ua3DCwhCBcjhbwsFUCoRi0UEsR3FRwMLfoEU4ohvcHm/4DMjEF7n+Jc6wCyMQour1WtneE6bzotvuawgCQ8uZMzrvHDAQwQPBZnyWPTjyF7Aw45bUo0F8l9KiDB78o0rzwcgvDIkwz66m9kFPDmgAOhv6FND6YRy/NxorVthxrraJy29iSAAeh8cAxzlFJpgbQc/bZuxk3sykPT90/dfz5DhW66Q6JpkK9++uOSSlyx5yCd+6E4Lde1u2hca1entTHIe5ddAT7TdvPl73x3oepg8tsIL0lAoyRMUhrJFa+aLl9R1EDg8d3YWnoO3PVr9nwpOpZs3WJw== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 598d6afb-5e6c-4712-5cb7-08d8cc441c90 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5636.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2021 15:13:38.3989 (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: T3EyRO8O3PVZdLsshk2f1PoOd5v6XfqYOVRfeJp5GFrotO5AgrnDnaAOrV8dUFxZlW6bw6XUFv560tufP2J1/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6435 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_101351_634435_6AB8140E X-CRM114-Status: GOOD ( 20.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Calvin Johnson , Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux.cj@gmail.com, Jakub Kicinski , Heiner Kallweit , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Laurentiu Tudor Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 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 06e0ddcca8c9..66e779cd905a 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 @@ -2852,6 +2853,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 8314051d384a..dee7064ea4eb 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1350,6 +1350,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); @@ -1359,6 +1362,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) {