diff options
author | Guenter Roeck <guenter.roeck@ericsson.com> | 2010-10-28 14:31:43 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-28 14:31:43 -0400 |
commit | 96512861c3733609ac3d558602574674fa95ebf4 (patch) | |
tree | a011fd9763b09ce8f3d7774e2d17d05660063ea2 /drivers/hwmon/lm90.c | |
parent | b6fc1bacc7eae99d276d096fe0c702b1e13e4499 (diff) |
hwmon: (lm90) Simplify set_temp11 register calculations
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r-- | drivers/hwmon/lm90.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 9b1d20515eba..e7ef9657ae17 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -418,7 +418,7 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | |||
418 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | 418 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
419 | char *buf) | 419 | char *buf) |
420 | { | 420 | { |
421 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 421 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
422 | struct lm90_data *data = lm90_update_device(dev); | 422 | struct lm90_data *data = lm90_update_device(dev); |
423 | int temp; | 423 | int temp; |
424 | 424 | ||
@@ -439,19 +439,20 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | |||
439 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | 439 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
440 | const char *buf, size_t count) | 440 | const char *buf, size_t count) |
441 | { | 441 | { |
442 | static const u8 reg[6] = { | 442 | struct { |
443 | LM90_REG_W_REMOTE_LOWH, | 443 | u8 high; |
444 | LM90_REG_W_REMOTE_LOWL, | 444 | u8 low; |
445 | LM90_REG_W_REMOTE_HIGHH, | 445 | } reg[3] = { |
446 | LM90_REG_W_REMOTE_HIGHL, | 446 | { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL }, |
447 | LM90_REG_W_REMOTE_OFFSH, | 447 | { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL }, |
448 | LM90_REG_W_REMOTE_OFFSL, | 448 | { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL } |
449 | }; | 449 | }; |
450 | 450 | ||
451 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 451 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
452 | struct i2c_client *client = to_i2c_client(dev); | 452 | struct i2c_client *client = to_i2c_client(dev); |
453 | struct lm90_data *data = i2c_get_clientdata(client); | 453 | struct lm90_data *data = i2c_get_clientdata(client); |
454 | int nr = attr->index; | 454 | int nr = attr->nr; |
455 | int index = attr->index; | ||
455 | long val; | 456 | long val; |
456 | int err; | 457 | int err; |
457 | 458 | ||
@@ -460,24 +461,24 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | |||
460 | return err; | 461 | return err; |
461 | 462 | ||
462 | /* +16 degrees offset for temp2 for the LM99 */ | 463 | /* +16 degrees offset for temp2 for the LM99 */ |
463 | if (data->kind == lm99 && attr->index <= 2) | 464 | if (data->kind == lm99 && index <= 2) |
464 | val -= 16000; | 465 | val -= 16000; |
465 | 466 | ||
466 | mutex_lock(&data->update_lock); | 467 | mutex_lock(&data->update_lock); |
467 | if (data->kind == adt7461) | 468 | if (data->kind == adt7461) |
468 | data->temp11[nr] = temp_to_u16_adt7461(data, val); | 469 | data->temp11[index] = temp_to_u16_adt7461(data, val); |
469 | else if (data->kind == max6646) | 470 | else if (data->kind == max6646) |
470 | data->temp11[nr] = temp_to_u8(val) << 8; | 471 | data->temp11[index] = temp_to_u8(val) << 8; |
471 | else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) | 472 | else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) |
472 | data->temp11[nr] = temp_to_s16(val); | 473 | data->temp11[index] = temp_to_s16(val); |
473 | else | 474 | else |
474 | data->temp11[nr] = temp_to_s8(val) << 8; | 475 | data->temp11[index] = temp_to_s8(val) << 8; |
475 | 476 | ||
476 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], | 477 | i2c_smbus_write_byte_data(client, reg[nr].high, |
477 | data->temp11[nr] >> 8); | 478 | data->temp11[index] >> 8); |
478 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) | 479 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) |
479 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], | 480 | i2c_smbus_write_byte_data(client, reg[nr].low, |
480 | data->temp11[nr] & 0xff); | 481 | data->temp11[index] & 0xff); |
481 | mutex_unlock(&data->update_lock); | 482 | mutex_unlock(&data->update_lock); |
482 | return count; | 483 | return count; |
483 | } | 484 | } |
@@ -549,16 +550,16 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute | |||
549 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 550 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
550 | } | 551 | } |
551 | 552 | ||
552 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4); | 553 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4); |
553 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); | 554 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0); |
554 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, | 555 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, |
555 | set_temp8, 0); | 556 | set_temp8, 0); |
556 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, | 557 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
557 | set_temp11, 1); | 558 | set_temp11, 0, 1); |
558 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, | 559 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, |
559 | set_temp8, 1); | 560 | set_temp8, 1); |
560 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, | 561 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
561 | set_temp11, 2); | 562 | set_temp11, 1, 2); |
562 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, | 563 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, |
563 | set_temp8, 2); | 564 | set_temp8, 2); |
564 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, | 565 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, |
@@ -566,8 +567,8 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, | |||
566 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, | 567 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, |
567 | set_temphyst, 2); | 568 | set_temphyst, 2); |
568 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); | 569 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); |
569 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, | 570 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
570 | set_temp11, 3); | 571 | set_temp11, 2, 3); |
571 | 572 | ||
572 | /* Individual alarm files */ | 573 | /* Individual alarm files */ |
573 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); | 574 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |