Messages in this thread Patch in this message |  | | From | Calvin Johnson <> | Subject | [PATCH v1 6/7] net: phylink: Introduce phylink_fwnode_phy_connect() | Date | Fri, 31 Jan 2020 21:04:39 +0530 |
| |
From: Calvin Johnson <calvin.johnson@oss.nxp.com>
Introduce phylink_fwnode_phy_connect API to connect the PHY using fwnode.
Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> ---
drivers/net/phy/phylink.c | 64 +++++++++++++++++++++++++++++++++++++++ include/linux/phylink.h | 2 ++ 2 files changed, 66 insertions(+)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index ee7a718662c6..f211f62283b5 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -18,6 +18,7 @@ #include <linux/spinlock.h> #include <linux/timer.h> #include <linux/workqueue.h> +#include <linux/acpi.h> #include "sfp.h" #include "swphy.h" @@ -817,6 +818,69 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy) } EXPORT_SYMBOL_GPL(phylink_connect_phy); +/** + * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode. + * @pl: a pointer to a &struct phylink returned from phylink_create() + * @dn: a pointer to a &struct device_node. + * @flags: PHY-specific flags to communicate to the PHY device driver + * + * Connect the phy specified in the device node @dn to the phylink instance + * specified by @pl. Actions specified in phylink_connect_phy() will be + * performed. + * + * Returns 0 on success or a negative errno. + */ +int phylink_fwnode_phy_connect(struct phylink *pl, + struct fwnode_handle *fwnode, + u32 flags) +{ + struct fwnode_handle *phy_node; + struct phy_device *phy_dev; + int ret; + int status; + struct fwnode_reference_args args; + + /* Fixed links and 802.3z are handled without needing a PHY */ + if (pl->link_an_mode == MLO_AN_FIXED || + (pl->link_an_mode == MLO_AN_INBAND && + phy_interface_mode_is_8023z(pl->link_interface))) + return 0; + + status = acpi_node_get_property_reference(fwnode, "phy-handle", 0, + &args); + if (ACPI_FAILURE(status) || !is_acpi_device_node(args.fwnode)) + status = acpi_node_get_property_reference(fwnode, "phy", 0, + &args); + if (ACPI_FAILURE(status) || !is_acpi_device_node(args.fwnode)) + status = acpi_node_get_property_reference(fwnode, + "phy-device", 0, + &args); + + if (ACPI_FAILURE(status) || !is_acpi_device_node(args.fwnode)) { + if (pl->link_an_mode == MLO_AN_PHY) + return -ENODEV; + return 0; + } + + phy_dev = fwnode_phy_find_device(args.fwnode); + if (phy_dev) + phy_attach_direct(pl->netdev, phy_dev, flags, + pl->link_interface); + + /* refcount is held by phy_attach_direct() on success */ + put_device(&phy_dev->mdio.dev); + + if (!phy_dev) + return -ENODEV; + + ret = phylink_bringup_phy(pl, phy_dev); + if (ret) + phy_detach(phy_dev); + + return ret; +} +EXPORT_SYMBOL_GPL(phylink_fwnode_phy_connect); + /** * phylink_of_phy_connect() - connect the PHY specified in the DT mode. * @pl: a pointer to a &struct phylink returned from phylink_create() diff --git a/include/linux/phylink.h b/include/linux/phylink.h index fed5488e3c75..cb07cf7a832e 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -240,6 +240,8 @@ void phylink_destroy(struct phylink *); int phylink_connect_phy(struct phylink *, struct phy_device *); int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); +int phylink_fwnode_phy_connect(struct phylink *pl, struct fwnode_handle *fwnode, + u32 flags); void phylink_disconnect_phy(struct phylink *); int phylink_fixed_state_cb(struct phylink *, void (*cb)(struct net_device *dev, -- 2.17.1
|  |