diff options
| -rw-r--r-- | Documentation/devicetree/bindings/net/fixed-link.txt | 30 | ||||
| -rw-r--r-- | drivers/of/of_mdio.c | 67 | ||||
| -rw-r--r-- | include/linux/of_mdio.h | 15 |
3 files changed, 112 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/net/fixed-link.txt b/Documentation/devicetree/bindings/net/fixed-link.txt new file mode 100644 index 000000000000..e956de1be935 --- /dev/null +++ b/Documentation/devicetree/bindings/net/fixed-link.txt | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | Fixed link Device Tree binding | ||
| 2 | ------------------------------ | ||
| 3 | |||
| 4 | Some Ethernet MACs have a "fixed link", and are not connected to a | ||
| 5 | normal MDIO-managed PHY device. For those situations, a Device Tree | ||
| 6 | binding allows to describe a "fixed link". | ||
| 7 | |||
| 8 | Such a fixed link situation is described by creating a 'fixed-link' | ||
| 9 | sub-node of the Ethernet MAC device node, with the following | ||
| 10 | properties: | ||
| 11 | |||
| 12 | * 'speed' (integer, mandatory), to indicate the link speed. Accepted | ||
| 13 | values are 10, 100 and 1000 | ||
| 14 | * 'full-duplex' (boolean, optional), to indicate that full duplex is | ||
| 15 | used. When absent, half duplex is assumed. | ||
| 16 | * 'pause' (boolean, optional), to indicate that pause should be | ||
| 17 | enabled. | ||
| 18 | * 'asym-pause' (boolean, optional), to indicate that asym_pause should | ||
| 19 | be enabled. | ||
| 20 | |||
| 21 | Example: | ||
| 22 | |||
| 23 | ethernet@0 { | ||
| 24 | ... | ||
| 25 | fixed-link { | ||
| 26 | speed = <1000>; | ||
| 27 | full-duplex; | ||
| 28 | }; | ||
| 29 | ... | ||
| 30 | }; | ||
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 9a95831bd065..1def0bb5cb37 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/err.h> | 15 | #include <linux/err.h> |
| 16 | #include <linux/phy.h> | 16 | #include <linux/phy.h> |
| 17 | #include <linux/phy_fixed.h> | ||
| 17 | #include <linux/of.h> | 18 | #include <linux/of.h> |
| 18 | #include <linux/of_irq.h> | 19 | #include <linux/of_irq.h> |
| 19 | #include <linux/of_mdio.h> | 20 | #include <linux/of_mdio.h> |
| @@ -301,3 +302,69 @@ struct phy_device *of_phy_attach(struct net_device *dev, | |||
| 301 | return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy; | 302 | return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy; |
| 302 | } | 303 | } |
| 303 | EXPORT_SYMBOL(of_phy_attach); | 304 | EXPORT_SYMBOL(of_phy_attach); |
| 305 | |||
| 306 | #if defined(CONFIG_FIXED_PHY) | ||
| 307 | /* | ||
| 308 | * of_phy_is_fixed_link() and of_phy_register_fixed_link() must | ||
| 309 | * support two DT bindings: | ||
| 310 | * - the old DT binding, where 'fixed-link' was a property with 5 | ||
| 311 | * cells encoding various informations about the fixed PHY | ||
| 312 | * - the new DT binding, where 'fixed-link' is a sub-node of the | ||
| 313 | * Ethernet device. | ||
| 314 | */ | ||
| 315 | bool of_phy_is_fixed_link(struct device_node *np) | ||
| 316 | { | ||
| 317 | struct device_node *dn; | ||
| 318 | int len; | ||
| 319 | |||
| 320 | /* New binding */ | ||
| 321 | dn = of_get_child_by_name(np, "fixed-link"); | ||
| 322 | if (dn) { | ||
| 323 | of_node_put(dn); | ||
| 324 | return true; | ||
| 325 | } | ||
| 326 | |||
| 327 | /* Old binding */ | ||
| 328 | if (of_get_property(np, "fixed-link", &len) && | ||
| 329 | len == (5 * sizeof(__be32))) | ||
| 330 | return true; | ||
| 331 | |||
| 332 | return false; | ||
| 333 | } | ||
| 334 | EXPORT_SYMBOL(of_phy_is_fixed_link); | ||
| 335 | |||
| 336 | int of_phy_register_fixed_link(struct device_node *np) | ||
| 337 | { | ||
| 338 | struct fixed_phy_status status = {}; | ||
| 339 | struct device_node *fixed_link_node; | ||
| 340 | const __be32 *fixed_link_prop; | ||
| 341 | int len; | ||
| 342 | |||
| 343 | /* New binding */ | ||
| 344 | fixed_link_node = of_get_child_by_name(np, "fixed-link"); | ||
| 345 | if (fixed_link_node) { | ||
| 346 | status.link = 1; | ||
| 347 | status.duplex = of_property_read_bool(np, "full-duplex"); | ||
| 348 | if (of_property_read_u32(fixed_link_node, "speed", &status.speed)) | ||
| 349 | return -EINVAL; | ||
| 350 | status.pause = of_property_read_bool(np, "pause"); | ||
| 351 | status.asym_pause = of_property_read_bool(np, "asym-pause"); | ||
| 352 | of_node_put(fixed_link_node); | ||
| 353 | return fixed_phy_register(PHY_POLL, &status, np); | ||
| 354 | } | ||
| 355 | |||
| 356 | /* Old binding */ | ||
| 357 | fixed_link_prop = of_get_property(np, "fixed-link", &len); | ||
| 358 | if (fixed_link_prop && len == (5 * sizeof(__be32))) { | ||
| 359 | status.link = 1; | ||
| 360 | status.duplex = be32_to_cpu(fixed_link_prop[1]); | ||
| 361 | status.speed = be32_to_cpu(fixed_link_prop[2]); | ||
| 362 | status.pause = be32_to_cpu(fixed_link_prop[3]); | ||
| 363 | status.asym_pause = be32_to_cpu(fixed_link_prop[4]); | ||
| 364 | return fixed_phy_register(PHY_POLL, &status, np); | ||
| 365 | } | ||
| 366 | |||
| 367 | return -ENODEV; | ||
| 368 | } | ||
| 369 | EXPORT_SYMBOL(of_phy_register_fixed_link); | ||
| 370 | #endif | ||
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h index 881a7c3571f4..0aa367e316cb 100644 --- a/include/linux/of_mdio.h +++ b/include/linux/of_mdio.h | |||
| @@ -72,4 +72,19 @@ static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np) | |||
| 72 | } | 72 | } |
| 73 | #endif /* CONFIG_OF */ | 73 | #endif /* CONFIG_OF */ |
| 74 | 74 | ||
| 75 | #if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY) | ||
| 76 | extern int of_phy_register_fixed_link(struct device_node *np); | ||
| 77 | extern bool of_phy_is_fixed_link(struct device_node *np); | ||
| 78 | #else | ||
| 79 | static inline int of_phy_register_fixed_link(struct device_node *np) | ||
| 80 | { | ||
| 81 | return -ENOSYS; | ||
| 82 | } | ||
| 83 | static inline bool of_phy_is_fixed_link(struct device_node *np) | ||
| 84 | { | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | |||
| 89 | |||
| 75 | #endif /* __LINUX_OF_MDIO_H */ | 90 | #endif /* __LINUX_OF_MDIO_H */ |
