<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From mhoffman@lightlink.com Fri Jul 15 18:42:15 2005
Date: Fri, 15 Jul 2005 21:38:08 -0400
From: "Mark M. Hoffman" &lt;mhoffman@lightlink.com&gt;
To: Greg KH &lt;greg@kroah.com&gt;
Cc: Jean Delvare &lt;khali@linux-fr.org&gt;,
	Yani Ioannou &lt;yani.ioannou@gmail.com&gt;,
	lm-sensors &lt;lm-sensors@lm-sensors.org&gt;
Subject: I2C hwmon: hwmon sysfs class
Message-ID: &lt;20050716013808.GC4265@jupiter.solarsys.private&gt;

This patch adds the sysfs class "hwmon" for use by hardware monitoring
(sensors) chip drivers.  It also fixes up the related Kconfig/Makefile
bits.

Signed-off-by: Mark M. Hoffman &lt;mhoffman@lightlink.com&gt;
Signed-off-by: Jean Delvare &lt;khali@linux-fr.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;


---
 drivers/hwmon/Kconfig  |    7 +++
 drivers/hwmon/Makefile |    2 +
 drivers/hwmon/hwmon.c  |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/hwmon.h  |   24 ++++++++++++
 4 files changed, 130 insertions(+), 1 deletion(-)

--- gregkh-2.6.orig/drivers/hwmon/Kconfig	2005-07-13 09:45:05.000000000 -0700
+++ gregkh-2.6/drivers/hwmon/Kconfig	2005-07-26 14:56:41.000000000 -0700
@@ -12,7 +12,12 @@
 	  of a system. Most modern motherboards include such a device. It
 	  can include temperature sensors, voltage sensors, fan speed
 	  sensors and various additional features such as the ability to
-	  control the speed of the fans.
+	  control the speed of the fans.  If you want this support you
+	  should say Y here and also to the specific driver(s) for your
+	  sensors chip(s) below.
+
+	  This support can also be built as a module.  If so, the module
+	  will be called hwmon.
 
 config SENSORS_ADM1021
 	tristate "Analog Devices ADM1021 and compatibles"
--- gregkh-2.6.orig/drivers/hwmon/Makefile	2005-07-13 09:45:05.000000000 -0700
+++ gregkh-2.6/drivers/hwmon/Makefile	2005-07-26 14:56:41.000000000 -0700
@@ -2,6 +2,8 @@
 # Makefile for sensor chip drivers.
 #
 
+obj-$(CONFIG_HWMON)		+= hwmon.o
+
 # asb100, then w83781d go first, as they can override other drivers' addresses.
 obj-$(CONFIG_SENSORS_ASB100)	+= asb100.o
 obj-$(CONFIG_SENSORS_W83627HF)	+= w83627hf.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gregkh-2.6/drivers/hwmon/hwmon.c	2005-07-26 14:56:41.000000000 -0700
@@ -0,0 +1,98 @@
+/*
+    hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring
+
+    This file defines the sysfs class "hwmon", for use by sensors drivers.
+
+    Copyright (C) 2005 Mark M. Hoffman &lt;mhoffman@lightlink.com&gt;
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; version 2 of the License.
+*/
+
+#include &lt;linux/module.h&gt;
+#include &lt;linux/device.h&gt;
+#include &lt;linux/err.h&gt;
+#include &lt;linux/kdev_t.h&gt;
+#include &lt;linux/idr.h&gt;
+#include &lt;linux/hwmon.h&gt;
+
+#define HWMON_ID_PREFIX "hwmon"
+#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
+
+static struct class *hwmon_class;
+
+static DEFINE_IDR(hwmon_idr);
+
+/**
+ * hwmon_device_register - register w/ hwmon sysfs class
+ * @dev: the device to register
+ *
+ * hwmon_device_unregister() must be called when the class device is no
+ * longer needed.
+ *
+ * Returns the pointer to the new struct class device.
+ */
+struct class_device *hwmon_device_register(struct device *dev)
+{
+	struct class_device *cdev;
+	int id;
+
+	if (idr_pre_get(&amp;hwmon_idr, GFP_KERNEL) == 0)
+		return ERR_PTR(-ENOMEM);
+
+	if (idr_get_new(&amp;hwmon_idr, NULL, &amp;id) &lt; 0)
+		return ERR_PTR(-ENOMEM);
+
+	id = id &amp; MAX_ID_MASK;
+	cdev = class_device_create(hwmon_class, MKDEV(0,0), dev,
+					HWMON_ID_FORMAT, id);
+
+	if (IS_ERR(cdev))
+		idr_remove(&amp;hwmon_idr, id);
+
+	return cdev;
+}
+
+/**
+ * hwmon_device_unregister - removes the previously registered class device
+ *
+ * @cdev: the class device to destroy
+ */
+void hwmon_device_unregister(struct class_device *cdev)
+{
+	int id;
+
+	if (sscanf(cdev-&gt;class_id, HWMON_ID_FORMAT, &amp;id) == 1) {
+		class_device_unregister(cdev);
+		idr_remove(&amp;hwmon_idr, id);
+	} else
+		dev_dbg(cdev-&gt;dev,
+			"hwmon_device_unregister() failed: bad class ID!\n");
+}
+
+static int __init hwmon_init(void)
+{
+	hwmon_class = class_create(THIS_MODULE, "hwmon");
+	if (IS_ERR(hwmon_class)) {
+		printk(KERN_ERR "hwmon.c: couldn't create sysfs class\n");
+		return PTR_ERR(hwmon_class);
+	}
+	return 0;
+}
+
+static void __exit hwmon_exit(void)
+{
+	class_destroy(hwmon_class);
+}
+
+module_init(hwmon_init);
+module_exit(hwmon_exit);
+
+EXPORT_SYMBOL_GPL(hwmon_device_register);
+EXPORT_SYMBOL_GPL(hwmon_device_unregister);
+
+MODULE_AUTHOR("Mark M. Hoffman &lt;mhoffman@lightlink.com&gt;");
+MODULE_DESCRIPTION("hardware monitoring sysfs/class support");
+MODULE_LICENSE("GPL");
+
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gregkh-2.6/include/linux/hwmon.h	2005-07-26 14:56:41.000000000 -0700
@@ -0,0 +1,24 @@
+/*
+    hwmon.h - part of lm_sensors, Linux kernel modules for hardware monitoring
+
+    This file declares helper functions for the sysfs class "hwmon",
+    for use by sensors drivers.
+
+    Copyright (C) 2005 Mark M. Hoffman &lt;mhoffman@lightlink.com&gt;
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; version 2 of the License.
+*/
+
+#ifndef _HWMON_H_
+#define _HWMON_H_
+
+#include &lt;linux/device.h&gt;
+
+struct class_device *hwmon_device_register(struct device *dev);
+
+void hwmon_device_unregister(struct class_device *cdev);
+
+#endif
+
</pre></body></html>