Commit ce785ab4 authored by R.Marek@sh.cvut.cz's avatar R.Marek@sh.cvut.cz Committed by Greg Kroah-Hartman

[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: default avatarRudolf Marek <r.marek@sh.cvut.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5563e27d
...@@ -42,7 +42,9 @@ ...@@ -42,7 +42,9 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/i2c-sensor.h> #include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h> #include <linux/i2c-vid.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/err.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
...@@ -267,6 +269,7 @@ DIV_TO_REG(long val) ...@@ -267,6 +269,7 @@ DIV_TO_REG(long val)
struct w83792d_data { struct w83792d_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -1289,6 +1292,11 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1289,6 +1292,11 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
} }
/* Register sysfs hooks */ /* 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, 0);
device_create_file_in(new_client, 1); device_create_file_in(new_client, 1);
device_create_file_in(new_client, 2); device_create_file_in(new_client, 2);
...@@ -1361,6 +1369,15 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1361,6 +1369,15 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
ERROR3:
if (data->lm75[0] != NULL) {
i2c_detach_client(data->lm75[0]);
kfree(data->lm75[0]);
}
if (data->lm75[1] != NULL) {
i2c_detach_client(data->lm75[1]);
kfree(data->lm75[1]);
}
ERROR2: ERROR2:
i2c_detach_client(new_client); i2c_detach_client(new_client);
ERROR1: ERROR1:
...@@ -1372,21 +1389,25 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1372,21 +1389,25 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
static int static int
w83792d_detach_client(struct i2c_client *client) w83792d_detach_client(struct i2c_client *client)
{ {
struct w83792d_data *data = i2c_get_clientdata(client);
int err; int err;
/* main client */
if (data)
hwmon_device_unregister(data->class_dev);
if ((err = i2c_detach_client(client))) { if ((err = i2c_detach_client(client))) {
dev_err(&client->dev, dev_err(&client->dev,
"Client deregistration failed, client not detached.\n"); "Client deregistration failed, client not detached.\n");
return err; return err;
} }
if (i2c_get_clientdata(client)==NULL) { /* main client */
/* subclients */ if (data)
kfree(data);
/* subclient */
else
kfree(client); kfree(client);
} else {
/* main client */
kfree(i2c_get_clientdata(client));
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment