aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/smsc47m192.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-15 01:31:08 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:08 -0400
commit7cc3cb6662a21a59a2e0e752a8ebd95137c71d3a (patch)
tree1fbdec51769a057e6861e0994465f83f42446db5 /drivers/hwmon/smsc47m192.c
parent8fda79ec8654afa98fb9bad04d1e08df853fe05e (diff)
hwmon: (smsc47m192) Fix checkpatch issues
Fixed: ERROR: code indent should use tabs where possible ERROR: do not use assignment in if condition ERROR: spaces required around that '<' (ctx:VxV) ERROR: spaces required around that '==' (ctx:VxV) ERROR: spaces required around that '=' (ctx:VxV) ERROR: spaces required around that '>' (ctx:VxV) NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or WARNING: please, no space before tabs WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Not fixed (false positive): ERROR: Macros with multiple statements should be enclosed in a do - while loop Cc: Hartmut Rick <linux@rick.claranet.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/smsc47m192.c')
-rw-r--r--drivers/hwmon/smsc47m192.c132
1 files changed, 86 insertions, 46 deletions
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index 8f88908cf78..4705a8bf11c 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -1,25 +1,25 @@
1/* 1/*
2 smsc47m192.c - Support for hardware monitoring block of 2 * smsc47m192.c - Support for hardware monitoring block of
3 SMSC LPC47M192 and compatible Super I/O chips 3 * SMSC LPC47M192 and compatible Super I/O chips
4 4 *
5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de> 5 * Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
6 6 *
7 Derived from lm78.c and other chip drivers. 7 * Derived from lm78.c and other chip drivers.
8 8 *
9 This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -37,16 +37,16 @@
37static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 37static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
38 38
39/* SMSC47M192 registers */ 39/* SMSC47M192 registers */
40#define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \ 40#define SMSC47M192_REG_IN(nr) ((nr) < 6 ? (0x20 + (nr)) : \
41 (0x50 + (nr) - 6)) 41 (0x50 + (nr) - 6))
42#define SMSC47M192_REG_IN_MAX(nr) ((nr)<6 ? (0x2b + (nr) * 2) : \ 42#define SMSC47M192_REG_IN_MAX(nr) ((nr) < 6 ? (0x2b + (nr) * 2) : \
43 (0x54 + (((nr) - 6) * 2))) 43 (0x54 + (((nr) - 6) * 2)))
44#define SMSC47M192_REG_IN_MIN(nr) ((nr)<6 ? (0x2c + (nr) * 2) : \ 44#define SMSC47M192_REG_IN_MIN(nr) ((nr) < 6 ? (0x2c + (nr) * 2) : \
45 (0x55 + (((nr) - 6) * 2))) 45 (0x55 + (((nr) - 6) * 2)))
46static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 }; 46static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 };
47static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 }; 47static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 };
48static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 }; 48static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 };
49#define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr)==2 ? 0x1e : 0x1f) 49#define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr) == 2 ? 0x1e : 0x1f)
50#define SMSC47M192_REG_ALARM1 0x41 50#define SMSC47M192_REG_ALARM1 0x41
51#define SMSC47M192_REG_ALARM2 0x42 51#define SMSC47M192_REG_ALARM2 0x42
52#define SMSC47M192_REG_VID 0x47 52#define SMSC47M192_REG_VID 0x47
@@ -80,8 +80,10 @@ static inline u8 IN_TO_REG(unsigned long val, int n)
80 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255); 80 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
81} 81}
82 82
83/* TEMP: 0.001 degC units (-128C to +127C) 83/*
84 REG: 1C/bit, two's complement */ 84 * TEMP: 0.001 degC units (-128C to +127C)
85 * REG: 1C/bit, two's complement
86 */
85static inline s8 TEMP_TO_REG(int val) 87static inline s8 TEMP_TO_REG(int val)
86{ 88{
87 return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000); 89 return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000);
@@ -170,7 +172,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
170 int nr = sensor_attr->index; 172 int nr = sensor_attr->index;
171 struct i2c_client *client = to_i2c_client(dev); 173 struct i2c_client *client = to_i2c_client(dev);
172 struct smsc47m192_data *data = i2c_get_clientdata(client); 174 struct smsc47m192_data *data = i2c_get_clientdata(client);
173 unsigned long val = simple_strtoul(buf, NULL, 10); 175 unsigned long val;
176 int err;
177
178 err = kstrtoul(buf, 10, &val);
179 if (err)
180 return err;
174 181
175 mutex_lock(&data->update_lock); 182 mutex_lock(&data->update_lock);
176 data->in_min[nr] = IN_TO_REG(val, nr); 183 data->in_min[nr] = IN_TO_REG(val, nr);
@@ -187,7 +194,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
187 int nr = sensor_attr->index; 194 int nr = sensor_attr->index;
188 struct i2c_client *client = to_i2c_client(dev); 195 struct i2c_client *client = to_i2c_client(dev);
189 struct smsc47m192_data *data = i2c_get_clientdata(client); 196 struct smsc47m192_data *data = i2c_get_clientdata(client);
190 unsigned long val = simple_strtoul(buf, NULL, 10); 197 unsigned long val;
198 int err;
199
200 err = kstrtoul(buf, 10, &val);
201 if (err)
202 return err;
191 203
192 mutex_lock(&data->update_lock); 204 mutex_lock(&data->update_lock);
193 data->in_max[nr] = IN_TO_REG(val, nr); 205 data->in_max[nr] = IN_TO_REG(val, nr);
@@ -249,7 +261,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
249 int nr = sensor_attr->index; 261 int nr = sensor_attr->index;
250 struct i2c_client *client = to_i2c_client(dev); 262 struct i2c_client *client = to_i2c_client(dev);
251 struct smsc47m192_data *data = i2c_get_clientdata(client); 263 struct smsc47m192_data *data = i2c_get_clientdata(client);
252 long val = simple_strtol(buf, NULL, 10); 264 long val;
265 int err;
266
267 err = kstrtol(buf, 10, &val);
268 if (err)
269 return err;
253 270
254 mutex_lock(&data->update_lock); 271 mutex_lock(&data->update_lock);
255 data->temp_min[nr] = TEMP_TO_REG(val); 272 data->temp_min[nr] = TEMP_TO_REG(val);
@@ -266,7 +283,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
266 int nr = sensor_attr->index; 283 int nr = sensor_attr->index;
267 struct i2c_client *client = to_i2c_client(dev); 284 struct i2c_client *client = to_i2c_client(dev);
268 struct smsc47m192_data *data = i2c_get_clientdata(client); 285 struct smsc47m192_data *data = i2c_get_clientdata(client);
269 long val = simple_strtol(buf, NULL, 10); 286 long val;
287 int err;
288
289 err = kstrtol(buf, 10, &val);
290 if (err)
291 return err;
270 292
271 mutex_lock(&data->update_lock); 293 mutex_lock(&data->update_lock);
272 data->temp_max[nr] = TEMP_TO_REG(val); 294 data->temp_max[nr] = TEMP_TO_REG(val);
@@ -293,22 +315,29 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute
293 struct i2c_client *client = to_i2c_client(dev); 315 struct i2c_client *client = to_i2c_client(dev);
294 struct smsc47m192_data *data = i2c_get_clientdata(client); 316 struct smsc47m192_data *data = i2c_get_clientdata(client);
295 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 317 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
296 long val = simple_strtol(buf, NULL, 10); 318 long val;
319 int err;
320
321 err = kstrtol(buf, 10, &val);
322 if (err)
323 return err;
297 324
298 mutex_lock(&data->update_lock); 325 mutex_lock(&data->update_lock);
299 data->temp_offset[nr] = TEMP_TO_REG(val); 326 data->temp_offset[nr] = TEMP_TO_REG(val);
300 if (nr>1) 327 if (nr > 1)
301 i2c_smbus_write_byte_data(client, 328 i2c_smbus_write_byte_data(client,
302 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 329 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
303 else if (data->temp_offset[nr] != 0) { 330 else if (data->temp_offset[nr] != 0) {
304 /* offset[0] and offset[1] share the same register, 331 /*
305 SFR bit 4 activates offset[0] */ 332 * offset[0] and offset[1] share the same register,
333 * SFR bit 4 activates offset[0]
334 */
306 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR, 335 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR,
307 (sfr & 0xef) | (nr==0 ? 0x10 : 0)); 336 (sfr & 0xef) | (nr == 0 ? 0x10 : 0));
308 data->temp_offset[1-nr] = 0; 337 data->temp_offset[1-nr] = 0;
309 i2c_smbus_write_byte_data(client, 338 i2c_smbus_write_byte_data(client,
310 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 339 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
311 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 340 } else if ((sfr & 0x10) == (nr == 0 ? 0x10 : 0))
312 i2c_smbus_write_byte_data(client, 341 i2c_smbus_write_byte_data(client,
313 SMSC47M192_REG_TEMP_OFFSET(nr), 0); 342 SMSC47M192_REG_TEMP_OFFSET(nr), 0);
314 mutex_unlock(&data->update_lock); 343 mutex_unlock(&data->update_lock);
@@ -349,7 +378,14 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
349 const char *buf, size_t count) 378 const char *buf, size_t count)
350{ 379{
351 struct smsc47m192_data *data = dev_get_drvdata(dev); 380 struct smsc47m192_data *data = dev_get_drvdata(dev);
352 data->vrm = simple_strtoul(buf, NULL, 10); 381 unsigned long val;
382 int err;
383
384 err = kstrtoul(buf, 10, &val);
385 if (err)
386 return err;
387
388 data->vrm = val;
353 return count; 389 return count;
354} 390}
355static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 391static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
@@ -458,13 +494,13 @@ static void smsc47m192_init_client(struct i2c_client *client)
458 (sfr & 0xfd) | 0x02); 494 (sfr & 0xfd) | 0x02);
459 if (!(config & 0x01)) { 495 if (!(config & 0x01)) {
460 /* initialize alarm limits */ 496 /* initialize alarm limits */
461 for (i=0; i<8; i++) { 497 for (i = 0; i < 8; i++) {
462 i2c_smbus_write_byte_data(client, 498 i2c_smbus_write_byte_data(client,
463 SMSC47M192_REG_IN_MIN(i), 0); 499 SMSC47M192_REG_IN_MIN(i), 0);
464 i2c_smbus_write_byte_data(client, 500 i2c_smbus_write_byte_data(client,
465 SMSC47M192_REG_IN_MAX(i), 0xff); 501 SMSC47M192_REG_IN_MAX(i), 0xff);
466 } 502 }
467 for (i=0; i<3; i++) { 503 for (i = 0; i < 3; i++) {
468 i2c_smbus_write_byte_data(client, 504 i2c_smbus_write_byte_data(client,
469 SMSC47M192_REG_TEMP_MIN[i], 0x80); 505 SMSC47M192_REG_TEMP_MIN[i], 0x80);
470 i2c_smbus_write_byte_data(client, 506 i2c_smbus_write_byte_data(client,
@@ -532,14 +568,16 @@ static int smsc47m192_probe(struct i2c_client *client,
532 smsc47m192_init_client(client); 568 smsc47m192_init_client(client);
533 569
534 /* Register sysfs hooks */ 570 /* Register sysfs hooks */
535 if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) 571 err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group);
572 if (err)
536 goto exit_free; 573 goto exit_free;
537 574
538 /* Pin 110 is either in4 (+12V) or VID4 */ 575 /* Pin 110 is either in4 (+12V) or VID4 */
539 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 576 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
540 if (!(config & 0x20)) { 577 if (!(config & 0x20)) {
541 if ((err = sysfs_create_group(&client->dev.kobj, 578 err = sysfs_create_group(&client->dev.kobj,
542 &smsc47m192_group_in4))) 579 &smsc47m192_group_in4);
580 if (err)
543 goto exit_remove_files; 581 goto exit_remove_files;
544 } 582 }
545 583
@@ -606,8 +644,10 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
606 for (i = 1; i < 3; i++) 644 for (i = 1; i < 3; i++)
607 data->temp_offset[i] = i2c_smbus_read_byte_data(client, 645 data->temp_offset[i] = i2c_smbus_read_byte_data(client,
608 SMSC47M192_REG_TEMP_OFFSET(i)); 646 SMSC47M192_REG_TEMP_OFFSET(i));
609 /* first offset is temp_offset[0] if SFR bit 4 is set, 647 /*
610 temp_offset[1] otherwise */ 648 * first offset is temp_offset[0] if SFR bit 4 is set,
649 * temp_offset[1] otherwise
650 */
611 if (sfr & 0x10) { 651 if (sfr & 0x10) {
612 data->temp_offset[0] = data->temp_offset[1]; 652 data->temp_offset[0] = data->temp_offset[1];
613 data->temp_offset[1] = 0; 653 data->temp_offset[1] = 0;
@@ -624,7 +664,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
624 data->alarms = i2c_smbus_read_byte_data(client, 664 data->alarms = i2c_smbus_read_byte_data(client,
625 SMSC47M192_REG_ALARM1) | 665 SMSC47M192_REG_ALARM1) |
626 (i2c_smbus_read_byte_data(client, 666 (i2c_smbus_read_byte_data(client,
627 SMSC47M192_REG_ALARM2) << 8); 667 SMSC47M192_REG_ALARM2) << 8);
628 668
629 data->last_updated = jiffies; 669 data->last_updated = jiffies;
630 data->valid = 1; 670 data->valid = 1;