1 From 3be2a49e5c08d268f8af0dd4fe89a24ea8cdc339 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Fri, 16 May 2014 16:14:05 +0200
4 Subject: of: provide a binding for fixed link PHYs
6 Some Ethernet MACs have a "fixed link", and are not connected to a
7 normal MDIO-managed PHY device. For those situations, a Device Tree
8 binding allows to describe a "fixed link" using a special PHY node.
12 * A documentation for the fixed PHY Device Tree binding.
14 * An of_phy_is_fixed_link() function that an Ethernet driver can call
15 on its PHY phandle to find out whether it's a fixed link PHY or
16 not. It should typically be used to know if
17 of_phy_register_fixed_link() should be called.
19 * An of_phy_register_fixed_link() function that instantiates the
20 fixed PHY into the PHY subsystem, so that when the driver calls
21 of_phy_connect(), the PHY device associated to the OF node will be
24 These two additional functions also support the old fixed-link Device
25 Tree binding used on PowerPC platforms, so that ultimately, the
26 network device drivers for those platforms could be converted to use
27 of_phy_is_fixed_link() and of_phy_register_fixed_link() instead of
28 of_phy_connect_fixed_link(), while keeping compatibility with their
29 respective Device Tree bindings.
31 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
32 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
33 Tested-by: Florian Fainelli <f.fainelli@gmail.com>
34 Signed-off-by: David S. Miller <davem@davemloft.net>
37 +++ b/Documentation/devicetree/bindings/net/fixed-link.txt
39 +Fixed link Device Tree binding
40 +------------------------------
42 +Some Ethernet MACs have a "fixed link", and are not connected to a
43 +normal MDIO-managed PHY device. For those situations, a Device Tree
44 +binding allows to describe a "fixed link".
46 +Such a fixed link situation is described by creating a 'fixed-link'
47 +sub-node of the Ethernet MAC device node, with the following
50 +* 'speed' (integer, mandatory), to indicate the link speed. Accepted
51 + values are 10, 100 and 1000
52 +* 'full-duplex' (boolean, optional), to indicate that full duplex is
53 + used. When absent, half duplex is assumed.
54 +* 'pause' (boolean, optional), to indicate that pause should be
56 +* 'asym-pause' (boolean, optional), to indicate that asym_pause should
69 --- a/drivers/of/of_mdio.c
70 +++ b/drivers/of/of_mdio.c
72 #include <linux/netdevice.h>
73 #include <linux/err.h>
74 #include <linux/phy.h>
75 +#include <linux/phy_fixed.h>
77 #include <linux/of_irq.h>
78 #include <linux/of_mdio.h>
79 @@ -280,3 +281,69 @@ struct phy_device *of_phy_attach(struct
80 return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy;
82 EXPORT_SYMBOL(of_phy_attach);
84 +#if defined(CONFIG_FIXED_PHY)
86 + * of_phy_is_fixed_link() and of_phy_register_fixed_link() must
87 + * support two DT bindings:
88 + * - the old DT binding, where 'fixed-link' was a property with 5
89 + * cells encoding various informations about the fixed PHY
90 + * - the new DT binding, where 'fixed-link' is a sub-node of the
93 +bool of_phy_is_fixed_link(struct device_node *np)
95 + struct device_node *dn;
99 + dn = of_get_child_by_name(np, "fixed-link");
106 + if (of_get_property(np, "fixed-link", &len) &&
107 + len == (5 * sizeof(__be32)))
112 +EXPORT_SYMBOL(of_phy_is_fixed_link);
114 +int of_phy_register_fixed_link(struct device_node *np)
116 + struct fixed_phy_status status = {};
117 + struct device_node *fixed_link_node;
118 + const __be32 *fixed_link_prop;
122 + fixed_link_node = of_get_child_by_name(np, "fixed-link");
123 + if (fixed_link_node) {
125 + status.duplex = of_property_read_bool(np, "full-duplex");
126 + if (of_property_read_u32(fixed_link_node, "speed", &status.speed))
128 + status.pause = of_property_read_bool(np, "pause");
129 + status.asym_pause = of_property_read_bool(np, "asym-pause");
130 + of_node_put(fixed_link_node);
131 + return fixed_phy_register(PHY_POLL, &status, np);
135 + fixed_link_prop = of_get_property(np, "fixed-link", &len);
136 + if (fixed_link_prop && len == (5 * sizeof(__be32))) {
138 + status.duplex = be32_to_cpu(fixed_link_prop[1]);
139 + status.speed = be32_to_cpu(fixed_link_prop[2]);
140 + status.pause = be32_to_cpu(fixed_link_prop[3]);
141 + status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
142 + return fixed_phy_register(PHY_POLL, &status, np);
147 +EXPORT_SYMBOL(of_phy_register_fixed_link);
149 --- a/include/linux/of_mdio.h
150 +++ b/include/linux/of_mdio.h
151 @@ -67,4 +67,19 @@ static inline struct mii_bus *of_mdio_fi
153 #endif /* CONFIG_OF */
155 +#if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY)
156 +extern int of_phy_register_fixed_link(struct device_node *np);
157 +extern bool of_phy_is_fixed_link(struct device_node *np);
159 +static inline int of_phy_register_fixed_link(struct device_node *np)
163 +static inline bool of_phy_is_fixed_link(struct device_node *np)
170 #endif /* __LINUX_OF_MDIO_H */