From patchwork Thu Mar 11 06:19:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Johnson X-Patchwork-Id: 12130359 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.0 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=unavailable 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 ABACCC433E0 for ; Thu, 11 Mar 2021 06:23:43 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 6D67064D9E for ; Thu, 11 Mar 2021 06:23:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D67064D9E 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BCOSxSlOzL/JPjLcTSIkk72Vhkaqu32FrLFk8ol7HxM=; b=PKGId/exC4CbzofUaw8piiJnv DwvRdSqXDfY8xosg6tJD78Kir3QBALbHU46ACrK8W4OimP+f96myzx6zyCRbnJq+/qD2Xs7KF65Wn W+rIJGd4/gaLwyytFaX7DLXX/lfUC9fDzYKMdBQ/nYmfTAo7NVEIsPalEAPPpQbfURN4il5HfSVE8 A7pFPUGSqbOaIx9E6R/KOMvenia2M8F10jqmKWqTtlBHx/BLui+3WHOJ7Q9vP8j3zxy3QVIBy+M22 tqbL+caoa6xbcU34w3qHc2JykrPFm0KYCOaMj0CvItn6NOjdQYtFmZ5j5wtkpnEJQ+ZJNJxxXePBw WAqi/+10w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lKEhN-008SOh-Rk; Thu, 11 Mar 2021 06:21:30 +0000 Received: from mail-db8eur05on2077.outbound.protection.outlook.com ([40.107.20.77] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lKEh6-008SLN-DS for linux-arm-kernel@lists.infradead.org; Thu, 11 Mar 2021 06:21:14 +0000 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> 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: 6slTvZb6krx/5RrFzdiiPnkwGXLieDRoUZuLUYRciKp5PiOKAKPAvgZdph2qtMG8NmF2Q5JxW+5Ry1jf8gnB3HbdopiZmUwGdGtQ6BRO8rpBBGEZVf+tHWonkQ8uqQq47Vcd1gxm3ufqKftX34NAW8tdHESL3amzO1MLppQG9G4SCHnUgTOPU3x/qbLTqmkVFGmFp/QtyXcrlpm3lctBk5XcUb04GjeJJQ8iRTu6lvMUGXYGtCPGPzKweK58POUo+U/RPtKvh3jgOp0nNRJ3xz10rr5L6juo64muCq7ntKS7AdgMbQTjZY+tz78jgC50h2muNBLDvW2tPLxv2bli8kTvCzI9mJI6zFYlY0qJWQe2A1dS6YS4RDuT3nt6b8nmOqzBbAVxOVN4KnzjJK6gV0GiTVzkLqyd0evbyTTn84JJvcHw5iKx3uVIYJOdQWTHn7LFI1VJwACNL94n5N1ZayRPP60pC0bdpvtD3GTKrdop8XfHS7N/KVNeDJXXDoxETbo4Jsr9NQIqgTUWg+PzcorYrqjxN1Dv5ziHwROprxXCiLnvIhJg8AZ4/dorkH33jvp/cky3lpeKq5F1KHGvRjYZd7dyanmG6Z9HnEHgqihAPb0GgsrTYtDZwzLN9uhAatizGVyA/PQH1CaxnRWSIWrDffy8ELHmRp7WfxoggJtdk/qVMAiio3TN8MXzzdmvMu57MyhB4YV3nUkJdKXtZEl9Z8JFNWvtsnkM2LX/FLo4vpMHd8kZB6jHMoNAi+8aiBvO6ZgRSczB/JBG8BaTp88MeJYYDH5AREwshdva3Y3PYwpwhvqwLDD2znIMtGcENYPp8H0JDDrIhp4oZP7aDftwHxujGq9aleag3ckPz/RP2yvviQuVhR4970tcd/MqOsnt7FslSh8FCsurNI6Fw6577cfvkEospdRVy4GrS0HoM75/tbRZ/7hMc/L8fDuq9do+Jl7hOHWnNkVpILeSDiH30aIC5pKor1gOz0+718bCej1PwD7ojKql8fNSTMGPAl7ACA+RbiersL9V/2KlQHxAVClrDb2zcBXLRCjdIQ4m/vp2hI5k/NEVxpc2qlTQeL/z2f7RwxuNLDKVyh/11jLIS3SMNxsXje/06e7YoWPk3LYJ64DGkmgdpUDMoXfUvhauNkorjL2JlYRBpA03zcPwBdhFCCoeqZ4JunUVfbFvo5//ZGzrDCQLfU80wyyMDfGu9y2O7m6mS+yVokAgafD7fbcE7SF9LvpWjjTuZRhLlHx0Sjl5q+wZLrhu3ZWlpNyrXBJyJkbDV4dng8quub0sh5ajFlZVi+z5KULSgBZlRr4IFTTcTbj0Ej4gN3IN 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210311_062112_498415_2EF7AB85 X-CRM114-Status: GOOD ( 18.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 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) {