Messages in this thread Patch in this message |  | | From | Calvin Johnson <> | Subject | [PATCH v1 7/7] dpaa2-eth: Add ACPI support for DPAA2 MAC driver | Date | Fri, 31 Jan 2020 21:04:40 +0530 |
| |
From: Calvin Johnson <calvin.johnson@oss.nxp.com>
fwnode APIs are used to handle both DT and ACPI nodes. Whereever common fwnode APIs cannot be used, corresponding DT and ACPI APIs are used.
Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
---
.../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 78 ++++++++++++------- 1 file changed, 50 insertions(+), 28 deletions(-)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c index 84233e467ed1..29d2d85383de 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c @@ -3,6 +3,7 @@ #include "dpaa2-eth.h" #include "dpaa2-mac.h" +#include <linux/acpi.h> #define phylink_to_dpaa2_mac(config) \ container_of((config), struct dpaa2_mac, phylink_config) @@ -23,37 +24,51 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode) } /* 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; + struct fwnode_handle *dpmac_fwnode; + struct fwnode_handle *dpmacs, *dpmac = NULL; u32 id; int err; - dpmacs = of_find_node_by_name(NULL, "dpmacs"); - if (!dpmacs) - return NULL; + if (is_of_node(dev->parent->fwnode)) { + dpmacs = device_get_named_child_node(dev->parent, "dpmacs"); + if (!dpmacs) + return NULL; + + while ((dpmac = fwnode_get_next_child_node(dpmacs, dpmac))) { + err = fwnode_property_read_u32(dpmac, "reg", &id); + if (err) + continue; + if (id == dpmac_id) + return dpmac; + } - while ((dpmac = of_get_next_child(dpmacs, dpmac)) != NULL) { - err = of_property_read_u32(dpmac, "reg", &id); - if (err) - continue; - if (id == dpmac_id) - break; + } else if (is_acpi_node(dev->parent->fwnode)) { + device_for_each_child_node(dev->parent, dpmac_fwnode) { + err = fwnode_property_read_u32(dpmac_fwnode, "reg", + &id); + if (err) { + dev_err(dev->parent, "failed to get reg\n"); + continue; + } else { + if (id == dpmac_id) + return dpmac_fwnode; + } + } } - - 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_fwnode, struct dpmac_attr attr) { phy_interface_t if_mode; int err; - err = of_get_phy_mode(node, &if_mode); - if (!err) + err = fwnode_get_phy_mode(dpmac_fwnode, &if_mode); + if (err > 0) return if_mode; err = phy_mode(attr.eth_if, &if_mode); @@ -220,7 +235,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) { struct fsl_mc_device *dpmac_dev = mac->mc_dev; struct net_device *net_dev = mac->net_dev; - struct device_node *dpmac_node; + struct fwnode_handle *dpmac_fwnode = NULL; struct phylink *phylink; struct dpmac_attr attr; int err; @@ -238,25 +253,26 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) goto err_close_dpmac; } - dpmac_node = dpaa2_mac_get_node(attr.id); - if (!dpmac_node) { + dpmac_fwnode = dpaa2_mac_get_node(&mac->mc_dev->dev, attr.id); + if (!dpmac_fwnode) { netdev_err(net_dev, "No dpmac@%d node found.\n", attr.id); err = -ENODEV; goto err_close_dpmac; } - err = dpaa2_mac_get_if_mode(dpmac_node, attr); + err = dpaa2_mac_get_if_mode(dpmac_fwnode, attr); if (err < 0) { err = -EINVAL; goto err_put_node; } + mac->if_mode = err; /* The MAC does not have the capability to add RGMII delays so * 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 (fwnode_phy_is_fixed_link(dpmac_fwnode) && (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) { @@ -269,7 +285,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_fwnode, mac->if_mode, &dpaa2_mac_phylink_ops); if (IS_ERR(phylink)) { err = PTR_ERR(phylink); @@ -277,20 +293,26 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) } mac->phylink = phylink; - err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0); + if (is_of_node(dpmac_fwnode)) + err = phylink_of_phy_connect(mac->phylink, + to_of_node(dpmac_fwnode), 0); + else if (is_acpi_node(dpmac_fwnode)) + err = phylink_fwnode_phy_connect(mac->phylink, dpmac_fwnode, 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); + if (is_of_node(dpmac_fwnode)) + of_node_put(to_of_node(dpmac_fwnode)); return 0; err_phylink_destroy: phylink_destroy(mac->phylink); err_put_node: - of_node_put(dpmac_node); + if (is_of_node(dpmac_fwnode)) + of_node_put(to_of_node(dpmac_fwnode)); err_close_dpmac: dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle); return err; -- 2.17.1
|  |