lantiq: clarify VG3503J name
[oweals/openwrt.git] / target / linux / mvebu / patches-4.9 / 401-net-phy-move-phy-MMD-accessors-to-phy-core.c.patch
1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Date: Wed, 4 Jan 2017 10:46:43 +0000
3 Subject: [PATCH] net: phy: move phy MMD accessors to phy-core.c
4
5 Move the phy_(read|write)__mmd() helpers out of line, they will become
6 our main MMD accessor functions, and so will be a little more complex.
7 This complexity doesn't belong in an inline function.  Also move the
8 _indirect variants as well to keep like functionality together.
9
10 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11 ---
12  create mode 100644 drivers/net/phy/phy-core.c
13
14 --- a/drivers/net/phy/Makefile
15 +++ b/drivers/net/phy/Makefile
16 @@ -1,6 +1,7 @@
17  # Makefile for Linux PHY drivers and MDIO bus drivers
18  
19 -libphy-y                       := phy.o phy_device.o mdio_bus.o mdio_device.o
20 +libphy-y                       := phy.o phy_device.o mdio_bus.o mdio_device.o \
21 +                                  phy-core.o
22  libphy-$(CONFIG_SWPHY)         += swphy.o
23  
24  obj-$(CONFIG_MDIO_BOARDINFO)   += mdio-boardinfo.o
25 --- a/drivers/net/phy/phy.c
26 +++ b/drivers/net/phy/phy.c
27 @@ -1171,91 +1171,6 @@ void phy_mac_interrupt(struct phy_device
28  }
29  EXPORT_SYMBOL(phy_mac_interrupt);
30  
31 -static inline void mmd_phy_indirect(struct mii_bus *bus, int prtad, int devad,
32 -                                   int addr)
33 -{
34 -       /* Write the desired MMD Devad */
35 -       bus->write(bus, addr, MII_MMD_CTRL, devad);
36 -
37 -       /* Write the desired MMD register address */
38 -       bus->write(bus, addr, MII_MMD_DATA, prtad);
39 -
40 -       /* Select the Function : DATA with no post increment */
41 -       bus->write(bus, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR));
42 -}
43 -
44 -/**
45 - * phy_read_mmd_indirect - reads data from the MMD registers
46 - * @phydev: The PHY device bus
47 - * @prtad: MMD Address
48 - * @devad: MMD DEVAD
49 - *
50 - * Description: it reads data from the MMD registers (clause 22 to access to
51 - * clause 45) of the specified phy address.
52 - * To read these register we have:
53 - * 1) Write reg 13 // DEVAD
54 - * 2) Write reg 14 // MMD Address
55 - * 3) Write reg 13 // MMD Data Command for MMD DEVAD
56 - * 3) Read  reg 14 // Read MMD data
57 - */
58 -int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, int devad)
59 -{
60 -       struct phy_driver *phydrv = phydev->drv;
61 -       int addr = phydev->mdio.addr;
62 -       int value = -1;
63 -
64 -       if (!phydrv->read_mmd_indirect) {
65 -               struct mii_bus *bus = phydev->mdio.bus;
66 -
67 -               mutex_lock(&bus->mdio_lock);
68 -               mmd_phy_indirect(bus, prtad, devad, addr);
69 -
70 -               /* Read the content of the MMD's selected register */
71 -               value = bus->read(bus, addr, MII_MMD_DATA);
72 -               mutex_unlock(&bus->mdio_lock);
73 -       } else {
74 -               value = phydrv->read_mmd_indirect(phydev, prtad, devad, addr);
75 -       }
76 -       return value;
77 -}
78 -EXPORT_SYMBOL(phy_read_mmd_indirect);
79 -
80 -/**
81 - * phy_write_mmd_indirect - writes data to the MMD registers
82 - * @phydev: The PHY device
83 - * @prtad: MMD Address
84 - * @devad: MMD DEVAD
85 - * @data: data to write in the MMD register
86 - *
87 - * Description: Write data from the MMD registers of the specified
88 - * phy address.
89 - * To write these register we have:
90 - * 1) Write reg 13 // DEVAD
91 - * 2) Write reg 14 // MMD Address
92 - * 3) Write reg 13 // MMD Data Command for MMD DEVAD
93 - * 3) Write reg 14 // Write MMD data
94 - */
95 -void phy_write_mmd_indirect(struct phy_device *phydev, int prtad,
96 -                                  int devad, u32 data)
97 -{
98 -       struct phy_driver *phydrv = phydev->drv;
99 -       int addr = phydev->mdio.addr;
100 -
101 -       if (!phydrv->write_mmd_indirect) {
102 -               struct mii_bus *bus = phydev->mdio.bus;
103 -
104 -               mutex_lock(&bus->mdio_lock);
105 -               mmd_phy_indirect(bus, prtad, devad, addr);
106 -
107 -               /* Write the data into MMD's selected register */
108 -               bus->write(bus, addr, MII_MMD_DATA, data);
109 -               mutex_unlock(&bus->mdio_lock);
110 -       } else {
111 -               phydrv->write_mmd_indirect(phydev, prtad, devad, addr, data);
112 -       }
113 -}
114 -EXPORT_SYMBOL(phy_write_mmd_indirect);
115 -
116  /**
117   * phy_init_eee - init and check the EEE feature
118   * @phydev: target phy_device struct
119 --- /dev/null
120 +++ b/drivers/net/phy/phy-core.c
121 @@ -0,0 +1,135 @@
122 +/*
123 + * Core PHY library, taken from phy.c
124 + *
125 + * This program is free software; you can redistribute  it and/or modify it
126 + * under  the terms of  the GNU General  Public License as published by the
127 + * Free Software Foundation;  either version 2 of the  License, or (at your
128 + * option) any later version.
129 + */
130 +#include <linux/export.h>
131 +#include <linux/phy.h>
132 +
133 +static inline void mmd_phy_indirect(struct mii_bus *bus, int prtad, int devad,
134 +                                   int addr)
135 +{
136 +       /* Write the desired MMD Devad */
137 +       bus->write(bus, addr, MII_MMD_CTRL, devad);
138 +
139 +       /* Write the desired MMD register address */
140 +       bus->write(bus, addr, MII_MMD_DATA, prtad);
141 +
142 +       /* Select the Function : DATA with no post increment */
143 +       bus->write(bus, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR));
144 +}
145 +
146 +/**
147 + * phy_read_mmd_indirect - reads data from the MMD registers
148 + * @phydev: The PHY device bus
149 + * @prtad: MMD Address
150 + * @devad: MMD DEVAD
151 + *
152 + * Description: it reads data from the MMD registers (clause 22 to access to
153 + * clause 45) of the specified phy address.
154 + * To read these register we have:
155 + * 1) Write reg 13 // DEVAD
156 + * 2) Write reg 14 // MMD Address
157 + * 3) Write reg 13 // MMD Data Command for MMD DEVAD
158 + * 3) Read  reg 14 // Read MMD data
159 + */
160 +int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, int devad)
161 +{
162 +       struct phy_driver *phydrv = phydev->drv;
163 +       int addr = phydev->mdio.addr;
164 +       int value = -1;
165 +
166 +       if (!phydrv->read_mmd_indirect) {
167 +               struct mii_bus *bus = phydev->mdio.bus;
168 +
169 +               mutex_lock(&bus->mdio_lock);
170 +               mmd_phy_indirect(bus, prtad, devad, addr);
171 +
172 +               /* Read the content of the MMD's selected register */
173 +               value = bus->read(bus, addr, MII_MMD_DATA);
174 +               mutex_unlock(&bus->mdio_lock);
175 +       } else {
176 +               value = phydrv->read_mmd_indirect(phydev, prtad, devad, addr);
177 +       }
178 +       return value;
179 +}
180 +EXPORT_SYMBOL(phy_read_mmd_indirect);
181 +
182 +/**
183 + * phy_read_mmd - Convenience function for reading a register
184 + * from an MMD on a given PHY.
185 + * @phydev: The phy_device struct
186 + * @devad: The MMD to read from
187 + * @regnum: The register on the MMD to read
188 + *
189 + * Same rules as for phy_read();
190 + */
191 +int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
192 +{
193 +       if (!phydev->is_c45)
194 +               return -EOPNOTSUPP;
195 +
196 +       return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
197 +                           MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));
198 +}
199 +EXPORT_SYMBOL(phy_read_mmd);
200 +
201 +/**
202 + * phy_write_mmd_indirect - writes data to the MMD registers
203 + * @phydev: The PHY device
204 + * @prtad: MMD Address
205 + * @devad: MMD DEVAD
206 + * @data: data to write in the MMD register
207 + *
208 + * Description: Write data from the MMD registers of the specified
209 + * phy address.
210 + * To write these register we have:
211 + * 1) Write reg 13 // DEVAD
212 + * 2) Write reg 14 // MMD Address
213 + * 3) Write reg 13 // MMD Data Command for MMD DEVAD
214 + * 3) Write reg 14 // Write MMD data
215 + */
216 +void phy_write_mmd_indirect(struct phy_device *phydev, int prtad,
217 +                                  int devad, u32 data)
218 +{
219 +       struct phy_driver *phydrv = phydev->drv;
220 +       int addr = phydev->mdio.addr;
221 +
222 +       if (!phydrv->write_mmd_indirect) {
223 +               struct mii_bus *bus = phydev->mdio.bus;
224 +
225 +               mutex_lock(&bus->mdio_lock);
226 +               mmd_phy_indirect(bus, prtad, devad, addr);
227 +
228 +               /* Write the data into MMD's selected register */
229 +               bus->write(bus, addr, MII_MMD_DATA, data);
230 +               mutex_unlock(&bus->mdio_lock);
231 +       } else {
232 +               phydrv->write_mmd_indirect(phydev, prtad, devad, addr, data);
233 +       }
234 +}
235 +EXPORT_SYMBOL(phy_write_mmd_indirect);
236 +
237 +/**
238 + * phy_write_mmd - Convenience function for writing a register
239 + * on an MMD on a given PHY.
240 + * @phydev: The phy_device struct
241 + * @devad: The MMD to read from
242 + * @regnum: The register on the MMD to read
243 + * @val: value to write to @regnum
244 + *
245 + * Same rules as for phy_write();
246 + */
247 +int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
248 +{
249 +       if (!phydev->is_c45)
250 +               return -EOPNOTSUPP;
251 +
252 +       regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff);
253 +
254 +       return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
255 +}
256 +EXPORT_SYMBOL(phy_write_mmd);
257 --- a/include/linux/phy.h
258 +++ b/include/linux/phy.h
259 @@ -627,14 +627,7 @@ struct phy_fixup {
260   *
261   * Same rules as for phy_read();
262   */
263 -static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
264 -{
265 -       if (!phydev->is_c45)
266 -               return -EOPNOTSUPP;
267 -
268 -       return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
269 -                           MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));
270 -}
271 +int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
272  
273  /**
274   * phy_read_mmd_indirect - reads data from the MMD registers
275 @@ -728,16 +721,7 @@ static inline bool phy_is_pseudo_fixed_l
276   *
277   * Same rules as for phy_write();
278   */
279 -static inline int phy_write_mmd(struct phy_device *phydev, int devad,
280 -                               u32 regnum, u16 val)
281 -{
282 -       if (!phydev->is_c45)
283 -               return -EOPNOTSUPP;
284 -
285 -       regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff);
286 -
287 -       return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
288 -}
289 +int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
290  
291  /**
292   * phy_write_mmd_indirect - writes data to the MMD registers