diff options
author | R.Marek@sh.cvut.cz <R.Marek@sh.cvut.cz> | 2005-07-27 07:50:18 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-05 12:14:13 -0400 |
commit | ce785ab460ce8728a9daf337ba8fab3ba692b6aa (patch) | |
tree | ff3bbb4d1f417b4db05ad8d3c7e96f1ee82caf93 /drivers/hwmon/w83792d.c | |
parent | 5563e27d3a42667734e81c1cb8ad72bff76321f6 (diff) |
[PATCH] I2C: W83792D add hwmon class register 2/3
This patch adds registration of hwmon class. Tested with help of i2c-stub.
Signed-off-by: Rudolf Marek <r.marek@sh.cvut.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon/w83792d.c')
-rw-r--r-- | drivers/hwmon/w83792d.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index fa43b6fd1212..05f9b92ad3e7 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -42,7 +42,9 @@ | |||
42 | #include <linux/i2c.h> | 42 | #include <linux/i2c.h> |
43 | #include <linux/i2c-sensor.h> | 43 | #include <linux/i2c-sensor.h> |
44 | #include <linux/i2c-vid.h> | 44 | #include <linux/i2c-vid.h> |
45 | #include <linux/hwmon.h> | ||
45 | #include <linux/hwmon-sysfs.h> | 46 | #include <linux/hwmon-sysfs.h> |
47 | #include <linux/err.h> | ||
46 | 48 | ||
47 | /* Addresses to scan */ | 49 | /* Addresses to scan */ |
48 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; | 50 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; |
@@ -267,6 +269,7 @@ DIV_TO_REG(long val) | |||
267 | 269 | ||
268 | struct w83792d_data { | 270 | struct w83792d_data { |
269 | struct i2c_client client; | 271 | struct i2c_client client; |
272 | struct class_device *class_dev; | ||
270 | struct semaphore lock; | 273 | struct semaphore lock; |
271 | enum chips type; | 274 | enum chips type; |
272 | 275 | ||
@@ -1289,6 +1292,11 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1289 | } | 1292 | } |
1290 | 1293 | ||
1291 | /* Register sysfs hooks */ | 1294 | /* Register sysfs hooks */ |
1295 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1296 | if (IS_ERR(data->class_dev)) { | ||
1297 | err = PTR_ERR(data->class_dev); | ||
1298 | goto ERROR3; | ||
1299 | } | ||
1292 | device_create_file_in(new_client, 0); | 1300 | device_create_file_in(new_client, 0); |
1293 | device_create_file_in(new_client, 1); | 1301 | device_create_file_in(new_client, 1); |
1294 | device_create_file_in(new_client, 2); | 1302 | device_create_file_in(new_client, 2); |
@@ -1361,6 +1369,15 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1361 | 1369 | ||
1362 | return 0; | 1370 | return 0; |
1363 | 1371 | ||
1372 | ERROR3: | ||
1373 | if (data->lm75[0] != NULL) { | ||
1374 | i2c_detach_client(data->lm75[0]); | ||
1375 | kfree(data->lm75[0]); | ||
1376 | } | ||
1377 | if (data->lm75[1] != NULL) { | ||
1378 | i2c_detach_client(data->lm75[1]); | ||
1379 | kfree(data->lm75[1]); | ||
1380 | } | ||
1364 | ERROR2: | 1381 | ERROR2: |
1365 | i2c_detach_client(new_client); | 1382 | i2c_detach_client(new_client); |
1366 | ERROR1: | 1383 | ERROR1: |
@@ -1372,21 +1389,25 @@ ERROR0: | |||
1372 | static int | 1389 | static int |
1373 | w83792d_detach_client(struct i2c_client *client) | 1390 | w83792d_detach_client(struct i2c_client *client) |
1374 | { | 1391 | { |
1392 | struct w83792d_data *data = i2c_get_clientdata(client); | ||
1375 | int err; | 1393 | int err; |
1376 | 1394 | ||
1395 | /* main client */ | ||
1396 | if (data) | ||
1397 | hwmon_device_unregister(data->class_dev); | ||
1398 | |||
1377 | if ((err = i2c_detach_client(client))) { | 1399 | if ((err = i2c_detach_client(client))) { |
1378 | dev_err(&client->dev, | 1400 | dev_err(&client->dev, |
1379 | "Client deregistration failed, client not detached.\n"); | 1401 | "Client deregistration failed, client not detached.\n"); |
1380 | return err; | 1402 | return err; |
1381 | } | 1403 | } |
1382 | 1404 | ||
1383 | if (i2c_get_clientdata(client)==NULL) { | 1405 | /* main client */ |
1384 | /* subclients */ | 1406 | if (data) |
1407 | kfree(data); | ||
1408 | /* subclient */ | ||
1409 | else | ||
1385 | kfree(client); | 1410 | kfree(client); |
1386 | } else { | ||
1387 | /* main client */ | ||
1388 | kfree(i2c_get_clientdata(client)); | ||
1389 | } | ||
1390 | 1411 | ||
1391 | return 0; | 1412 | return 0; |
1392 | } | 1413 | } |