Commit 91ca0844 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

i2c: convert adm1021 chip driver to use sysfs files.

Note, some data is not converted and will not be displayed.
Someone with this hardware is going to have to finish the rest of 
this conversion.
parent 98ab0b5d
......@@ -104,37 +104,36 @@ clearing it. Weird, ey? --Phil */
/* Each client has this additional data */
struct adm1021_data {
int sysctl_id;
enum chips type;
struct semaphore update_lock;
char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */
u8 temp, temp_os, temp_hyst; /* Register values */
u8 remote_temp, remote_temp_os, remote_temp_hyst, alarms, die_code;
u8 temp_max; /* Register values */
u8 temp_hyst;
u8 temp_input;
u8 remote_temp_max;
u8 remote_temp_hyst;
u8 remote_temp_input;
u8 alarms;
/* special values for ADM1021 only */
u8 die_code;
/* Special values for ADM1023 only */
u8 remote_temp_prec, remote_temp_os_prec, remote_temp_hyst_prec,
remote_temp_offset, remote_temp_offset_prec;
u8 remote_temp_prec;
u8 remote_temp_os_prec;
u8 remote_temp_hyst_prec;
u8 remote_temp_offset;
u8 remote_temp_offset_prec;
};
static int adm1021_attach_adapter(struct i2c_adapter *adapter);
static int adm1021_detect(struct i2c_adapter *adapter, int address,
unsigned short flags, int kind);
static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind);
static void adm1021_init_client(struct i2c_client *client);
static int adm1021_detach_client(struct i2c_client *client);
static int adm1021_read_value(struct i2c_client *client, u8 reg);
static int adm1021_write_value(struct i2c_client *client, u8 reg,
u16 value);
static void adm1021_temp(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
static void adm1021_remote_temp(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag,
long *results);
static void adm1021_alarms(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
static void adm1021_die_code(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
static void adm1021_update_client(struct i2c_client *client);
/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
......@@ -151,45 +150,63 @@ static struct i2c_driver adm1021_driver = {
.detach_client = adm1021_detach_client,
};
/* These files are created for each detected adm1021. This is just a template;
though at first sight, you might think we could use a statically
allocated list, we need some way to get back to the parent - which
is done through one of the 'extra' fields which are initialized
when a new copy is allocated. */
static ctl_table adm1021_dir_table_template[] = {
{ADM1021_SYSCTL_TEMP, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_temp},
{ADM1021_SYSCTL_REMOTE_TEMP, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_remote_temp},
{ADM1021_SYSCTL_DIE_CODE, "die_code", NULL, 0, 0444, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_die_code},
{ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_alarms},
{0}
};
static ctl_table adm1021_max_dir_table_template[] = {
{ADM1021_SYSCTL_TEMP, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_temp},
{ADM1021_SYSCTL_REMOTE_TEMP, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_remote_temp},
{ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real,
&i2c_sysctl_real, NULL, &adm1021_alarms},
{0}
};
/* I choose here for semi-static allocation. Complete dynamic
allocation could also be used; the code needed for this would probably
take more memory than the datastructure takes now. */
static int adm1021_id = 0;
#define show(value) \
static ssize_t show_##value(struct device *dev, char *buf) \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1021_data *data = i2c_get_clientdata(client); \
int temp; \
\
adm1021_update_client(client); \
temp = TEMP_FROM_REG(data->value); \
return sprintf(buf, "%d\n", temp); \
}
show(temp_max);
show(temp_hyst);
show(temp_input);
show(remote_temp_max);
show(remote_temp_hyst);
show(remote_temp_input);
show(alarms);
show(die_code);
#define set(value, reg) \
static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1021_data *data = i2c_get_clientdata(client); \
int temp = simple_strtoul(buf, NULL, 10); \
\
data->value = TEMP_TO_REG(temp); \
adm1021_write_value(client, reg, data->value); \
return count; \
}
set(temp_max, ADM1021_REG_TOS_W);
set(temp_hyst, ADM1021_REG_THYST_W);
set(remote_temp_max, ADM1021_REG_REMOTE_TOS_W);
set(remote_temp_hyst, ADM1021_REG_REMOTE_THYST_W);
static DEVICE_ATTR(temp_max1, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
static DEVICE_ATTR(temp_min1, S_IWUSR | S_IRUGO, show_temp_hyst, set_temp_hyst);
static DEVICE_ATTR(temp_input1, S_IRUGO, show_temp_input, NULL);
static DEVICE_ATTR(temp_max2, S_IWUSR | S_IRUGO, show_remote_temp_max, set_remote_temp_max);
static DEVICE_ATTR(temp_min2, S_IWUSR | S_IRUGO, show_remote_temp_hyst, set_remote_temp_hyst);
static DEVICE_ATTR(temp_input2, S_IRUGO, show_remote_temp_input, NULL);
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
static DEVICE_ATTR(die_code, S_IRUGO, show_die_code, NULL);
static int adm1021_attach_adapter(struct i2c_adapter *adapter)
{
return i2c_detect(adapter, &addr_data, adm1021_detect);
}
static int adm1021_detect(struct i2c_adapter *adapter, int address,
unsigned short flags, int kind)
static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
{
int i;
struct i2c_client *new_client;
......@@ -202,8 +219,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address,
at this moment; i2c_detect really won't call us. */
#ifdef DEBUG
if (i2c_is_isa_adapter(adapter)) {
printk
("adm1021.o: adm1021_detect called for an ISA bus adapter?!?\n");
dev_dbg(&adapter->dev, "adm1021_detect called for an ISA bus adapter?!?\n");
return 0;
}
#endif
......@@ -232,20 +248,16 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address,
new_client->flags = 0;
/* Now, we do the remaining detection. */
if (kind < 0) {
if (
(adm1021_read_value(new_client, ADM1021_REG_STATUS) &
0x03) != 0x00)
if ((adm1021_read_value(new_client, ADM1021_REG_STATUS) & 0x03) != 0x00)
goto error1;
}
/* Determine the chip type. */
if (kind <= 0) {
i = adm1021_read_value(new_client, ADM1021_REG_MAN_ID);
if (i == 0x41)
if ((adm1021_read_value (new_client, ADM1021_REG_DEV_ID) & 0x0F0) == 0x030)
if ((adm1021_read_value(new_client, ADM1021_REG_DEV_ID) & 0x0F0) == 0x030)
kind = adm1023;
else
kind = adm1021;
......@@ -254,13 +266,10 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address,
else if (i == 0x23)
kind = gl523sm;
else if ((i == 0x4d) &&
(adm1021_read_value
(new_client, ADM1021_REG_DEV_ID) == 0x01))
(adm1021_read_value(new_client, ADM1021_REG_DEV_ID) == 0x01))
kind = max1617a;
/* LM84 Mfr ID in a different place */
else
if (adm1021_read_value
(new_client, ADM1021_REG_CONV_RATE_R) == 0x00)
else if (adm1021_read_value(new_client, ADM1021_REG_CONV_RATE_R) == 0x00)
kind = lm84;
else if (i == 0x54)
kind = mc1066;
......@@ -293,10 +302,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address,
type_name = "mc1066";
client_name = "MC1066 chip";
} else {
#ifdef DEBUG
printk("adm1021.o: Internal error: unknown kind (%d)?!?",
dev_err(&adapter->dev, "Internal error: unknown kind (%d)?!?",
kind);
#endif
goto error1;
}
......@@ -312,25 +319,24 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address,
if ((err = i2c_attach_client(new_client)))
goto error3;
/* Register a new directory entry with module sensors */
err = i2c_register_entry(new_client, type_name,
(data->type == adm1021) ?
adm1021_dir_table_template :
adm1021_max_dir_table_template);
if (err < 0)
goto error4;
device_create_file(&new_client->dev, &dev_attr_temp_max1);
device_create_file(&new_client->dev, &dev_attr_temp_min1);
device_create_file(&new_client->dev, &dev_attr_temp_input1);
device_create_file(&new_client->dev, &dev_attr_temp_max2);
device_create_file(&new_client->dev, &dev_attr_temp_min2);
device_create_file(&new_client->dev, &dev_attr_temp_input2);
device_create_file(&new_client->dev, &dev_attr_alarms);
if (data->type == adm1021)
device_create_file(&new_client->dev, &dev_attr_die_code);
data->sysctl_id = err;
/* Initialize the ADM1021 chip */
adm1021_init_client(new_client);
return 0;
error4:
i2c_detach_client(new_client);
error3:
error1:
error3:
error1:
kfree(new_client);
error0:
error0:
return err;
}
......@@ -353,21 +359,15 @@ static void adm1021_init_client(struct i2c_client *client)
static int adm1021_detach_client(struct i2c_client *client)
{
int err;
i2c_deregister_entry(((struct adm1021_data *) (i2c_get_clientdata(client)))->sysctl_id);
if ((err = i2c_detach_client(client))) {
printk
("adm1021.o: Client deregistration failed, client not detached.\n");
dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
return err;
}
kfree(client);
return 0;
}
/* All registers are byte-sized */
......@@ -391,39 +391,23 @@ static void adm1021_update_client(struct i2c_client *client)
if ((jiffies - data->last_updated > HZ + HZ / 2) ||
(jiffies < data->last_updated) || !data->valid) {
#ifdef DEBUG
printk("Starting adm1021 update\n");
#endif
data->temp = adm1021_read_value(client, ADM1021_REG_TEMP);
data->temp_os =
adm1021_read_value(client, ADM1021_REG_TOS_R);
data->temp_hyst =
adm1021_read_value(client, ADM1021_REG_THYST_R);
data->remote_temp =
adm1021_read_value(client, ADM1021_REG_REMOTE_TEMP);
data->remote_temp_os =
adm1021_read_value(client, ADM1021_REG_REMOTE_TOS_R);
data->remote_temp_hyst =
adm1021_read_value(client, ADM1021_REG_REMOTE_THYST_R);
data->alarms =
adm1021_read_value(client, ADM1021_REG_STATUS) & 0xec;
dev_dbg(&client->dev, "Starting adm1021 update\n");
data->temp_input = adm1021_read_value(client, ADM1021_REG_TEMP);
data->temp_max = adm1021_read_value(client, ADM1021_REG_TOS_R);
data->temp_hyst = adm1021_read_value(client, ADM1021_REG_THYST_R);
data->remote_temp_input = adm1021_read_value(client, ADM1021_REG_REMOTE_TEMP);
data->remote_temp_max = adm1021_read_value(client, ADM1021_REG_REMOTE_TOS_R);
data->remote_temp_hyst = adm1021_read_value(client, ADM1021_REG_REMOTE_THYST_R);
data->alarms = adm1021_read_value(client, ADM1021_REG_STATUS) & 0xec;
if (data->type == adm1021)
data->die_code =
adm1021_read_value(client,
ADM1021_REG_DIE_CODE);
data->die_code = adm1021_read_value(client, ADM1021_REG_DIE_CODE);
if (data->type == adm1023) {
data->remote_temp_prec =
adm1021_read_value(client, ADM1021_REG_REM_TEMP_PREC);
data->remote_temp_os_prec =
adm1021_read_value(client, ADM1021_REG_REM_TOS_PREC);
data->remote_temp_hyst_prec =
adm1021_read_value(client, ADM1021_REG_REM_THYST_PREC);
data->remote_temp_offset =
adm1021_read_value(client, ADM1021_REG_REM_OFFSET);
data->remote_temp_offset_prec =
adm1021_read_value(client, ADM1021_REG_REM_OFFSET_PREC);
data->remote_temp_prec = adm1021_read_value(client, ADM1021_REG_REM_TEMP_PREC);
data->remote_temp_os_prec = adm1021_read_value(client, ADM1021_REG_REM_TOS_PREC);
data->remote_temp_hyst_prec = adm1021_read_value(client, ADM1021_REG_REM_THYST_PREC);
data->remote_temp_offset = adm1021_read_value(client, ADM1021_REG_REM_OFFSET);
data->remote_temp_offset_prec = adm1021_read_value(client, ADM1021_REG_REM_OFFSET_PREC);
}
data->last_updated = jiffies;
data->valid = 1;
......@@ -433,6 +417,9 @@ static void adm1021_update_client(struct i2c_client *client)
}
/* FIXME, remove these four functions, they are here to verify the sysfs
* conversion is correct, or not */
__attribute__((unused))
static void adm1021_temp(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results)
{
......@@ -442,15 +429,15 @@ static void adm1021_temp(struct i2c_client *client, int operation,
*nrels_mag = 0;
else if (operation == SENSORS_PROC_REAL_READ) {
adm1021_update_client(client);
results[0] = TEMP_FROM_REG(data->temp_os);
results[0] = TEMP_FROM_REG(data->temp_max);
results[1] = TEMP_FROM_REG(data->temp_hyst);
results[2] = TEMP_FROM_REG(data->temp);
results[2] = TEMP_FROM_REG(data->temp_input);
*nrels_mag = 3;
} else if (operation == SENSORS_PROC_REAL_WRITE) {
if (*nrels_mag >= 1) {
data->temp_os = TEMP_TO_REG(results[0]);
data->temp_max = TEMP_TO_REG(results[0]);
adm1021_write_value(client, ADM1021_REG_TOS_W,
data->temp_os);
data->temp_max);
}
if (*nrels_mag >= 2) {
data->temp_hyst = TEMP_TO_REG(results[1]);
......@@ -460,6 +447,7 @@ static void adm1021_temp(struct i2c_client *client, int operation,
}
}
__attribute__((unused))
static void adm1021_remote_temp(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results)
{
......@@ -471,18 +459,14 @@ static void adm1021_remote_temp(struct i2c_client *client, int operation,
else { *nrels_mag = 0; }
else if (operation == SENSORS_PROC_REAL_READ) {
adm1021_update_client(client);
results[0] = TEMP_FROM_REG(data->remote_temp_os);
results[0] = TEMP_FROM_REG(data->remote_temp_max);
results[1] = TEMP_FROM_REG(data->remote_temp_hyst);
results[2] = TEMP_FROM_REG(data->remote_temp);
results[2] = TEMP_FROM_REG(data->remote_temp_input);
if (data->type == adm1023) {
results[0]=results[0]*1000 +
((data->remote_temp_os_prec >> 5) * 125);
results[1]=results[1]*1000 +
((data->remote_temp_hyst_prec >> 5) * 125);
results[2]=(TEMP_FROM_REG(data->remote_temp_offset)*1000) +
((data->remote_temp_offset_prec >> 5) * 125);
results[3]=TEMP_FROM_REG(data->remote_temp)*1000 +
((data->remote_temp_prec >> 5) * 125);
results[0] = results[0]*1000 + ((data->remote_temp_os_prec >> 5) * 125);
results[1] = results[1]*1000 + ((data->remote_temp_hyst_prec >> 5) * 125);
results[2] = (TEMP_FROM_REG(data->remote_temp_offset)*1000) + ((data->remote_temp_offset_prec >> 5) * 125);
results[3] = (TEMP_FROM_REG(data->remote_temp_input)*1000) + ((data->remote_temp_prec >> 5) * 125);
*nrels_mag = 4;
} else {
*nrels_mag = 3;
......@@ -490,49 +474,38 @@ static void adm1021_remote_temp(struct i2c_client *client, int operation,
} else if (operation == SENSORS_PROC_REAL_WRITE) {
if (*nrels_mag >= 1) {
if (data->type == adm1023) {
prec=((results[0]-((results[0]/1000)*1000))/125)<<5;
adm1021_write_value(client,
ADM1021_REG_REM_TOS_PREC,
prec);
results[0]=results[0]/1000;
prec = ((results[0]-((results[0]/1000)*1000))/125)<<5;
adm1021_write_value(client, ADM1021_REG_REM_TOS_PREC, prec);
results[0] = results[0]/1000;
data->remote_temp_os_prec=prec;
}
data->remote_temp_os = TEMP_TO_REG(results[0]);
adm1021_write_value(client,
ADM1021_REG_REMOTE_TOS_W,
data->remote_temp_os);
data->remote_temp_max = TEMP_TO_REG(results[0]);
adm1021_write_value(client, ADM1021_REG_REMOTE_TOS_W, data->remote_temp_max);
}
if (*nrels_mag >= 2) {
if (data->type == adm1023) {
prec=((results[1]-((results[1]/1000)*1000))/125)<<5;
adm1021_write_value(client,
ADM1021_REG_REM_THYST_PREC,
prec);
results[1]=results[1]/1000;
prec = ((results[1]-((results[1]/1000)*1000))/125)<<5;
adm1021_write_value(client, ADM1021_REG_REM_THYST_PREC, prec);
results[1] = results[1]/1000;
data->remote_temp_hyst_prec=prec;
}
data->remote_temp_hyst = TEMP_TO_REG(results[1]);
adm1021_write_value(client,
ADM1021_REG_REMOTE_THYST_W,
data->remote_temp_hyst);
adm1021_write_value(client, ADM1021_REG_REMOTE_THYST_W, data->remote_temp_hyst);
}
if (*nrels_mag >= 3) {
if (data->type == adm1023) {
prec=((results[2]-((results[2]/1000)*1000))/125)<<5;
adm1021_write_value(client,
ADM1021_REG_REM_OFFSET_PREC,
prec);
prec = ((results[2]-((results[2]/1000)*1000))/125)<<5;
adm1021_write_value(client, ADM1021_REG_REM_OFFSET_PREC, prec);
results[2]=results[2]/1000;
data->remote_temp_offset_prec=prec;
data->remote_temp_offset=results[2];
adm1021_write_value(client,
ADM1021_REG_REM_OFFSET,
data->remote_temp_offset);
adm1021_write_value(client, ADM1021_REG_REM_OFFSET, data->remote_temp_offset);
}
}
}
}
__attribute__((unused))
static void adm1021_die_code(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results)
{
......@@ -549,6 +522,7 @@ static void adm1021_die_code(struct i2c_client *client, int operation,
}
}
__attribute__((unused))
static void adm1021_alarms(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results)
{
......@@ -574,8 +548,8 @@ static void __exit sensors_adm1021_exit(void)
i2c_del_driver(&adm1021_driver);
}
MODULE_AUTHOR
("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl> and "
"Philip Edelbrock <phil@netroedge.com>");
MODULE_DESCRIPTION("adm1021 driver");
MODULE_LICENSE("GPL");
......
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