aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-14 23:47:36 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:25 -0400
commit09770b261914166f326dcff5e43794a5f53e0f6a (patch)
tree1a4d0d1ea98882d9fd37af1ef406efe024c4269c /drivers
parent9b03079fca96a5815f197f02e09b9ac20d67b71e (diff)
hwmon: (lm85) Fix checkpatch issues
Fixed: ERROR: code indent should use tabs where possible ERROR: do not use assignment in if condition WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Also: s/#define^I/#define / Not fixed (false positive): ERROR: Macros with multiple statements should be enclosed in a do - while loop Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/lm85.c360
1 files changed, 230 insertions, 130 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index fd269831788f..864c7d999e0c 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1,28 +1,28 @@
1/* 1/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 5 * Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 6 * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 7 * Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8 Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org> 8 * Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org>
9 9 *
10 Chip details at <http://www.national.com/ds/LM/LM85.pdf> 10 * Chip details at <http://www.national.com/ds/LM/LM85.pdf>
11 11 *
12 This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version. 15 * (at your option) any later version.
16 16 *
17 This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 20 * GNU General Public License for more details.
21 21 *
22 You should have received a copy of the GNU General Public License 22 * You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 23 * along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/ 25 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
@@ -46,88 +46,89 @@ enum chips {
46 46
47/* The LM85 registers */ 47/* The LM85 registers */
48 48
49#define LM85_REG_IN(nr) (0x20 + (nr)) 49#define LM85_REG_IN(nr) (0x20 + (nr))
50#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) 50#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
51#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) 51#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
52 52
53#define LM85_REG_TEMP(nr) (0x25 + (nr)) 53#define LM85_REG_TEMP(nr) (0x25 + (nr))
54#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) 54#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
55#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) 55#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
56 56
57/* Fan speeds are LSB, MSB (2 bytes) */ 57/* Fan speeds are LSB, MSB (2 bytes) */
58#define LM85_REG_FAN(nr) (0x28 + (nr) * 2) 58#define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
59#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) 59#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
60 60
61#define LM85_REG_PWM(nr) (0x30 + (nr)) 61#define LM85_REG_PWM(nr) (0x30 + (nr))
62 62
63#define LM85_REG_COMPANY 0x3e 63#define LM85_REG_COMPANY 0x3e
64#define LM85_REG_VERSTEP 0x3f 64#define LM85_REG_VERSTEP 0x3f
65 65
66#define ADT7468_REG_CFG5 0x7c 66#define ADT7468_REG_CFG5 0x7c
67#define ADT7468_OFF64 (1 << 0) 67#define ADT7468_OFF64 (1 << 0)
68#define ADT7468_HFPWM (1 << 1) 68#define ADT7468_HFPWM (1 << 1)
69#define IS_ADT7468_OFF64(data) \ 69#define IS_ADT7468_OFF64(data) \
70 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) 70 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
71#define IS_ADT7468_HFPWM(data) \ 71#define IS_ADT7468_HFPWM(data) \
72 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM)) 72 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
73 73
74/* These are the recognized values for the above regs */ 74/* These are the recognized values for the above regs */
75#define LM85_COMPANY_NATIONAL 0x01 75#define LM85_COMPANY_NATIONAL 0x01
76#define LM85_COMPANY_ANALOG_DEV 0x41 76#define LM85_COMPANY_ANALOG_DEV 0x41
77#define LM85_COMPANY_SMSC 0x5c 77#define LM85_COMPANY_SMSC 0x5c
78#define LM85_VERSTEP_VMASK 0xf0 78#define LM85_VERSTEP_VMASK 0xf0
79#define LM85_VERSTEP_GENERIC 0x60 79#define LM85_VERSTEP_GENERIC 0x60
80#define LM85_VERSTEP_GENERIC2 0x70 80#define LM85_VERSTEP_GENERIC2 0x70
81#define LM85_VERSTEP_LM85C 0x60 81#define LM85_VERSTEP_LM85C 0x60
82#define LM85_VERSTEP_LM85B 0x62 82#define LM85_VERSTEP_LM85B 0x62
83#define LM85_VERSTEP_LM96000_1 0x68 83#define LM85_VERSTEP_LM96000_1 0x68
84#define LM85_VERSTEP_LM96000_2 0x69 84#define LM85_VERSTEP_LM96000_2 0x69
85#define LM85_VERSTEP_ADM1027 0x60 85#define LM85_VERSTEP_ADM1027 0x60
86#define LM85_VERSTEP_ADT7463 0x62 86#define LM85_VERSTEP_ADT7463 0x62
87#define LM85_VERSTEP_ADT7463C 0x6A 87#define LM85_VERSTEP_ADT7463C 0x6A
88#define LM85_VERSTEP_ADT7468_1 0x71 88#define LM85_VERSTEP_ADT7468_1 0x71
89#define LM85_VERSTEP_ADT7468_2 0x72 89#define LM85_VERSTEP_ADT7468_2 0x72
90#define LM85_VERSTEP_EMC6D100_A0 0x60 90#define LM85_VERSTEP_EMC6D100_A0 0x60
91#define LM85_VERSTEP_EMC6D100_A1 0x61 91#define LM85_VERSTEP_EMC6D100_A1 0x61
92#define LM85_VERSTEP_EMC6D102 0x65 92#define LM85_VERSTEP_EMC6D102 0x65
93#define LM85_VERSTEP_EMC6D103_A0 0x68 93#define LM85_VERSTEP_EMC6D103_A0 0x68
94#define LM85_VERSTEP_EMC6D103_A1 0x69 94#define LM85_VERSTEP_EMC6D103_A1 0x69
95#define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */ 95#define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */
96 96
97#define LM85_REG_CONFIG 0x40 97#define LM85_REG_CONFIG 0x40
98 98
99#define LM85_REG_ALARM1 0x41 99#define LM85_REG_ALARM1 0x41
100#define LM85_REG_ALARM2 0x42 100#define LM85_REG_ALARM2 0x42
101 101
102#define LM85_REG_VID 0x43 102#define LM85_REG_VID 0x43
103 103
104/* Automated FAN control */ 104/* Automated FAN control */
105#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) 105#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
106#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) 106#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
107#define LM85_REG_AFAN_SPIKE1 0x62 107#define LM85_REG_AFAN_SPIKE1 0x62
108#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) 108#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
109#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) 109#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
110#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) 110#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
111#define LM85_REG_AFAN_HYST1 0x6d 111#define LM85_REG_AFAN_HYST1 0x6d
112#define LM85_REG_AFAN_HYST2 0x6e 112#define LM85_REG_AFAN_HYST2 0x6e
113 113
114#define ADM1027_REG_EXTEND_ADC1 0x76 114#define ADM1027_REG_EXTEND_ADC1 0x76
115#define ADM1027_REG_EXTEND_ADC2 0x77 115#define ADM1027_REG_EXTEND_ADC2 0x77
116 116
117#define EMC6D100_REG_ALARM3 0x7d 117#define EMC6D100_REG_ALARM3 0x7d
118/* IN5, IN6 and IN7 */ 118/* IN5, IN6 and IN7 */
119#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) 119#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
120#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) 120#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
121#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) 121#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
122#define EMC6D102_REG_EXTEND_ADC1 0x85 122#define EMC6D102_REG_EXTEND_ADC1 0x85
123#define EMC6D102_REG_EXTEND_ADC2 0x86 123#define EMC6D102_REG_EXTEND_ADC2 0x86
124#define EMC6D102_REG_EXTEND_ADC3 0x87 124#define EMC6D102_REG_EXTEND_ADC3 0x87
125#define EMC6D102_REG_EXTEND_ADC4 0x88 125#define EMC6D102_REG_EXTEND_ADC4 0x88
126 126
127 127
128/* Conversions. Rounding and limit checking is only done on the TO_REG 128/*
129 variants. Note that you should be a bit careful with which arguments 129 * Conversions. Rounding and limit checking is only done on the TO_REG
130 these macros are called: arguments may be evaluated more than once. 130 * variants. Note that you should be a bit careful with which arguments
131 * these macros are called: arguments may be evaluated more than once.
131 */ 132 */
132 133
133/* IN are scaled according to built-in resistors */ 134/* IN are scaled according to built-in resistors */
@@ -166,7 +167,8 @@ static inline u16 FAN_TO_REG(unsigned long val)
166#define PWM_FROM_REG(val) (val) 167#define PWM_FROM_REG(val) (val)
167 168
168 169
169/* ZONEs have the following parameters: 170/*
171 * ZONEs have the following parameters:
170 * Limit (low) temp, 1. degC 172 * Limit (low) temp, 1. degC
171 * Hysteresis (below limit), 1. degC (0-15) 173 * Hysteresis (below limit), 1. degC (0-15)
172 * Range of speed control, .1 degC (2-80) 174 * Range of speed control, .1 degC (2-80)
@@ -228,7 +230,8 @@ static int FREQ_FROM_REG(const int *map, u8 reg)
228 return map[reg & 0x07]; 230 return map[reg & 0x07];
229} 231}
230 232
231/* Since we can't use strings, I'm abusing these numbers 233/*
234 * Since we can't use strings, I'm abusing these numbers
232 * to stand in for the following meanings: 235 * to stand in for the following meanings:
233 * 1 -- PWM responds to Zone 1 236 * 1 -- PWM responds to Zone 1
234 * 2 -- PWM responds to Zone 2 237 * 2 -- PWM responds to Zone 2
@@ -258,7 +261,8 @@ static int ZONE_TO_REG(int zone)
258#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) 261#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
259#define HYST_FROM_REG(val) ((val) * 1000) 262#define HYST_FROM_REG(val) ((val) * 1000)
260 263
261/* Chip sampling rates 264/*
265 * Chip sampling rates
262 * 266 *
263 * Some sensors are not updated more frequently than once per second 267 * Some sensors are not updated more frequently than once per second
264 * so it doesn't make sense to read them more often than that. 268 * so it doesn't make sense to read them more often than that.
@@ -274,7 +278,8 @@ static int ZONE_TO_REG(int zone)
274#define LM85_DATA_INTERVAL (HZ + HZ / 2) 278#define LM85_DATA_INTERVAL (HZ + HZ / 2)
275#define LM85_CONFIG_INTERVAL (1 * 60 * HZ) 279#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
276 280
277/* LM85 can automatically adjust fan speeds based on temperature 281/*
282 * LM85 can automatically adjust fan speeds based on temperature
278 * This structure encapsulates an entire Zone config. There are 283 * This structure encapsulates an entire Zone config. There are
279 * three zones (one for each temperature input) on the lm85 284 * three zones (one for each temperature input) on the lm85
280 */ 285 */
@@ -283,7 +288,8 @@ struct lm85_zone {
283 u8 hyst; /* Low limit hysteresis. (0-15) */ 288 u8 hyst; /* Low limit hysteresis. (0-15) */
284 u8 range; /* Temp range, encoded */ 289 u8 range; /* Temp range, encoded */
285 s8 critical; /* "All fans ON" temp limit */ 290 s8 critical; /* "All fans ON" temp limit */
286 u8 max_desired; /* Actual "max" temperature specified. Preserved 291 u8 max_desired; /*
292 * Actual "max" temperature specified. Preserved
287 * to prevent "drift" as other autofan control 293 * to prevent "drift" as other autofan control
288 * values change. 294 * values change.
289 */ 295 */
@@ -295,8 +301,10 @@ struct lm85_autofan {
295 u8 min_off; /* Min PWM or OFF below "limit", flag */ 301 u8 min_off; /* Min PWM or OFF below "limit", flag */
296}; 302};
297 303
298/* For each registered chip, we need to keep some data in memory. 304/*
299 The structure is dynamically allocated. */ 305 * For each registered chip, we need to keep some data in memory.
306 * The structure is dynamically allocated.
307 */
300struct lm85_data { 308struct lm85_data {
301 struct device *hwmon_dev; 309 struct device *hwmon_dev;
302 const int *freq_map; 310 const int *freq_map;
@@ -391,7 +399,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
391 int nr = to_sensor_dev_attr(attr)->index; 399 int nr = to_sensor_dev_attr(attr)->index;
392 struct i2c_client *client = to_i2c_client(dev); 400 struct i2c_client *client = to_i2c_client(dev);
393 struct lm85_data *data = i2c_get_clientdata(client); 401 struct lm85_data *data = i2c_get_clientdata(client);
394 unsigned long val = simple_strtoul(buf, NULL, 10); 402 unsigned long val;
403 int err;
404
405 err = kstrtoul(buf, 10, &val);
406 if (err)
407 return err;
395 408
396 mutex_lock(&data->update_lock); 409 mutex_lock(&data->update_lock);
397 data->fan_min[nr] = FAN_TO_REG(val); 410 data->fan_min[nr] = FAN_TO_REG(val);
@@ -443,7 +456,14 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
443 const char *buf, size_t count) 456 const char *buf, size_t count)
444{ 457{
445 struct lm85_data *data = dev_get_drvdata(dev); 458 struct lm85_data *data = dev_get_drvdata(dev);
446 data->vrm = simple_strtoul(buf, NULL, 10); 459 unsigned long val;
460 int err;
461
462 err = kstrtoul(buf, 10, &val);
463 if (err)
464 return err;
465
466 data->vrm = val;
447 return count; 467 return count;
448} 468}
449 469
@@ -500,7 +520,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
500 int nr = to_sensor_dev_attr(attr)->index; 520 int nr = to_sensor_dev_attr(attr)->index;
501 struct i2c_client *client = to_i2c_client(dev); 521 struct i2c_client *client = to_i2c_client(dev);
502 struct lm85_data *data = i2c_get_clientdata(client); 522 struct lm85_data *data = i2c_get_clientdata(client);
503 long val = simple_strtol(buf, NULL, 10); 523 unsigned long val;
524 int err;
525
526 err = kstrtoul(buf, 10, &val);
527 if (err)
528 return err;
504 529
505 mutex_lock(&data->update_lock); 530 mutex_lock(&data->update_lock);
506 data->pwm[nr] = PWM_TO_REG(val); 531 data->pwm[nr] = PWM_TO_REG(val);
@@ -537,8 +562,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
537 int nr = to_sensor_dev_attr(attr)->index; 562 int nr = to_sensor_dev_attr(attr)->index;
538 struct i2c_client *client = to_i2c_client(dev); 563 struct i2c_client *client = to_i2c_client(dev);
539 struct lm85_data *data = i2c_get_clientdata(client); 564 struct lm85_data *data = i2c_get_clientdata(client);
540 long val = simple_strtol(buf, NULL, 10);
541 u8 config; 565 u8 config;
566 unsigned long val;
567 int err;
568
569 err = kstrtoul(buf, 10, &val);
570 if (err)
571 return err;
542 572
543 switch (val) { 573 switch (val) {
544 case 0: 574 case 0:
@@ -548,8 +578,10 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
548 config = 7; 578 config = 7;
549 break; 579 break;
550 case 2: 580 case 2:
551 /* Here we have to choose arbitrarily one of the 5 possible 581 /*
552 configurations; I go for the safest */ 582 * Here we have to choose arbitrarily one of the 5 possible
583 * configurations; I go for the safest
584 */
553 config = 6; 585 config = 6;
554 break; 586 break;
555 default: 587 default:
@@ -588,12 +620,19 @@ static ssize_t set_pwm_freq(struct device *dev,
588 int nr = to_sensor_dev_attr(attr)->index; 620 int nr = to_sensor_dev_attr(attr)->index;
589 struct i2c_client *client = to_i2c_client(dev); 621 struct i2c_client *client = to_i2c_client(dev);
590 struct lm85_data *data = i2c_get_clientdata(client); 622 struct lm85_data *data = i2c_get_clientdata(client);
591 long val = simple_strtol(buf, NULL, 10); 623 unsigned long val;
624 int err;
625
626 err = kstrtoul(buf, 10, &val);
627 if (err)
628 return err;
592 629
593 mutex_lock(&data->update_lock); 630 mutex_lock(&data->update_lock);
594 /* The ADT7468 has a special high-frequency PWM output mode, 631 /*
632 * The ADT7468 has a special high-frequency PWM output mode,
595 * where all PWM outputs are driven by a 22.5 kHz clock. 633 * where all PWM outputs are driven by a 22.5 kHz clock.
596 * This might confuse the user, but there's not much we can do. */ 634 * This might confuse the user, but there's not much we can do.
635 */
597 if (data->type == adt7468 && val >= 11300) { /* High freq. mode */ 636 if (data->type == adt7468 && val >= 11300) { /* High freq. mode */
598 data->cfg5 &= ~ADT7468_HFPWM; 637 data->cfg5 &= ~ADT7468_HFPWM;
599 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 638 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
@@ -648,7 +687,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
648 int nr = to_sensor_dev_attr(attr)->index; 687 int nr = to_sensor_dev_attr(attr)->index;
649 struct i2c_client *client = to_i2c_client(dev); 688 struct i2c_client *client = to_i2c_client(dev);
650 struct lm85_data *data = i2c_get_clientdata(client); 689 struct lm85_data *data = i2c_get_clientdata(client);
651 long val = simple_strtol(buf, NULL, 10); 690 long val;
691 int err;
692
693 err = kstrtol(buf, 10, &val);
694 if (err)
695 return err;
652 696
653 mutex_lock(&data->update_lock); 697 mutex_lock(&data->update_lock);
654 data->in_min[nr] = INS_TO_REG(nr, val); 698 data->in_min[nr] = INS_TO_REG(nr, val);
@@ -671,7 +715,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
671 int nr = to_sensor_dev_attr(attr)->index; 715 int nr = to_sensor_dev_attr(attr)->index;
672 struct i2c_client *client = to_i2c_client(dev); 716 struct i2c_client *client = to_i2c_client(dev);
673 struct lm85_data *data = i2c_get_clientdata(client); 717 struct lm85_data *data = i2c_get_clientdata(client);
674 long val = simple_strtol(buf, NULL, 10); 718 long val;
719 int err;
720
721 err = kstrtol(buf, 10, &val);
722 if (err)
723 return err;
675 724
676 mutex_lock(&data->update_lock); 725 mutex_lock(&data->update_lock);
677 data->in_max[nr] = INS_TO_REG(nr, val); 726 data->in_max[nr] = INS_TO_REG(nr, val);
@@ -722,7 +771,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
722 int nr = to_sensor_dev_attr(attr)->index; 771 int nr = to_sensor_dev_attr(attr)->index;
723 struct i2c_client *client = to_i2c_client(dev); 772 struct i2c_client *client = to_i2c_client(dev);
724 struct lm85_data *data = i2c_get_clientdata(client); 773 struct lm85_data *data = i2c_get_clientdata(client);
725 long val = simple_strtol(buf, NULL, 10); 774 long val;
775 int err;
776
777 err = kstrtol(buf, 10, &val);
778 if (err)
779 return err;
726 780
727 if (IS_ADT7468_OFF64(data)) 781 if (IS_ADT7468_OFF64(data))
728 val += 64; 782 val += 64;
@@ -748,7 +802,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
748 int nr = to_sensor_dev_attr(attr)->index; 802 int nr = to_sensor_dev_attr(attr)->index;
749 struct i2c_client *client = to_i2c_client(dev); 803 struct i2c_client *client = to_i2c_client(dev);
750 struct lm85_data *data = i2c_get_clientdata(client); 804 struct lm85_data *data = i2c_get_clientdata(client);
751 long val = simple_strtol(buf, NULL, 10); 805 long val;
806 int err;
807
808 err = kstrtol(buf, 10, &val);
809 if (err)
810 return err;
752 811
753 if (IS_ADT7468_OFF64(data)) 812 if (IS_ADT7468_OFF64(data))
754 val += 64; 813 val += 64;
@@ -789,7 +848,12 @@ static ssize_t set_pwm_auto_channels(struct device *dev,
789 int nr = to_sensor_dev_attr(attr)->index; 848 int nr = to_sensor_dev_attr(attr)->index;
790 struct i2c_client *client = to_i2c_client(dev); 849 struct i2c_client *client = to_i2c_client(dev);
791 struct lm85_data *data = i2c_get_clientdata(client); 850 struct lm85_data *data = i2c_get_clientdata(client);
792 long val = simple_strtol(buf, NULL, 10); 851 long val;
852 int err;
853
854 err = kstrtol(buf, 10, &val);
855 if (err)
856 return err;
793 857
794 mutex_lock(&data->update_lock); 858 mutex_lock(&data->update_lock);
795 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) 859 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
@@ -814,7 +878,12 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev,
814 int nr = to_sensor_dev_attr(attr)->index; 878 int nr = to_sensor_dev_attr(attr)->index;
815 struct i2c_client *client = to_i2c_client(dev); 879 struct i2c_client *client = to_i2c_client(dev);
816 struct lm85_data *data = i2c_get_clientdata(client); 880 struct lm85_data *data = i2c_get_clientdata(client);
817 long val = simple_strtol(buf, NULL, 10); 881 unsigned long val;
882 int err;
883
884 err = kstrtoul(buf, 10, &val);
885 if (err)
886 return err;
818 887
819 mutex_lock(&data->update_lock); 888 mutex_lock(&data->update_lock);
820 data->autofan[nr].min_pwm = PWM_TO_REG(val); 889 data->autofan[nr].min_pwm = PWM_TO_REG(val);
@@ -838,8 +907,13 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
838 int nr = to_sensor_dev_attr(attr)->index; 907 int nr = to_sensor_dev_attr(attr)->index;
839 struct i2c_client *client = to_i2c_client(dev); 908 struct i2c_client *client = to_i2c_client(dev);
840 struct lm85_data *data = i2c_get_clientdata(client); 909 struct lm85_data *data = i2c_get_clientdata(client);
841 long val = simple_strtol(buf, NULL, 10);
842 u8 tmp; 910 u8 tmp;
911 long val;
912 int err;
913
914 err = kstrtol(buf, 10, &val);
915 if (err)
916 return err;
843 917
844 mutex_lock(&data->update_lock); 918 mutex_lock(&data->update_lock);
845 data->autofan[nr].min_off = val; 919 data->autofan[nr].min_off = val;
@@ -885,7 +959,12 @@ static ssize_t set_temp_auto_temp_off(struct device *dev,
885 struct i2c_client *client = to_i2c_client(dev); 959 struct i2c_client *client = to_i2c_client(dev);
886 struct lm85_data *data = i2c_get_clientdata(client); 960 struct lm85_data *data = i2c_get_clientdata(client);
887 int min; 961 int min;
888 long val = simple_strtol(buf, NULL, 10); 962 long val;
963 int err;
964
965 err = kstrtol(buf, 10, &val);
966 if (err)
967 return err;
889 968
890 mutex_lock(&data->update_lock); 969 mutex_lock(&data->update_lock);
891 min = TEMP_FROM_REG(data->zone[nr].limit); 970 min = TEMP_FROM_REG(data->zone[nr].limit);
@@ -916,7 +995,12 @@ static ssize_t set_temp_auto_temp_min(struct device *dev,
916 int nr = to_sensor_dev_attr(attr)->index; 995 int nr = to_sensor_dev_attr(attr)->index;
917 struct i2c_client *client = to_i2c_client(dev); 996 struct i2c_client *client = to_i2c_client(dev);
918 struct lm85_data *data = i2c_get_clientdata(client); 997 struct lm85_data *data = i2c_get_clientdata(client);
919 long val = simple_strtol(buf, NULL, 10); 998 long val;
999 int err;
1000
1001 err = kstrtol(buf, 10, &val);
1002 if (err)
1003 return err;
920 1004
921 mutex_lock(&data->update_lock); 1005 mutex_lock(&data->update_lock);
922 data->zone[nr].limit = TEMP_TO_REG(val); 1006 data->zone[nr].limit = TEMP_TO_REG(val);
@@ -951,7 +1035,12 @@ static ssize_t set_temp_auto_temp_max(struct device *dev,
951 struct i2c_client *client = to_i2c_client(dev); 1035 struct i2c_client *client = to_i2c_client(dev);
952 struct lm85_data *data = i2c_get_clientdata(client); 1036 struct lm85_data *data = i2c_get_clientdata(client);
953 int min; 1037 int min;
954 long val = simple_strtol(buf, NULL, 10); 1038 long val;
1039 int err;
1040
1041 err = kstrtol(buf, 10, &val);
1042 if (err)
1043 return err;
955 1044
956 mutex_lock(&data->update_lock); 1045 mutex_lock(&data->update_lock);
957 min = TEMP_FROM_REG(data->zone[nr].limit); 1046 min = TEMP_FROM_REG(data->zone[nr].limit);
@@ -979,7 +1068,12 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev,
979 int nr = to_sensor_dev_attr(attr)->index; 1068 int nr = to_sensor_dev_attr(attr)->index;
980 struct i2c_client *client = to_i2c_client(dev); 1069 struct i2c_client *client = to_i2c_client(dev);
981 struct lm85_data *data = i2c_get_clientdata(client); 1070 struct lm85_data *data = i2c_get_clientdata(client);
982 long val = simple_strtol(buf, NULL, 10); 1071 long val;
1072 int err;
1073
1074 err = kstrtol(buf, 10, &val);
1075 if (err)
1076 return err;
983 1077
984 mutex_lock(&data->update_lock); 1078 mutex_lock(&data->update_lock);
985 data->zone[nr].critical = TEMP_TO_REG(val); 1079 data->zone[nr].critical = TEMP_TO_REG(val);
@@ -1338,24 +1432,28 @@ static int lm85_probe(struct i2c_client *client,
1338 goto err_remove_files; 1432 goto err_remove_files;
1339 } 1433 }
1340 1434
1341 /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used 1435 /*
1342 as a sixth digital VID input rather than an analog input. */ 1436 * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
1437 * as a sixth digital VID input rather than an analog input.
1438 */
1343 if (data->type == adt7463 || data->type == adt7468) { 1439 if (data->type == adt7463 || data->type == adt7468) {
1344 u8 vid = lm85_read_value(client, LM85_REG_VID); 1440 u8 vid = lm85_read_value(client, LM85_REG_VID);
1345 if (vid & 0x80) 1441 if (vid & 0x80)
1346 data->has_vid5 = true; 1442 data->has_vid5 = true;
1347 } 1443 }
1348 1444
1349 if (!data->has_vid5) 1445 if (!data->has_vid5) {
1350 if ((err = sysfs_create_group(&client->dev.kobj, 1446 err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4);
1351 &lm85_group_in4))) 1447 if (err)
1352 goto err_remove_files; 1448 goto err_remove_files;
1449 }
1353 1450
1354 /* The EMC6D100 has 3 additional voltage inputs */ 1451 /* The EMC6D100 has 3 additional voltage inputs */
1355 if (data->type == emc6d100) 1452 if (data->type == emc6d100) {
1356 if ((err = sysfs_create_group(&client->dev.kobj, 1453 err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567);
1357 &lm85_group_in567))) 1454 if (err)
1358 goto err_remove_files; 1455 goto err_remove_files;
1456 }
1359 1457
1360 data->hwmon_dev = hwmon_device_register(&client->dev); 1458 data->hwmon_dev = hwmon_device_register(&client->dev);
1361 if (IS_ERR(data->hwmon_dev)) { 1459 if (IS_ERR(data->hwmon_dev)) {
@@ -1443,7 +1541,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1443 /* Things that change quickly */ 1541 /* Things that change quickly */
1444 dev_dbg(&client->dev, "Reading sensor values\n"); 1542 dev_dbg(&client->dev, "Reading sensor values\n");
1445 1543
1446 /* Have to read extended bits first to "freeze" the 1544 /*
1545 * Have to read extended bits first to "freeze" the
1447 * more significant bits that are read later. 1546 * more significant bits that are read later.
1448 * There are 2 additional resolution bits per channel and we 1547 * There are 2 additional resolution bits per channel and we
1449 * have room for 4, so we shift them to the left. 1548 * have room for 4, so we shift them to the left.
@@ -1503,9 +1602,10 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1503 EMC6D100_REG_ALARM3) << 16; 1602 EMC6D100_REG_ALARM3) << 16;
1504 } else if (data->type == emc6d102 || data->type == emc6d103 || 1603 } else if (data->type == emc6d102 || data->type == emc6d103 ||
1505 data->type == emc6d103s) { 1604 data->type == emc6d103s) {
1506 /* Have to read LSB bits after the MSB ones because 1605 /*
1507 the reading of the MSB bits has frozen the 1606 * Have to read LSB bits after the MSB ones because
1508 LSBs (backward from the ADM1027). 1607 * the reading of the MSB bits has frozen the
1608 * LSBs (backward from the ADM1027).
1509 */ 1609 */
1510 int ext1 = lm85_read_value(client, 1610 int ext1 = lm85_read_value(client,
1511 EMC6D102_REG_EXTEND_ADC1); 1611 EMC6D102_REG_EXTEND_ADC1);