Lines Matching +full:0 +full:- +full:mdio
1 // SPDX-License-Identifier: GPL-2.0-only
3 * OF helpers for the MDIO (Ethernet PHY) API
29 * ethernet-phy-idAAAA.BBBB */
37 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) { in of_get_phy_id()
38 *phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF); in of_get_phy_id()
39 return 0; in of_get_phy_id()
42 return -EINVAL; in of_get_phy_id()
50 err = of_parse_phandle_with_fixed_args(node, "timestamper", 1, 0, &arg); in of_find_mii_timestamper()
52 if (err == -ENOENT) in of_find_mii_timestamper()
58 return ERR_PTR(-EINVAL); in of_find_mii_timestamper()
60 return register_mii_timestamper(arg.np, arg.args[0]); in of_find_mii_timestamper()
63 int of_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, in of_mdiobus_phy_device_register() argument
68 rc = of_irq_get(child, 0); in of_mdiobus_phy_device_register()
69 if (rc == -EPROBE_DEFER) in of_mdiobus_phy_device_register()
72 if (rc > 0) { in of_mdiobus_phy_device_register()
73 phy->irq = rc; in of_mdiobus_phy_device_register()
74 mdio->irq[addr] = rc; in of_mdiobus_phy_device_register()
76 phy->irq = mdio->irq[addr]; in of_mdiobus_phy_device_register()
79 if (of_property_read_bool(child, "broken-turn-around")) in of_mdiobus_phy_device_register()
80 mdio->phy_ignore_ta_mask |= 1 << addr; in of_mdiobus_phy_device_register()
82 of_property_read_u32(child, "reset-assert-us", in of_mdiobus_phy_device_register()
83 &phy->mdio.reset_assert_delay); in of_mdiobus_phy_device_register()
84 of_property_read_u32(child, "reset-deassert-us", in of_mdiobus_phy_device_register()
85 &phy->mdio.reset_deassert_delay); in of_mdiobus_phy_device_register()
90 phy->mdio.dev.of_node = child; in of_mdiobus_phy_device_register()
91 phy->mdio.dev.fwnode = of_fwnode_handle(child); in of_mdiobus_phy_device_register()
101 dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n", in of_mdiobus_phy_device_register()
103 return 0; in of_mdiobus_phy_device_register()
107 static int of_mdiobus_register_phy(struct mii_bus *mdio, in of_mdiobus_register_phy() argument
121 "ethernet-phy-ieee802.3-c45"); in of_mdiobus_register_phy()
124 phy = phy_device_create(mdio, addr, phy_id, 0, NULL); in of_mdiobus_register_phy()
126 phy = get_phy_device(mdio, addr, is_c45); in of_mdiobus_register_phy()
133 rc = of_mdiobus_phy_device_register(mdio, phy, child, addr); in of_mdiobus_register_phy()
141 /* phy->mii_ts may already be defined by the PHY driver. A in of_mdiobus_register_phy()
146 phy->mii_ts = mii_ts; in of_mdiobus_register_phy()
148 return 0; in of_mdiobus_register_phy()
151 static int of_mdiobus_register_device(struct mii_bus *mdio, in of_mdiobus_register_device() argument
158 mdiodev = mdio_device_create(mdio, addr); in of_mdiobus_register_device()
166 device_set_node(&mdiodev->dev, fwnode); in of_mdiobus_register_device()
171 device_set_node(&mdiodev->dev, NULL); in of_mdiobus_register_device()
177 dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n", in of_mdiobus_register_device()
179 return 0; in of_mdiobus_register_device()
185 * to have a compatible string, so they can be matched to an MDIO
189 { .compatible = "brcm,40nm-ephy" },
199 { .compatible = "moxa,moxart-rtl8201cp", },
205 * o Compatible string of "ethernet-phy-idX.X"
206 * o Compatible string of "ethernet-phy-ieee802.3-c45"
207 * o Compatible string of "ethernet-phy-ieee802.3-c22"
218 if (of_get_phy_id(child, &phy_id) != -EINVAL) in of_mdiobus_child_is_phy()
221 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) in of_mdiobus_child_is_phy()
224 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22")) in of_mdiobus_child_is_phy()
242 * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
243 * @mdio: pointer to mii_bus structure
244 * @np: pointer to device_node of MDIO bus.
245 * @owner: module owning the @mdio object.
250 int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, in __of_mdiobus_register() argument
258 return __mdiobus_register(mdio, owner); in __of_mdiobus_register()
262 return -ENODEV; in __of_mdiobus_register()
266 mdio->phy_mask = ~0; in __of_mdiobus_register()
268 device_set_node(&mdio->dev, of_fwnode_handle(np)); in __of_mdiobus_register()
271 mdio->reset_delay_us = DEFAULT_GPIO_RESET_DELAY; in __of_mdiobus_register()
272 of_property_read_u32(np, "reset-delay-us", &mdio->reset_delay_us); in __of_mdiobus_register()
273 mdio->reset_post_delay_us = 0; in __of_mdiobus_register()
274 of_property_read_u32(np, "reset-post-delay-us", &mdio->reset_post_delay_us); in __of_mdiobus_register()
276 /* Register the MDIO bus */ in __of_mdiobus_register()
277 rc = __mdiobus_register(mdio, owner); in __of_mdiobus_register()
283 addr = of_mdio_parse_addr(&mdio->dev, child); in __of_mdiobus_register()
284 if (addr < 0) { in __of_mdiobus_register()
290 rc = of_mdiobus_register_phy(mdio, child, addr); in __of_mdiobus_register()
292 rc = of_mdiobus_register_device(mdio, child, addr); in __of_mdiobus_register()
294 if (rc == -ENODEV) in __of_mdiobus_register()
295 dev_err(&mdio->dev, in __of_mdiobus_register()
296 "MDIO device at address %d is missing.\n", in __of_mdiobus_register()
303 return 0; in __of_mdiobus_register()
311 for (addr = 0; addr < PHY_MAX_ADDR; addr++) { in __of_mdiobus_register()
313 if (mdiobus_is_registered_device(mdio, addr)) in __of_mdiobus_register()
317 dev_info(&mdio->dev, "scan phy %pOFn at address %i\n", in __of_mdiobus_register()
321 /* -ENODEV is the return code that PHYLIB has in __of_mdiobus_register()
325 rc = of_mdiobus_register_phy(mdio, child, addr); in __of_mdiobus_register()
328 if (rc != -ENODEV) in __of_mdiobus_register()
334 return 0; in __of_mdiobus_register()
338 mdiobus_unregister(mdio); in __of_mdiobus_register()
344 * of_mdio_find_device - Given a device tree node, find the mdio_device
367 * of_phy_find_device - Give a PHY node, find the phy_device
381 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in of_phy_find_device()
382 return to_phy_device(&mdiodev->dev); in of_phy_find_device()
384 put_device(&mdiodev->dev); in of_phy_find_device()
391 * of_phy_connect - Connect to the phy described in the device tree
413 phy->dev_flags |= flags; in of_phy_connect()
418 put_device(&phy->mdio.dev); in of_phy_connect()
426 * - Get phy node and connect to the phy described in the device tree
449 if (ret < 0) { in of_phy_get_and_connect()
450 netdev_err(dev, "broken fixed-link specification\n"); in of_phy_get_and_connect()
455 phy_np = of_parse_phandle(np, "phy-handle", 0); in of_phy_get_and_connect()
460 phy = of_phy_connect(dev, phy_np, hndlr, 0, iface); in of_phy_get_and_connect()
469 * of_phy_attach - Attach to a PHY without starting the state machine
492 put_device(&phy->mdio.dev); in of_phy_attach()
501 * - the old DT binding, where 'fixed-link' was a property with 5
503 * - the new DT binding, where 'fixed-link' is a sub-node of the
513 dn = of_get_child_by_name(np, "fixed-link"); in of_phy_is_fixed_link()
520 if (err == 0 && strcmp(managed, "auto") != 0) in of_phy_is_fixed_link()
524 if (of_get_property(np, "fixed-link", &len) && in of_phy_is_fixed_link()
539 if (of_property_read_string(np, "managed", &managed) == 0 && in of_phy_register_fixed_link()
540 strcmp(managed, "in-band-status") == 0) { in of_phy_register_fixed_link()
546 fixed_link_node = of_get_child_by_name(np, "fixed-link"); in of_phy_register_fixed_link()
550 "full-duplex"); in of_phy_register_fixed_link()
554 return -EINVAL; in of_phy_register_fixed_link()
558 "asym-pause"); in of_phy_register_fixed_link()
565 if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, in of_phy_register_fixed_link()
566 ARRAY_SIZE(fixed_link_prop)) == 0) { in of_phy_register_fixed_link()
575 return -ENODEV; in of_phy_register_fixed_link()
592 put_device(&phydev->mdio.dev); /* of_phy_find_device() */ in of_phy_deregister_fixed_link()