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/asb100.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'drivers/hwmon/asb100.c') diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 70d996d6fe0..3ab7a2ddafb 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include "lm75.h" @@ -183,6 +185,7 @@ static u8 DIV_TO_REG(long val) dynamically allocated, at the same time the client itself is allocated. */ struct asb100_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore lock; enum chips type; @@ -821,6 +824,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); /* 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 ERROR3; + } + device_create_file_in(new_client, 0); device_create_file_in(new_client, 1); device_create_file_in(new_client, 2); @@ -847,6 +856,11 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +ERROR3: + i2c_detach_client(data->lm75[1]); + i2c_detach_client(data->lm75[0]); + kfree(data->lm75[1]); + kfree(data->lm75[0]); ERROR2: i2c_detach_client(new_client); ERROR1: @@ -857,21 +871,26 @@ ERROR0: static int asb100_detach_client(struct i2c_client *client) { + struct asb100_data *data = i2c_get_clientdata(client); int err; + /* main client */ + if (data) + hwmon_device_unregister(data->class_dev); + if ((err = i2c_detach_client(client))) { dev_err(&client->dev, "client deregistration failed; " "client not detached.\n"); 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