hwmon: (lm90) Introduce device feature bits

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
Guenter Roeck 2010-10-28 20:31:43 +02:00 committed by Jean Delvare
parent 11e578129a
commit 88073bb1ba

View File

@ -142,7 +142,11 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646,
/* /*
* Device flags * Device flags
*/ */
#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */ #define LM90_FLAG_ADT7461_EXT (1 << 0) /* ADT7461 extended mode */
/* Device features */
#define LM90_HAVE_OFFSET (1 << 1) /* temperature offset register */
#define LM90_HAVE_LOCAL_EXT (1 << 2) /* extended local temperature */
#define LM90_HAVE_REM_LIMIT_EXT (1 << 3) /* extended remote limit */
/* /*
* Functions declaration * Functions declaration
@ -462,17 +466,16 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
if (data->kind == adt7461) if (data->kind == adt7461)
data->temp11[nr] = temp_to_u16_adt7461(data, val); data->temp11[nr] = temp_to_u16_adt7461(data, val);
else if (data->kind == max6657 || data->kind == max6680)
data->temp11[nr] = temp_to_s8(val) << 8;
else if (data->kind == max6646) else if (data->kind == max6646)
data->temp11[nr] = temp_to_u8(val) << 8; data->temp11[nr] = temp_to_u8(val) << 8;
else else if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
data->temp11[nr] = temp_to_s16(val); data->temp11[nr] = temp_to_s16(val);
else
data->temp11[nr] = temp_to_s8(val) << 8;
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
data->temp11[nr] >> 8); data->temp11[nr] >> 8);
if (data->kind != max6657 && data->kind != max6680 if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
&& data->kind != max6646)
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
data->temp11[nr] & 0xff); data->temp11[nr] & 0xff);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
@ -847,6 +850,17 @@ static int lm90_probe(struct i2c_client *new_client,
break; break;
} }
/* Set chip capabilities */
if (data->kind != max6657 && data->kind != max6646)
data->flags |= LM90_HAVE_OFFSET;
if (data->kind == max6657 || data->kind == max6646)
data->flags |= LM90_HAVE_LOCAL_EXT;
if (data->kind != max6657 && data->kind != max6646
&& data->kind != max6680)
data->flags |= LM90_HAVE_REM_LIMIT_EXT;
/* Initialize the LM90 chip */ /* Initialize the LM90 chip */
lm90_init_client(new_client); lm90_init_client(new_client);
@ -859,7 +873,7 @@ static int lm90_probe(struct i2c_client *new_client,
if (err) if (err)
goto exit_remove_files; goto exit_remove_files;
} }
if (data->kind != max6657 && data->kind != max6646) { if (data->flags & LM90_HAVE_OFFSET) {
err = device_create_file(&new_client->dev, err = device_create_file(&new_client->dev,
&sensor_dev_attr_temp2_offset.dev_attr); &sensor_dev_attr_temp2_offset.dev_attr);
if (err) if (err)
@ -925,7 +939,7 @@ static int lm90_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &lm90_group); sysfs_remove_group(&client->dev.kobj, &lm90_group);
device_remove_file(&client->dev, &dev_attr_pec); device_remove_file(&client->dev, &dev_attr_pec);
if (data->kind != max6657 && data->kind != max6646) if (data->flags & LM90_HAVE_OFFSET)
device_remove_file(&client->dev, device_remove_file(&client->dev,
&sensor_dev_attr_temp2_offset.dev_attr); &sensor_dev_attr_temp2_offset.dev_attr);
@ -1019,7 +1033,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
if (data->kind == max6657 || data->kind == max6646) { if (data->flags & LM90_HAVE_LOCAL_EXT) {
lm90_read16(client, LM90_REG_R_LOCAL_TEMP, lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
MAX6657_REG_R_LOCAL_TEMPL, MAX6657_REG_R_LOCAL_TEMPL,
&data->temp11[4]); &data->temp11[4]);
@ -1033,22 +1047,20 @@ static struct lm90_data *lm90_update_device(struct device *dev)
if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
data->temp11[1] = h << 8; data->temp11[1] = h << 8;
if (data->kind != max6657 && data->kind != max6680 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
&& data->kind != max6646
&& lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
&l) == 0) &l) == 0)
data->temp11[1] |= l; data->temp11[1] |= l;
} }
if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
data->temp11[2] = h << 8; data->temp11[2] = h << 8;
if (data->kind != max6657 && data->kind != max6680 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
&& data->kind != max6646
&& lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
&l) == 0) &l) == 0)
data->temp11[2] |= l; data->temp11[2] |= l;
} }
if (data->kind != max6657 && data->kind != max6646) { if (data->flags & LM90_HAVE_OFFSET) {
if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
&h) == 0 &h) == 0
&& lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,