kernel: add missing MTD_SPLIT_FIT_FW symbol
[openwrt.git] / target / linux / mvebu / patches-3.14 / 020-of_fixed_link_phy.patch
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
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" using a special PHY node.
9
10 This patch adds:
11
12  * A documentation for the fixed PHY Device Tree binding.
13
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.
18
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
22    found.
23
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.
30
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>
35
36 --- /dev/null
37 +++ b/Documentation/devicetree/bindings/net/fixed-link.txt
38 @@ -0,0 +1,30 @@
39 +Fixed link Device Tree binding
40 +------------------------------
41 +
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".
45 +
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
48 +properties:
49 +
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
55 +  enabled.
56 +* 'asym-pause' (boolean, optional), to indicate that asym_pause should
57 +  be enabled.
58 +
59 +Example:
60 +
61 +ethernet@0 {
62 +       ...
63 +       fixed-link {
64 +             speed = <1000>;
65 +             full-duplex;
66 +       };
67 +       ...
68 +};
69 --- a/drivers/of/of_mdio.c
70 +++ b/drivers/of/of_mdio.c
71 @@ -14,6 +14,7 @@
72  #include <linux/netdevice.h>
73  #include <linux/err.h>
74  #include <linux/phy.h>
75 +#include <linux/phy_fixed.h>
76  #include <linux/of.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;
81  }
82  EXPORT_SYMBOL(of_phy_attach);
83 +
84 +#if defined(CONFIG_FIXED_PHY)
85 +/*
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
91 + *   Ethernet device.
92 + */
93 +bool of_phy_is_fixed_link(struct device_node *np)
94 +{
95 +       struct device_node *dn;
96 +       int len;
97 +
98 +       /* New binding */
99 +       dn = of_get_child_by_name(np, "fixed-link");
100 +       if (dn) {
101 +               of_node_put(dn);
102 +               return true;
103 +       }
104 +
105 +       /* Old binding */
106 +       if (of_get_property(np, "fixed-link", &len) &&
107 +           len == (5 * sizeof(__be32)))
108 +               return true;
109 +
110 +       return false;
111 +}
112 +EXPORT_SYMBOL(of_phy_is_fixed_link);
113 +
114 +int of_phy_register_fixed_link(struct device_node *np)
115 +{
116 +       struct fixed_phy_status status = {};
117 +       struct device_node *fixed_link_node;
118 +       const __be32 *fixed_link_prop;
119 +       int len;
120 +
121 +       /* New binding */
122 +       fixed_link_node = of_get_child_by_name(np, "fixed-link");
123 +       if (fixed_link_node) {
124 +               status.link = 1;
125 +               status.duplex = of_property_read_bool(np, "full-duplex");
126 +               if (of_property_read_u32(fixed_link_node, "speed", &status.speed))
127 +                       return -EINVAL;
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);
132 +       }
133 +
134 +       /* Old binding */
135 +       fixed_link_prop = of_get_property(np, "fixed-link", &len);
136 +       if (fixed_link_prop && len == (5 * sizeof(__be32))) {
137 +               status.link = 1;
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);
143 +       }
144 +
145 +       return -ENODEV;
146 +}
147 +EXPORT_SYMBOL(of_phy_register_fixed_link);
148 +#endif
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
152  }
153  #endif /* CONFIG_OF */
154  
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);
158 +#else
159 +static inline int of_phy_register_fixed_link(struct device_node *np)
160 +{
161 +       return -ENOSYS;
162 +}
163 +static inline bool of_phy_is_fixed_link(struct device_node *np)
164 +{
165 +       return false;
166 +}
167 +#endif
168 +
169 +
170  #endif /* __LINUX_OF_MDIO_H */