Commit cbc22621 authored by Mark M. Hoffman's avatar Mark M. Hoffman Committed by Greg Kroah-Hartman

[PATCH] I2C: sensor chip driver refactoring

This patch is a refactoring of some common code among all sensors chip
drivers (except asb100, which was written this way to begin with.)
It saves a handful of lines and ~100-300 bytes per module.  It compiles
ok.  I've only tested it against one of the drivers, but the changes are
similar across the board and quite mechanical.  Please apply.
parent c188b751
...@@ -139,7 +139,7 @@ static int adm1021_detach_client(struct i2c_client *client); ...@@ -139,7 +139,7 @@ static int adm1021_detach_client(struct i2c_client *client);
static int adm1021_read_value(struct i2c_client *client, u8 reg); static int adm1021_read_value(struct i2c_client *client, u8 reg);
static int adm1021_write_value(struct i2c_client *client, u8 reg, static int adm1021_write_value(struct i2c_client *client, u8 reg,
u16 value); u16 value);
static void adm1021_update_client(struct i2c_client *client); static struct adm1021_data *adm1021_update_device(struct device *dev);
/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
static int read_only = 0; static int read_only = 0;
...@@ -161,15 +161,10 @@ static struct i2c_driver adm1021_driver = { ...@@ -161,15 +161,10 @@ static struct i2c_driver adm1021_driver = {
static int adm1021_id = 0; static int adm1021_id = 0;
#define show(value) \ #define show(value) \
static ssize_t show_##value(struct device *dev, char *buf) \ static ssize_t show_##value(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct adm1021_data *data = adm1021_update_device(dev); \
struct adm1021_data *data = i2c_get_clientdata(client); \ return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
int temp; \
\
adm1021_update_client(client); \
temp = TEMP_FROM_REG(data->value); \
return sprintf(buf, "%d\n", temp); \
} }
show(temp_max); show(temp_max);
show(temp_hyst); show(temp_hyst);
...@@ -179,13 +174,10 @@ show(remote_temp_hyst); ...@@ -179,13 +174,10 @@ show(remote_temp_hyst);
show(remote_temp_input); show(remote_temp_input);
#define show2(value) \ #define show2(value) \
static ssize_t show_##value(struct device *dev, char *buf) \ static ssize_t show_##value(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct adm1021_data *data = adm1021_update_device(dev); \
struct adm1021_data *data = i2c_get_clientdata(client); \ return sprintf(buf, "%d\n", data->value); \
\
adm1021_update_client(client); \
return sprintf(buf, "%d\n", data->value); \
} }
show2(alarms); show2(alarms);
show2(die_code); show2(die_code);
...@@ -393,8 +385,9 @@ static int adm1021_write_value(struct i2c_client *client, u8 reg, u16 value) ...@@ -393,8 +385,9 @@ static int adm1021_write_value(struct i2c_client *client, u8 reg, u16 value)
return 0; return 0;
} }
static void adm1021_update_client(struct i2c_client *client) static struct adm1021_data *adm1021_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct adm1021_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -424,6 +417,8 @@ static void adm1021_update_client(struct i2c_client *client) ...@@ -424,6 +417,8 @@ static void adm1021_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_adm1021_init(void) static int __init sensors_adm1021_init(void)
......
...@@ -113,7 +113,7 @@ SENSORS_INSMOD_1(fscher); ...@@ -113,7 +113,7 @@ SENSORS_INSMOD_1(fscher);
static int fscher_attach_adapter(struct i2c_adapter *adapter); static int fscher_attach_adapter(struct i2c_adapter *adapter);
static int fscher_detect(struct i2c_adapter *adapter, int address, int kind); static int fscher_detect(struct i2c_adapter *adapter, int address, int kind);
static int fscher_detach_client(struct i2c_client *client); static int fscher_detach_client(struct i2c_client *client);
static void fscher_update_client(struct i2c_client *client); static struct fscher_data *fscher_update_device(struct device *dev);
static void fscher_init_client(struct i2c_client *client); static void fscher_init_client(struct i2c_client *client);
static int fscher_read_value(struct i2c_client *client, u8 reg); static int fscher_read_value(struct i2c_client *client, u8 reg);
...@@ -170,9 +170,7 @@ static ssize_t show_##kind##sub (struct fscher_data *, char *, int); \ ...@@ -170,9 +170,7 @@ static ssize_t show_##kind##sub (struct fscher_data *, char *, int); \
static ssize_t show_##kind##offset##sub (struct device *, char *); \ static ssize_t show_##kind##offset##sub (struct device *, char *); \
static ssize_t show_##kind##offset##sub (struct device *dev, char *buf) \ static ssize_t show_##kind##offset##sub (struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct fscher_data *data = fscher_update_device(dev); \
struct fscher_data *data = i2c_get_clientdata(client); \
fscher_update_client(client); \
return show_##kind##sub(data, buf, (offset)); \ return show_##kind##sub(data, buf, (offset)); \
} }
...@@ -420,8 +418,9 @@ static void fscher_init_client(struct i2c_client *client) ...@@ -420,8 +418,9 @@ static void fscher_init_client(struct i2c_client *client)
data->revision = fscher_read_value(client, FSCHER_REG_REVISION); data->revision = fscher_read_value(client, FSCHER_REG_REVISION);
} }
static void fscher_update_client(struct i2c_client *client) static struct fscher_data *fscher_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct fscher_data *data = i2c_get_clientdata(client); struct fscher_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -466,6 +465,8 @@ static void fscher_update_client(struct i2c_client *client) ...@@ -466,6 +465,8 @@ static void fscher_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
......
...@@ -151,7 +151,7 @@ static void gl518_init_client(struct i2c_client *client); ...@@ -151,7 +151,7 @@ static void gl518_init_client(struct i2c_client *client);
static int gl518_detach_client(struct i2c_client *client); static int gl518_detach_client(struct i2c_client *client);
static int gl518_read_value(struct i2c_client *client, u8 reg); static int gl518_read_value(struct i2c_client *client, u8 reg);
static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value);
static void gl518_update_client(struct i2c_client *client); static struct gl518_data *gl518_update_device(struct device *dev);
/* This is the driver that will be inserted */ /* This is the driver that will be inserted */
static struct i2c_driver gl518_driver = { static struct i2c_driver gl518_driver = {
...@@ -176,18 +176,14 @@ static int gl518_id = 0; ...@@ -176,18 +176,14 @@ static int gl518_id = 0;
#define show(type, suffix, value) \ #define show(type, suffix, value) \
static ssize_t show_##suffix(struct device *dev, char *buf) \ static ssize_t show_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct gl518_data *data = gl518_update_device(dev); \
struct gl518_data *data = i2c_get_clientdata(client); \
gl518_update_client(client); \
return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
} }
#define show_fan(suffix, value, index) \ #define show_fan(suffix, value, index) \
static ssize_t show_##suffix(struct device *dev, char *buf) \ static ssize_t show_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct gl518_data *data = gl518_update_device(dev); \
struct gl518_data *data = i2c_get_clientdata(client); \
gl518_update_client(client); \
return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index], \ return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index], \
DIV_FROM_REG(data->fan_div[index]))); \ DIV_FROM_REG(data->fan_div[index]))); \
} }
...@@ -523,8 +519,9 @@ static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) ...@@ -523,8 +519,9 @@ static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
return i2c_smbus_write_byte_data(client, reg, value); return i2c_smbus_write_byte_data(client, reg, value);
} }
static void gl518_update_client(struct i2c_client *client) static struct gl518_data *gl518_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct gl518_data *data = i2c_get_clientdata(client); struct gl518_data *data = i2c_get_clientdata(client);
int val; int val;
...@@ -590,6 +587,8 @@ static void gl518_update_client(struct i2c_client *client) ...@@ -590,6 +587,8 @@ static void gl518_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_gl518sm_init(void) static int __init sensors_gl518sm_init(void)
......
...@@ -167,7 +167,7 @@ static int it87_detach_client(struct i2c_client *client); ...@@ -167,7 +167,7 @@ static int it87_detach_client(struct i2c_client *client);
static int it87_read_value(struct i2c_client *client, u8 register); static int it87_read_value(struct i2c_client *client, u8 register);
static int it87_write_value(struct i2c_client *client, u8 register, static int it87_write_value(struct i2c_client *client, u8 register,
u8 value); u8 value);
static void it87_update_client(struct i2c_client *client); static struct it87_data *it87_update_device(struct device *dev);
static void it87_init_client(struct i2c_client *client, struct it87_data *data); static void it87_init_client(struct i2c_client *client, struct it87_data *data);
...@@ -184,25 +184,19 @@ static int it87_id = 0; ...@@ -184,25 +184,19 @@ static int it87_id = 0;
static ssize_t show_in(struct device *dev, char *buf, int nr) static ssize_t show_in(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])*10 ); return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])*10 );
} }
static ssize_t show_in_min(struct device *dev, char *buf, int nr) static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])*10 ); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])*10 );
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])*10 ); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])*10 );
} }
...@@ -284,23 +278,17 @@ show_in_offset(8); ...@@ -284,23 +278,17 @@ show_in_offset(8);
/* 3 temperatures */ /* 3 temperatures */
static ssize_t show_temp(struct device *dev, char *buf, int nr) static ssize_t show_temp(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])*100 ); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])*100 );
} }
static ssize_t show_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])*100); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])*100);
} }
static ssize_t show_temp_min(struct device *dev, char *buf, int nr) static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])*100); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])*100);
} }
static ssize_t set_temp_max(struct device *dev, const char *buf, static ssize_t set_temp_max(struct device *dev, const char *buf,
...@@ -360,9 +348,7 @@ show_temp_offset(3); ...@@ -360,9 +348,7 @@ show_temp_offset(3);
static ssize_t show_sensor(struct device *dev, char *buf, int nr) static ssize_t show_sensor(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
if (data->sensor & (1 << nr)) if (data->sensor & (1 << nr))
return sprintf(buf, "3\n"); /* thermal diode */ return sprintf(buf, "3\n"); /* thermal diode */
if (data->sensor & (8 << nr)) if (data->sensor & (8 << nr))
...@@ -408,25 +394,19 @@ show_sensor_offset(3); ...@@ -408,25 +394,19 @@ show_sensor_offset(3);
/* 3 Fans */ /* 3 Fans */
static ssize_t show_fan(struct device *dev, char *buf, int nr) static ssize_t show_fan(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
DIV_FROM_REG(data->fan_div[nr])) ); DIV_FROM_REG(data->fan_div[nr])) );
} }
static ssize_t show_fan_min(struct device *dev, char *buf, int nr) static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf,"%d\n", return sprintf(buf,"%d\n",
FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) );
} }
static ssize_t show_fan_div(struct device *dev, char *buf, int nr) static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) ); return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) );
} }
static ssize_t set_fan_min(struct device *dev, const char *buf, static ssize_t set_fan_min(struct device *dev, const char *buf,
...@@ -512,9 +492,7 @@ show_fan_offset(3); ...@@ -512,9 +492,7 @@ show_fan_offset(3);
/* Alarms */ /* Alarms */
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = it87_update_device(dev);
struct it87_data *data = i2c_get_clientdata(client);
it87_update_client(client);
return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms)); return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms));
} }
static DEVICE_ATTR(alarms, S_IRUGO | S_IWUSR, show_alarms, NULL); static DEVICE_ATTR(alarms, S_IRUGO | S_IWUSR, show_alarms, NULL);
...@@ -811,8 +789,9 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data) ...@@ -811,8 +789,9 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
| (update_vbat ? 0x41 : 0x01)); | (update_vbat ? 0x41 : 0x01));
} }
static void it87_update_client(struct i2c_client *client) static struct it87_data *it87_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -883,6 +862,8 @@ static void it87_update_client(struct i2c_client *client) ...@@ -883,6 +862,8 @@ static void it87_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sm_it87_init(void) static int __init sm_it87_init(void)
......
...@@ -64,7 +64,7 @@ static void lm75_init_client(struct i2c_client *client); ...@@ -64,7 +64,7 @@ static void lm75_init_client(struct i2c_client *client);
static int lm75_detach_client(struct i2c_client *client); static int lm75_detach_client(struct i2c_client *client);
static int lm75_read_value(struct i2c_client *client, u8 reg); static int lm75_read_value(struct i2c_client *client, u8 reg);
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value);
static void lm75_update_client(struct i2c_client *client); static struct lm75_data *lm75_update_device(struct device *dev);
/* This is the driver that will be inserted */ /* This is the driver that will be inserted */
...@@ -82,9 +82,7 @@ static int lm75_id = 0; ...@@ -82,9 +82,7 @@ static int lm75_id = 0;
#define show(value) \ #define show(value) \
static ssize_t show_##value(struct device *dev, char *buf) \ static ssize_t show_##value(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm75_data *data = lm75_update_device(dev); \
struct lm75_data *data = i2c_get_clientdata(client); \
lm75_update_client(client); \
return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \
} }
show(temp_max); show(temp_max);
...@@ -250,8 +248,9 @@ static void lm75_init_client(struct i2c_client *client) ...@@ -250,8 +248,9 @@ static void lm75_init_client(struct i2c_client *client)
lm75_write_value(client, LM75_REG_CONF, 0); lm75_write_value(client, LM75_REG_CONF, 0);
} }
static void lm75_update_client(struct i2c_client *client) static struct lm75_data *lm75_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm75_data *data = i2c_get_clientdata(client); struct lm75_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -268,6 +267,8 @@ static void lm75_update_client(struct i2c_client *client) ...@@ -268,6 +267,8 @@ static void lm75_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_lm75_init(void) static int __init sensors_lm75_init(void)
......
...@@ -223,7 +223,7 @@ static int lm78_detach_client(struct i2c_client *client); ...@@ -223,7 +223,7 @@ static int lm78_detach_client(struct i2c_client *client);
static int lm78_read_value(struct i2c_client *client, u8 register); static int lm78_read_value(struct i2c_client *client, u8 register);
static int lm78_write_value(struct i2c_client *client, u8 register, u8 value); static int lm78_write_value(struct i2c_client *client, u8 register, u8 value);
static void lm78_update_client(struct i2c_client *client); static struct lm78_data *lm78_update_device(struct device *dev);
static void lm78_init_client(struct i2c_client *client); static void lm78_init_client(struct i2c_client *client);
...@@ -239,25 +239,19 @@ static struct i2c_driver lm78_driver = { ...@@ -239,25 +239,19 @@ static struct i2c_driver lm78_driver = {
/* 7 Voltages */ /* 7 Voltages */
static ssize_t show_in(struct device *dev, char *buf, int nr) static ssize_t show_in(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
} }
static ssize_t show_in_min(struct device *dev, char *buf, int nr) static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
} }
...@@ -327,17 +321,13 @@ show_in_offset(6); ...@@ -327,17 +321,13 @@ show_in_offset(6);
/* Temperature */ /* Temperature */
static ssize_t show_temp(struct device *dev, char *buf) static ssize_t show_temp(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
} }
static ssize_t show_temp_over(struct device *dev, char *buf) static ssize_t show_temp_over(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
} }
...@@ -353,9 +343,7 @@ static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count) ...@@ -353,9 +343,7 @@ static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count)
static ssize_t show_temp_hyst(struct device *dev, char *buf) static ssize_t show_temp_hyst(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
} }
...@@ -378,18 +366,14 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, ...@@ -378,18 +366,14 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
/* 3 Fans */ /* 3 Fans */
static ssize_t show_fan(struct device *dev, char *buf, int nr) static ssize_t show_fan(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
DIV_FROM_REG(data->fan_div[nr])) ); DIV_FROM_REG(data->fan_div[nr])) );
} }
static ssize_t show_fan_min(struct device *dev, char *buf, int nr) static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])) ); DIV_FROM_REG(data->fan_div[nr])) );
} }
...@@ -407,9 +391,7 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -407,9 +391,7 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
static ssize_t show_fan_div(struct device *dev, char *buf, int nr) static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
} }
...@@ -490,9 +472,7 @@ static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL) ...@@ -490,9 +472,7 @@ static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL)
/* VID */ /* VID */
static ssize_t show_vid(struct device *dev, char *buf) static ssize_t show_vid(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", VID_FROM_REG(data->vid)); return sprintf(buf, "%d\n", VID_FROM_REG(data->vid));
} }
static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid, NULL); static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid, NULL);
...@@ -500,9 +480,7 @@ static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid, NULL); ...@@ -500,9 +480,7 @@ static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid, NULL);
/* Alarms */ /* Alarms */
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm78_data *data = lm78_update_device(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms)); return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
} }
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
...@@ -829,8 +807,9 @@ static void lm78_init_client(struct i2c_client *client) ...@@ -829,8 +807,9 @@ static void lm78_init_client(struct i2c_client *client)
} }
static void lm78_update_client(struct i2c_client *client) static struct lm78_data *lm78_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -879,6 +858,8 @@ static void lm78_update_client(struct i2c_client *client) ...@@ -879,6 +858,8 @@ static void lm78_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sm_lm78_init(void) static int __init sm_lm78_init(void)
......
...@@ -141,7 +141,7 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter); ...@@ -141,7 +141,7 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter);
static int lm80_detect(struct i2c_adapter *adapter, int address, int kind); static int lm80_detect(struct i2c_adapter *adapter, int address, int kind);
static void lm80_init_client(struct i2c_client *client); static void lm80_init_client(struct i2c_client *client);
static int lm80_detach_client(struct i2c_client *client); static int lm80_detach_client(struct i2c_client *client);
static void lm80_update_client(struct i2c_client *client); static struct lm80_data *lm80_update_device(struct device *dev);
static int lm80_read_value(struct i2c_client *client, u8 reg); static int lm80_read_value(struct i2c_client *client, u8 reg);
static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value);
...@@ -171,9 +171,7 @@ static struct i2c_driver lm80_driver = { ...@@ -171,9 +171,7 @@ static struct i2c_driver lm80_driver = {
#define show_in(suffix, value) \ #define show_in(suffix, value) \
static ssize_t show_in_##suffix(struct device *dev, char *buf) \ static ssize_t show_in_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = lm80_update_device(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \
lm80_update_client(client); \
return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \
} }
show_in(min0, in_min[0]); show_in(min0, in_min[0]);
...@@ -227,9 +225,7 @@ set_in(max6, in_max[6], LM80_REG_IN_MAX(6)); ...@@ -227,9 +225,7 @@ set_in(max6, in_max[6], LM80_REG_IN_MAX(6));
#define show_fan(suffix, value, div) \ #define show_fan(suffix, value, div) \
static ssize_t show_fan_##suffix(struct device *dev, char *buf) \ static ssize_t show_fan_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = lm80_update_device(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \
lm80_update_client(client); \
return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \ return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \
DIV_FROM_REG(data->div))); \ DIV_FROM_REG(data->div))); \
} }
...@@ -241,9 +237,7 @@ show_fan(input2, fan[1], fan_div[1]); ...@@ -241,9 +237,7 @@ show_fan(input2, fan[1], fan_div[1]);
#define show_fan_div(suffix, value) \ #define show_fan_div(suffix, value) \
static ssize_t show_fan_div##suffix(struct device *dev, char *buf) \ static ssize_t show_fan_div##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = lm80_update_device(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \
lm80_update_client(client); \
return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \
} }
show_fan_div(1, fan_div[0]); show_fan_div(1, fan_div[0]);
...@@ -265,18 +259,14 @@ set_fan(min2, fan_min[1], LM80_REG_FAN2_MIN, fan_div[1]); ...@@ -265,18 +259,14 @@ set_fan(min2, fan_min[1], LM80_REG_FAN2_MIN, fan_div[1]);
static ssize_t show_temp_input1(struct device *dev, char *buf) static ssize_t show_temp_input1(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm80_data *data = lm80_update_device(dev);
struct lm80_data *data = i2c_get_clientdata(client);
lm80_update_client(client);
return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp)); return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp));
} }
#define show_temp(suffix, value) \ #define show_temp(suffix, value) \
static ssize_t show_temp_##suffix(struct device *dev, char *buf) \ static ssize_t show_temp_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm80_data *data = lm80_update_device(dev); \
struct lm80_data *data = i2c_get_clientdata(client); \
lm80_update_client(client); \
return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \
} }
show_temp(hot_max, temp_hot_max); show_temp(hot_max, temp_hot_max);
...@@ -302,9 +292,7 @@ set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST); ...@@ -302,9 +292,7 @@ set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST);
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm80_data *data = lm80_update_device(dev);
struct lm80_data *data = i2c_get_clientdata(client);
lm80_update_client(client);
return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms)); return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
} }
...@@ -498,8 +486,9 @@ static void lm80_init_client(struct i2c_client *client) ...@@ -498,8 +486,9 @@ static void lm80_init_client(struct i2c_client *client)
lm80_write_value(client, LM80_REG_CONFIG, 0x01); lm80_write_value(client, LM80_REG_CONFIG, 0x01);
} }
static void lm80_update_client(struct i2c_client *client) static struct lm80_data *lm80_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm80_data *data = i2c_get_clientdata(client); struct lm80_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -546,6 +535,8 @@ static void lm80_update_client(struct i2c_client *client) ...@@ -546,6 +535,8 @@ static void lm80_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_lm80_init(void) static int __init sensors_lm80_init(void)
......
...@@ -118,7 +118,7 @@ static const u8 LM83_REG_W_HIGH[] = { ...@@ -118,7 +118,7 @@ static const u8 LM83_REG_W_HIGH[] = {
static int lm83_attach_adapter(struct i2c_adapter *adapter); static int lm83_attach_adapter(struct i2c_adapter *adapter);
static int lm83_detect(struct i2c_adapter *adapter, int address, int kind); static int lm83_detect(struct i2c_adapter *adapter, int address, int kind);
static int lm83_detach_client(struct i2c_client *client); static int lm83_detach_client(struct i2c_client *client);
static void lm83_update_client(struct i2c_client *client); static struct lm83_data *lm83_update_device(struct device *dev);
/* /*
* Driver data (common to all clients) * Driver data (common to all clients)
...@@ -162,9 +162,7 @@ static int lm83_id = 0; ...@@ -162,9 +162,7 @@ static int lm83_id = 0;
#define show_temp(suffix, value) \ #define show_temp(suffix, value) \
static ssize_t show_temp_##suffix(struct device *dev, char *buf) \ static ssize_t show_temp_##suffix(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm83_data *data = lm83_update_device(dev); \
struct lm83_data *data = i2c_get_clientdata(client); \
lm83_update_client(client); \
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
} }
show_temp(input1, temp_input[0]); show_temp(input1, temp_input[0]);
...@@ -195,9 +193,7 @@ set_temp(crit, temp_crit, LM83_REG_W_TCRIT); ...@@ -195,9 +193,7 @@ set_temp(crit, temp_crit, LM83_REG_W_TCRIT);
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm83_data *data = lm83_update_device(dev);
struct lm83_data *data = i2c_get_clientdata(client);
lm83_update_client(client);
return sprintf(buf, "%d\n", data->alarms); return sprintf(buf, "%d\n", data->alarms);
} }
...@@ -353,8 +349,9 @@ static int lm83_detach_client(struct i2c_client *client) ...@@ -353,8 +349,9 @@ static int lm83_detach_client(struct i2c_client *client)
return 0; return 0;
} }
static void lm83_update_client(struct i2c_client *client) static struct lm83_data *lm83_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm83_data *data = i2c_get_clientdata(client); struct lm83_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -385,6 +382,8 @@ static void lm83_update_client(struct i2c_client *client) ...@@ -385,6 +382,8 @@ static void lm83_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_lm83_init(void) static int __init sensors_lm83_init(void)
......
...@@ -397,7 +397,7 @@ static int lm85_detach_client(struct i2c_client *client); ...@@ -397,7 +397,7 @@ static int lm85_detach_client(struct i2c_client *client);
static int lm85_read_value(struct i2c_client *client, u8 register); static int lm85_read_value(struct i2c_client *client, u8 register);
static int lm85_write_value(struct i2c_client *client, u8 register, int value); static int lm85_write_value(struct i2c_client *client, u8 register, int value);
static void lm85_update_client(struct i2c_client *client); static struct lm85_data *lm85_update_device(struct device *dev);
static void lm85_init_client(struct i2c_client *client); static void lm85_init_client(struct i2c_client *client);
...@@ -417,18 +417,12 @@ static int lm85_id = 0; ...@@ -417,18 +417,12 @@ static int lm85_id = 0;
/* 4 Fans */ /* 4 Fans */
static ssize_t show_fan(struct device *dev, char *buf, int nr) static ssize_t show_fan(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) ); return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) );
} }
static ssize_t show_fan_min(struct device *dev, char *buf, int nr) static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) ); return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) );
} }
static ssize_t set_fan_min(struct device *dev, const char *buf, static ssize_t set_fan_min(struct device *dev, const char *buf,
...@@ -473,10 +467,7 @@ show_fan_offset(4); ...@@ -473,10 +467,7 @@ show_fan_offset(4);
static ssize_t show_vid_reg(struct device *dev, char *buf) static ssize_t show_vid_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
} }
...@@ -484,10 +475,7 @@ static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid_reg, NULL) ...@@ -484,10 +475,7 @@ static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid_reg, NULL)
static ssize_t show_vrm_reg(struct device *dev, char *buf) static ssize_t show_vrm_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf, "%ld\n", (long) data->vrm); return sprintf(buf, "%ld\n", (long) data->vrm);
} }
...@@ -506,10 +494,7 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg) ...@@ -506,10 +494,7 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg)
static ssize_t show_alarms_reg(struct device *dev, char *buf) static ssize_t show_alarms_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms)); return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms));
} }
...@@ -519,10 +504,7 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL) ...@@ -519,10 +504,7 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL)
static ssize_t show_pwm(struct device *dev, char *buf, int nr) static ssize_t show_pwm(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) ); return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) );
} }
static ssize_t set_pwm(struct device *dev, const char *buf, static ssize_t set_pwm(struct device *dev, const char *buf,
...@@ -541,11 +523,9 @@ static ssize_t set_pwm(struct device *dev, const char *buf, ...@@ -541,11 +523,9 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
} }
static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
int pwm_zone; int pwm_zone;
lm85_update_client(client);
pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) ); return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) );
} }
...@@ -576,18 +556,12 @@ show_pwm_reg(3); ...@@ -576,18 +556,12 @@ show_pwm_reg(3);
static ssize_t show_in(struct device *dev, char *buf, int nr) static ssize_t show_in(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) ); return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]) );
} }
static ssize_t show_in_min(struct device *dev, char *buf, int nr) static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) ); return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) );
} }
static ssize_t set_in_min(struct device *dev, const char *buf, static ssize_t set_in_min(struct device *dev, const char *buf,
...@@ -606,10 +580,7 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -606,10 +580,7 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) ); return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) );
} }
static ssize_t set_in_max(struct device *dev, const char *buf, static ssize_t set_in_max(struct device *dev, const char *buf,
...@@ -665,18 +636,12 @@ show_in_reg(4); ...@@ -665,18 +636,12 @@ show_in_reg(4);
static ssize_t show_temp(struct device *dev, char *buf, int nr) static ssize_t show_temp(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]) ); return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]) );
} }
static ssize_t show_temp_min(struct device *dev, char *buf, int nr) static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) ); return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
} }
static ssize_t set_temp_min(struct device *dev, const char *buf, static ssize_t set_temp_min(struct device *dev, const char *buf,
...@@ -695,10 +660,7 @@ static ssize_t set_temp_min(struct device *dev, const char *buf, ...@@ -695,10 +660,7 @@ static ssize_t set_temp_min(struct device *dev, const char *buf,
} }
static ssize_t show_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm85_data *data = lm85_update_device(dev);
struct lm85_data *data = i2c_get_clientdata(client);
lm85_update_client(client);
return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) ); return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
} }
static ssize_t set_temp_max(struct device *dev, const char *buf, static ssize_t set_temp_max(struct device *dev, const char *buf,
...@@ -1047,8 +1009,9 @@ void lm85_init_client(struct i2c_client *client) ...@@ -1047,8 +1009,9 @@ void lm85_init_client(struct i2c_client *client)
lm85_write_value(client, LM85_REG_CONFIG, value); lm85_write_value(client, LM85_REG_CONFIG, value);
} }
void lm85_update_client(struct i2c_client *client) static struct lm85_data *lm85_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -1189,6 +1152,8 @@ void lm85_update_client(struct i2c_client *client) ...@@ -1189,6 +1152,8 @@ void lm85_update_client(struct i2c_client *client)
data->valid = 1; data->valid = 1;
up(&data->update_lock); up(&data->update_lock);
return data;
} }
......
...@@ -126,7 +126,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, ...@@ -126,7 +126,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address,
int kind); int kind);
static void lm90_init_client(struct i2c_client *client); static void lm90_init_client(struct i2c_client *client);
static int lm90_detach_client(struct i2c_client *client); static int lm90_detach_client(struct i2c_client *client);
static void lm90_update_client(struct i2c_client *client); static struct lm90_data *lm90_update_device(struct device *dev);
/* /*
* Driver data (common to all clients) * Driver data (common to all clients)
...@@ -171,9 +171,7 @@ static int lm90_id = 0; ...@@ -171,9 +171,7 @@ static int lm90_id = 0;
#define show_temp(value, converter) \ #define show_temp(value, converter) \
static ssize_t show_##value(struct device *dev, char *buf) \ static ssize_t show_##value(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm90_data *data = lm90_update_device(dev); \
struct lm90_data *data = i2c_get_clientdata(client); \
lm90_update_client(client); \
return sprintf(buf, "%d\n", converter(data->value)); \ return sprintf(buf, "%d\n", converter(data->value)); \
} }
show_temp(temp_input1, TEMP1_FROM_REG); show_temp(temp_input1, TEMP1_FROM_REG);
...@@ -216,9 +214,7 @@ set_temp1(temp_crit2, LM90_REG_W_REMOTE_CRIT); ...@@ -216,9 +214,7 @@ set_temp1(temp_crit2, LM90_REG_W_REMOTE_CRIT);
#define show_temp_hyst(value, basereg) \ #define show_temp_hyst(value, basereg) \
static ssize_t show_##value(struct device *dev, char *buf) \ static ssize_t show_##value(struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct lm90_data *data = lm90_update_device(dev); \
struct lm90_data *data = i2c_get_clientdata(client); \
lm90_update_client(client); \
return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->basereg) \ return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->basereg) \
- HYST_FROM_REG(data->temp_hyst)); \ - HYST_FROM_REG(data->temp_hyst)); \
} }
...@@ -239,9 +235,7 @@ static ssize_t set_temp_hyst1(struct device *dev, const char *buf, ...@@ -239,9 +235,7 @@ static ssize_t set_temp_hyst1(struct device *dev, const char *buf,
static ssize_t show_alarms(struct device *dev, char *buf) static ssize_t show_alarms(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct lm90_data *data = lm90_update_device(dev);
struct lm90_data *data = i2c_get_clientdata(client);
lm90_update_client(client);
return sprintf(buf, "%d\n", data->alarms); return sprintf(buf, "%d\n", data->alarms);
} }
...@@ -430,8 +424,9 @@ static int lm90_detach_client(struct i2c_client *client) ...@@ -430,8 +424,9 @@ static int lm90_detach_client(struct i2c_client *client)
return 0; return 0;
} }
static void lm90_update_client(struct i2c_client *client) static struct lm90_data *lm90_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct lm90_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -505,6 +500,8 @@ static void lm90_update_client(struct i2c_client *client) ...@@ -505,6 +500,8 @@ static void lm90_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_lm90_init(void) static int __init sensors_lm90_init(void)
......
...@@ -409,30 +409,24 @@ static inline void via686a_write_value(struct i2c_client *client, u8 reg, ...@@ -409,30 +409,24 @@ static inline void via686a_write_value(struct i2c_client *client, u8 reg,
outb_p(value, client->addr + reg); outb_p(value, client->addr + reg);
} }
static void via686a_update_client(struct i2c_client *client); static struct via686a_data *via686a_update_device(struct device *dev);
static void via686a_init_client(struct i2c_client *client); static void via686a_init_client(struct i2c_client *client);
/* following are the sysfs callback functions */ /* following are the sysfs callback functions */
/* 7 voltage sensors */ /* 7 voltage sensors */
static ssize_t show_in(struct device *dev, char *buf, int nr) { static ssize_t show_in(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)*10 ); return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)*10 );
} }
static ssize_t show_in_min(struct device *dev, char *buf, int nr) { static ssize_t show_in_min(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)*10 ); return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)*10 );
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) { static ssize_t show_in_max(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)*10 ); return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)*10 );
} }
...@@ -496,21 +490,15 @@ show_in_offset(4); ...@@ -496,21 +490,15 @@ show_in_offset(4);
/* 3 temperatures */ /* 3 temperatures */
static ssize_t show_temp(struct device *dev, char *buf, int nr) { static ssize_t show_temp(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])*100 ); return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])*100 );
} }
static ssize_t show_temp_over(struct device *dev, char *buf, int nr) { static ssize_t show_temp_over(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])*100); return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])*100);
} }
static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) { static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])*100); return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])*100);
} }
static ssize_t set_temp_over(struct device *dev, const char *buf, static ssize_t set_temp_over(struct device *dev, const char *buf,
...@@ -568,23 +556,17 @@ show_temp_offset(3); ...@@ -568,23 +556,17 @@ show_temp_offset(3);
/* 2 Fans */ /* 2 Fans */
static ssize_t show_fan(struct device *dev, char *buf, int nr) { static ssize_t show_fan(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
DIV_FROM_REG(data->fan_div[nr])) ); DIV_FROM_REG(data->fan_div[nr])) );
} }
static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { static ssize_t show_fan_min(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf,"%d\n", return sprintf(buf,"%d\n",
FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) );
} }
static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { static ssize_t show_fan_div(struct device *dev, char *buf, int nr) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) ); return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) );
} }
static ssize_t set_fan_min(struct device *dev, const char *buf, static ssize_t set_fan_min(struct device *dev, const char *buf,
...@@ -642,9 +624,7 @@ show_fan_offset(2); ...@@ -642,9 +624,7 @@ show_fan_offset(2);
/* Alarms */ /* Alarms */
static ssize_t show_alarms(struct device *dev, char *buf) { static ssize_t show_alarms(struct device *dev, char *buf) {
struct i2c_client *client = to_i2c_client(dev); struct via686a_data *data = via686a_update_device(dev);
struct via686a_data *data = i2c_get_clientdata(client);
via686a_update_client(client);
return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms)); return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms));
} }
static DEVICE_ATTR(alarms, S_IRUGO | S_IWUSR, show_alarms, NULL); static DEVICE_ATTR(alarms, S_IRUGO | S_IWUSR, show_alarms, NULL);
...@@ -854,8 +834,9 @@ static void via686a_init_client(struct i2c_client *client) ...@@ -854,8 +834,9 @@ static void via686a_init_client(struct i2c_client *client)
!(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS)); !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS));
} }
static void via686a_update_client(struct i2c_client *client) static struct via686a_data *via686a_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -916,6 +897,8 @@ static void via686a_update_client(struct i2c_client *client) ...@@ -916,6 +897,8 @@ static void via686a_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static struct pci_device_id via686a_pci_ids[] = { static struct pci_device_id via686a_pci_ids[] = {
......
...@@ -322,7 +322,7 @@ static int w83627hf_detach_client(struct i2c_client *client); ...@@ -322,7 +322,7 @@ static int w83627hf_detach_client(struct i2c_client *client);
static int w83627hf_read_value(struct i2c_client *client, u16 register); static int w83627hf_read_value(struct i2c_client *client, u16 register);
static int w83627hf_write_value(struct i2c_client *client, u16 register, static int w83627hf_write_value(struct i2c_client *client, u16 register,
u16 value); u16 value);
static void w83627hf_update_client(struct i2c_client *client); static struct w83627hf_data *w83627hf_update_device(struct device *dev);
static void w83627hf_init_client(struct i2c_client *client); static void w83627hf_init_client(struct i2c_client *client);
static struct i2c_driver w83627hf_driver = { static struct i2c_driver w83627hf_driver = {
...@@ -338,11 +338,7 @@ static struct i2c_driver w83627hf_driver = { ...@@ -338,11 +338,7 @@ static struct i2c_driver w83627hf_driver = {
#define show_in_reg(reg) \ #define show_in_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83627hf_data *data = w83627hf_update_device(dev); \
struct w83627hf_data *data = i2c_get_clientdata(client); \
\
w83627hf_update_client(client); \
\
return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr])); \ return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr])); \
} }
show_in_reg(in) show_in_reg(in)
...@@ -414,11 +410,7 @@ device_create_file(&client->dev, &dev_attr_in##offset##_max); \ ...@@ -414,11 +410,7 @@ device_create_file(&client->dev, &dev_attr_in##offset##_max); \
#define show_fan_reg(reg) \ #define show_fan_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83627hf_data *data = w83627hf_update_device(dev); \
struct w83627hf_data *data = i2c_get_clientdata(client); \
\
w83627hf_update_client(client); \
\
return sprintf(buf,"%ld\n", \ return sprintf(buf,"%ld\n", \
FAN_FROM_REG(data->reg[nr-1], \ FAN_FROM_REG(data->reg[nr-1], \
(long)DIV_FROM_REG(data->fan_div[nr-1]))); \ (long)DIV_FROM_REG(data->fan_div[nr-1]))); \
...@@ -478,11 +470,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_min); \ ...@@ -478,11 +470,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
#define show_temp_reg(reg) \ #define show_temp_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83627hf_data *data = w83627hf_update_device(dev); \
struct w83627hf_data *data = i2c_get_clientdata(client); \
\
w83627hf_update_client(client); \
\
if (nr >= 2) { /* TEMP2 and TEMP3 */ \ if (nr >= 2) { /* TEMP2 and TEMP3 */ \
return sprintf(buf,"%ld\n", \ return sprintf(buf,"%ld\n", \
(long)LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ (long)LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
...@@ -560,11 +548,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \ ...@@ -560,11 +548,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
static ssize_t static ssize_t
show_vid_reg(struct device *dev, char *buf) show_vid_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
} }
static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid_reg, NULL) static DEVICE_ATTR(in0_ref, S_IRUGO, show_vid_reg, NULL)
...@@ -574,11 +558,7 @@ device_create_file(&client->dev, &dev_attr_in0_ref) ...@@ -574,11 +558,7 @@ device_create_file(&client->dev, &dev_attr_in0_ref)
static ssize_t static ssize_t
show_vrm_reg(struct device *dev, char *buf) show_vrm_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", (long) data->vrm); return sprintf(buf, "%ld\n", (long) data->vrm);
} }
static ssize_t static ssize_t
...@@ -600,11 +580,7 @@ device_create_file(&client->dev, &dev_attr_vrm) ...@@ -600,11 +580,7 @@ device_create_file(&client->dev, &dev_attr_vrm)
static ssize_t static ssize_t
show_alarms_reg(struct device *dev, char *buf) show_alarms_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", (long) data->alarms); return sprintf(buf, "%ld\n", (long) data->alarms);
} }
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL) static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL)
...@@ -614,11 +590,7 @@ device_create_file(&client->dev, &dev_attr_alarms) ...@@ -614,11 +590,7 @@ device_create_file(&client->dev, &dev_attr_alarms)
#define show_beep_reg(REG, reg) \ #define show_beep_reg(REG, reg) \
static ssize_t show_beep_##reg (struct device *dev, char *buf) \ static ssize_t show_beep_##reg (struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83627hf_data *data = w83627hf_update_device(dev); \
struct w83627hf_data *data = i2c_get_clientdata(client); \
\
w83627hf_update_client(client); \
\
return sprintf(buf,"%ld\n", \ return sprintf(buf,"%ld\n", \
(long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \ (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \
} }
...@@ -682,11 +654,7 @@ device_create_file(&client->dev, &dev_attr_beep_mask); \ ...@@ -682,11 +654,7 @@ device_create_file(&client->dev, &dev_attr_beep_mask); \
static ssize_t static ssize_t
show_fan_div_reg(struct device *dev, char *buf, int nr) show_fan_div_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", return sprintf(buf, "%ld\n",
(long) DIV_FROM_REG(data->fan_div[nr - 1])); (long) DIV_FROM_REG(data->fan_div[nr - 1]));
} }
...@@ -749,11 +717,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ ...@@ -749,11 +717,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
static ssize_t static ssize_t
show_pwm_reg(struct device *dev, char *buf, int nr) show_pwm_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", (long) data->pwm[nr - 1]); return sprintf(buf, "%ld\n", (long) data->pwm[nr - 1]);
} }
...@@ -809,11 +773,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_pwm); \ ...@@ -809,11 +773,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_pwm); \
static ssize_t static ssize_t
show_sensor_reg(struct device *dev, char *buf, int nr) show_sensor_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
struct w83627hf_data *data = i2c_get_clientdata(client);
w83627hf_update_client(client);
return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]);
} }
...@@ -1273,8 +1233,9 @@ static void w83627hf_init_client(struct i2c_client *client) ...@@ -1273,8 +1233,9 @@ static void w83627hf_init_client(struct i2c_client *client)
| 0x01); | 0x01);
} }
static void w83627hf_update_client(struct i2c_client *client) static struct w83627hf_data *w83627hf_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct w83627hf_data *data = i2c_get_clientdata(client); struct w83627hf_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -1362,6 +1323,8 @@ static void w83627hf_update_client(struct i2c_client *client) ...@@ -1362,6 +1323,8 @@ static void w83627hf_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_w83627hf_init(void) static int __init sensors_w83627hf_init(void)
......
...@@ -276,7 +276,7 @@ static int w83781d_detach_client(struct i2c_client *client); ...@@ -276,7 +276,7 @@ static int w83781d_detach_client(struct i2c_client *client);
static int w83781d_read_value(struct i2c_client *client, u16 register); static int w83781d_read_value(struct i2c_client *client, u16 register);
static int w83781d_write_value(struct i2c_client *client, u16 register, static int w83781d_write_value(struct i2c_client *client, u16 register,
u16 value); u16 value);
static void w83781d_update_client(struct i2c_client *client); static struct w83781d_data *w83781d_update_device(struct device *dev);
static void w83781d_init_client(struct i2c_client *client); static void w83781d_init_client(struct i2c_client *client);
static inline u16 swap_bytes(u16 val) static inline u16 swap_bytes(u16 val)
...@@ -297,11 +297,7 @@ static struct i2c_driver w83781d_driver = { ...@@ -297,11 +297,7 @@ static struct i2c_driver w83781d_driver = {
#define show_in_reg(reg) \ #define show_in_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83781d_data *data = w83781d_update_device(dev); \
struct w83781d_data *data = i2c_get_clientdata(client); \
\
w83781d_update_client(client); \
\
return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr] * 10)); \ return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr] * 10)); \
} }
show_in_reg(in); show_in_reg(in);
...@@ -368,11 +364,7 @@ device_create_file(&client->dev, &dev_attr_in##offset##_max); \ ...@@ -368,11 +364,7 @@ device_create_file(&client->dev, &dev_attr_in##offset##_max); \
#define show_fan_reg(reg) \ #define show_fan_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83781d_data *data = w83781d_update_device(dev); \
struct w83781d_data *data = i2c_get_clientdata(client); \
\
w83781d_update_client(client); \
\
return sprintf(buf,"%ld\n", \ return sprintf(buf,"%ld\n", \
FAN_FROM_REG(data->reg[nr-1], (long)DIV_FROM_REG(data->fan_div[nr-1]))); \ FAN_FROM_REG(data->reg[nr-1], (long)DIV_FROM_REG(data->fan_div[nr-1]))); \
} }
...@@ -429,11 +421,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_min); \ ...@@ -429,11 +421,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
#define show_temp_reg(reg) \ #define show_temp_reg(reg) \
static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83781d_data *data = w83781d_update_device(dev); \
struct w83781d_data *data = i2c_get_clientdata(client); \
\
w83781d_update_client(client); \
\
if (nr >= 2) { /* TEMP2 and TEMP3 */ \ if (nr >= 2) { /* TEMP2 and TEMP3 */ \
if (data->type == as99127f) { \ if (data->type == as99127f) { \
return sprintf(buf,"%ld\n", \ return sprintf(buf,"%ld\n", \
...@@ -516,11 +504,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \ ...@@ -516,11 +504,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
static ssize_t static ssize_t
show_vid_reg(struct device *dev, char *buf) show_vid_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
} }
...@@ -531,11 +515,7 @@ device_create_file(&client->dev, &dev_attr_in0_ref); ...@@ -531,11 +515,7 @@ device_create_file(&client->dev, &dev_attr_in0_ref);
static ssize_t static ssize_t
show_vrm_reg(struct device *dev, char *buf) show_vrm_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) data->vrm); return sprintf(buf, "%ld\n", (long) data->vrm);
} }
...@@ -559,11 +539,7 @@ device_create_file(&client->dev, &dev_attr_vrm); ...@@ -559,11 +539,7 @@ device_create_file(&client->dev, &dev_attr_vrm);
static ssize_t static ssize_t
show_alarms_reg(struct device *dev, char *buf) show_alarms_reg(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms)); return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms));
} }
...@@ -574,11 +550,7 @@ device_create_file(&client->dev, &dev_attr_alarms); ...@@ -574,11 +550,7 @@ device_create_file(&client->dev, &dev_attr_alarms);
#define show_beep_reg(REG, reg) \ #define show_beep_reg(REG, reg) \
static ssize_t show_beep_##reg (struct device *dev, char *buf) \ static ssize_t show_beep_##reg (struct device *dev, char *buf) \
{ \ { \
struct i2c_client *client = to_i2c_client(dev); \ struct w83781d_data *data = w83781d_update_device(dev); \
struct w83781d_data *data = i2c_get_clientdata(client); \
\
w83781d_update_client(client); \
\
return sprintf(buf,"%ld\n", (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \ return sprintf(buf,"%ld\n", (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \
} }
show_beep_reg(ENABLE, enable); show_beep_reg(ENABLE, enable);
...@@ -642,11 +614,7 @@ device_create_file(&client->dev, &dev_attr_beep_mask); \ ...@@ -642,11 +614,7 @@ device_create_file(&client->dev, &dev_attr_beep_mask); \
static ssize_t static ssize_t
show_fan_div_reg(struct device *dev, char *buf, int nr) show_fan_div_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", return sprintf(buf, "%ld\n",
(long) DIV_FROM_REG(data->fan_div[nr - 1])); (long) DIV_FROM_REG(data->fan_div[nr - 1]));
} }
...@@ -743,11 +711,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ ...@@ -743,11 +711,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
static ssize_t static ssize_t
show_pwm_reg(struct device *dev, char *buf, int nr) show_pwm_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr - 1])); return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr - 1]));
} }
...@@ -755,11 +719,7 @@ show_pwm_reg(struct device *dev, char *buf, int nr) ...@@ -755,11 +719,7 @@ show_pwm_reg(struct device *dev, char *buf, int nr)
static ssize_t static ssize_t
show_pwmenable_reg(struct device *dev, char *buf, int nr) show_pwmenable_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) data->pwmenable[nr - 1]); return sprintf(buf, "%ld\n", (long) data->pwmenable[nr - 1]);
} }
...@@ -861,11 +821,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_pwm_enable); \ ...@@ -861,11 +821,7 @@ device_create_file(&client->dev, &dev_attr_fan##offset##_pwm_enable); \
static ssize_t static ssize_t
show_sensor_reg(struct device *dev, char *buf, int nr) show_sensor_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
w83781d_update_client(client);
return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]);
} }
...@@ -937,12 +893,9 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_type); \ ...@@ -937,12 +893,9 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
static ssize_t static ssize_t
show_rt_reg(struct device *dev, char *buf, int nr) show_rt_reg(struct device *dev, char *buf, int nr)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83781d_data *data = w83781d_update_device(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
int i, j = 0; int i, j = 0;
w83781d_update_client(client);
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (i > 0) if (i > 0)
j += sprintf(buf, " %ld", (long) data->rt[nr - 1][i]); j += sprintf(buf, " %ld", (long) data->rt[nr - 1][i]);
...@@ -1667,9 +1620,9 @@ w83781d_init_client(struct i2c_client *client) ...@@ -1667,9 +1620,9 @@ w83781d_init_client(struct i2c_client *client)
| 0x01); | 0x01);
} }
static void static struct w83781d_data *w83781d_update_device(struct device *dev)
w83781d_update_client(struct i2c_client *client)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct w83781d_data *data = i2c_get_clientdata(client); struct w83781d_data *data = i2c_get_clientdata(client);
int i; int i;
...@@ -1782,6 +1735,8 @@ w83781d_update_client(struct i2c_client *client) ...@@ -1782,6 +1735,8 @@ w83781d_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init static int __init
......
...@@ -89,7 +89,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, ...@@ -89,7 +89,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address,
int kind); int kind);
static int w83l785ts_detach_client(struct i2c_client *client); static int w83l785ts_detach_client(struct i2c_client *client);
static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval);
static void w83l785ts_update_client(struct i2c_client *client); static struct w83l785ts_data *w83l785ts_update_device(struct device *dev);
/* /*
* Driver data (common to all clients) * Driver data (common to all clients)
...@@ -130,17 +130,13 @@ static int w83l785ts_id = 0; ...@@ -130,17 +130,13 @@ static int w83l785ts_id = 0;
static ssize_t show_temp(struct device *dev, char *buf) static ssize_t show_temp(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83l785ts_data *data = w83l785ts_update_device(dev);
struct w83l785ts_data *data = i2c_get_clientdata(client);
w83l785ts_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
} }
static ssize_t show_temp_over(struct device *dev, char *buf) static ssize_t show_temp_over(struct device *dev, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct w83l785ts_data *data = w83l785ts_update_device(dev);
struct w83l785ts_data *data = i2c_get_clientdata(client);
w83l785ts_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
} }
...@@ -304,8 +300,9 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval) ...@@ -304,8 +300,9 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval)
return defval; return defval;
} }
static void w83l785ts_update_client(struct i2c_client *client) static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev);
struct w83l785ts_data *data = i2c_get_clientdata(client); struct w83l785ts_data *data = i2c_get_clientdata(client);
down(&data->update_lock); down(&data->update_lock);
...@@ -324,6 +321,8 @@ static void w83l785ts_update_client(struct i2c_client *client) ...@@ -324,6 +321,8 @@ static void w83l785ts_update_client(struct i2c_client *client)
} }
up(&data->update_lock); up(&data->update_lock);
return data;
} }
static int __init sensors_w83l785ts_init(void) static int __init sensors_w83l785ts_init(void)
......
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