From patchwork Thu Mar 11 06:20:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Johnson X-Patchwork-Id: 12130407 X-Patchwork-Delegate: kuba@kernel.org 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=-16.7 required=3.0 tests=BAYES_00,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 CAC24C433E6 for ; Thu, 11 Mar 2021 06:24:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4E8764FD2 for ; Thu, 11 Mar 2021 06:24:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbhCKGXo (ORCPT ); Thu, 11 Mar 2021 01:23:44 -0500 Received: from mail-eopbgr20089.outbound.protection.outlook.com ([40.107.2.89]:57088 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229958AbhCKGXL (ORCPT ); Thu, 11 Mar 2021 01:23:11 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dvrpa0KoSFW6w7li76k7BOgmDOpcvs0Xhd2HGA2CcC+VEGfcS9HjZ0lbBsgePtnMizIXmmzgvkhhok08DoF0+rUE7DCdlLyoaMhhOlEH413domAGu525PX/01UIt2tl3RVrGxE3lD8hez8UYuKQs5aOsPNM7EWlE7wUJz9bGXZw5JHctz3PqJN8ClD4+t5AwolENxKKteeyyRcRewiNrKSn92w5/yuFtWP2Yp54cl/QycXN9gwSmj8YHxNYTodhgU3DalQ4Y3c4PBziGJgjnX8XZCy83U2OPIVyl2ZNZuJbspLiZykONbnlwi9ankC5HRtVgiL9VDdePnc7qe0Invw== 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=5BB8oRWGf6ebgOGGFaRhtiriNkAtzWGJ/AKVABejizU=; b=oYSE+zC5MJpPsPfj9V+vWYBhJlnShXTif49XKXWd6/xIR/Keg3QsjcawyKz+0ZhqtslE7Lqyt+zlMypz6jFcSUnqEWDykl5dUazvqpRIC5LOW/X8NRmuzV+ei0yIpORQPGU4QgaOafnvz4SUb0hnoLhobhAbM3a+JLkpme9sGRghZGxTgjbujw4mC/LRmLhz3H38r/UY0yrKzkUqtb4rhp+6dIKnBCpyNsMhxEm2MRD0Dtfwz7iY54A6tYPMe+63GUkMbCWqcOmwvSF1BoI7DYJeEX33CNbdN6es4T4D4pa4sbduvRZY8vH+GAc5oZSIH1fbVa9CcqjwyZvhvMdQGQ== 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=5BB8oRWGf6ebgOGGFaRhtiriNkAtzWGJ/AKVABejizU=; b=UZVo1kVk0iE0NRA2EBKjooN9AE8FfK4FQY29aTe+1JahtYDi2GihHOyUdlBpafZWjMqvNDF65T/oxT4x7lUTuM7mxCQtfJyUhhTwmQX7B61OPaRZ0D0Q1OG6MsaQu2PbrNifxSw7SAouc6gB+TG8YdI8ZYZuQUMQxDt8pRVCbF4= 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 AM0PR04MB6611.eurprd04.prod.outlook.com (2603:10a6:208:176::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Thu, 11 Mar 2021 06:23:08 +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:23:07 +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" , Ioana Radulescu , Jakub Kicinski Subject: [net-next PATCH v7 16/16] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver Date: Thu, 11 Mar 2021 11:50:11 +0530 Message-Id: <20210311062011.8054-17-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:22:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4065a34b-ffab-4422-549e-08d8e4562296 X-MS-TrafficTypeDiagnostic: AM0PR04MB6611: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:972; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tIWaEuJiSpryl1R8owVZuSCEZ+Bo1sfSktp8WBYLjre1bLaGFOT6GpjLmgVlc40dG8tbsCAVcPpn7ivUlN1BqRBx0d0QamrJx3ptiXQtJ63dT8E6WDZUTOZsf17IQJIDbkoS7jl5S3CuPVrW/QQSUYQiognQlXvX9tP2w0nLAddtFs3/axnmTELJLwxYzrgoA1ylWHCWBA6CPHbAL34C22rCjW2dgPJTBD9aF60MLqYLdbQSGo+FO1dKUIm6VOTAua02ErlR8N27tUijLF2h/zqvmWMllWcHEZts7kEtdWXpmyy7lTCpEaHHB86M1Wjxs+8NHSB9BWuIL7hbIkiGGmD7Hp5X0gQMbnOaeA9x0vwA+9Q/3YYW+x+Iw0yycyJQRfHFbNNOuvObqclnyuQYXUqmkaJPDO7mZYxRQjoRDc7KIaKyEeJp/mzquMYN/0KukTY/OrIBingFLUjF/PJi4wTcl4wzgwCw8EbqS8+WqT4sOa7Znw8s/3D1xSaCV7mHlSEMeewY+8unA9K9dfX8wPSw5Aay85Z87YwlrB1LT2V57nJglF9sopxeSGPXT+271mlxr+HlFlyMq84Azwe1fqObVQnpEhKhiMz8ck6iH6M= 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)(136003)(39860400002)(396003)(376002)(366004)(346002)(2906002)(921005)(16526019)(26005)(186003)(83380400001)(6486002)(8936002)(6506007)(66556008)(66946007)(55236004)(66476007)(44832011)(478600001)(6512007)(2616005)(316002)(54906003)(5660300002)(956004)(1006002)(52116002)(8676002)(6666004)(110136005)(86362001)(4326008)(7416002)(1076003)(110426009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: eI9HjoISiipJ4UtKVIsNtJ+qxC1vVGAXs4trxgKQov3/dyf2/2ZimDLHDLZcUoHdnFgJiXvizHEEww53rhBypq5ErO0QQYvi7flSQE3BzWmxGTv6ubyaFr7xa7rFpfdFOllNTWMNwHiLomGoRuZxA2AbN837J8JeOBeKaZSRpoCVre195BNMnZ0We3ioM6wm3eTZHgxz46GeMrRE5VHLZP6QneauQEJdYb7GlXmW0grdEfRsVO6xfu640aIedyCOv0IpZk94wPy0TLUHnz9Sd1iujC9l0IDFWVLb0YPC1H8rorfLzsWas9jvkJXNM48XIh6bCdnJdKhZo/HDBQD2f9+UDwBOcD7RrEr7jjdW1tqdrdfr1AyMCyBbSNCQeFkkE3+EpSMKNVabZF3OuwB2aRRH3F/im/GcC0OZ1BP5fPS11mpxc/d+69an9DH5k8EcO23CynvFcjuJbOqwLqxVzjk0TfqzN/JVyG/n6J7u+WWiBpDKPJtXflsfiAGL4IfoEbAWlTM2oSL/lNFpMFjfrTFhYs+5yUeLj/dzROWP7jABzBjeoR2knFQe0A6LvZOvSVVklrYCxjAphWU9XujJZdCu+6M5Q9UASj5/YxfwRo5j0hbj3Xh9VuWvE1866WiZoJja466ZJorRhgOKntTjh/EPKZTcZkIP9whDZJ/HOjhEQAeg1BbW/JN3OayXsP6yfXZEuahpUnZJgE7ISszRVBiP89EkmJKKUGbM+x59dGu8D958Jc0eGFnfuOabCa8ULydgp12wTe7SEPLlf5WAJwi3OMI//ywQGFjSrRBZEcR7o55KfU5AGtq0ktuVWLVm3n50Cqvy02EUGgfDKbTucA93bBwNYY/7Y8l6hrmG1h6WZ8OEQmHOe/prdz+NNmhrP7ZyGpt+ImtJOnnr/y7R46zp3qCYkh7m9p31Zux41UCyQFe2iAU6EzE1dGhRYyYx9wrwtbL0fvPA5/Ka5x9rE243/AkZc5XRQdFTbxZsxE1/yF1eVPT4vjCjHw8HfztVIbXk7D8a2wGZXT7heojAUQDxYP4YFucHLS1PvgOsVon7iVUnqjlrYYzgWCAVLtQ92VxdENvdb0w4ixxqqp3k+pAP/lgEJjgavyVSkxTsSu8lttSAIqkJaYKw2FuiYUSjoEF9LyCWtkXSfJ4l5o04eMHyHsbl4V1mDarmRqIxLzuzKgHHaAbWWCUoELIF1tD4LZiw0yvgZx4Ms7vPUQHGgYx3oBm+44p6mgNb2soIcA/vcsimSm54SzZUZL1jaIufhjse7/TXy0Uxz0obeXFZj+HORvLzfUbLAs4hoO4OZDgo4eb+0P+F3CBznWCme9U9 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4065a34b-ffab-4422-549e-08d8e4562296 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:23:07.3132 (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: znQaxha961y8FALA7XDjIznOQuZaaXTdT8HOAPHA85wcZQ78jlbf1HAqm+A+5cO8Kod63q4XjFxEqBQzlmN3IA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6611 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Modify dpaa2_mac_get_node() to get the dpmac fwnode from either DT or ACPI. Modify dpaa2_mac_get_if_mode() to get interface mode from dpmac_node which is a fwnode. Modify dpaa2_pcs_create() to create pcs from dpmac_node fwnode. Modify dpaa2_mac_connect() to support ACPI along with DT. Signed-off-by: Calvin Johnson --- Changes in v7: - remove unnecassary checks Changes in v6: - use dev_fwnode() - remove useless else - replace of_device_is_available() to fwnode_device_is_available() Changes in v5: - replace fwnode_get_id() with OF and ACPI function calls Changes in v4: None Changes in v3: None Changes in v2: - Refactor OF functions to use fwnode functions .../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 84 +++++++++++-------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c index ccaf7e35abeb..0cb6760dce88 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) /* Copyright 2019 NXP */ +#include +#include + #include "dpaa2-eth.h" #include "dpaa2-mac.h" @@ -34,39 +37,51 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode) return 0; } -/* Caller must call of_node_put on the returned value */ -static struct device_node *dpaa2_mac_get_node(u16 dpmac_id) +static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev, + u16 dpmac_id) { - struct device_node *dpmacs, *dpmac = NULL; - u32 id; + struct fwnode_handle *fwnode, *parent, *child = NULL; + struct device_node *dpmacs = NULL; int err; + u32 id; - dpmacs = of_find_node_by_name(NULL, "dpmacs"); - if (!dpmacs) - return NULL; + fwnode = dev_fwnode(dev->parent); + if (is_of_node(fwnode)) { + dpmacs = of_find_node_by_name(NULL, "dpmacs"); + if (!dpmacs) + return NULL; + parent = of_fwnode_handle(dpmacs); + } else if (is_acpi_node(fwnode)) { + parent = fwnode; + } - while ((dpmac = of_get_next_child(dpmacs, dpmac)) != NULL) { - err = of_property_read_u32(dpmac, "reg", &id); + fwnode_for_each_child_node(parent, child) { + err = -EINVAL; + if (is_acpi_device_node(child)) + err = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &id); + else if (is_of_node(child)) + err = of_property_read_u32(to_of_node(child), "reg", &id); if (err) continue; - if (id == dpmac_id) - break; - } + if (id == dpmac_id) { + of_node_put(dpmacs); + return child; + } + } of_node_put(dpmacs); - - return dpmac; + return NULL; } -static int dpaa2_mac_get_if_mode(struct device_node *node, +static int dpaa2_mac_get_if_mode(struct fwnode_handle *dpmac_node, struct dpmac_attr attr) { phy_interface_t if_mode; int err; - err = of_get_phy_mode(node, &if_mode); - if (!err) - return if_mode; + err = fwnode_get_phy_mode(dpmac_node); + if (err > 0) + return err; err = phy_mode(attr.eth_if, &if_mode); if (!err) @@ -235,26 +250,27 @@ static const struct phylink_mac_ops dpaa2_mac_phylink_ops = { }; static int dpaa2_pcs_create(struct dpaa2_mac *mac, - struct device_node *dpmac_node, int id) + struct fwnode_handle *dpmac_node, + int id) { struct mdio_device *mdiodev; - struct device_node *node; + struct fwnode_handle *node; - node = of_parse_phandle(dpmac_node, "pcs-handle", 0); - if (!node) { + node = fwnode_find_reference(dpmac_node, "pcs-handle", 0); + if (IS_ERR(node)) { /* do not error out on old DTS files */ netdev_warn(mac->net_dev, "pcs-handle node not found\n"); return 0; } - if (!of_device_is_available(node)) { + if (!fwnode_device_is_available(node)) { netdev_err(mac->net_dev, "pcs-handle node not available\n"); - of_node_put(node); + fwnode_handle_put(node); return -ENODEV; } - mdiodev = of_mdio_find_device(node); - of_node_put(node); + mdiodev = fwnode_mdio_find_device(node); + fwnode_handle_put(node); if (!mdiodev) return -EPROBE_DEFER; @@ -283,13 +299,13 @@ static void dpaa2_pcs_destroy(struct dpaa2_mac *mac) int dpaa2_mac_connect(struct dpaa2_mac *mac) { struct net_device *net_dev = mac->net_dev; - struct device_node *dpmac_node; + struct fwnode_handle *dpmac_node = NULL; struct phylink *phylink; int err; mac->if_link_type = mac->attr.link_type; - dpmac_node = dpaa2_mac_get_node(mac->attr.id); + dpmac_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id); if (!dpmac_node) { netdev_err(net_dev, "No dpmac@%d node found.\n", mac->attr.id); return -ENODEV; @@ -306,7 +322,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) * error out if the interface mode requests them and there is no PHY * to act upon them */ - if (of_phy_is_fixed_link(dpmac_node) && + if (of_phy_is_fixed_link(to_of_node(dpmac_node)) && (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) { @@ -327,7 +343,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) mac->phylink_config.type = PHYLINK_NETDEV; phylink = phylink_create(&mac->phylink_config, - of_fwnode_handle(dpmac_node), mac->if_mode, + dpmac_node, mac->if_mode, &dpaa2_mac_phylink_ops); if (IS_ERR(phylink)) { err = PTR_ERR(phylink); @@ -338,13 +354,13 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) if (mac->pcs) phylink_set_pcs(mac->phylink, &mac->pcs->pcs); - err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0); + err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0); if (err) { - netdev_err(net_dev, "phylink_of_phy_connect() = %d\n", err); + netdev_err(net_dev, "phylink_fwnode_phy_connect() = %d\n", err); goto err_phylink_destroy; } - of_node_put(dpmac_node); + fwnode_handle_put(dpmac_node); return 0; @@ -353,7 +369,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) err_pcs_destroy: dpaa2_pcs_destroy(mac); err_put_node: - of_node_put(dpmac_node); + fwnode_handle_put(dpmac_node); return err; }