From 943b0830cebe4711354945ed3cb44e84152aaca0 Mon Sep 17 00:00:00 2001 From: "Mark M. Hoffman" Date: Fri, 15 Jul 2005 21:39:18 -0400 Subject: [PATCH] I2C hwmon: add hwmon sysfs class to drivers This patch modifies sensors chip drivers to make use of the new sysfs class "hwmon". Signed-off-by: Mark M. Hoffman Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/w83781d.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'drivers/hwmon/w83781d.c') diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index 0bb131ce09e..c83ae769e36 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include "lm75.h" @@ -218,6 +220,7 @@ DIV_TO_REG(long val, enum chips type) allocated. */ struct w83781d_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -961,10 +964,10 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ERROR_SC_3: i2c_detach_client(data->lm75[0]); ERROR_SC_2: - if (NULL != data->lm75[1]) + if (data->lm75[1]) kfree(data->lm75[1]); ERROR_SC_1: - if (NULL != data->lm75[0]) + if (data->lm75[0]) kfree(data->lm75[0]); ERROR_SC_0: return err; @@ -1189,6 +1192,12 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) data->pwmenable[i] = 1; /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto ERROR4; + } + device_create_file_in(new_client, 0); if (kind != w83783s) device_create_file_in(new_client, 1); @@ -1241,6 +1250,15 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +ERROR4: + if (data->lm75[1]) { + i2c_detach_client(data->lm75[1]); + kfree(data->lm75[1]); + } + if (data->lm75[0]) { + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[0]); + } ERROR3: i2c_detach_client(new_client); ERROR2: @@ -1255,8 +1273,13 @@ ERROR0: static int w83781d_detach_client(struct i2c_client *client) { + struct w83781d_data *data = i2c_get_clientdata(client); int err; + /* main client */ + if (data) + hwmon_device_unregister(data->class_dev); + if (i2c_is_isa_client(client)) release_region(client->addr, W83781D_EXTENT); @@ -1266,13 +1289,13 @@ w83781d_detach_client(struct i2c_client *client) return err; } - if (i2c_get_clientdata(client)==NULL) { - /* subclients */ + /* main client */ + if (data) + kfree(data); + + /* subclient */ + else kfree(client); - } else { - /* main client */ - kfree(i2c_get_clientdata(client)); - } return 0; } -- cgit v1.2.3-70-g09d2