diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-15 14:03:08 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:31 -0400 |
commit | ca3ccad827175fa47f4b20ea4c7072e1ddc33128 (patch) | |
tree | 5327fb658b633950f942d0508a5724df5a486e3a /drivers/hwmon/w83l786ng.c | |
parent | 47efe8772f241c4be540355d90e38b79cc1092a4 (diff) |
hwmon: (w83l786ng) Fix checkpatch issues
Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: space required after that ',' (ctx:VxV)
WARNING: braces {} are not necessary for single statement blocks
WARNING: please, no space before tabs
WARNING: please, no spaces at the start of a line
WARNING: simple_strtol is obsolete, use kstrtol instead
WARNING: simple_strtoul is obsolete, use kstrtoul instead
WARNING: space prohibited between function name and open parenthesis '('
Not fixed (false positive):
ERROR: Macros with complex values should be enclosed in parenthesis
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/w83l786ng.c')
-rw-r--r-- | drivers/hwmon/w83l786ng.c | 103 |
1 files changed, 70 insertions, 33 deletions
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index deac4b625305..a6310b89dedc 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -52,7 +52,7 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); | |||
52 | 52 | ||
53 | #define W83L786NG_REG_CONFIG 0x40 | 53 | #define W83L786NG_REG_CONFIG 0x40 |
54 | #define W83L786NG_REG_ALARM1 0x41 | 54 | #define W83L786NG_REG_ALARM1 0x41 |
55 | #define W83L786NG_REG_ALARM2 0x42 | 55 | #define W83L786NG_REG_ALARM2 0x42 |
56 | #define W83L786NG_REG_GPIO_EN 0x47 | 56 | #define W83L786NG_REG_GPIO_EN 0x47 |
57 | #define W83L786NG_REG_MAN_ID2 0x4C | 57 | #define W83L786NG_REG_MAN_ID2 0x4C |
58 | #define W83L786NG_REG_MAN_ID1 0x4D | 58 | #define W83L786NG_REG_MAN_ID1 0x4D |
@@ -89,19 +89,21 @@ FAN_TO_REG(long rpm, int div) | |||
89 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); | 89 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
90 | } | 90 | } |
91 | 91 | ||
92 | #define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ | 92 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ |
93 | ((val) == 255 ? 0 : \ | 93 | ((val) == 255 ? 0 : \ |
94 | 1350000 / ((val) * (div)))) | 94 | 1350000 / ((val) * (div)))) |
95 | 95 | ||
96 | /* for temp */ | 96 | /* for temp */ |
97 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ | 97 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? \ |
98 | : (val)) / 1000, 0, 0xff)) | 98 | (val) + 0x100 * 1000 \ |
99 | #define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) | 99 | : (val)) / 1000, 0, 0xff)) |
100 | #define TEMP_FROM_REG(val) (((val) & 0x80 ? \ | ||
101 | (val) - 0x100 : (val)) * 1000) | ||
100 | 102 | ||
101 | /* The analog voltage inputs have 8mV LSB. Since the sysfs output is | 103 | /* The analog voltage inputs have 8mV LSB. Since the sysfs output is |
102 | in mV as would be measured on the chip input pin, need to just | 104 | in mV as would be measured on the chip input pin, need to just |
103 | multiply/divide by 8 to translate from/to register values. */ | 105 | multiply/divide by 8 to translate from/to register values. */ |
104 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255)) | 106 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255)) |
105 | #define IN_FROM_REG(val) ((val) * 8) | 107 | #define IN_FROM_REG(val) ((val) * 8) |
106 | 108 | ||
107 | #define DIV_FROM_REG(val) (1 << (val)) | 109 | #define DIV_FROM_REG(val) (1 << (val)) |
@@ -186,11 +188,11 @@ w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value) | |||
186 | #define show_in_reg(reg) \ | 188 | #define show_in_reg(reg) \ |
187 | static ssize_t \ | 189 | static ssize_t \ |
188 | show_##reg(struct device *dev, struct device_attribute *attr, \ | 190 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
189 | char *buf) \ | 191 | char *buf) \ |
190 | { \ | 192 | { \ |
191 | int nr = to_sensor_dev_attr(attr)->index; \ | 193 | int nr = to_sensor_dev_attr(attr)->index; \ |
192 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ | 194 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ |
193 | return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \ | 195 | return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ |
194 | } | 196 | } |
195 | 197 | ||
196 | show_in_reg(in) | 198 | show_in_reg(in) |
@@ -199,13 +201,16 @@ show_in_reg(in_max) | |||
199 | 201 | ||
200 | #define store_in_reg(REG, reg) \ | 202 | #define store_in_reg(REG, reg) \ |
201 | static ssize_t \ | 203 | static ssize_t \ |
202 | store_in_##reg (struct device *dev, struct device_attribute *attr, \ | 204 | store_in_##reg(struct device *dev, struct device_attribute *attr, \ |
203 | const char *buf, size_t count) \ | 205 | const char *buf, size_t count) \ |
204 | { \ | 206 | { \ |
205 | int nr = to_sensor_dev_attr(attr)->index; \ | 207 | int nr = to_sensor_dev_attr(attr)->index; \ |
206 | struct i2c_client *client = to_i2c_client(dev); \ | 208 | struct i2c_client *client = to_i2c_client(dev); \ |
207 | struct w83l786ng_data *data = i2c_get_clientdata(client); \ | 209 | struct w83l786ng_data *data = i2c_get_clientdata(client); \ |
208 | unsigned long val = simple_strtoul(buf, NULL, 10); \ | 210 | unsigned long val; \ |
211 | int err = kstrtoul(buf, 10, &val); \ | ||
212 | if (err) \ | ||
213 | return err; \ | ||
209 | mutex_lock(&data->update_lock); \ | 214 | mutex_lock(&data->update_lock); \ |
210 | data->in_##reg[nr] = IN_TO_REG(val); \ | 215 | data->in_##reg[nr] = IN_TO_REG(val); \ |
211 | w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \ | 216 | w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \ |
@@ -241,8 +246,8 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ | |||
241 | { \ | 246 | { \ |
242 | int nr = to_sensor_dev_attr(attr)->index; \ | 247 | int nr = to_sensor_dev_attr(attr)->index; \ |
243 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ | 248 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ |
244 | return sprintf(buf,"%d\n", \ | 249 | return sprintf(buf, "%d\n", \ |
245 | FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \ | 250 | FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \ |
246 | } | 251 | } |
247 | 252 | ||
248 | show_fan_reg(fan); | 253 | show_fan_reg(fan); |
@@ -255,9 +260,13 @@ store_fan_min(struct device *dev, struct device_attribute *attr, | |||
255 | int nr = to_sensor_dev_attr(attr)->index; | 260 | int nr = to_sensor_dev_attr(attr)->index; |
256 | struct i2c_client *client = to_i2c_client(dev); | 261 | struct i2c_client *client = to_i2c_client(dev); |
257 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 262 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
258 | u32 val; | 263 | unsigned long val; |
264 | int err; | ||
265 | |||
266 | err = kstrtoul(buf, 10, &val); | ||
267 | if (err) | ||
268 | return err; | ||
259 | 269 | ||
260 | val = simple_strtoul(buf, NULL, 10); | ||
261 | mutex_lock(&data->update_lock); | 270 | mutex_lock(&data->update_lock); |
262 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 271 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
263 | w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr), | 272 | w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr), |
@@ -294,11 +303,18 @@ store_fan_div(struct device *dev, struct device_attribute *attr, | |||
294 | u8 keep_mask = 0; | 303 | u8 keep_mask = 0; |
295 | u8 new_shift = 0; | 304 | u8 new_shift = 0; |
296 | 305 | ||
306 | unsigned long val; | ||
307 | int err; | ||
308 | |||
309 | err = kstrtoul(buf, 10, &val); | ||
310 | if (err) | ||
311 | return err; | ||
312 | |||
297 | /* Save fan_min */ | 313 | /* Save fan_min */ |
298 | mutex_lock(&data->update_lock); | 314 | mutex_lock(&data->update_lock); |
299 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); | 315 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); |
300 | 316 | ||
301 | data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10)); | 317 | data->fan_div[nr] = DIV_TO_REG(val); |
302 | 318 | ||
303 | switch (nr) { | 319 | switch (nr) { |
304 | case 0: | 320 | case 0: |
@@ -371,16 +387,20 @@ store_temp(struct device *dev, struct device_attribute *attr, | |||
371 | int index = sensor_attr->index; | 387 | int index = sensor_attr->index; |
372 | struct i2c_client *client = to_i2c_client(dev); | 388 | struct i2c_client *client = to_i2c_client(dev); |
373 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 389 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
374 | s32 val; | 390 | long val; |
391 | int err; | ||
392 | |||
393 | err = kstrtol(buf, 10, &val); | ||
394 | if (err) | ||
395 | return err; | ||
375 | 396 | ||
376 | val = simple_strtol(buf, NULL, 10); | ||
377 | mutex_lock(&data->update_lock); | 397 | mutex_lock(&data->update_lock); |
378 | data->temp[nr][index] = TEMP_TO_REG(val); | 398 | data->temp[nr][index] = TEMP_TO_REG(val); |
379 | w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index], | 399 | w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index], |
380 | data->temp[nr][index]); | 400 | data->temp[nr][index]); |
381 | mutex_unlock(&data->update_lock); | 401 | mutex_unlock(&data->update_lock); |
382 | 402 | ||
383 | return count; | 403 | return count; |
384 | } | 404 | } |
385 | 405 | ||
386 | static struct sensor_device_attribute_2 sda_temp_input[] = { | 406 | static struct sensor_device_attribute_2 sda_temp_input[] = { |
@@ -403,8 +423,8 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = { | |||
403 | }; | 423 | }; |
404 | 424 | ||
405 | #define show_pwm_reg(reg) \ | 425 | #define show_pwm_reg(reg) \ |
406 | static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ | 426 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
407 | char *buf) \ | 427 | char *buf) \ |
408 | { \ | 428 | { \ |
409 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ | 429 | struct w83l786ng_data *data = w83l786ng_update_device(dev); \ |
410 | int nr = to_sensor_dev_attr(attr)->index; \ | 430 | int nr = to_sensor_dev_attr(attr)->index; \ |
@@ -422,8 +442,13 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, | |||
422 | int nr = to_sensor_dev_attr(attr)->index; | 442 | int nr = to_sensor_dev_attr(attr)->index; |
423 | struct i2c_client *client = to_i2c_client(dev); | 443 | struct i2c_client *client = to_i2c_client(dev); |
424 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 444 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
425 | u32 val = simple_strtoul(buf, NULL, 10); | ||
426 | u8 reg; | 445 | u8 reg; |
446 | unsigned long val; | ||
447 | int err; | ||
448 | |||
449 | err = kstrtoul(buf, 10, &val); | ||
450 | if (err) | ||
451 | return err; | ||
427 | 452 | ||
428 | if (val > 1) | 453 | if (val > 1) |
429 | return -EINVAL; | 454 | return -EINVAL; |
@@ -445,7 +470,13 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
445 | int nr = to_sensor_dev_attr(attr)->index; | 470 | int nr = to_sensor_dev_attr(attr)->index; |
446 | struct i2c_client *client = to_i2c_client(dev); | 471 | struct i2c_client *client = to_i2c_client(dev); |
447 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 472 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
448 | u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); | 473 | unsigned long val; |
474 | int err; | ||
475 | |||
476 | err = kstrtoul(buf, 10, &val); | ||
477 | if (err) | ||
478 | return err; | ||
479 | val = SENSORS_LIMIT(val, 0, 255); | ||
449 | 480 | ||
450 | mutex_lock(&data->update_lock); | 481 | mutex_lock(&data->update_lock); |
451 | data->pwm[nr] = val; | 482 | data->pwm[nr] = val; |
@@ -461,11 +492,15 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, | |||
461 | int nr = to_sensor_dev_attr(attr)->index; | 492 | int nr = to_sensor_dev_attr(attr)->index; |
462 | struct i2c_client *client = to_i2c_client(dev); | 493 | struct i2c_client *client = to_i2c_client(dev); |
463 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 494 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
464 | u32 val = simple_strtoul(buf, NULL, 10); | ||
465 | |||
466 | u8 reg; | 495 | u8 reg; |
496 | unsigned long val; | ||
497 | int err; | ||
467 | 498 | ||
468 | if (!val || (val > 2)) /* only modes 1 and 2 are supported */ | 499 | err = kstrtoul(buf, 10, &val); |
500 | if (err) | ||
501 | return err; | ||
502 | |||
503 | if (!val || val > 2) /* only modes 1 and 2 are supported */ | ||
469 | return -EINVAL; | 504 | return -EINVAL; |
470 | 505 | ||
471 | mutex_lock(&data->update_lock); | 506 | mutex_lock(&data->update_lock); |
@@ -513,10 +548,13 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
513 | int nr = to_sensor_dev_attr(attr)->index; | 548 | int nr = to_sensor_dev_attr(attr)->index; |
514 | struct i2c_client *client = to_i2c_client(dev); | 549 | struct i2c_client *client = to_i2c_client(dev); |
515 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 550 | struct w83l786ng_data *data = i2c_get_clientdata(client); |
516 | u32 val; | ||
517 | u8 tol_tmp, tol_mask; | 551 | u8 tol_tmp, tol_mask; |
552 | unsigned long val; | ||
553 | int err; | ||
518 | 554 | ||
519 | val = simple_strtoul(buf, NULL, 10); | 555 | err = kstrtoul(buf, 10, &val); |
556 | if (err) | ||
557 | return err; | ||
520 | 558 | ||
521 | mutex_lock(&data->update_lock); | 559 | mutex_lock(&data->update_lock); |
522 | tol_mask = w83l786ng_read_value(client, | 560 | tol_mask = w83l786ng_read_value(client, |
@@ -524,9 +562,8 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
524 | tol_tmp = SENSORS_LIMIT(val, 0, 15); | 562 | tol_tmp = SENSORS_LIMIT(val, 0, 15); |
525 | tol_tmp &= 0x0f; | 563 | tol_tmp &= 0x0f; |
526 | data->tolerance[nr] = tol_tmp; | 564 | data->tolerance[nr] = tol_tmp; |
527 | if (nr == 1) { | 565 | if (nr == 1) |
528 | tol_tmp <<= 4; | 566 | tol_tmp <<= 4; |
529 | } | ||
530 | 567 | ||
531 | w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE, | 568 | w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE, |
532 | tol_mask | tol_tmp); | 569 | tol_mask | tol_tmp); |
@@ -591,9 +628,8 @@ w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
591 | u16 man_id; | 628 | u16 man_id; |
592 | u8 chip_id; | 629 | u8 chip_id; |
593 | 630 | ||
594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 631 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
595 | return -ENODEV; | 632 | return -ENODEV; |
596 | } | ||
597 | 633 | ||
598 | /* Detection */ | 634 | /* Detection */ |
599 | if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) { | 635 | if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) { |
@@ -652,7 +688,8 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
652 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; | 688 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; |
653 | 689 | ||
654 | /* Register sysfs hooks */ | 690 | /* Register sysfs hooks */ |
655 | if ((err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group))) | 691 | err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group); |
692 | if (err) | ||
656 | goto exit_remove; | 693 | goto exit_remove; |
657 | 694 | ||
658 | data->hwmon_dev = hwmon_device_register(dev); | 695 | data->hwmon_dev = hwmon_device_register(dev); |