mvebu: backport mainline patches from kernel 3.12
[openwrt/staging/lynxis/omap.git] / target / linux / mvebu / patches-3.10 / 0080-of-provide-a-binding-for-the-fixed-link-property.patch
1 From 5378928ebac13756fc13d0b2de8dd45ace8026aa Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Mon, 15 Jul 2013 17:34:08 +0200
4 Subject: [PATCH 080/203] of: provide a binding for the 'fixed-link' property
5
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", as a "fixed-link" property
9 of the Ethernet device Device Tree node.
10
11 This patch adds:
12
13 * A documentation for the Device Tree property "fixed-link".
14
15 * A of_phy_register_fixed_link() OF helper, which provided an OF node
16 that contains a "fixed-link" property, registers the corresponding
17 fixed PHY.
18
19 * Removes the warning on the of_phy_connect_fixed_link() that says
20 new drivers should not use it, since Grant Likely indicated that
21 this "fixed-link" property is indeed the way to go.
22
23 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
24 ---
25 .../devicetree/bindings/net/fixed-link.txt | 26 ++++++++++++++++
26 drivers/of/of_mdio.c | 36 +++++++++++++++++++---
27 include/linux/of_mdio.h | 10 ++++++
28 3 files changed, 68 insertions(+), 4 deletions(-)
29 create mode 100644 Documentation/devicetree/bindings/net/fixed-link.txt
30
31 --- /dev/null
32 +++ b/Documentation/devicetree/bindings/net/fixed-link.txt
33 @@ -0,0 +1,26 @@
34 +Fixed link Device Tree binding
35 +------------------------------
36 +
37 +Some Ethernet MACs have a "fixed link", and are not connected to a
38 +normal MDIO-managed PHY device. For those situations, a Device Tree
39 +binding allows to describe a "fixed link".
40 +
41 +Such a fixed link situation is described within an Ethernet device
42 +Device Tree node using a 'fixed-link' property, composed of 5
43 +elements:
44 +
45 + 1. A fake PHY ID, which must be unique accross all fixed-link PHYs in
46 + the system.
47 + 2. The duplex (1 for full-duplex, 0 for half-duplex)
48 + 3. The speed (10, 100, 1000)
49 + 4. The pause setting (1 for enabled, 0 for disabled)
50 + 5. The asym pause setting (1 for enabled, 0 for disabled)
51 +
52 +Example:
53 +
54 +ethernet@0 {
55 + ...
56 + fixed-link = <1 1 1000 0 0>;
57 + ...
58 +};
59 +
60 --- a/drivers/of/of_mdio.c
61 +++ b/drivers/of/of_mdio.c
62 @@ -14,6 +14,7 @@
63 #include <linux/netdevice.h>
64 #include <linux/err.h>
65 #include <linux/phy.h>
66 +#include <linux/phy_fixed.h>
67 #include <linux/of.h>
68 #include <linux/of_irq.h>
69 #include <linux/of_mdio.h>
70 @@ -215,10 +216,6 @@ EXPORT_SYMBOL(of_phy_connect);
71 * @dev: pointer to net_device claiming the phy
72 * @hndlr: Link state callback for the network device
73 * @iface: PHY data interface type
74 - *
75 - * This function is a temporary stop-gap and will be removed soon. It is
76 - * only to support the fs_enet, ucc_geth and gianfar Ethernet drivers. Do
77 - * not call this function from new drivers.
78 */
79 struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
80 void (*hndlr)(struct net_device *),
81 @@ -247,3 +244,34 @@ struct phy_device *of_phy_connect_fixed_
82 return IS_ERR(phy) ? NULL : phy;
83 }
84 EXPORT_SYMBOL(of_phy_connect_fixed_link);
85 +
86 +#if defined(CONFIG_FIXED_PHY)
87 +/**
88 + * of_phy_register_fixed_link - Parse fixed-link property and register a dummy phy
89 + * @np: pointer to the OF device node that contains the "fixed-link"
90 + * property for which a dummy phy should be registered.
91 + */
92 +#define FIXED_LINK_PROPERTIES_COUNT 5
93 +int of_phy_register_fixed_link(struct device_node *np)
94 +{
95 + struct fixed_phy_status status = {};
96 + u32 fixed_link_props[FIXED_LINK_PROPERTIES_COUNT];
97 + int ret;
98 +
99 + ret = of_property_read_u32_array(np, "fixed-link",
100 + fixed_link_props,
101 + FIXED_LINK_PROPERTIES_COUNT);
102 + if (ret < 0)
103 + return ret;
104 +
105 + status.link = 1;
106 + status.duplex = fixed_link_props[1];
107 + status.speed = fixed_link_props[2];
108 + status.pause = fixed_link_props[3];
109 + status.asym_pause = fixed_link_props[4];
110 +
111 + return fixed_phy_add(PHY_POLL, fixed_link_props[0],
112 + &status);
113 +}
114 +EXPORT_SYMBOL(of_phy_register_fixed_link);
115 +#endif
116 --- a/include/linux/of_mdio.h
117 +++ b/include/linux/of_mdio.h
118 @@ -57,4 +57,14 @@ static inline struct mii_bus *of_mdio_fi
119 }
120 #endif /* CONFIG_OF */
121
122 +#if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY)
123 +extern int of_phy_register_fixed_link(struct device_node *np);
124 +#else
125 +static inline int of_phy_register_fixed_link(struct device_node *np)
126 +{
127 + return -ENOSYS;
128 +}
129 +#endif
130 +
131 +
132 #endif /* __LINUX_OF_MDIO_H */