1 // SPDX-License-Identifier: GPL-2.0+
9 #include <dm/device-internal.h>
10 #include <dm/uclass-internal.h>
13 struct eth_phy_device_priv {
14 struct mii_dev *mdio_bus;
17 int eth_phy_binds_nodes(struct udevice *eth_dev)
19 ofnode mdio_node, phy_node;
20 const char *node_name;
23 mdio_node = dev_read_subnode(eth_dev, "mdio");
24 if (!ofnode_valid(mdio_node)) {
25 debug("%s: %s mdio subnode not found!", __func__,
30 ofnode_for_each_subnode(phy_node, mdio_node) {
31 node_name = ofnode_get_name(phy_node);
33 debug("* Found child node: '%s'\n", node_name);
35 ret = device_bind_driver_to_node(eth_dev,
36 "eth_phy_generic_drv",
37 node_name, phy_node, NULL);
39 debug(" - Eth phy binding error: %d\n", ret);
43 debug(" - bound phy device: '%s'\n", node_name);
49 int eth_phy_set_mdio_bus(struct udevice *eth_dev, struct mii_dev *mdio_bus)
52 struct eth_phy_device_priv *uc_priv;
54 for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev;
55 uclass_next_device(&dev)) {
56 if (dev->parent == eth_dev) {
57 uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(dev));
59 if (!uc_priv->mdio_bus)
60 uc_priv->mdio_bus = mdio_bus;
67 struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev)
70 struct udevice *phy_dev;
71 struct eth_phy_device_priv *uc_priv;
73 /* Will probe the parent of phy device, then phy device */
74 ret = uclass_get_device_by_phandle(UCLASS_ETH_PHY, eth_dev,
75 "phy-handle", &phy_dev);
77 if (eth_dev != phy_dev->parent) {
79 * phy_dev is shared and controlled by
80 * other eth controller
82 uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(phy_dev));
83 if (uc_priv->mdio_bus)
84 printf("Get shared mii bus on %s\n", eth_dev->name);
86 printf("Can't get shared mii bus on %s\n", eth_dev->name);
88 return uc_priv->mdio_bus;
91 printf("FEC: can't find phy-handle\n");
97 int eth_phy_get_addr(struct udevice *dev)
99 struct ofnode_phandle_args phandle_args;
102 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
104 debug("Failed to find phy-handle");
108 reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
113 UCLASS_DRIVER(eth_phy_generic) = {
114 .id = UCLASS_ETH_PHY,
115 .name = "eth_phy_generic",
116 .per_device_auto = sizeof(struct eth_phy_device_priv),
119 U_BOOT_DRIVER(eth_phy_generic_drv) = {
120 .name = "eth_phy_generic_drv",
121 .id = UCLASS_ETH_PHY,