From: Guenter Roeck <linux@roeck-us.net>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
linux-kernel@vger.kernel.org, Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v3 07/15] net: dsa/mv88e6352: Report chip temperature
Date: Wed, 29 Oct 2014 10:44:59 -0700 [thread overview]
Message-ID: <1414604707-22407-8-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1414604707-22407-1-git-send-email-linux@roeck-us.net>
MV88E6352 supports reading the chip temperature from two PHY registers,
6:26 and 6:27. Report it using the more accurate register 6:27.
Also report temperature limit and alarm.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3:
- No change
v2:
- Make new functionality optional, depending on CONFIG_NET_DSA_HWMON
drivers/net/dsa/mv88e6352.c | 101 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index f17364f..744e6fa 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -325,6 +325,101 @@ static int mv88e6352_setup_port(struct dsa_switch *ds, int p)
return 0;
}
+#ifdef CONFIG_NET_DSA_HWMON
+
+static int mv88e6352_phy_page_read(struct dsa_switch *ds,
+ int port, int page, int reg)
+{
+ struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ int ret;
+
+ mutex_lock(&ps->phy_mutex);
+ ret = __mv88e6352_phy_write(ds, port, 0x16, page);
+ if (ret < 0)
+ goto error;
+ ret = __mv88e6352_phy_read(ds, port, reg);
+error:
+ __mv88e6352_phy_write(ds, port, 0x16, 0x0);
+ mutex_unlock(&ps->phy_mutex);
+ return ret;
+}
+
+static int mv88e6352_phy_page_write(struct dsa_switch *ds,
+ int port, int page, int reg, int val)
+{
+ struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+ int ret;
+
+ mutex_lock(&ps->phy_mutex);
+ ret = __mv88e6352_phy_write(ds, port, 0x16, page);
+ if (ret < 0)
+ goto error;
+
+ ret = __mv88e6352_phy_write(ds, port, reg, val);
+error:
+ __mv88e6352_phy_write(ds, port, 0x16, 0x0);
+ mutex_unlock(&ps->phy_mutex);
+ return ret;
+}
+
+static int mv88e6352_get_temp(struct dsa_switch *ds, int *temp)
+{
+ int ret;
+
+ *temp = 0;
+
+ ret = mv88e6352_phy_page_read(ds, 0, 6, 27);
+ if (ret < 0)
+ return ret;
+
+ *temp = (ret & 0xff) - 25;
+
+ return 0;
+}
+
+static int mv88e6352_get_temp_limit(struct dsa_switch *ds, int *temp)
+{
+ int ret;
+
+ *temp = 0;
+
+ ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
+ if (ret < 0)
+ return ret;
+
+ *temp = (((ret >> 8) & 0x1f) * 5) - 25;
+
+ return 0;
+}
+
+static int mv88e6352_set_temp_limit(struct dsa_switch *ds, int temp)
+{
+ int ret;
+
+ ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
+ if (ret < 0)
+ return ret;
+ temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
+ return mv88e6352_phy_page_write(ds, 0, 6, 26,
+ (ret & 0xe0ff) | (temp << 8));
+}
+
+static int mv88e6352_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
+{
+ int ret;
+
+ *alarm = false;
+
+ ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
+ if (ret < 0)
+ return ret;
+
+ *alarm = !!(ret & 0x40);
+
+ return 0;
+}
+#endif /* CONFIG_NET_DSA_HWMON */
+
static int mv88e6352_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
@@ -461,6 +556,12 @@ struct dsa_switch_driver mv88e6352_switch_driver = {
.get_strings = mv88e6352_get_strings,
.get_ethtool_stats = mv88e6352_get_ethtool_stats,
.get_sset_count = mv88e6352_get_sset_count,
+#ifdef CONFIG_NET_DSA_HWMON
+ .get_temp = mv88e6352_get_temp,
+ .get_temp_limit = mv88e6352_get_temp_limit,
+ .set_temp_limit = mv88e6352_set_temp_limit,
+ .get_temp_alarm = mv88e6352_get_temp_alarm,
+#endif
};
MODULE_ALIAS("platform:mv88e6352");
--
1.9.1
next prev parent reply other threads:[~2014-10-29 17:44 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 17:44 [PATCH v3 00/15] net: dsa: Fixes and enhancements Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 01/15] net: dsa: Don't set skb->protocol on outgoing tagged packets Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 02/15] net: dsa: Report known silicon revisions for Marvell 88E6060 Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 03/15] net: dsa: Report known silicon revisions for Marvell 88E6131 Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 04/15] net: dsa: Add support for Marvell 88E6352 Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 05/15] net: dsa/mv88e6352: Add support for MV88E6176 Guenter Roeck
2014-10-29 17:44 ` [PATCH v3 06/15] net: dsa: Add support for reporting switch chip temperatures Guenter Roeck
2014-10-29 17:44 ` Guenter Roeck [this message]
2014-10-29 17:45 ` [PATCH v3 08/15] net: dsa/mv88e6123_61_65: Report chip temperature Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 09/15] net: dsa: Add support for switch EEPROM access Guenter Roeck
2014-10-30 21:11 ` Andrew Lunn
2014-10-30 22:39 ` Guenter Roeck
2014-10-31 1:00 ` Guenter Roeck
2014-10-31 2:40 ` Andrew Lunn
2014-10-31 2:53 ` Guenter Roeck
2014-10-31 3:43 ` David Miller
2014-10-29 17:45 ` [PATCH v3 10/15] dsa: Add new optional devicetree property to describe EEPROM size Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 11/15] net: dsa/mv88e6352: Implement EEPROM access functions Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 12/15] net: dsa: Add support for reading switch registers with ethtool Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 13/15] net: dsa/mv88e6123_61_65: Add support for reading switch registers Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 14/15] net: dsa/mv88e6352: " Guenter Roeck
2014-10-29 17:45 ` [PATCH v3 15/15] net: dsa: Provide additional RMON statistics Guenter Roeck
2014-10-29 18:22 ` [PATCH v3 00/15] net: dsa: Fixes and enhancements Florian Fainelli
2014-10-29 21:39 ` Guenter Roeck
2014-10-30 18:54 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414604707-22407-8-git-send-email-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).