diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-15 12:29:36 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:11 -0400 |
commit | ec1c3194179579df41be78551a0ca642f49e52ff (patch) | |
tree | ebe6684c3f156f912245467bd2e40423c1130d77 | |
parent | a80b10ccac53087a6ad47f45e29a3800e84448fa (diff) |
hwmon: (w83791d) Fix checkpatch issues
Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: space prohibited after that open parenthesis '('
ERROR: space required after that ',' (ctx:VxV)
WARNING: braces {} are not necessary for single statement blocks
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 complex values should be enclosed in parenthesis
Cc: Charles Spirakis <bezaur@gmail.com>
Cc: Marc Hulsman <m.hulsman@tudelft.nl>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/w83791d.c | 318 |
1 files changed, 196 insertions, 122 deletions
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 1ff97b0e867a..2f446f92acf2 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -1,36 +1,36 @@ | |||
1 | /* | 1 | /* |
2 | w83791d.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * w83791d.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | * monitoring |
4 | 4 | * | |
5 | Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com> | 5 | * Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com> |
6 | 6 | * | |
7 | This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | 10 | * (at your option) any later version. |
11 | 11 | * | |
12 | This program is distributed in the hope that it will be useful, | 12 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | 16 | * | |
17 | You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Supports following chips: | 23 | * Supports following chips: |
24 | 24 | * | |
25 | Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA | 25 | * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA |
26 | w83791d 10 5 5 3 0x71 0x5ca3 yes no | 26 | * w83791d 10 5 5 3 0x71 0x5ca3 yes no |
27 | 27 | * | |
28 | The w83791d chip appears to be part way between the 83781d and the | 28 | * The w83791d chip appears to be part way between the 83781d and the |
29 | 83792d. Thus, this file is derived from both the w83792d.c and | 29 | * 83792d. Thus, this file is derived from both the w83792d.c and |
30 | w83781d.c files. | 30 | * w83781d.c files. |
31 | 31 | * | |
32 | The w83791g chip is the same as the w83791d but lead-free. | 32 | * The w83791g chip is the same as the w83791d but lead-free. |
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
@@ -198,10 +198,12 @@ static const u8 W83791D_REG_BEEP_CTRL[3] = { | |||
198 | #define W83791D_REG_VBAT 0x5D | 198 | #define W83791D_REG_VBAT 0x5D |
199 | #define W83791D_REG_I2C_ADDR 0x48 | 199 | #define W83791D_REG_I2C_ADDR 0x48 |
200 | 200 | ||
201 | /* The SMBus locks itself. The Winbond W83791D has a bank select register | 201 | /* |
202 | (index 0x4e), but the driver only accesses registers in bank 0. Since | 202 | * The SMBus locks itself. The Winbond W83791D has a bank select register |
203 | we don't switch banks, we don't need any special code to handle | 203 | * (index 0x4e), but the driver only accesses registers in bank 0. Since |
204 | locking access between bank switches */ | 204 | * we don't switch banks, we don't need any special code to handle |
205 | * locking access between bank switches | ||
206 | */ | ||
205 | static inline int w83791d_read(struct i2c_client *client, u8 reg) | 207 | static inline int w83791d_read(struct i2c_client *client, u8 reg) |
206 | { | 208 | { |
207 | return i2c_smbus_read_byte_data(client, reg); | 209 | return i2c_smbus_read_byte_data(client, reg); |
@@ -212,9 +214,11 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value) | |||
212 | return i2c_smbus_write_byte_data(client, reg, value); | 214 | return i2c_smbus_write_byte_data(client, reg, value); |
213 | } | 215 | } |
214 | 216 | ||
215 | /* The analog voltage inputs have 16mV LSB. Since the sysfs output is | 217 | /* |
216 | in mV as would be measured on the chip input pin, need to just | 218 | * The analog voltage inputs have 16mV LSB. Since the sysfs output is |
217 | multiply/divide by 16 to translate from/to register values. */ | 219 | * in mV as would be measured on the chip input pin, need to just |
220 | * multiply/divide by 16 to translate from/to register values. | ||
221 | */ | ||
218 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) | 222 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) |
219 | #define IN_FROM_REG(val) ((val) * 16) | 223 | #define IN_FROM_REG(val) ((val) * 16) |
220 | 224 | ||
@@ -226,7 +230,7 @@ static u8 fan_to_reg(long rpm, int div) | |||
226 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 230 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
227 | } | 231 | } |
228 | 232 | ||
229 | #define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ | 233 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
230 | ((val) == 255 ? 0 : \ | 234 | ((val) == 255 ? 0 : \ |
231 | 1350000 / ((val) * (div)))) | 235 | 1350000 / ((val) * (div)))) |
232 | 236 | ||
@@ -237,10 +241,12 @@ static u8 fan_to_reg(long rpm, int div) | |||
237 | (val) < 0 ? ((val) - 500) / 1000 : \ | 241 | (val) < 0 ? ((val) - 500) / 1000 : \ |
238 | ((val) + 500) / 1000) | 242 | ((val) + 500) / 1000) |
239 | 243 | ||
240 | /* for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius | 244 | /* |
241 | Assumes the top 8 bits are the integral amount and the bottom 8 bits | 245 | * for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius |
242 | are the fractional amount. Since we only have 0.5 degree resolution, | 246 | * Assumes the top 8 bits are the integral amount and the bottom 8 bits |
243 | the bottom 7 bits will always be zero */ | 247 | * are the fractional amount. Since we only have 0.5 degree resolution, |
248 | * the bottom 7 bits will always be zero | ||
249 | */ | ||
244 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) | 250 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) |
245 | #define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 251 | #define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
246 | (val) >= 127500 ? 0x7F80 : \ | 252 | (val) >= 127500 ? 0x7F80 : \ |
@@ -300,17 +306,19 @@ struct w83791d_data { | |||
300 | 306 | ||
301 | s8 temp1[3]; /* current, over, thyst */ | 307 | s8 temp1[3]; /* current, over, thyst */ |
302 | s16 temp_add[2][3]; /* fixed point value. Top 8 bits are the | 308 | s16 temp_add[2][3]; /* fixed point value. Top 8 bits are the |
303 | integral part, bottom 8 bits are the | 309 | * integral part, bottom 8 bits are the |
304 | fractional part. We only use the top | 310 | * fractional part. We only use the top |
305 | 9 bits as the resolution is only | 311 | * 9 bits as the resolution is only |
306 | to the 0.5 degree C... | 312 | * to the 0.5 degree C... |
307 | two sensors with three values | 313 | * two sensors with three values |
308 | (cur, over, hyst) */ | 314 | * (cur, over, hyst) |
315 | */ | ||
309 | 316 | ||
310 | /* PWMs */ | 317 | /* PWMs */ |
311 | u8 pwm[5]; /* pwm duty cycle */ | 318 | u8 pwm[5]; /* pwm duty cycle */ |
312 | u8 pwm_enable[3]; /* pwm enable status for fan 1-3 | 319 | u8 pwm_enable[3]; /* pwm enable status for fan 1-3 |
313 | (fan 4-5 only support manual mode) */ | 320 | * (fan 4-5 only support manual mode) |
321 | */ | ||
314 | 322 | ||
315 | u8 temp_target[3]; /* pwm 1-3 target temperature */ | 323 | u8 temp_target[3]; /* pwm 1-3 target temperature */ |
316 | u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */ | 324 | u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */ |
@@ -366,7 +374,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ | |||
366 | to_sensor_dev_attr(attr); \ | 374 | to_sensor_dev_attr(attr); \ |
367 | struct w83791d_data *data = w83791d_update_device(dev); \ | 375 | struct w83791d_data *data = w83791d_update_device(dev); \ |
368 | int nr = sensor_attr->index; \ | 376 | int nr = sensor_attr->index; \ |
369 | return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \ | 377 | return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ |
370 | } | 378 | } |
371 | 379 | ||
372 | show_in_reg(in); | 380 | show_in_reg(in); |
@@ -382,9 +390,11 @@ static ssize_t store_in_##reg(struct device *dev, \ | |||
382 | to_sensor_dev_attr(attr); \ | 390 | to_sensor_dev_attr(attr); \ |
383 | struct i2c_client *client = to_i2c_client(dev); \ | 391 | struct i2c_client *client = to_i2c_client(dev); \ |
384 | struct w83791d_data *data = i2c_get_clientdata(client); \ | 392 | struct w83791d_data *data = i2c_get_clientdata(client); \ |
385 | unsigned long val = simple_strtoul(buf, NULL, 10); \ | ||
386 | int nr = sensor_attr->index; \ | 393 | int nr = sensor_attr->index; \ |
387 | \ | 394 | unsigned long val; \ |
395 | int err = kstrtoul(buf, 10, &val); \ | ||
396 | if (err) \ | ||
397 | return err; \ | ||
388 | mutex_lock(&data->update_lock); \ | 398 | mutex_lock(&data->update_lock); \ |
389 | data->in_##reg[nr] = IN_TO_REG(val); \ | 399 | data->in_##reg[nr] = IN_TO_REG(val); \ |
390 | w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \ | 400 | w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \ |
@@ -455,7 +465,14 @@ static ssize_t store_beep(struct device *dev, struct device_attribute *attr, | |||
455 | struct w83791d_data *data = i2c_get_clientdata(client); | 465 | struct w83791d_data *data = i2c_get_clientdata(client); |
456 | int bitnr = sensor_attr->index; | 466 | int bitnr = sensor_attr->index; |
457 | int bytenr = bitnr / 8; | 467 | int bytenr = bitnr / 8; |
458 | long val = simple_strtol(buf, NULL, 10) ? 1 : 0; | 468 | unsigned long val; |
469 | int err; | ||
470 | |||
471 | err = kstrtoul(buf, 10, &val); | ||
472 | if (err) | ||
473 | return err; | ||
474 | |||
475 | val = val ? 1 : 0; | ||
459 | 476 | ||
460 | mutex_lock(&data->update_lock); | 477 | mutex_lock(&data->update_lock); |
461 | 478 | ||
@@ -485,8 +502,10 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | |||
485 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 502 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
486 | } | 503 | } |
487 | 504 | ||
488 | /* Note: The bitmask for the beep enable/disable is different than | 505 | /* |
489 | the bitmask for the alarm. */ | 506 | * Note: The bitmask for the beep enable/disable is different than |
507 | * the bitmask for the alarm. | ||
508 | */ | ||
490 | static struct sensor_device_attribute sda_in_beep[] = { | 509 | static struct sensor_device_attribute sda_in_beep[] = { |
491 | SENSOR_ATTR(in0_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 0), | 510 | SENSOR_ATTR(in0_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 0), |
492 | SENSOR_ATTR(in1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 13), | 511 | SENSOR_ATTR(in1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 13), |
@@ -521,7 +540,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ | |||
521 | to_sensor_dev_attr(attr); \ | 540 | to_sensor_dev_attr(attr); \ |
522 | struct w83791d_data *data = w83791d_update_device(dev); \ | 541 | struct w83791d_data *data = w83791d_update_device(dev); \ |
523 | int nr = sensor_attr->index; \ | 542 | int nr = sensor_attr->index; \ |
524 | return sprintf(buf,"%d\n", \ | 543 | return sprintf(buf, "%d\n", \ |
525 | FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ | 544 | FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ |
526 | } | 545 | } |
527 | 546 | ||
@@ -534,8 +553,13 @@ static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, | |||
534 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 553 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
535 | struct i2c_client *client = to_i2c_client(dev); | 554 | struct i2c_client *client = to_i2c_client(dev); |
536 | struct w83791d_data *data = i2c_get_clientdata(client); | 555 | struct w83791d_data *data = i2c_get_clientdata(client); |
537 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
538 | int nr = sensor_attr->index; | 556 | int nr = sensor_attr->index; |
557 | unsigned long val; | ||
558 | int err; | ||
559 | |||
560 | err = kstrtoul(buf, 10, &val); | ||
561 | if (err) | ||
562 | return err; | ||
539 | 563 | ||
540 | mutex_lock(&data->update_lock); | 564 | mutex_lock(&data->update_lock); |
541 | data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr])); | 565 | data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr])); |
@@ -554,10 +578,12 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | |||
554 | return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); | 578 | return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); |
555 | } | 579 | } |
556 | 580 | ||
557 | /* Note: we save and restore the fan minimum here, because its value is | 581 | /* |
558 | determined in part by the fan divisor. This follows the principle of | 582 | * Note: we save and restore the fan minimum here, because its value is |
559 | least surprise; the user doesn't expect the fan minimum to change just | 583 | * determined in part by the fan divisor. This follows the principle of |
560 | because the divisor changed. */ | 584 | * least surprise; the user doesn't expect the fan minimum to change just |
585 | * because the divisor changed. | ||
586 | */ | ||
561 | static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr, | 587 | static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr, |
562 | const char *buf, size_t count) | 588 | const char *buf, size_t count) |
563 | { | 589 | { |
@@ -572,12 +598,18 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr, | |||
572 | int indx = 0; | 598 | int indx = 0; |
573 | u8 keep_mask = 0; | 599 | u8 keep_mask = 0; |
574 | u8 new_shift = 0; | 600 | u8 new_shift = 0; |
601 | unsigned long val; | ||
602 | int err; | ||
603 | |||
604 | err = kstrtoul(buf, 10, &val); | ||
605 | if (err) | ||
606 | return err; | ||
575 | 607 | ||
576 | /* Save fan_min */ | 608 | /* Save fan_min */ |
577 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); | 609 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); |
578 | 610 | ||
579 | mutex_lock(&data->update_lock); | 611 | mutex_lock(&data->update_lock); |
580 | data->fan_div[nr] = div_to_reg(nr, simple_strtoul(buf, NULL, 10)); | 612 | data->fan_div[nr] = div_to_reg(nr, val); |
581 | 613 | ||
582 | switch (nr) { | 614 | switch (nr) { |
583 | case 0: | 615 | case 0: |
@@ -918,8 +950,13 @@ static ssize_t store_temp1(struct device *dev, struct device_attribute *devattr, | |||
918 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 950 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
919 | struct i2c_client *client = to_i2c_client(dev); | 951 | struct i2c_client *client = to_i2c_client(dev); |
920 | struct w83791d_data *data = i2c_get_clientdata(client); | 952 | struct w83791d_data *data = i2c_get_clientdata(client); |
921 | long val = simple_strtol(buf, NULL, 10); | ||
922 | int nr = attr->index; | 953 | int nr = attr->index; |
954 | long val; | ||
955 | int err; | ||
956 | |||
957 | err = kstrtol(buf, 10, &val); | ||
958 | if (err) | ||
959 | return err; | ||
923 | 960 | ||
924 | mutex_lock(&data->update_lock); | 961 | mutex_lock(&data->update_lock); |
925 | data->temp1[nr] = TEMP1_TO_REG(val); | 962 | data->temp1[nr] = TEMP1_TO_REG(val); |
@@ -946,10 +983,15 @@ static ssize_t store_temp23(struct device *dev, | |||
946 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 983 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
947 | struct i2c_client *client = to_i2c_client(dev); | 984 | struct i2c_client *client = to_i2c_client(dev); |
948 | struct w83791d_data *data = i2c_get_clientdata(client); | 985 | struct w83791d_data *data = i2c_get_clientdata(client); |
949 | long val = simple_strtol(buf, NULL, 10); | 986 | long val; |
987 | int err; | ||
950 | int nr = attr->nr; | 988 | int nr = attr->nr; |
951 | int index = attr->index; | 989 | int index = attr->index; |
952 | 990 | ||
991 | err = kstrtol(buf, 10, &val); | ||
992 | if (err) | ||
993 | return err; | ||
994 | |||
953 | mutex_lock(&data->update_lock); | 995 | mutex_lock(&data->update_lock); |
954 | data->temp_add[nr][index] = TEMP23_TO_REG(val); | 996 | data->temp_add[nr][index] = TEMP23_TO_REG(val); |
955 | w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2], | 997 | w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2], |
@@ -985,8 +1027,10 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = { | |||
985 | show_temp23, store_temp23, 1, 2), | 1027 | show_temp23, store_temp23, 1, 2), |
986 | }; | 1028 | }; |
987 | 1029 | ||
988 | /* Note: The bitmask for the beep enable/disable is different than | 1030 | /* |
989 | the bitmask for the alarm. */ | 1031 | * Note: The bitmask for the beep enable/disable is different than |
1032 | * the bitmask for the alarm. | ||
1033 | */ | ||
990 | static struct sensor_device_attribute sda_temp_beep[] = { | 1034 | static struct sensor_device_attribute sda_temp_beep[] = { |
991 | SENSOR_ATTR(temp1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 4), | 1035 | SENSOR_ATTR(temp1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 4), |
992 | SENSOR_ATTR(temp2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 5), | 1036 | SENSOR_ATTR(temp2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 5), |
@@ -1035,13 +1079,20 @@ static ssize_t store_beep_mask(struct device *dev, | |||
1035 | { | 1079 | { |
1036 | struct i2c_client *client = to_i2c_client(dev); | 1080 | struct i2c_client *client = to_i2c_client(dev); |
1037 | struct w83791d_data *data = i2c_get_clientdata(client); | 1081 | struct w83791d_data *data = i2c_get_clientdata(client); |
1038 | long val = simple_strtol(buf, NULL, 10); | ||
1039 | int i; | 1082 | int i; |
1083 | long val; | ||
1084 | int err; | ||
1085 | |||
1086 | err = kstrtol(buf, 10, &val); | ||
1087 | if (err) | ||
1088 | return err; | ||
1040 | 1089 | ||
1041 | mutex_lock(&data->update_lock); | 1090 | mutex_lock(&data->update_lock); |
1042 | 1091 | ||
1043 | /* The beep_enable state overrides any enabling request from | 1092 | /* |
1044 | the masks */ | 1093 | * The beep_enable state overrides any enabling request from |
1094 | * the masks | ||
1095 | */ | ||
1045 | data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK; | 1096 | data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK; |
1046 | data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); | 1097 | data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); |
1047 | 1098 | ||
@@ -1063,7 +1114,12 @@ static ssize_t store_beep_enable(struct device *dev, | |||
1063 | { | 1114 | { |
1064 | struct i2c_client *client = to_i2c_client(dev); | 1115 | struct i2c_client *client = to_i2c_client(dev); |
1065 | struct w83791d_data *data = i2c_get_clientdata(client); | 1116 | struct w83791d_data *data = i2c_get_clientdata(client); |
1066 | long val = simple_strtol(buf, NULL, 10); | 1117 | long val; |
1118 | int err; | ||
1119 | |||
1120 | err = kstrtol(buf, 10, &val); | ||
1121 | if (err) | ||
1122 | return err; | ||
1067 | 1123 | ||
1068 | mutex_lock(&data->update_lock); | 1124 | mutex_lock(&data->update_lock); |
1069 | 1125 | ||
@@ -1073,8 +1129,10 @@ static ssize_t store_beep_enable(struct device *dev, | |||
1073 | data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK; | 1129 | data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK; |
1074 | data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); | 1130 | data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); |
1075 | 1131 | ||
1076 | /* The global control is in the second beep control register | 1132 | /* |
1077 | so only need to update that register */ | 1133 | * The global control is in the second beep control register |
1134 | * so only need to update that register | ||
1135 | */ | ||
1078 | val = (data->beep_mask >> 8) & 0xff; | 1136 | val = (data->beep_mask >> 8) & 0xff; |
1079 | 1137 | ||
1080 | w83791d_write(client, W83791D_REG_BEEP_CTRL[1], val); | 1138 | w83791d_write(client, W83791D_REG_BEEP_CTRL[1], val); |
@@ -1113,36 +1171,44 @@ static ssize_t store_vrm_reg(struct device *dev, | |||
1113 | const char *buf, size_t count) | 1171 | const char *buf, size_t count) |
1114 | { | 1172 | { |
1115 | struct w83791d_data *data = dev_get_drvdata(dev); | 1173 | struct w83791d_data *data = dev_get_drvdata(dev); |
1174 | unsigned long val; | ||
1175 | int err; | ||
1116 | 1176 | ||
1117 | /* No lock needed as vrm is internal to the driver | 1177 | /* |
1118 | (not read from a chip register) and so is not | 1178 | * No lock needed as vrm is internal to the driver |
1119 | updated in w83791d_update_device() */ | 1179 | * (not read from a chip register) and so is not |
1120 | data->vrm = simple_strtoul(buf, NULL, 10); | 1180 | * updated in w83791d_update_device() |
1181 | */ | ||
1121 | 1182 | ||
1183 | err = kstrtoul(buf, 10, &val); | ||
1184 | if (err) | ||
1185 | return err; | ||
1186 | |||
1187 | data->vrm = val; | ||
1122 | return count; | 1188 | return count; |
1123 | } | 1189 | } |
1124 | 1190 | ||
1125 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | 1191 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
1126 | 1192 | ||
1127 | #define IN_UNIT_ATTRS(X) \ | 1193 | #define IN_UNIT_ATTRS(X) \ |
1128 | &sda_in_input[X].dev_attr.attr, \ | 1194 | &sda_in_input[X].dev_attr.attr, \ |
1129 | &sda_in_min[X].dev_attr.attr, \ | 1195 | &sda_in_min[X].dev_attr.attr, \ |
1130 | &sda_in_max[X].dev_attr.attr, \ | 1196 | &sda_in_max[X].dev_attr.attr, \ |
1131 | &sda_in_beep[X].dev_attr.attr, \ | 1197 | &sda_in_beep[X].dev_attr.attr, \ |
1132 | &sda_in_alarm[X].dev_attr.attr | 1198 | &sda_in_alarm[X].dev_attr.attr |
1133 | 1199 | ||
1134 | #define FAN_UNIT_ATTRS(X) \ | 1200 | #define FAN_UNIT_ATTRS(X) \ |
1135 | &sda_fan_input[X].dev_attr.attr, \ | 1201 | &sda_fan_input[X].dev_attr.attr, \ |
1136 | &sda_fan_min[X].dev_attr.attr, \ | 1202 | &sda_fan_min[X].dev_attr.attr, \ |
1137 | &sda_fan_div[X].dev_attr.attr, \ | 1203 | &sda_fan_div[X].dev_attr.attr, \ |
1138 | &sda_fan_beep[X].dev_attr.attr, \ | 1204 | &sda_fan_beep[X].dev_attr.attr, \ |
1139 | &sda_fan_alarm[X].dev_attr.attr | 1205 | &sda_fan_alarm[X].dev_attr.attr |
1140 | 1206 | ||
1141 | #define TEMP_UNIT_ATTRS(X) \ | 1207 | #define TEMP_UNIT_ATTRS(X) \ |
1142 | &sda_temp_input[X].dev_attr.attr, \ | 1208 | &sda_temp_input[X].dev_attr.attr, \ |
1143 | &sda_temp_max[X].dev_attr.attr, \ | 1209 | &sda_temp_max[X].dev_attr.attr, \ |
1144 | &sda_temp_max_hyst[X].dev_attr.attr, \ | 1210 | &sda_temp_max_hyst[X].dev_attr.attr, \ |
1145 | &sda_temp_beep[X].dev_attr.attr, \ | 1211 | &sda_temp_beep[X].dev_attr.attr, \ |
1146 | &sda_temp_alarm[X].dev_attr.attr | 1212 | &sda_temp_alarm[X].dev_attr.attr |
1147 | 1213 | ||
1148 | static struct attribute *w83791d_attributes[] = { | 1214 | static struct attribute *w83791d_attributes[] = { |
@@ -1186,9 +1252,11 @@ static const struct attribute_group w83791d_group = { | |||
1186 | .attrs = w83791d_attributes, | 1252 | .attrs = w83791d_attributes, |
1187 | }; | 1253 | }; |
1188 | 1254 | ||
1189 | /* Separate group of attributes for fan/pwm 4-5. Their pins can also be | 1255 | /* |
1190 | in use for GPIO in which case their sysfs-interface should not be made | 1256 | * Separate group of attributes for fan/pwm 4-5. Their pins can also be |
1191 | available */ | 1257 | * in use for GPIO in which case their sysfs-interface should not be made |
1258 | * available | ||
1259 | */ | ||
1192 | static struct attribute *w83791d_attributes_fanpwm45[] = { | 1260 | static struct attribute *w83791d_attributes_fanpwm45[] = { |
1193 | FAN_UNIT_ATTRS(3), | 1261 | FAN_UNIT_ATTRS(3), |
1194 | FAN_UNIT_ATTRS(4), | 1262 | FAN_UNIT_ATTRS(4), |
@@ -1228,9 +1296,8 @@ static int w83791d_detect_subclients(struct i2c_client *client) | |||
1228 | } | 1296 | } |
1229 | 1297 | ||
1230 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); | 1298 | val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); |
1231 | if (!(val & 0x08)) { | 1299 | if (!(val & 0x08)) |
1232 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); | 1300 | data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); |
1233 | } | ||
1234 | if (!(val & 0x80)) { | 1301 | if (!(val & 0x80)) { |
1235 | if ((data->lm75[0] != NULL) && | 1302 | if ((data->lm75[0] != NULL) && |
1236 | ((val & 0x7) == ((val >> 4) & 0x7))) { | 1303 | ((val & 0x7) == ((val >> 4) & 0x7))) { |
@@ -1265,9 +1332,8 @@ static int w83791d_detect(struct i2c_client *client, | |||
1265 | int val1, val2; | 1332 | int val1, val2; |
1266 | unsigned short address = client->addr; | 1333 | unsigned short address = client->addr; |
1267 | 1334 | ||
1268 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1335 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1269 | return -ENODEV; | 1336 | return -ENODEV; |
1270 | } | ||
1271 | 1337 | ||
1272 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) | 1338 | if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) |
1273 | return -ENODEV; | 1339 | return -ENODEV; |
@@ -1277,12 +1343,14 @@ static int w83791d_detect(struct i2c_client *client, | |||
1277 | /* Check for Winbond ID if in bank 0 */ | 1343 | /* Check for Winbond ID if in bank 0 */ |
1278 | if (!(val1 & 0x07)) { | 1344 | if (!(val1 & 0x07)) { |
1279 | if ((!(val1 & 0x80) && val2 != 0xa3) || | 1345 | if ((!(val1 & 0x80) && val2 != 0xa3) || |
1280 | ( (val1 & 0x80) && val2 != 0x5c)) { | 1346 | ((val1 & 0x80) && val2 != 0x5c)) { |
1281 | return -ENODEV; | 1347 | return -ENODEV; |
1282 | } | 1348 | } |
1283 | } | 1349 | } |
1284 | /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR | 1350 | /* |
1285 | should match */ | 1351 | * If Winbond chip, address of chip and W83791D_REG_I2C_ADDR |
1352 | * should match | ||
1353 | */ | ||
1286 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) | 1354 | if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) |
1287 | return -ENODEV; | 1355 | return -ENODEV; |
1288 | 1356 | ||
@@ -1332,14 +1400,16 @@ static int w83791d_probe(struct i2c_client *client, | |||
1332 | /* Initialize the chip */ | 1400 | /* Initialize the chip */ |
1333 | w83791d_init_client(client); | 1401 | w83791d_init_client(client); |
1334 | 1402 | ||
1335 | /* If the fan_div is changed, make sure there is a rational | 1403 | /* |
1336 | fan_min in place */ | 1404 | * If the fan_div is changed, make sure there is a rational |
1337 | for (i = 0; i < NUMBER_OF_FANIN; i++) { | 1405 | * fan_min in place |
1406 | */ | ||
1407 | for (i = 0; i < NUMBER_OF_FANIN; i++) | ||
1338 | data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]); | 1408 | data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]); |
1339 | } | ||
1340 | 1409 | ||
1341 | /* Register sysfs hooks */ | 1410 | /* Register sysfs hooks */ |
1342 | if ((err = sysfs_create_group(&client->dev.kobj, &w83791d_group))) | 1411 | err = sysfs_create_group(&client->dev.kobj, &w83791d_group); |
1412 | if (err) | ||
1343 | goto error3; | 1413 | goto error3; |
1344 | 1414 | ||
1345 | /* Check if pins of fan/pwm 4-5 are in use as GPIO */ | 1415 | /* Check if pins of fan/pwm 4-5 are in use as GPIO */ |
@@ -1398,19 +1468,20 @@ static void w83791d_init_client(struct i2c_client *client) | |||
1398 | u8 tmp; | 1468 | u8 tmp; |
1399 | u8 old_beep; | 1469 | u8 old_beep; |
1400 | 1470 | ||
1401 | /* The difference between reset and init is that reset | 1471 | /* |
1402 | does a hard reset of the chip via index 0x40, bit 7, | 1472 | * The difference between reset and init is that reset |
1403 | but init simply forces certain registers to have "sane" | 1473 | * does a hard reset of the chip via index 0x40, bit 7, |
1404 | values. The hope is that the BIOS has done the right | 1474 | * but init simply forces certain registers to have "sane" |
1405 | thing (which is why the default is reset=0, init=0), | 1475 | * values. The hope is that the BIOS has done the right |
1406 | but if not, reset is the hard hammer and init | 1476 | * thing (which is why the default is reset=0, init=0), |
1407 | is the soft mallet both of which are trying to whack | 1477 | * but if not, reset is the hard hammer and init |
1408 | things into place... | 1478 | * is the soft mallet both of which are trying to whack |
1409 | NOTE: The data sheet makes a distinction between | 1479 | * things into place... |
1410 | "power on defaults" and "reset by MR". As far as I can tell, | 1480 | * NOTE: The data sheet makes a distinction between |
1411 | the hard reset puts everything into a power-on state so I'm | 1481 | * "power on defaults" and "reset by MR". As far as I can tell, |
1412 | not sure what "reset by MR" means or how it can happen. | 1482 | * the hard reset puts everything into a power-on state so I'm |
1413 | */ | 1483 | * not sure what "reset by MR" means or how it can happen. |
1484 | */ | ||
1414 | if (reset || init) { | 1485 | if (reset || init) { |
1415 | /* keep some BIOS settings when we... */ | 1486 | /* keep some BIOS settings when we... */ |
1416 | old_beep = w83791d_read(client, W83791D_REG_BEEP_CONFIG); | 1487 | old_beep = w83791d_read(client, W83791D_REG_BEEP_CONFIG); |
@@ -1494,8 +1565,10 @@ static struct w83791d_data *w83791d_update_device(struct device *dev) | |||
1494 | data->fan_div[3] = reg_array_tmp[2] & 0x07; | 1565 | data->fan_div[3] = reg_array_tmp[2] & 0x07; |
1495 | data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07; | 1566 | data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07; |
1496 | 1567 | ||
1497 | /* The fan divisor for fans 0-2 get bit 2 from | 1568 | /* |
1498 | bits 5-7 respectively of vbat register */ | 1569 | * The fan divisor for fans 0-2 get bit 2 from |
1570 | * bits 5-7 respectively of vbat register | ||
1571 | */ | ||
1499 | vbat_reg = w83791d_read(client, W83791D_REG_VBAT); | 1572 | vbat_reg = w83791d_read(client, W83791D_REG_VBAT); |
1500 | for (i = 0; i < 3; i++) | 1573 | for (i = 0; i < 3; i++) |
1501 | data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04; | 1574 | data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04; |
@@ -1601,12 +1674,13 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev) | |||
1601 | dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]); | 1674 | dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]); |
1602 | } | 1675 | } |
1603 | 1676 | ||
1604 | /* temperature math is signed, but only print out the | 1677 | /* |
1605 | bits that matter */ | 1678 | * temperature math is signed, but only print out the |
1679 | * bits that matter | ||
1680 | */ | ||
1606 | dev_dbg(dev, "%d set of Temperatures: ===>\n", NUMBER_OF_TEMPIN); | 1681 | dev_dbg(dev, "%d set of Temperatures: ===>\n", NUMBER_OF_TEMPIN); |
1607 | for (i = 0; i < 3; i++) { | 1682 | for (i = 0; i < 3; i++) |
1608 | dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]); | 1683 | dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]); |
1609 | } | ||
1610 | for (i = 0; i < 2; i++) { | 1684 | for (i = 0; i < 2; i++) { |
1611 | for (j = 0; j < 3; j++) { | 1685 | for (j = 0; j < 3; j++) { |
1612 | dev_dbg(dev, "temp_add[%d][%d] is: 0x%04x\n", i, j, | 1686 | dev_dbg(dev, "temp_add[%d][%d] is: 0x%04x\n", i, j, |