diff options
author | Andrew Lunn <andrew@lunn.ch> | 2015-04-01 22:06:35 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-04-01 22:55:40 -0400 |
commit | 4914358567d81d6f1d95f7809c77658c55555f1c (patch) | |
tree | 9e608c7e48faa10d958b7e6868e021f020d936fb /drivers/net/dsa | |
parent | 143a83073aaea145aa050cd0ebb80454c9362608 (diff) |
net: dsa: Move phy page access functions into shared code
These functions could in future be used by other drivers. Move them
into the shared area.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa')
-rw-r--r-- | drivers/net/dsa/mv88e6352.c | 45 | ||||
-rw-r--r-- | drivers/net/dsa/mv88e6xxx.c | 34 | ||||
-rw-r--r-- | drivers/net/dsa/mv88e6xxx.h | 4 |
3 files changed, 42 insertions, 41 deletions
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c index 214bdbc8a5b1..fb16671c5f92 100644 --- a/drivers/net/dsa/mv88e6352.c +++ b/drivers/net/dsa/mv88e6352.c | |||
@@ -230,48 +230,13 @@ static int mv88e6352_setup_port(struct dsa_switch *ds, int p) | |||
230 | 230 | ||
231 | #ifdef CONFIG_NET_DSA_HWMON | 231 | #ifdef CONFIG_NET_DSA_HWMON |
232 | 232 | ||
233 | static int mv88e6352_phy_page_read(struct dsa_switch *ds, | ||
234 | int port, int page, int reg) | ||
235 | { | ||
236 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
237 | int ret; | ||
238 | |||
239 | mutex_lock(&ps->phy_mutex); | ||
240 | ret = mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); | ||
241 | if (ret < 0) | ||
242 | goto error; | ||
243 | ret = mv88e6xxx_phy_read_indirect(ds, port, reg); | ||
244 | error: | ||
245 | mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); | ||
246 | mutex_unlock(&ps->phy_mutex); | ||
247 | return ret; | ||
248 | } | ||
249 | |||
250 | static int mv88e6352_phy_page_write(struct dsa_switch *ds, | ||
251 | int port, int page, int reg, int val) | ||
252 | { | ||
253 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
254 | int ret; | ||
255 | |||
256 | mutex_lock(&ps->phy_mutex); | ||
257 | ret = mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); | ||
258 | if (ret < 0) | ||
259 | goto error; | ||
260 | |||
261 | ret = mv88e6xxx_phy_write_indirect(ds, port, reg, val); | ||
262 | error: | ||
263 | mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); | ||
264 | mutex_unlock(&ps->phy_mutex); | ||
265 | return ret; | ||
266 | } | ||
267 | |||
268 | static int mv88e6352_get_temp(struct dsa_switch *ds, int *temp) | 233 | static int mv88e6352_get_temp(struct dsa_switch *ds, int *temp) |
269 | { | 234 | { |
270 | int ret; | 235 | int ret; |
271 | 236 | ||
272 | *temp = 0; | 237 | *temp = 0; |
273 | 238 | ||
274 | ret = mv88e6352_phy_page_read(ds, 0, 6, 27); | 239 | ret = mv88e6xxx_phy_page_read(ds, 0, 6, 27); |
275 | if (ret < 0) | 240 | if (ret < 0) |
276 | return ret; | 241 | return ret; |
277 | 242 | ||
@@ -286,7 +251,7 @@ static int mv88e6352_get_temp_limit(struct dsa_switch *ds, int *temp) | |||
286 | 251 | ||
287 | *temp = 0; | 252 | *temp = 0; |
288 | 253 | ||
289 | ret = mv88e6352_phy_page_read(ds, 0, 6, 26); | 254 | ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26); |
290 | if (ret < 0) | 255 | if (ret < 0) |
291 | return ret; | 256 | return ret; |
292 | 257 | ||
@@ -299,11 +264,11 @@ static int mv88e6352_set_temp_limit(struct dsa_switch *ds, int temp) | |||
299 | { | 264 | { |
300 | int ret; | 265 | int ret; |
301 | 266 | ||
302 | ret = mv88e6352_phy_page_read(ds, 0, 6, 26); | 267 | ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26); |
303 | if (ret < 0) | 268 | if (ret < 0) |
304 | return ret; | 269 | return ret; |
305 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); | 270 | temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); |
306 | return mv88e6352_phy_page_write(ds, 0, 6, 26, | 271 | return mv88e6xxx_phy_page_write(ds, 0, 6, 26, |
307 | (ret & 0xe0ff) | (temp << 8)); | 272 | (ret & 0xe0ff) | (temp << 8)); |
308 | } | 273 | } |
309 | 274 | ||
@@ -313,7 +278,7 @@ static int mv88e6352_get_temp_alarm(struct dsa_switch *ds, bool *alarm) | |||
313 | 278 | ||
314 | *alarm = false; | 279 | *alarm = false; |
315 | 280 | ||
316 | ret = mv88e6352_phy_page_read(ds, 0, 6, 26); | 281 | ret = mv88e6xxx_phy_page_read(ds, 0, 6, 26); |
317 | if (ret < 0) | 282 | if (ret < 0) |
318 | return ret; | 283 | return ret; |
319 | 284 | ||
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c index 9db5b40d78ea..df727e1db18d 100644 --- a/drivers/net/dsa/mv88e6xxx.c +++ b/drivers/net/dsa/mv88e6xxx.c | |||
@@ -1201,6 +1201,40 @@ int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active) | |||
1201 | return 0; | 1201 | return 0; |
1202 | } | 1202 | } |
1203 | 1203 | ||
1204 | int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg) | ||
1205 | { | ||
1206 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
1207 | int ret; | ||
1208 | |||
1209 | mutex_lock(&ps->phy_mutex); | ||
1210 | ret = mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); | ||
1211 | if (ret < 0) | ||
1212 | goto error; | ||
1213 | ret = mv88e6xxx_phy_read_indirect(ds, port, reg); | ||
1214 | error: | ||
1215 | mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); | ||
1216 | mutex_unlock(&ps->phy_mutex); | ||
1217 | return ret; | ||
1218 | } | ||
1219 | |||
1220 | int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page, | ||
1221 | int reg, int val) | ||
1222 | { | ||
1223 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
1224 | int ret; | ||
1225 | |||
1226 | mutex_lock(&ps->phy_mutex); | ||
1227 | ret = mv88e6xxx_phy_write_indirect(ds, port, 0x16, page); | ||
1228 | if (ret < 0) | ||
1229 | goto error; | ||
1230 | |||
1231 | ret = mv88e6xxx_phy_write_indirect(ds, port, reg, val); | ||
1232 | error: | ||
1233 | mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0); | ||
1234 | mutex_unlock(&ps->phy_mutex); | ||
1235 | return ret; | ||
1236 | } | ||
1237 | |||
1204 | static int __init mv88e6xxx_init(void) | 1238 | static int __init mv88e6xxx_init(void) |
1205 | { | 1239 | { |
1206 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) | 1240 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h index f84d3d5178b9..49614765760f 100644 --- a/drivers/net/dsa/mv88e6xxx.h +++ b/drivers/net/dsa/mv88e6xxx.h | |||
@@ -175,7 +175,9 @@ int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, | |||
175 | const unsigned char *addr, u16 vid); | 175 | const unsigned char *addr, u16 vid); |
176 | int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, | 176 | int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, |
177 | unsigned char *addr, bool *is_static); | 177 | unsigned char *addr, bool *is_static); |
178 | 178 | int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg); | |
179 | int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page, | ||
180 | int reg, int val); | ||
179 | extern struct dsa_switch_driver mv88e6131_switch_driver; | 181 | extern struct dsa_switch_driver mv88e6131_switch_driver; |
180 | extern struct dsa_switch_driver mv88e6123_61_65_switch_driver; | 182 | extern struct dsa_switch_driver mv88e6123_61_65_switch_driver; |
181 | extern struct dsa_switch_driver mv88e6352_switch_driver; | 183 | extern struct dsa_switch_driver mv88e6352_switch_driver; |