aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/adm9240.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 64e7ef885411..c3c2865a8967 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware 2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * 4 *
5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl> 5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl>
6 * Philip Edelbrock <phil@netroedge.com> 6 * Philip Edelbrock <phil@netroedge.com>
7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl> 7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl>
8 * Copyright (C) 2005 Grant Coady <gcoady.lk@gmail.com> with valuable 8 * Copyright (C) 2005 Grant Coady <gcoady.lk@gmail.com> with valuable
9 * guidance from Jean Delvare 9 * guidance from Jean Delvare
10 * 10 *
11 * Driver supports Analog Devices ADM9240 11 * Driver supports Analog Devices ADM9240
12 * Dallas Semiconductor DS1780 12 * Dallas Semiconductor DS1780
@@ -204,7 +204,12 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
204 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 204 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
205 struct i2c_client *client = to_i2c_client(dev); 205 struct i2c_client *client = to_i2c_client(dev);
206 struct adm9240_data *data = i2c_get_clientdata(client); 206 struct adm9240_data *data = i2c_get_clientdata(client);
207 long val = simple_strtol(buf, NULL, 10); 207 long val;
208 int err;
209
210 err = kstrtol(buf, 10, &val);
211 if (err)
212 return err;
208 213
209 mutex_lock(&data->update_lock); 214 mutex_lock(&data->update_lock);
210 data->temp_max[attr->index] = TEMP_TO_REG(val); 215 data->temp_max[attr->index] = TEMP_TO_REG(val);
@@ -255,7 +260,12 @@ static ssize_t set_in_min(struct device *dev,
255 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 260 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
256 struct i2c_client *client = to_i2c_client(dev); 261 struct i2c_client *client = to_i2c_client(dev);
257 struct adm9240_data *data = i2c_get_clientdata(client); 262 struct adm9240_data *data = i2c_get_clientdata(client);
258 unsigned long val = simple_strtoul(buf, NULL, 10); 263 unsigned long val;
264 int err;
265
266 err = kstrtoul(buf, 10, &val);
267 if (err)
268 return err;
259 269
260 mutex_lock(&data->update_lock); 270 mutex_lock(&data->update_lock);
261 data->in_min[attr->index] = IN_TO_REG(val, attr->index); 271 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
@@ -272,7 +282,12 @@ static ssize_t set_in_max(struct device *dev,
272 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 282 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
273 struct i2c_client *client = to_i2c_client(dev); 283 struct i2c_client *client = to_i2c_client(dev);
274 struct adm9240_data *data = i2c_get_clientdata(client); 284 struct adm9240_data *data = i2c_get_clientdata(client);
275 unsigned long val = simple_strtoul(buf, NULL, 10); 285 unsigned long val;
286 int err;
287
288 err = kstrtoul(buf, 10, &val);
289 if (err)
290 return err;
276 291
277 mutex_lock(&data->update_lock); 292 mutex_lock(&data->update_lock);
278 data->in_max[attr->index] = IN_TO_REG(val, attr->index); 293 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
@@ -283,7 +298,7 @@ static ssize_t set_in_max(struct device *dev,
283} 298}
284 299
285#define vin(nr) \ 300#define vin(nr) \
286static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \ 301static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
287 show_in, NULL, nr); \ 302 show_in, NULL, nr); \
288static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \ 303static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
289 show_in_min, set_in_min, nr); \ 304 show_in_min, set_in_min, nr); \
@@ -357,9 +372,14 @@ static ssize_t set_fan_min(struct device *dev,
357 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 372 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
358 struct i2c_client *client = to_i2c_client(dev); 373 struct i2c_client *client = to_i2c_client(dev);
359 struct adm9240_data *data = i2c_get_clientdata(client); 374 struct adm9240_data *data = i2c_get_clientdata(client);
360 unsigned long val = simple_strtoul(buf, NULL, 10);
361 int nr = attr->index; 375 int nr = attr->index;
362 u8 new_div; 376 u8 new_div;
377 unsigned long val;
378 int err;
379
380 err = kstrtoul(buf, 10, &val);
381 if (err)
382 return err;
363 383
364 mutex_lock(&data->update_lock); 384 mutex_lock(&data->update_lock);
365 385
@@ -465,7 +485,12 @@ static ssize_t set_aout(struct device *dev,
465{ 485{
466 struct i2c_client *client = to_i2c_client(dev); 486 struct i2c_client *client = to_i2c_client(dev);
467 struct adm9240_data *data = i2c_get_clientdata(client); 487 struct adm9240_data *data = i2c_get_clientdata(client);
468 unsigned long val = simple_strtol(buf, NULL, 10); 488 long val;
489 int err;
490
491 err = kstrtol(buf, 10, &val);
492 if (err)
493 return err;
469 494
470 mutex_lock(&data->update_lock); 495 mutex_lock(&data->update_lock);
471 data->aout = AOUT_TO_REG(val); 496 data->aout = AOUT_TO_REG(val);
@@ -481,7 +506,12 @@ static ssize_t chassis_clear_legacy(struct device *dev,
481 const char *buf, size_t count) 506 const char *buf, size_t count)
482{ 507{
483 struct i2c_client *client = to_i2c_client(dev); 508 struct i2c_client *client = to_i2c_client(dev);
484 unsigned long val = simple_strtol(buf, NULL, 10); 509 long val;
510 int err;
511
512 err = kstrtol(buf, 10, &val);
513 if (err)
514 return err;
485 515
486 dev_warn(dev, "Attribute chassis_clear is deprecated, " 516 dev_warn(dev, "Attribute chassis_clear is deprecated, "
487 "use intrusion0_alarm instead\n"); 517 "use intrusion0_alarm instead\n");
@@ -632,7 +662,8 @@ static int adm9240_probe(struct i2c_client *new_client,
632 adm9240_init_client(new_client); 662 adm9240_init_client(new_client);
633 663
634 /* populate sysfs filesystem */ 664 /* populate sysfs filesystem */
635 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) 665 err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group);
666 if (err)
636 goto exit_free; 667 goto exit_free;
637 668
638 data->hwmon_dev = hwmon_device_register(&new_client->dev); 669 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -681,8 +712,7 @@ static void adm9240_init_client(struct i2c_client *client)
681 } else { /* cold start: open limits before starting chip */ 712 } else { /* cold start: open limits before starting chip */
682 int i; 713 int i;
683 714
684 for (i = 0; i < 6; i++) 715 for (i = 0; i < 6; i++) {
685 {
686 i2c_smbus_write_byte_data(client, 716 i2c_smbus_write_byte_data(client,
687 ADM9240_REG_IN_MIN(i), 0); 717 ADM9240_REG_IN_MIN(i), 0);
688 i2c_smbus_write_byte_data(client, 718 i2c_smbus_write_byte_data(client,
@@ -717,8 +747,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
717 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) 747 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
718 || !data->valid) { 748 || !data->valid) {
719 749
720 for (i = 0; i < 6; i++) /* read voltages */ 750 for (i = 0; i < 6; i++) { /* read voltages */
721 {
722 data->in[i] = i2c_smbus_read_byte_data(client, 751 data->in[i] = i2c_smbus_read_byte_data(client,
723 ADM9240_REG_IN(i)); 752 ADM9240_REG_IN(i));
724 } 753 }
@@ -727,16 +756,17 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
727 i2c_smbus_read_byte_data(client, 756 i2c_smbus_read_byte_data(client,
728 ADM9240_REG_INT(1)) << 8; 757 ADM9240_REG_INT(1)) << 8;
729 758
730 /* read temperature: assume temperature changes less than 759 /*
760 * read temperature: assume temperature changes less than
731 * 0.5'C per two measurement cycles thus ignore possible 761 * 0.5'C per two measurement cycles thus ignore possible
732 * but unlikely aliasing error on lsb reading. --Grant */ 762 * but unlikely aliasing error on lsb reading. --Grant
763 */
733 data->temp = ((i2c_smbus_read_byte_data(client, 764 data->temp = ((i2c_smbus_read_byte_data(client,
734 ADM9240_REG_TEMP) << 8) | 765 ADM9240_REG_TEMP) << 8) |
735 i2c_smbus_read_byte_data(client, 766 i2c_smbus_read_byte_data(client,
736 ADM9240_REG_TEMP_CONF)) / 128; 767 ADM9240_REG_TEMP_CONF)) / 128;
737 768
738 for (i = 0; i < 2; i++) /* read fans */ 769 for (i = 0; i < 2; i++) { /* read fans */
739 {
740 data->fan[i] = i2c_smbus_read_byte_data(client, 770 data->fan[i] = i2c_smbus_read_byte_data(client,
741 ADM9240_REG_FAN(i)); 771 ADM9240_REG_FAN(i));
742 772
@@ -760,15 +790,13 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
760 if (time_after(jiffies, data->last_updated_config + (HZ * 300)) 790 if (time_after(jiffies, data->last_updated_config + (HZ * 300))
761 || !data->valid) { 791 || !data->valid) {
762 792
763 for (i = 0; i < 6; i++) 793 for (i = 0; i < 6; i++) {
764 {
765 data->in_min[i] = i2c_smbus_read_byte_data(client, 794 data->in_min[i] = i2c_smbus_read_byte_data(client,
766 ADM9240_REG_IN_MIN(i)); 795 ADM9240_REG_IN_MIN(i));
767 data->in_max[i] = i2c_smbus_read_byte_data(client, 796 data->in_max[i] = i2c_smbus_read_byte_data(client,
768 ADM9240_REG_IN_MAX(i)); 797 ADM9240_REG_IN_MAX(i));
769 } 798 }
770 for (i = 0; i < 2; i++) 799 for (i = 0; i < 2; i++) {
771 {
772 data->fan_min[i] = i2c_smbus_read_byte_data(client, 800 data->fan_min[i] = i2c_smbus_read_byte_data(client,
773 ADM9240_REG_FAN_MIN(i)); 801 ADM9240_REG_FAN_MIN(i));
774 } 802 }