Lines Matching +full:phy +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-only
3 * OF helpers for the MDIO (Ethernet PHY) API
7 * This file provides helper functions for extracting PHY device information
8 * out of the OpenFirmware device tree and using it to populate an mii_bus.
11 #include <linux/device.h>
21 #include <linux/phy.h>
28 MODULE_DESCRIPTION("OpenFirmware MDIO bus (Ethernet PHY) accessors");
30 /* Extract the clause 22 phy ID from the compatible string of the form
31 * ethernet-phy-idAAAA.BBBB */
32 static int of_get_phy_id(struct device_node *device, u32 *phy_id) in of_get_phy_id() argument
34 return fwnode_get_phy_id(of_fwnode_handle(device), phy_id); in of_get_phy_id()
37 int of_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, in of_mdiobus_phy_device_register() argument
40 return fwnode_mdiobus_phy_device_register(mdio, phy, in of_mdiobus_phy_device_register()
63 /* Associate the OF node with the device structure so it in of_mdiobus_register_device()
67 device_set_node(&mdiodev->dev, fwnode); in of_mdiobus_register_device()
72 device_set_node(&mdiodev->dev, NULL); in of_mdiobus_register_device()
78 dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n", in of_mdiobus_register_device()
83 /* The following is a list of PHY compatible strings which appear in
84 * some DTBs. The compatible string is never matched against a PHY
90 { .compatible = "brcm,40nm-ephy" },
100 { .compatible = "moxa,moxart-rtl8201cp", },
105 * Return true if the child node is for a phy. It must either:
106 * o Compatible string of "ethernet-phy-idX.X"
107 * o Compatible string of "ethernet-phy-ieee802.3-c45"
108 * o Compatible string of "ethernet-phy-ieee802.3-c22"
112 * A device which is not a phy is expected to have a compatible string
113 * indicating what sort of device it is.
119 if (of_get_phy_id(child, &phy_id) != -EINVAL) in of_mdiobus_child_is_phy()
122 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) in of_mdiobus_child_is_phy()
125 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22")) in of_mdiobus_child_is_phy()
148 /* Loop over the child nodes and register a phy_device for each phy */ in __of_mdiobus_parse_phys()
150 if (of_node_name_eq(child, "ethernet-phy-package")) { in __of_mdiobus_parse_phys()
151 /* Ignore invalid ethernet-phy-package node */ in __of_mdiobus_parse_phys()
156 if (rc && rc != -ENODEV) in __of_mdiobus_parse_phys()
162 addr = of_mdio_parse_addr(&mdio->dev, child); in __of_mdiobus_parse_phys()
164 /* Skip scanning for invalid ethernet-phy-package node */ in __of_mdiobus_parse_phys()
175 if (rc == -ENODEV) in __of_mdiobus_parse_phys()
176 dev_err(&mdio->dev, in __of_mdiobus_parse_phys()
177 "MDIO device at address %d is missing.\n", in __of_mdiobus_parse_phys()
190 * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
210 return -ENODEV; in __of_mdiobus_register()
213 * the device tree are populated after the bus has been registered */ in __of_mdiobus_register()
214 mdio->phy_mask = ~0; in __of_mdiobus_register()
216 device_set_node(&mdio->dev, of_fwnode_handle(np)); in __of_mdiobus_register()
218 /* Get bus level PHY reset GPIO details */ in __of_mdiobus_register()
219 mdio->reset_delay_us = DEFAULT_GPIO_RESET_DELAY; in __of_mdiobus_register()
220 of_property_read_u32(np, "reset-delay-us", &mdio->reset_delay_us); in __of_mdiobus_register()
221 mdio->reset_post_delay_us = 0; in __of_mdiobus_register()
222 of_property_read_u32(np, "reset-post-delay-us", &mdio->reset_post_delay_us); in __of_mdiobus_register()
229 /* Loop over the child nodes and register a phy_device for each phy */ in __of_mdiobus_register()
239 /* Skip PHYs with reg property set or ethernet-phy-package node */ in __of_mdiobus_register()
241 of_node_name_eq(child, "ethernet-phy-package")) in __of_mdiobus_register()
250 dev_info(&mdio->dev, "scan phy %pOFn at address %i\n", in __of_mdiobus_register()
254 /* -ENODEV is the return code that PHYLIB has in __of_mdiobus_register()
261 if (rc != -ENODEV) in __of_mdiobus_register()
278 * of_mdio_find_device - Given a device tree node, find the mdio_device
279 * @np: pointer to the mdio_device's device tree node
282 * struct device refcount incremented by one, or NULL on failure.
292 * of_phy_find_device - Give a PHY node, find the phy_device
293 * @phy_np: Pointer to the phy's device tree node
296 * struct device refcount incremented by one, or NULL on failure.
305 * of_phy_connect - Connect to the phy described in the device tree
306 * @dev: pointer to net_device claiming the phy
307 * @phy_np: Pointer to device tree node for the PHY
308 * @hndlr: Link state callback for the network device
309 * @flags: flags to pass to the PHY
310 * @iface: PHY data interface type
313 * struct device refcount incremented by one, or NULL on failure. The
321 struct phy_device *phy = of_phy_find_device(phy_np); in of_phy_connect() local
324 if (!phy) in of_phy_connect()
327 phy->dev_flags |= flags; in of_phy_connect()
329 ret = phy_connect_direct(dev, phy, hndlr, iface); in of_phy_connect()
332 put_device(&phy->mdio.dev); in of_phy_connect()
334 return ret ? NULL : phy; in of_phy_connect()
340 * - Get phy node and connect to the phy described in the device tree
341 * @dev: pointer to net_device claiming the phy
342 * @np: Pointer to device tree node for the net_device claiming the phy
343 * @hndlr: Link state callback for the network device
346 * struct device refcount incremented by one, or NULL on failure. The
355 struct phy_device *phy; in of_phy_get_and_connect() local
364 netdev_err(dev, "broken fixed-link specification\n"); in of_phy_get_and_connect()
369 phy_np = of_parse_phandle(np, "phy-handle", 0); in of_phy_get_and_connect()
374 phy = of_phy_connect(dev, phy_np, hndlr, 0, iface); in of_phy_get_and_connect()
378 return phy; in of_phy_get_and_connect()
385 * - the old DT binding, where 'fixed-link' was a property with 5
386 * cells encoding various information about the fixed PHY
387 * - the new DT binding, where 'fixed-link' is a sub-node of the
388 * Ethernet device.
397 dn = of_get_child_by_name(np, "fixed-link"); in of_phy_is_fixed_link()
408 if (of_property_count_u32_elems(np, "fixed-link") == 5) in of_phy_is_fixed_link()
423 strcmp(managed, "in-band-status") == 0) { in of_phy_register_fixed_link()
429 fixed_link_node = of_get_child_by_name(np, "fixed-link"); in of_phy_register_fixed_link()
433 "full-duplex"); in of_phy_register_fixed_link()
437 return -EINVAL; in of_phy_register_fixed_link()
441 "asym-pause"); in of_phy_register_fixed_link()
448 if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, in of_phy_register_fixed_link()
458 return -ENODEV; in of_phy_register_fixed_link()
475 put_device(&phydev->mdio.dev); /* of_phy_find_device() */ in of_phy_deregister_fixed_link()