aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/of_mdio.c
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2014-05-16 10:14:05 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-16 17:19:22 -0400
commit3be2a49e5c08d268f8af0dd4fe89a24ea8cdc339 (patch)
tree83d32019dd08257b68821bafa59bbcd4e089ce76 /drivers/of/of_mdio.c
parenta75951217472c522c324adb0a4de3ba69d656ef5 (diff)
of: provide a binding for fixed link PHYs
Some Ethernet MACs have a "fixed link", and are not connected to a normal MDIO-managed PHY device. For those situations, a Device Tree binding allows to describe a "fixed link" using a special PHY node. This patch adds: * A documentation for the fixed PHY Device Tree binding. * An of_phy_is_fixed_link() function that an Ethernet driver can call on its PHY phandle to find out whether it's a fixed link PHY or not. It should typically be used to know if of_phy_register_fixed_link() should be called. * An of_phy_register_fixed_link() function that instantiates the fixed PHY into the PHY subsystem, so that when the driver calls of_phy_connect(), the PHY device associated to the OF node will be found. These two additional functions also support the old fixed-link Device Tree binding used on PowerPC platforms, so that ultimately, the network device drivers for those platforms could be converted to use of_phy_is_fixed_link() and of_phy_register_fixed_link() instead of of_phy_connect_fixed_link(), while keeping compatibility with their respective Device Tree bindings. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/of/of_mdio.c')
-rw-r--r--drivers/of/of_mdio.c67
1 files changed, 67 insertions, 0 deletions
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}
303EXPORT_SYMBOL(of_phy_attach); 304EXPORT_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 */
315bool 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}
334EXPORT_SYMBOL(of_phy_is_fixed_link);
335
336int 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}
369EXPORT_SYMBOL(of_phy_register_fixed_link);
370#endif