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 06/14] net: dsa: Add support for hardware monitoring
Date: Wed, 22 Oct 2014 21:03:14 -0700 [thread overview]
Message-ID: <1414037002-25528-7-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1414037002-25528-1-git-send-email-linux@roeck-us.net>
Some Marvell switches provide chip temperature data.
Add support for reporting it to the dsa infrastructure.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
include/net/dsa.h | 6 +++
net/dsa/dsa.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index b765592..d8b3057 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -242,6 +242,12 @@ struct dsa_switch_driver {
struct ethtool_eee *e);
int (*get_eee)(struct dsa_switch *ds, int port,
struct ethtool_eee *e);
+
+ /* Hardware monitoring */
+ int (*get_temp)(struct dsa_switch *ds, int *temp);
+ int (*get_temp_limit)(struct dsa_switch *ds, int *temp);
+ int (*set_temp_limit)(struct dsa_switch *ds, int temp);
+ int (*get_temp_alarm)(struct dsa_switch *ds, bool *alarm);
};
void register_switch_driver(struct dsa_switch_driver *type);
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 22f34cf..6567c8e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -9,6 +9,8 @@
* (at your option) any later version.
*/
+#include <linux/device.h>
+#include <linux/hwmon.h>
#include <linux/list.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
@@ -17,6 +19,7 @@
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_platform.h>
+#include <linux/sysfs.h>
#include "dsa_priv.h"
char dsa_driver_version[] = "0.1";
@@ -71,6 +74,104 @@ dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
return ret;
}
+/* hwmon support ************************************************************/
+
+#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
+
+static ssize_t temp1_input_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dsa_switch *ds = dev_get_drvdata(dev);
+ int temp, ret;
+
+ ret = ds->drv->get_temp(ds, &temp);
+ if (ret < 0)
+ return ret;
+
+ return sprintf(buf, "%d\n", temp * 1000);
+}
+static DEVICE_ATTR_RO(temp1_input);
+
+static ssize_t temp1_max_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dsa_switch *ds = dev_get_drvdata(dev);
+ int temp, ret;
+
+ ret = ds->drv->get_temp_limit(ds, &temp);
+ if (ret < 0)
+ return ret;
+
+ return sprintf(buf, "%d\n", temp * 1000);
+}
+
+static ssize_t temp1_max_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ struct dsa_switch *ds = dev_get_drvdata(dev);
+ int temp, ret;
+
+ ret = kstrtoint(buf, 0, &temp);
+ if (ret < 0)
+ return ret;
+
+ ret = ds->drv->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+static DEVICE_ATTR(temp1_max, S_IRUGO, temp1_max_show, temp1_max_store);
+
+static ssize_t temp1_max_alarm_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dsa_switch *ds = dev_get_drvdata(dev);
+ bool alarm;
+ int ret;
+
+ ret = ds->drv->get_temp_alarm(ds, &alarm);
+ if (ret < 0)
+ return ret;
+
+ return sprintf(buf, "%d\n", alarm);
+}
+static DEVICE_ATTR_RO(temp1_max_alarm);
+
+static struct attribute *dsa_hwmon_attrs[] = {
+ &dev_attr_temp1_input.attr, /* 0 */
+ &dev_attr_temp1_max.attr, /* 1 */
+ &dev_attr_temp1_max_alarm.attr, /* 2 */
+ NULL
+};
+
+static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj,
+ struct attribute *attr, int index)
+{
+ struct device *dev = container_of(kobj, struct device, kobj);
+ struct dsa_switch *ds = dev_get_drvdata(dev);
+ struct dsa_switch_driver *drv = ds->drv;
+ umode_t mode = attr->mode;
+
+ if (index == 1) {
+ if (!drv->get_temp_limit)
+ mode = 0;
+ else if (drv->set_temp_limit)
+ mode |= S_IWUSR;
+ } else if (index == 2 && !drv->get_temp_alarm) {
+ mode = 0;
+ }
+ return mode;
+}
+
+static const struct attribute_group dsa_hwmon_group = {
+ .attrs = dsa_hwmon_attrs,
+ .is_visible = dsa_hwmon_attrs_visible,
+};
+__ATTRIBUTE_GROUPS(dsa_hwmon);
+
+#endif /* CONFIG_HWMON */
/* basic switch operations **************************************************/
static struct dsa_switch *
@@ -225,6 +326,16 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
ds->ports[i] = slave_dev;
}
+#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
+ /* If the switch provides a temperature sensor,
+ * register with hardware monitoring subsystem.
+ * Treat registration error as non-fatal and ignore it.
+ */
+ if (drv->get_temp)
+ devm_hwmon_device_register_with_groups(parent, "dsa", ds,
+ dsa_hwmon_groups);
+#endif
+
return ds;
out_free:
--
1.9.1
next prev parent reply other threads:[~2014-10-23 4:03 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-23 4:03 [PATCH 00/14] net: dsa: Fixes and enhancements Guenter Roeck
2014-10-23 4:03 ` [PATCH 01/14] net: dsa: Don't set skb->protocol on outgoing tagged packets Guenter Roeck
2014-10-23 4:03 ` [PATCH 02/14] net: dsa: Report known silicon revisions for Marvell 88E6060 Guenter Roeck
2014-10-23 12:51 ` Sergei Shtylyov
2014-10-23 13:20 ` Guenter Roeck
2014-10-23 16:00 ` Sergei Shtylyov
2014-10-23 4:03 ` [PATCH 03/14] net: dsa: Report known silicon revisions for Marvell 88E6131 Guenter Roeck
2014-10-23 4:03 ` [PATCH 04/14] net: dsa: Add support for Marvell 88E6352 Guenter Roeck
2014-10-23 4:03 ` [PATCH 05/14] net: dsa/mv88e6352: Add support for MV88E6176 Guenter Roeck
2014-10-23 4:03 ` Guenter Roeck [this message]
2014-10-23 4:37 ` [PATCH 06/14] net: dsa: Add support for hardware monitoring Florian Fainelli
2014-10-23 5:06 ` Guenter Roeck
2014-10-23 8:24 ` Richard Cochran
2014-10-23 13:27 ` Guenter Roeck
2014-10-23 13:47 ` Andrew Lunn
2014-10-23 16:27 ` Guenter Roeck
2014-10-23 16:54 ` Andrew Lunn
2014-10-23 17:38 ` Guenter Roeck
2014-10-23 18:03 ` Andrew Lunn
2014-10-23 18:43 ` Guenter Roeck
2014-10-23 19:55 ` Andrew Lunn
2014-10-24 13:53 ` Guenter Roeck
2014-10-24 16:19 ` Guenter Roeck
2014-10-25 14:01 ` Andrew Lunn
2014-10-25 17:23 ` Florian Fainelli
2014-10-25 18:00 ` Andrew Lunn
2014-10-26 15:57 ` Guenter Roeck
2014-10-25 17:26 ` Florian Fainelli
2014-10-25 19:44 ` Guenter Roeck
2014-10-24 5:03 ` David Miller
2014-10-24 5:40 ` Guenter Roeck
2014-10-24 6:10 ` David Miller
2014-10-24 12:52 ` Florian Fainelli
2014-10-24 6:09 ` Guenter Roeck
2014-10-23 4:03 ` [PATCH 07/14] net: dsa/mv88e6352: Report chip temperature Guenter Roeck
2014-10-23 4:03 ` [PATCH 08/14] net: dsa/mv88e6123_61_65: " Guenter Roeck
2014-10-23 4:03 ` [PATCH 09/14] net: dsa: Add support for switch EEPROM access Guenter Roeck
2014-10-23 4:03 ` [PATCH 10/14] net: dsa/mv88e6352: Implement EEPROM access functions Guenter Roeck
2014-10-23 13:54 ` Andrew Lunn
2014-10-23 16:40 ` Guenter Roeck
2014-10-23 18:41 ` [PATCH 10/14] net: dsa/mv88e6352: Implement EEPROM accessfunctions Chris Healy
2014-10-23 18:55 ` Florian Fainelli
2014-10-24 3:59 ` Guenter Roeck
2014-10-23 4:03 ` [PATCH 11/14] net: dsa: Add support for reading switch registers with ethtool Guenter Roeck
2014-10-23 4:40 ` Florian Fainelli
2014-10-23 5:21 ` Guenter Roeck
2014-10-23 4:03 ` [PATCH 12/14] net: dsa/mv88e6123_61_65: Add support for reading switch registers Guenter Roeck
2014-10-23 4:03 ` [PATCH 13/14] net: dsa/mv88e6352: " Guenter Roeck
2014-10-23 4:03 ` [PATCH 14/14] net: dsa: Provide additional RMON statistics Guenter Roeck
2014-10-23 4:45 ` [PATCH 00/14] net: dsa: Fixes and enhancements Florian Fainelli
2014-10-23 5:22 ` Guenter Roeck
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=1414037002-25528-7-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).