• Home
  • Raw
  • Download

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

2  * OF helpers for the MDIO (Ethernet PHY) API
8 * This file provides helper functions for extracting PHY device information
9 * out of the OpenFirmware device tree and using it to populate an mii_bus.
13 #include <linux/device.h>
16 #include <linux/phy.h>
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
38 of_property_for_each_string(device, "compatible", prop, cp) { in of_get_phy_id()
39 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) { in of_get_phy_id()
44 return -EINVAL; in of_get_phy_id()
50 struct phy_device *phy; in of_mdiobus_register_phy() local
56 "ethernet-phy-ieee802.3-c45"); in of_mdiobus_register_phy()
59 phy = phy_device_create(mdio, addr, phy_id, 0, NULL); in of_mdiobus_register_phy()
61 phy = get_phy_device(mdio, addr, is_c45); in of_mdiobus_register_phy()
62 if (IS_ERR(phy)) in of_mdiobus_register_phy()
63 return PTR_ERR(phy); in of_mdiobus_register_phy()
66 if (rc == -EPROBE_DEFER) { in of_mdiobus_register_phy()
67 phy_device_free(phy); in of_mdiobus_register_phy()
71 phy->irq = rc; in of_mdiobus_register_phy()
72 mdio->irq[addr] = rc; in of_mdiobus_register_phy()
74 phy->irq = mdio->irq[addr]; in of_mdiobus_register_phy()
77 if (of_property_read_bool(child, "broken-turn-around")) in of_mdiobus_register_phy()
78 mdio->phy_ignore_ta_mask |= 1 << addr; in of_mdiobus_register_phy()
80 of_property_read_u32(child, "reset-assert-us", in of_mdiobus_register_phy()
81 &phy->mdio.reset_assert_delay); in of_mdiobus_register_phy()
82 of_property_read_u32(child, "reset-deassert-us", in of_mdiobus_register_phy()
83 &phy->mdio.reset_deassert_delay); in of_mdiobus_register_phy()
85 /* Associate the OF node with the device structure so it in of_mdiobus_register_phy()
88 phy->mdio.dev.of_node = child; in of_mdiobus_register_phy()
89 phy->mdio.dev.fwnode = of_fwnode_handle(child); in of_mdiobus_register_phy()
91 /* All data is now stored in the phy struct; in of_mdiobus_register_phy()
93 rc = phy_device_register(phy); in of_mdiobus_register_phy()
95 phy_device_free(phy); in of_mdiobus_register_phy()
100 dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n", in of_mdiobus_register_phy()
115 /* Associate the OF node with the device structure so it in of_mdiobus_register_device()
119 mdiodev->dev.of_node = child; in of_mdiobus_register_device()
120 mdiodev->dev.fwnode = of_fwnode_handle(child); in of_mdiobus_register_device()
130 dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n", in of_mdiobus_register_device()
135 /* The following is a list of PHY compatible strings which appear in
136 * some DTBs. The compatible string is never matched against a PHY
142 { .compatible = "brcm,40nm-ephy" },
152 { .compatible = "moxa,moxart-rtl8201cp", },
157 * Return true if the child node is for a phy. It must either:
158 * o Compatible string of "ethernet-phy-idX.X"
159 * o Compatible string of "ethernet-phy-ieee802.3-c45"
160 * o Compatible string of "ethernet-phy-ieee802.3-c22"
164 * A device which is not a phy is expected to have a compatible string
165 * indicating what sort of device it is.
171 if (of_get_phy_id(child, &phy_id) != -EINVAL) in of_mdiobus_child_is_phy()
174 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) in of_mdiobus_child_is_phy()
177 if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22")) in of_mdiobus_child_is_phy()
194 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
212 return -ENODEV; in of_mdiobus_register()
215 * the device tree are populated after the bus has been registered */ in of_mdiobus_register()
216 mdio->phy_mask = ~0; in of_mdiobus_register()
218 mdio->dev.of_node = np; in of_mdiobus_register()
219 mdio->dev.fwnode = of_fwnode_handle(np); in of_mdiobus_register()
221 /* Get bus level PHY reset GPIO details */ in of_mdiobus_register()
222 mdio->reset_delay_us = DEFAULT_GPIO_RESET_DELAY; in of_mdiobus_register()
223 of_property_read_u32(np, "reset-delay-us", &mdio->reset_delay_us); in of_mdiobus_register()
230 /* Loop over the child nodes and register a phy_device for each phy */ in of_mdiobus_register()
232 addr = of_mdio_parse_addr(&mdio->dev, child); in of_mdiobus_register()
243 if (rc == -ENODEV) in of_mdiobus_register()
244 dev_err(&mdio->dev, in of_mdiobus_register()
245 "MDIO device at address %d is missing.\n", in of_mdiobus_register()
266 dev_info(&mdio->dev, "scan phy %pOFn at address %i\n", in of_mdiobus_register()
270 /* -ENODEV is the return code that PHYLIB has in of_mdiobus_register()
277 if (rc != -ENODEV) in of_mdiobus_register()
292 static int of_phy_match(struct device *dev, void *phy_np) in of_phy_match()
294 return dev->of_node == phy_np; in of_phy_match()
298 * of_phy_find_device - Give a PHY node, find the phy_device
299 * @phy_np: Pointer to the phy's device tree node
302 * struct device refcount incremented by one, or NULL on failure.
306 struct device *d; in of_phy_find_device()
315 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in of_phy_find_device()
325 * of_phy_connect - Connect to the phy described in the device tree
326 * @dev: pointer to net_device claiming the phy
327 * @phy_np: Pointer to device tree node for the PHY
328 * @hndlr: Link state callback for the network device
329 * @flags: flags to pass to the PHY
330 * @iface: PHY data interface type
333 * struct device refcount incremented by one, or NULL on failure. The
341 struct phy_device *phy = of_phy_find_device(phy_np); in of_phy_connect() local
344 if (!phy) in of_phy_connect()
347 phy->dev_flags = flags; in of_phy_connect()
349 ret = phy_connect_direct(dev, phy, hndlr, iface); in of_phy_connect()
352 put_device(&phy->mdio.dev); in of_phy_connect()
354 return ret ? NULL : phy; in of_phy_connect()
360 * - Get phy node and connect to the phy described in the device tree
361 * @dev: pointer to net_device claiming the phy
362 * @np: Pointer to device tree node for the net_device claiming the phy
363 * @hndlr: Link state callback for the network device
366 * struct device refcount incremented by one, or NULL on failure. The
375 struct phy_device *phy; in of_phy_get_and_connect() local
384 netdev_err(dev, "broken fixed-link specification\n"); in of_phy_get_and_connect()
389 phy_np = of_parse_phandle(np, "phy-handle", 0); in of_phy_get_and_connect()
394 phy = of_phy_connect(dev, phy_np, hndlr, 0, iface); in of_phy_get_and_connect()
398 return phy; in of_phy_get_and_connect()
403 * of_phy_attach - Attach to a PHY without starting the state machine
404 * @dev: pointer to net_device claiming the phy
405 * @phy_np: Node pointer for the PHY
406 * @flags: flags to pass to the PHY
407 * @iface: PHY data interface type
410 * struct device refcount incremented by one, or NULL on failure. The
417 struct phy_device *phy = of_phy_find_device(phy_np); in of_phy_attach() local
420 if (!phy) in of_phy_attach()
423 ret = phy_attach_direct(dev, phy, flags, iface); in of_phy_attach()
426 put_device(&phy->mdio.dev); in of_phy_attach()
428 return ret ? NULL : phy; in of_phy_attach()
435 * - the old DT binding, where 'fixed-link' was a property with 5
436 * cells encoding various informations about the fixed PHY
437 * - the new DT binding, where 'fixed-link' is a sub-node of the
438 * Ethernet device.
447 dn = of_get_child_by_name(np, "fixed-link"); in of_phy_is_fixed_link()
458 if (of_get_property(np, "fixed-link", &len) && in of_phy_is_fixed_link()
472 int link_gpio = -1; in of_phy_register_fixed_link()
475 strcmp(managed, "in-band-status") == 0) { in of_phy_register_fixed_link()
481 fixed_link_node = of_get_child_by_name(np, "fixed-link"); in of_phy_register_fixed_link()
485 "full-duplex"); in of_phy_register_fixed_link()
489 return -EINVAL; in of_phy_register_fixed_link()
493 "asym-pause"); in of_phy_register_fixed_link()
495 "link-gpios", 0, NULL); in of_phy_register_fixed_link()
497 if (link_gpio == -EPROBE_DEFER) in of_phy_register_fixed_link()
498 return -EPROBE_DEFER; in of_phy_register_fixed_link()
504 if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, in of_phy_register_fixed_link()
514 return -ENODEV; in of_phy_register_fixed_link()
532 put_device(&phydev->mdio.dev); /* of_phy_find_device() */ in of_phy_deregister_fixed_link()