Subject: i2c: modify sensors drivers to use sysfs class 'hwmon'

From: "Mark M. Hoffman" <[email-masked]>
Date: Wed, 1 Jun 2005 23:37:27 -0400

This patch modifies sensors chip drivers to make use of the new
sysfs class "hwmon".

Signed-off-by: Mark M. Hoffman <[email-masked]>
Signed-off-by: Greg Kroah-Hartman <[email-masked]>

---
 drivers/i2c/chips/adm1021.c    |   15 +++++++++++++++
 drivers/i2c/chips/adm1025.c    |   15 +++++++++++++++
 drivers/i2c/chips/adm1026.c    |   14 ++++++++++++++
 drivers/i2c/chips/adm1031.c    |   15 +++++++++++++++
 drivers/i2c/chips/adm9240.c    |   16 ++++++++++++++++
 drivers/i2c/chips/asb100.c     |   17 +++++++++++++++++
 drivers/i2c/chips/ds1621.c     |   15 +++++++++++++++
 drivers/i2c/chips/fscher.c     |   15 +++++++++++++++
 drivers/i2c/chips/fscpos.c     |   15 +++++++++++++++
 drivers/i2c/chips/gl518sm.c    |   15 +++++++++++++++
 drivers/i2c/chips/gl520sm.c    |   15 +++++++++++++++
 drivers/i2c/chips/it87.c       |   16 +++++++++++++++-
 drivers/i2c/chips/lm63.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm75.c       |   14 ++++++++++++++
 drivers/i2c/chips/lm77.c       |   15 ++++++++++++++-
 drivers/i2c/chips/lm78.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm80.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm83.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm85.c       |   14 ++++++++++++++
 drivers/i2c/chips/lm87.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm90.c       |   15 +++++++++++++++
 drivers/i2c/chips/lm92.c       |   16 +++++++++++++++-
 drivers/i2c/chips/max1619.c    |   16 +++++++++++++++-
 drivers/i2c/chips/pc87360.c    |   15 +++++++++++++++
 drivers/i2c/chips/sis5595.c    |   17 ++++++++++++++++-
 drivers/i2c/chips/smsc47b397.c |   15 +++++++++++++++
 drivers/i2c/chips/smsc47m1.c   |   16 ++++++++++++++++
 drivers/i2c/chips/via686a.c    |   23 +++++++++++++++++++----
 drivers/i2c/chips/w83627ehf.c  |   15 +++++++++++++++
 drivers/i2c/chips/w83627hf.c   |   15 +++++++++++++++
 drivers/i2c/chips/w83781d.c    |   23 +++++++++++++++++++++++
 drivers/i2c/chips/w83l785ts.c  |   15 +++++++++++++++
 include/linux/i2c.h            |    1 +
 33 files changed, 494 insertions(+), 9 deletions(-)

--- gregkh-2.6.orig/drivers/i2c/chips/adm1021.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/adm1021.c	2005-06-05 23:27:07.000000000 -0700
@@ -25,6 +25,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>

 /* Addresses to scan */
@@ -37,6 +39,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066);
 
+static int id;	/* increment once for every chip found */
+
 /* adm1021 constants specified below */
 
 /* The adm1021 registers */
@@ -295,6 +299,13 @@
 		adm1021_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto error2;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_max);
 	device_create_file(&new_client->dev, &dev_attr_temp1_min);
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
@@ -305,6 +316,8 @@
 
 	return 0;
 
+error2:
+	i2c_detach_client(new_client);
 error1:
 	kfree(data);
 error0:
@@ -324,6 +337,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
 		return err;
--- gregkh-2.6.orig/drivers/i2c/chips/adm1025.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/adm1025.c	2005-06-05 23:27:07.000000000 -0700
@@ -52,6 +52,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -68,6 +70,8 @@
 
 SENSORS_INSMOD_2(adm1025, ne1619);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The ADM1025 registers
  */
@@ -416,6 +420,13 @@
 	adm1025_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
 	device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -452,6 +463,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -504,6 +517,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/adm1026.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/adm1026.c	2005-06-05 23:27:07.000000000 -0700
@@ -31,6 +31,8 @@
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-sysfs.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -62,6 +64,8 @@
 module_param_array(gpio_fan,int,NULL,0);
 MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
 
+static int id;	/* increment once for every chip found */
+
 /* Many ADM1026 constants specified below */
 
 /* The ADM1026 registers */
@@ -324,6 +328,7 @@
 
 int adm1026_detach_client(struct i2c_client *client)
 {
+	hwmon_device_unregister(client->class_dev);
 	i2c_detach_client(client);
 	kfree(client);
 	return 0;
@@ -1555,6 +1560,13 @@
 	adm1026_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exitdetach;
+	}
+
 	device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
 	device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
 	device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
@@ -1690,6 +1702,8 @@
 	return 0;
 
 	/* Error out and cleanup code */
+exitdetach:
+	i2c_detach_client(new_client);
 exitfree:
 	kfree(new_client);
 exit:
--- gregkh-2.6.orig/drivers/i2c/chips/adm1031.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/adm1031.c	2005-06-05 23:27:07.000000000 -0700
@@ -27,6 +27,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Following macros takes channel parameter starting from 0 to 2 */
 #define ADM1031_REG_FAN_SPEED(nr)	(0x08 + (nr))
@@ -64,6 +66,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_2(adm1030, adm1031);
 
+static int id;	/* increment once for every chip found */
+
 typedef u8 auto_chan_table_t[8][2];
 
 /* Each client has this additional data */
@@ -788,6 +792,13 @@
 	adm1031_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_fan1_input);
 	device_create_file(&new_client->dev, &dev_attr_fan1_div);
 	device_create_file(&new_client->dev, &dev_attr_fan1_min);
@@ -833,6 +844,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(new_client);
 exit:
@@ -842,6 +855,8 @@
 static int adm1031_detach_client(struct i2c_client *client)
 {
 	int ret;
+
+	hwmon_device_unregister(client->class_dev);
 	if ((ret = i2c_detach_client(client)) != 0) {
 		return ret;
 	}
--- gregkh-2.6.orig/drivers/i2c/chips/adm9240.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/adm9240.c	2005-06-05 23:27:07.000000000 -0700
@@ -47,6 +47,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
@@ -57,6 +59,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_3(adm9240, ds1780, lm81);
 
+static int id;	/* increment once for every chip found */
+
 /* ADM9240 registers */
 #define ADM9240_REG_MAN_ID		0x3e
 #define ADM9240_REG_DIE_REV		0x3f
@@ -582,6 +586,13 @@
 	adm9240_init_client(new_client);
 
 	/* populate sysfs filesystem */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in0_min);
 	device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -615,6 +626,9 @@
 	device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
 
 	return 0;
+
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(new_client);
 exit:
@@ -632,6 +646,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 				"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/asb100.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/asb100.c	2005-06-05 23:27:07.000000000 -0700
@@ -41,6 +41,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <linux/jiffies.h>
 #include "lm75.h"
@@ -62,6 +64,8 @@
 I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
 	"{bus, clientaddr, subclientaddr1, subclientaddr2}");
 
+static int id;	/* increment once for every chip found */
+
 /* Voltage IN registers 0-6 */
 #define ASB100_REG_IN(nr)	(0x20 + (nr))
 #define ASB100_REG_IN_MAX(nr)	(0x2b + (nr * 2))
@@ -821,6 +825,13 @@
 	data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
 
 	/* Register sysfs hooks */
+        new_client->class_dev = hwmon_device_register(&new_client->dev,
+                "%s-%d", new_client->name, id++);
+        if (IS_ERR(new_client->class_dev)) {
+                err = PTR_ERR(new_client->class_dev);
+                goto ERROR3;
+        }
+
 	device_create_file_in(new_client, 0);
 	device_create_file_in(new_client, 1);
 	device_create_file_in(new_client, 2);
@@ -847,6 +858,10 @@
 
 	return 0;
 
+ERROR3:
+	i2c_detach_client(data->lm75[0]);
+	kfree(data->lm75[1]);
+	kfree(data->lm75[0]);
 ERROR2:
 	i2c_detach_client(new_client);
 ERROR1:
@@ -859,6 +874,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "client deregistration failed; "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/ds1621.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/ds1621.c	2005-06-05 23:27:07.000000000 -0700
@@ -27,6 +27,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include "lm75.h"
 
 /* Addresses to scan */
@@ -40,6 +42,8 @@
 module_param(polarity, int, 0);
 MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
 
+static int id;	/* increment once for every chip found */
+
 /* Many DS1621 constants specified below */
 /* Config register used for detection         */
 /*  7    6    5    4    3    2    1    0      */
@@ -250,6 +254,13 @@
 	ds1621_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_alarms);
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 	device_create_file(&new_client->dev, &dev_attr_temp1_min);
@@ -259,6 +270,8 @@
 
 /* OK, this is not exactly good programming practice, usually. But it is
    very code-efficient in this case. */
+      exit_detach:
+	i2c_detach_client(new_client);
       exit_free:
 	kfree(data);
       exit:
@@ -269,6 +282,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/fscher.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/fscher.c	2005-06-05 23:27:07.000000000 -0700
@@ -32,6 +32,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -46,6 +48,8 @@
 
 SENSORS_INSMOD_1(fscher);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The FSCHER registers
  */
@@ -341,6 +345,13 @@
 	fscher_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file_revision(new_client);
 	device_create_file_alarms(new_client);
 	device_create_file_control(new_client);
@@ -360,6 +371,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -370,6 +383,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/fscpos.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/fscpos.c	2005-06-05 23:27:07.000000000 -0700
@@ -35,6 +35,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/init.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -47,6 +49,8 @@
  */
 SENSORS_INSMOD_1(fscpos);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The FSCPOS registers
  */
@@ -495,6 +499,13 @@
 	dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_event);
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
@@ -525,6 +536,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -535,6 +548,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, client"
 							" not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/gl518sm.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/gl518sm.c	2005-06-05 23:27:07.000000000 -0700
@@ -42,6 +42,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -50,6 +52,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80);
 
+static int id;	/* increment once for every chip found */
+
 /* Many GL518 constants specified below */
 
 /* The GL518 registers */
@@ -419,6 +423,13 @@
 	gl518_init_client((struct i2c_client *) new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
 	device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -450,6 +461,8 @@
 /* OK, this is not exactly good programming practice, usually. But it is
    very code-efficient in this case. */
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -479,6 +492,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/gl520sm.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/gl520sm.c	2005-06-05 23:27:07.000000000 -0700
@@ -27,6 +27,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Type of the extra sensor */
 static unsigned short extra_sensor_type;
@@ -40,6 +42,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(gl520sm);
 
+static int id;	/* increment once for each chip found */
+
 /* Many GL520 constants specified below 
 One of the inputs can be configured as either temp or voltage.
 That's why _TEMP2 and _IN4 access the same register 
@@ -570,6 +574,13 @@
 	gl520_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file_vid(new_client, 0);
 
 	device_create_file_in(new_client, 0);
@@ -591,6 +602,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -640,6 +653,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/it87.c	2005-06-05 23:26:51.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/it87.c	2005-06-05 23:28:05.000000000 -0700
@@ -39,9 +39,10 @@
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-sysfs.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 
-
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
 					0x2e, 0x2f, I2C_CLIENT_END };
@@ -50,6 +51,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_2(it87, it8712);
 
+static int id;	/* increment once for every chip found */
+
 #define	REG	0x2e	/* The register to read/write */
 #define	DEV	0x07	/* Register: Logical device select */
 #define	VAL	0x2f	/* The value to read/write */
@@ -840,6 +843,13 @@
 	it87_init_client(new_client, data);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR3;
+	}
+
 	device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
 	device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
 	device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
@@ -904,6 +914,8 @@
 
 	return 0;
 
+ERROR3:
+	i2c_detach_client(new_client);
 ERROR2:
 	kfree(data);
 ERROR1:
@@ -917,6 +929,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 			"Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm63.c	2005-06-05 23:26:50.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm63.c	2005-06-05 23:28:54.000000000 -0700
@@ -44,6 +44,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-sysfs.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -59,6 +61,8 @@
 
 SENSORS_INSMOD_1(lm63);
 
+static int id;	/* increment once for each chip found */
+
 /*
  * The LM63 registers
  */
@@ -437,6 +441,13 @@
 	lm63_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	if (data->config & 0x04) { /* tachometer enabled */
 		device_create_file(&new_client->dev,
 				   &sensor_dev_attr_fan1_input.dev_attr);
@@ -462,6 +473,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -507,6 +520,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm75.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm75.c	2005-06-05 23:27:07.000000000 -0700
@@ -24,6 +24,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include "lm75.h"

@@ -35,6 +37,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(lm75);
 
+static int id;	/* increment once for every chip found */
+
 /* Many LM75 constants specified below */
 
 /* The LM75 registers */
@@ -208,12 +212,21 @@
 	lm75_init_client(new_client);
 	
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_max);
 	device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -222,6 +235,7 @@
 
 static int lm75_detach_client(struct i2c_client *client)
 {
+	hwmon_device_unregister(client->class_dev);
 	i2c_detach_client(client);
 	kfree(i2c_get_clientdata(client));
 	return 0;
--- gregkh-2.6.orig/drivers/i2c/chips/lm77.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm77.c	2005-06-05 23:27:07.000000000 -0700
@@ -31,7 +31,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
-
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END };
@@ -40,6 +41,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(lm77);
 
+static int id;	/* increment once for every chip found */
+
 /* The LM77 registers */
 #define LM77_REG_TEMP		0x00
 #define LM77_REG_CONF		0x01
@@ -317,6 +320,13 @@
 	lm77_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 	device_create_file(&new_client->dev, &dev_attr_temp1_crit);
 	device_create_file(&new_client->dev, &dev_attr_temp1_min);
@@ -327,6 +337,8 @@
 	device_create_file(&new_client->dev, &dev_attr_alarms);
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -335,6 +347,7 @@
 
 static int lm77_detach_client(struct i2c_client *client)
 {
+	hwmon_device_unregister(client->class_dev);
 	i2c_detach_client(client);
 	kfree(i2c_get_clientdata(client));
 	return 0;
--- gregkh-2.6.orig/drivers/i2c/chips/lm78.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm78.c	2005-06-05 23:27:07.000000000 -0700
@@ -24,6 +24,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 
 /* Addresses to scan */
@@ -36,6 +38,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_3(lm78, lm78j, lm79);
 
+static int id;	/* increment once for every chip found */
+
 /* Many LM78 constants specified below */
 
 /* Length of ISA address segment */
@@ -605,6 +609,13 @@
 	}
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR3;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in0_min);
 	device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -643,6 +654,8 @@
 
 	return 0;
 
+ERROR3:
+	i2c_detach_client(new_client);
 ERROR2:
 	kfree(data);
 ERROR1:
@@ -656,6 +669,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		    "Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm80.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm80.c	2005-06-05 23:27:07.000000000 -0700
@@ -27,6 +27,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
@@ -36,6 +38,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(lm80);
 
+static int id;	/* increment once for every chip found */
+
 /* Many LM80 constants specified below */
 
 /* The LM80 registers */
@@ -451,6 +455,13 @@
 	data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto error_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_min);
 	device_create_file(&new_client->dev, &dev_attr_in1_min);
 	device_create_file(&new_client->dev, &dev_attr_in2_min);
@@ -487,6 +498,8 @@
 
 	return 0;
 
+error_detach:
+	i2c_detach_client(new_client);
 error_free:
 	kfree(data);
 exit:
@@ -497,6 +510,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm83.c	2005-06-05 23:26:50.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm83.c	2005-06-05 23:29:29.000000000 -0700
@@ -34,6 +34,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-sysfs.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -53,6 +55,8 @@
 
 SENSORS_INSMOD_1(lm83);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The LM83 registers
  * Manufacturer ID is 0x01 for National Semiconductor.
@@ -312,6 +316,13 @@
 	 */
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev,
 			   &sensor_dev_attr_temp1_input.dev_attr);
 	device_create_file(&new_client->dev,
@@ -340,6 +351,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -350,6 +363,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		    "Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm85.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm85.c	2005-06-05 23:27:07.000000000 -0700
@@ -30,6 +30,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -38,6 +40,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
 
+static int id;	/* increment once for every chip found */
+
 /* The LM85 registers */
 
 #define	LM85_REG_IN(nr)			(0x20 + (nr))
@@ -1166,6 +1170,13 @@
 	lm85_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR2;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_fan1_input);
 	device_create_file(&new_client->dev, &dev_attr_fan2_input);
 	device_create_file(&new_client->dev, &dev_attr_fan3_input);
@@ -1235,6 +1246,8 @@
 	return 0;
 
 	/* Error out and cleanup code */
+    ERROR2:
+	i2c_detach_client(new_client);
     ERROR1:
 	kfree(data);
     ERROR0:
@@ -1243,6 +1256,7 @@
 
 int lm85_detach_client(struct i2c_client *client)
 {
+	hwmon_device_unregister(client->class_dev);
 	i2c_detach_client(client);
 	kfree(i2c_get_clientdata(client));
 	return 0;
--- gregkh-2.6.orig/drivers/i2c/chips/lm87.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm87.c	2005-06-05 23:27:07.000000000 -0700
@@ -59,6 +59,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -74,6 +76,8 @@
 
 SENSORS_INSMOD_1(lm87);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The LM87 registers
  */
@@ -608,6 +612,13 @@
 	data->in_scale[7] = 1875;
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_min);
 	device_create_file(&new_client->dev, &dev_attr_in1_max);
@@ -673,6 +684,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -721,6 +734,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm90.c	2005-06-05 23:26:50.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm90.c	2005-06-05 23:30:07.000000000 -0700
@@ -77,6 +77,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-sysfs.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
@@ -97,6 +99,8 @@
 
 SENSORS_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The LM90 registers
  */
@@ -500,6 +504,13 @@
 	lm90_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev,
 			   &sensor_dev_attr_temp1_input.dev_attr);
 	device_create_file(&new_client->dev,
@@ -524,6 +535,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -549,6 +562,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/lm92.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/lm92.c	2005-06-05 23:27:07.000000000 -0700
@@ -45,7 +45,8 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
-
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* The LM92 and MAX6635 have 2 two-state pins for address selection,
    resulting in 4 possible addresses. */
@@ -56,6 +57,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(lm92);
 
+static int id;	/* increment once for every chip found */
+
 /* The LM92 registers */
 #define LM92_REG_CONFIG			0x01 /* 8-bit, RW */
 #define LM92_REG_TEMP			0x00 /* 16-bit, RO */
@@ -359,6 +362,13 @@
 	lm92_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 	device_create_file(&new_client->dev, &dev_attr_temp1_crit);
 	device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
@@ -370,6 +380,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -387,6 +399,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/max1619.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/max1619.c	2005-06-05 23:27:07.000000000 -0700
@@ -32,7 +32,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
-
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
 					0x29, 0x2a, 0x2b,
@@ -46,6 +47,8 @@
 
 SENSORS_INSMOD_1(max1619);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The MAX1619 registers
  */
@@ -275,6 +278,13 @@
 	max1619_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 	device_create_file(&new_client->dev, &dev_attr_temp2_input);
 	device_create_file(&new_client->dev, &dev_attr_temp2_min);
@@ -285,6 +295,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -310,6 +322,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/pc87360.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/pc87360.c	2005-06-05 23:27:07.000000000 -0700
@@ -40,6 +40,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 
 static unsigned short normal_i2c[] = { I2C_CLIENT_END };
@@ -65,6 +67,8 @@
  " 2: Forcibly enable all voltage and temperature channels, except in9\n"
  " 3: Forcibly enable all voltage and temperature channels, including in9");
 
+static int id;	/* increment once for every chip found */
+
 /*
  * Super-I/O registers and operations
  */
@@ -838,6 +842,13 @@
 	}
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR3;
+	}
+
 	if (data->innr) {
 		device_create_file(&new_client->dev, &dev_attr_in0_input);
 		device_create_file(&new_client->dev, &dev_attr_in1_input);
@@ -974,6 +985,8 @@
 
 	return 0;
 
+ERROR3:
+	i2c_detach_client(new_client);
 ERROR2:
 	for (i = 0; i < 3; i++) {
 		if (data->address[i]) {
@@ -990,6 +1003,8 @@
 	struct pc87360_data *data = i2c_get_clientdata(client);
 	int i;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((i = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/sis5595.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/sis5595.c	2005-06-05 23:27:07.000000000 -0700
@@ -56,6 +56,8 @@
 #include <linux/pci.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <linux/jiffies.h>
 #include <asm/io.h>
@@ -77,6 +79,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(sis5595);
 
+static int id;	/* increment once for every chip found */
+
 /* Many SIS5595 constants specified below */
 
 /* Length of ISA address segment */
@@ -578,6 +582,13 @@
 	}
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in0_min);
 	device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -608,7 +619,9 @@
 		device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
 	}
 	return 0;
-	
+
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit_release:
@@ -621,6 +634,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		    "Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/smsc47b397.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/smsc47b397.c	2005-06-05 23:27:07.000000000 -0700
@@ -32,6 +32,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <asm/io.h>
 
@@ -49,6 +51,8 @@
 	.forces			= forces,
 };
 
+static int id;	/* increment once for every chip found */
+
 /* Super-I/0 registers and commands */
 
 #define	REG	0x2e	/* The register to read/write */
@@ -228,6 +232,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
@@ -285,6 +291,13 @@
 	if ((err = i2c_attach_client(new_client)))
 		goto error_free;
 
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto error_detach;
+	}
+
 	device_create_file_temp(new_client, 1);
 	device_create_file_temp(new_client, 2);
 	device_create_file_temp(new_client, 3);
@@ -297,6 +310,8 @@
 
 	return 0;
 
+error_detach:
+	i2c_detach_client(new_client);
 error_free:
 	kfree(new_client);
 error_release:
--- gregkh-2.6.orig/drivers/i2c/chips/smsc47m1.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/smsc47m1.c	2005-06-05 23:27:07.000000000 -0700
@@ -31,6 +31,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <asm/io.h>
 
@@ -46,6 +48,8 @@
 	.forces			= forces,
 };
 
+static int id;	/* increment once for every chip found */
+
 /* Super-I/0 registers and commands */
 
 #define	REG	0x2e	/* The register to read/write */
@@ -461,6 +465,14 @@
 	   function. */
 	smsc47m1_update_device(&new_client->dev, 1);
 
+	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto error_detach;
+	}
+
 	if (fan1) {
 		device_create_file(&new_client->dev, &dev_attr_fan1_input);
 		device_create_file(&new_client->dev, &dev_attr_fan1_min);
@@ -494,6 +506,8 @@
 
 	return 0;
 
+error_detach:
+	i2c_detach_client(new_client);
 error_free:
 	kfree(new_client);
 error_release:
@@ -505,6 +519,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/via686a.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/via686a.c	2005-06-05 23:27:07.000000000 -0700
@@ -36,6 +36,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <asm/io.h>
 
@@ -56,6 +58,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(via686a);
 
+static int id;	/* increment once for every chip found */
+
 /*
    The Via 686a southbridge has a LM78-like chip integrated on the same IC.
    This driver is a customized copy of lm78.c
@@ -637,7 +641,7 @@
 
 	if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) {
 		err = -ENOMEM;
-		goto ERROR0;
+		goto exit_release;
 	}
 	memset(data, 0, sizeof(struct via686a_data));
 
@@ -655,12 +659,19 @@
 	init_MUTEX(&data->update_lock);
 	/* Tell the I2C layer a new client has arrived */
 	if ((err = i2c_attach_client(new_client)))
-		goto ERROR3;
+		goto exit_free;
 
 	/* Initialize the VIA686A chip */
 	via686a_init_client(new_client);
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_in0_input);
 	device_create_file(&new_client->dev, &dev_attr_in1_input);
 	device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -695,9 +706,11 @@
 
 	return 0;
 
-ERROR3:
+exit_detach:
+	i2c_detach_client(new_client);
+exit_free:
 	kfree(data);
-ERROR0:
+exit_release:
 	release_region(address, VIA686A_EXTENT);
 	return err;
 }
@@ -706,6 +719,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		"Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/w83627ehf.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/w83627ehf.c	2005-06-05 23:27:07.000000000 -0700
@@ -38,6 +38,8 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 #include "lm75.h"
 
@@ -49,6 +51,8 @@
 /* Insmod parameters */
 SENSORS_INSMOD_1(w83627ehf);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * Super-I/O constants and functions
  */
@@ -720,6 +724,13 @@
 		data->has_fan |= (1 << 4);
 
 	/* Register sysfs hooks */
+	client->class_dev = hwmon_device_register(&client->dev,
+		"%s-%d", client->name, id++);
+	if (IS_ERR(client->class_dev)) {
+		err = PTR_ERR(client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&client->dev, &dev_attr_fan1_input);
 	device_create_file(&client->dev, &dev_attr_fan1_min);
 	device_create_file(&client->dev, &dev_attr_fan1_div);
@@ -753,6 +764,8 @@
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(client);
 exit_free:
 	kfree(data);
 exit_release:
@@ -772,6 +785,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/w83627hf.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/w83627hf.c	2005-06-05 23:27:07.000000000 -0700
@@ -44,6 +44,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 #include "lm75.h"
 
@@ -67,6 +69,8 @@
 module_param(init, bool, 0);
 MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
 
+static int id;	/* increment once for every chip found */
+
 /* modified from kernel/include/traps.c */
 static int REG;		/* The register to read/write */
 #define	DEV	0x07	/* Register: Logical device select */
@@ -1102,6 +1106,13 @@
 	data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR3;
+	}
+
 	device_create_file_in(new_client, 0);
 	if (kind != w83697hf)
 		device_create_file_in(new_client, 1);
@@ -1152,6 +1163,8 @@
 
 	return 0;
 
+      ERROR3:
+	i2c_detach_client(new_client);
       ERROR2:
 	kfree(data);
       ERROR1:
@@ -1164,6 +1177,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev,
 		       "Client deregistration failed, client not detached.\n");
--- gregkh-2.6.orig/drivers/i2c/chips/w83781d.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/w83781d.c	2005-06-05 23:27:07.000000000 -0700
@@ -42,6 +42,8 @@
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 #include "lm75.h"
 
@@ -60,6 +62,8 @@
 module_param(init, bool, 0);
 MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
 
+static int id;	/* increment once for every chip found */
+
 /* Constants specified below */
 
 /* Length of ISA address segment */
@@ -1205,6 +1209,13 @@
 			data->pwmenable[i] = 1;
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto ERROR4;
+	}
+
 	device_create_file_in(new_client, 0);
 	if (kind != w83783s && kind != w83697hf)
 		device_create_file_in(new_client, 1);
@@ -1262,6 +1273,15 @@
 
 	return 0;
 
+ERROR4:
+	if (NULL != data->lm75[1]) {
+		i2c_detach_client(data->lm75[1]);
+		kfree(data->lm75[1]);
+	}
+	if (NULL != data->lm75[0]) {
+		i2c_detach_client(data->lm75[0]);
+		kfree(data->lm75[0]);
+	}
 ERROR3:
 	i2c_detach_client(new_client);
 ERROR2:
@@ -1278,6 +1298,9 @@
 {
 	int err;
 
+	if (client->class_dev)
+		hwmon_device_unregister(client->class_dev);
+
 	if (i2c_is_isa_client(client))
 		release_region(client->addr, W83781D_EXTENT);
 
--- gregkh-2.6.orig/drivers/i2c/chips/w83l785ts.c	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/drivers/i2c/chips/w83l785ts.c	2005-06-05 23:27:07.000000000 -0700
@@ -37,6 +37,8 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /* How many retries on register read error */
 #define MAX_RETRIES	5
@@ -55,6 +57,8 @@
 
 SENSORS_INSMOD_1(w83l785ts);
 
+static int id;	/* increment once for every chip found */
+
 /*
  * The W83L785TS-S registers
  * Manufacturer ID is 0x5CA3 for Winbond.
@@ -239,11 +243,20 @@
 	 */
 
 	/* Register sysfs hooks */
+	new_client->class_dev = hwmon_device_register(&new_client->dev,
+		"%s-%d", new_client->name, id++);
+	if (IS_ERR(new_client->class_dev)) {
+		err = PTR_ERR(new_client->class_dev);
+		goto exit_detach;
+	}
+
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 	device_create_file(&new_client->dev, &dev_attr_temp1_max);
 
 	return 0;
 
+exit_detach:
+	i2c_detach_client(new_client);
 exit_free:
 	kfree(data);
 exit:
@@ -254,6 +267,8 @@
 {
 	int err;
 
+	hwmon_device_unregister(client->class_dev);
+
 	if ((err = i2c_detach_client(client))) {
 		dev_err(&client->dev, "Client deregistration failed, "
 			"client not detached.\n");
--- gregkh-2.6.orig/include/linux/i2c.h	2005-06-05 23:13:10.000000000 -0700
+++ gregkh-2.6/include/linux/i2c.h	2005-06-05 23:27:07.000000000 -0700
@@ -154,6 +154,7 @@
 	int usage_count;		/* How many accesses currently  */
 					/* to the client		*/
 	struct device dev;		/* the device structure		*/
+	struct class_device *class_dev;
 	struct list_head list;
 	char name[I2C_NAME_SIZE];
 	struct completion released;