Skip to content

Commit

Permalink
[PATCH] I2C hwmon: add hwmon sysfs class to drivers
Browse files Browse the repository at this point in the history
This patch modifies sensors chip drivers to make use of the new
sysfs class "hwmon".

Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Mark M. Hoffman authored and Greg Kroah-Hartman committed Sep 5, 2005
1 parent 1236441 commit 943b083
Show file tree
Hide file tree
Showing 33 changed files with 522 additions and 53 deletions.
16 changes: 15 additions & 1 deletion drivers/hwmon/adm1021.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -89,6 +91,7 @@ clearing it. Weird, ey? --Phil */
/* Each client has this additional data */
struct adm1021_data {
struct i2c_client client;
struct class_device *class_dev;
enum chips type;

struct semaphore update_lock;
Expand Down Expand Up @@ -295,6 +298,12 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
adm1021_init_client(new_client);

/* 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 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);
Expand All @@ -305,6 +314,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)

return 0;

error2:
i2c_detach_client(new_client);
error1:
kfree(data);
error0:
Expand All @@ -322,14 +333,17 @@ static void adm1021_init_client(struct i2c_client *client)

static int adm1021_detach_client(struct i2c_client *client)
{
struct adm1021_data *data = i2c_get_clientdata(client);
int err;

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;
}

kfree(i2c_get_clientdata(client));
kfree(data);
return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/hwmon/adm1025.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,6 +134,7 @@ static struct i2c_driver adm1025_driver = {

struct adm1025_data {
struct i2c_client client;
struct class_device *class_dev;
struct semaphore update_lock;
char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
Expand Down Expand Up @@ -416,6 +419,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
adm1025_init_client(new_client);

/* 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 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);
Expand Down Expand Up @@ -452,6 +461,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)

return 0;

exit_detach:
i2c_detach_client(new_client);
exit_free:
kfree(data);
exit:
Expand Down Expand Up @@ -502,15 +513,18 @@ static void adm1025_init_client(struct i2c_client *client)

static int adm1025_detach_client(struct i2c_client *client)
{
struct adm1025_data *data = i2c_get_clientdata(client);
int err;

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;
}

kfree(i2c_get_clientdata(client));
kfree(data);
return 0;
}

Expand Down
15 changes: 14 additions & 1 deletion drivers/hwmon/adm1026.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
#include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h>
#include <linux/err.h>

/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Expand Down Expand Up @@ -259,6 +261,7 @@ struct pwm_data {

struct adm1026_data {
struct i2c_client client;
struct class_device *class_dev;
struct semaphore lock;
enum chips type;

Expand Down Expand Up @@ -324,8 +327,10 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter)

int adm1026_detach_client(struct i2c_client *client)
{
struct adm1026_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->class_dev);
i2c_detach_client(client);
kfree(i2c_get_clientdata(client));
kfree(data);
return 0;
}

Expand Down Expand Up @@ -1555,6 +1560,12 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
adm1026_init_client(new_client);

/* 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 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);
Expand Down Expand Up @@ -1690,6 +1701,8 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
return 0;

/* Error out and cleanup code */
exitdetach:
i2c_detach_client(new_client);
exitfree:
kfree(data);
exit:
Expand Down
16 changes: 15 additions & 1 deletion drivers/hwmon/adm1031.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -69,6 +71,7 @@ typedef u8 auto_chan_table_t[8][2];
/* Each client has this additional data */
struct adm1031_data {
struct i2c_client client;
struct class_device *class_dev;
struct semaphore update_lock;
int chip_type;
char valid; /* !=0 if following fields are valid */
Expand Down Expand Up @@ -788,6 +791,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
adm1031_init_client(new_client);

/* 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 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);
Expand Down Expand Up @@ -833,6 +842,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)

return 0;

exit_detach:
i2c_detach_client(new_client);
exit_free:
kfree(data);
exit:
Expand All @@ -841,11 +852,14 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)

static int adm1031_detach_client(struct i2c_client *client)
{
struct adm1031_data *data = i2c_get_clientdata(client);
int ret;

hwmon_device_unregister(data->class_dev);
if ((ret = i2c_detach_client(client)) != 0) {
return ret;
}
kfree(i2c_get_clientdata(client));
kfree(data);
return 0;
}

Expand Down
17 changes: 16 additions & 1 deletion drivers/hwmon/adm9240.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -150,6 +152,7 @@ static struct i2c_driver adm9240_driver = {
struct adm9240_data {
enum chips type;
struct i2c_client client;
struct class_device *class_dev;
struct semaphore update_lock;
char valid;
unsigned long last_updated_measure;
Expand Down Expand Up @@ -582,6 +585,12 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
adm9240_init_client(new_client);

/* populate sysfs filesystem */
data->class_dev = hwmon_device_register(&new_client->dev);
if (IS_ERR(data->class_dev)) {
err = PTR_ERR(data->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);
Expand Down Expand Up @@ -615,6 +624,9 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
device_create_file(&new_client->dev, &dev_attr_cpu0_vid);

return 0;

exit_detach:
i2c_detach_client(new_client);
exit_free:
kfree(data);
exit:
Expand All @@ -630,15 +642,18 @@ static int adm9240_attach_adapter(struct i2c_adapter *adapter)

static int adm9240_detach_client(struct i2c_client *client)
{
struct adm9240_data *data = i2c_get_clientdata(client);
int err;

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;
}

kfree(i2c_get_clientdata(client));
kfree(data);
return 0;
}

Expand Down
31 changes: 25 additions & 6 deletions drivers/hwmon/asb100.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -857,21 +871,26 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)

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;
}
Expand Down
Loading

0 comments on commit 943b083

Please sign in to comment.