diff options
author | Andrew Lunn <andrew@lunn.ch> | 2014-11-15 16:24:51 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-11-16 15:47:26 -0500 |
commit | eaa237657b97068db0eb49bae86714e9324cff9a (patch) | |
tree | c14858ba1398bfe294b1a5dde678e920e9f50715 /drivers/net/dsa | |
parent | 6f2aed6ad7242ead0db1278b4b48fabb81bbc6a7 (diff) |
net: dsa: Centralise code for reading the temperature sensor
The method to read the temperature used in the mve6123_61_65 driver
can also be used for other chips. Move the code into the shared code
base of mv88e6xxx.c.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa')
-rw-r--r-- | drivers/net/dsa/mv88e6123_61_65.c | 50 | ||||
-rw-r--r-- | drivers/net/dsa/mv88e6xxx.c | 48 | ||||
-rw-r--r-- | drivers/net/dsa/mv88e6xxx.h | 1 |
3 files changed, 50 insertions, 49 deletions
diff --git a/drivers/net/dsa/mv88e6123_61_65.c b/drivers/net/dsa/mv88e6123_61_65.c index 9a3f9e0b0532..e9c736e1cef3 100644 --- a/drivers/net/dsa/mv88e6123_61_65.c +++ b/drivers/net/dsa/mv88e6123_61_65.c | |||
@@ -291,54 +291,6 @@ static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p) | |||
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | #ifdef CONFIG_NET_DSA_HWMON | ||
295 | |||
296 | static int mv88e6123_61_65_get_temp(struct dsa_switch *ds, int *temp) | ||
297 | { | ||
298 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
299 | int ret; | ||
300 | int val; | ||
301 | |||
302 | *temp = 0; | ||
303 | |||
304 | mutex_lock(&ps->phy_mutex); | ||
305 | |||
306 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6); | ||
307 | if (ret < 0) | ||
308 | goto error; | ||
309 | |||
310 | /* Enable temperature sensor */ | ||
311 | ret = mv88e6xxx_phy_read(ds, 0x0, 0x1a); | ||
312 | if (ret < 0) | ||
313 | goto error; | ||
314 | |||
315 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5)); | ||
316 | if (ret < 0) | ||
317 | goto error; | ||
318 | |||
319 | /* Wait for temperature to stabilize */ | ||
320 | usleep_range(10000, 12000); | ||
321 | |||
322 | val = mv88e6xxx_phy_read(ds, 0x0, 0x1a); | ||
323 | if (val < 0) { | ||
324 | ret = val; | ||
325 | goto error; | ||
326 | } | ||
327 | |||
328 | /* Disable temperature sensor */ | ||
329 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5)); | ||
330 | if (ret < 0) | ||
331 | goto error; | ||
332 | |||
333 | *temp = ((val & 0x1f) - 5) * 5; | ||
334 | |||
335 | error: | ||
336 | mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0); | ||
337 | mutex_unlock(&ps->phy_mutex); | ||
338 | return ret; | ||
339 | } | ||
340 | #endif /* CONFIG_NET_DSA_HWMON */ | ||
341 | |||
342 | static int mv88e6123_61_65_setup(struct dsa_switch *ds) | 294 | static int mv88e6123_61_65_setup(struct dsa_switch *ds) |
343 | { | 295 | { |
344 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | 296 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
@@ -471,7 +423,7 @@ struct dsa_switch_driver mv88e6123_61_65_switch_driver = { | |||
471 | .get_ethtool_stats = mv88e6123_61_65_get_ethtool_stats, | 423 | .get_ethtool_stats = mv88e6123_61_65_get_ethtool_stats, |
472 | .get_sset_count = mv88e6123_61_65_get_sset_count, | 424 | .get_sset_count = mv88e6123_61_65_get_sset_count, |
473 | #ifdef CONFIG_NET_DSA_HWMON | 425 | #ifdef CONFIG_NET_DSA_HWMON |
474 | .get_temp = mv88e6123_61_65_get_temp, | 426 | .get_temp = mv88e6xxx_get_temp, |
475 | #endif | 427 | #endif |
476 | .get_regs_len = mv88e6xxx_get_regs_len, | 428 | .get_regs_len = mv88e6xxx_get_regs_len, |
477 | .get_regs = mv88e6xxx_get_regs, | 429 | .get_regs = mv88e6xxx_get_regs, |
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c index da558d887dad..cd6807c6b4ed 100644 --- a/drivers/net/dsa/mv88e6xxx.c +++ b/drivers/net/dsa/mv88e6xxx.c | |||
@@ -539,6 +539,54 @@ void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, | |||
539 | } | 539 | } |
540 | } | 540 | } |
541 | 541 | ||
542 | #ifdef CONFIG_NET_DSA_HWMON | ||
543 | |||
544 | int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp) | ||
545 | { | ||
546 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); | ||
547 | int ret; | ||
548 | int val; | ||
549 | |||
550 | *temp = 0; | ||
551 | |||
552 | mutex_lock(&ps->phy_mutex); | ||
553 | |||
554 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6); | ||
555 | if (ret < 0) | ||
556 | goto error; | ||
557 | |||
558 | /* Enable temperature sensor */ | ||
559 | ret = mv88e6xxx_phy_read(ds, 0x0, 0x1a); | ||
560 | if (ret < 0) | ||
561 | goto error; | ||
562 | |||
563 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5)); | ||
564 | if (ret < 0) | ||
565 | goto error; | ||
566 | |||
567 | /* Wait for temperature to stabilize */ | ||
568 | usleep_range(10000, 12000); | ||
569 | |||
570 | val = mv88e6xxx_phy_read(ds, 0x0, 0x1a); | ||
571 | if (val < 0) { | ||
572 | ret = val; | ||
573 | goto error; | ||
574 | } | ||
575 | |||
576 | /* Disable temperature sensor */ | ||
577 | ret = mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5)); | ||
578 | if (ret < 0) | ||
579 | goto error; | ||
580 | |||
581 | *temp = ((val & 0x1f) - 5) * 5; | ||
582 | |||
583 | error: | ||
584 | mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0); | ||
585 | mutex_unlock(&ps->phy_mutex); | ||
586 | return ret; | ||
587 | } | ||
588 | #endif /* CONFIG_NET_DSA_HWMON */ | ||
589 | |||
542 | static int __init mv88e6xxx_init(void) | 590 | static int __init mv88e6xxx_init(void) |
543 | { | 591 | { |
544 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) | 592 | #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131) |
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h index a0780b08bb4c..03e397efde36 100644 --- a/drivers/net/dsa/mv88e6xxx.h +++ b/drivers/net/dsa/mv88e6xxx.h | |||
@@ -81,6 +81,7 @@ void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, | |||
81 | int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port); | 81 | int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port); |
82 | void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, | 82 | void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, |
83 | struct ethtool_regs *regs, void *_p); | 83 | struct ethtool_regs *regs, void *_p); |
84 | int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp); | ||
84 | 85 | ||
85 | extern struct dsa_switch_driver mv88e6131_switch_driver; | 86 | extern struct dsa_switch_driver mv88e6131_switch_driver; |
86 | extern struct dsa_switch_driver mv88e6123_61_65_switch_driver; | 87 | extern struct dsa_switch_driver mv88e6123_61_65_switch_driver; |