diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-05-08 11:22:03 -0400 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2007-05-08 11:22:03 -0400 |
commit | 348753379a7704087603dad403603e825422fd9a (patch) | |
tree | e25a054150850ae6ab2f733413c3f0659ee675fe /drivers/hwmon/w83781d.c | |
parent | 31b8dc4d58b9905a77412c06fc0b22aa19c1cc1d (diff) |
hwmon/w83781d: Use dynamic sysfs callbacks
This lets us get rid of some of the macro-generated functions and
shrinks the driver size significantly (about 9%).
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/w83781d.c')
-rw-r--r-- | drivers/hwmon/w83781d.c | 478 |
1 files changed, 214 insertions, 264 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index ad6b6ca90f6b..b62bb28ac870 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/ioport.h> | 43 | #include <linux/ioport.h> |
44 | #include <linux/hwmon.h> | 44 | #include <linux/hwmon.h> |
45 | #include <linux/hwmon-vid.h> | 45 | #include <linux/hwmon-vid.h> |
46 | #include <linux/hwmon-sysfs.h> | ||
46 | #include <linux/sysfs.h> | 47 | #include <linux/sysfs.h> |
47 | #include <linux/err.h> | 48 | #include <linux/err.h> |
48 | #include <linux/mutex.h> | 49 | #include <linux/mutex.h> |
@@ -80,8 +81,8 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); | |||
80 | #define W83781D_ADDR_REG_OFFSET 5 | 81 | #define W83781D_ADDR_REG_OFFSET 5 |
81 | #define W83781D_DATA_REG_OFFSET 6 | 82 | #define W83781D_DATA_REG_OFFSET 6 |
82 | 83 | ||
83 | /* The W83781D registers */ | 84 | /* The device registers */ |
84 | /* The W83782D registers for nr=7,8 are in bank 5 */ | 85 | /* in nr from 0 to 8 */ |
85 | #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ | 86 | #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ |
86 | (0x554 + (((nr) - 7) * 2))) | 87 | (0x554 + (((nr) - 7) * 2))) |
87 | #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ | 88 | #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ |
@@ -89,12 +90,14 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); | |||
89 | #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ | 90 | #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ |
90 | (0x550 + (nr) - 7)) | 91 | (0x550 + (nr) - 7)) |
91 | 92 | ||
92 | #define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) | 93 | /* fan nr from 0 to 2 */ |
93 | #define W83781D_REG_FAN(nr) (0x27 + (nr)) | 94 | #define W83781D_REG_FAN_MIN(nr) (0x3b + (nr)) |
95 | #define W83781D_REG_FAN(nr) (0x28 + (nr)) | ||
94 | 96 | ||
95 | #define W83781D_REG_BANK 0x4E | 97 | #define W83781D_REG_BANK 0x4E |
96 | #define W83781D_REG_TEMP2_CONFIG 0x152 | 98 | #define W83781D_REG_TEMP2_CONFIG 0x152 |
97 | #define W83781D_REG_TEMP3_CONFIG 0x252 | 99 | #define W83781D_REG_TEMP3_CONFIG 0x252 |
100 | /* temp nr from 1 to 3 */ | ||
98 | #define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ | 101 | #define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ |
99 | ((nr == 2) ? (0x0150) : \ | 102 | ((nr == 2) ? (0x0150) : \ |
100 | (0x27))) | 103 | (0x27))) |
@@ -132,19 +135,9 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); | |||
132 | #define W83781D_REG_VBAT 0x5D | 135 | #define W83781D_REG_VBAT 0x5D |
133 | 136 | ||
134 | /* PWM 782D (1-4) and 783S (1-2) only */ | 137 | /* PWM 782D (1-4) and 783S (1-2) only */ |
135 | #define W83781D_REG_PWM1 0x5B /* 782d and 783s/627hf datasheets disagree */ | 138 | static const u8 W83781D_REG_PWM[] = { 0x5B, 0x5A, 0x5E, 0x5F }; |
136 | /* on which is which; */ | ||
137 | #define W83781D_REG_PWM2 0x5A /* We follow the 782d convention here, */ | ||
138 | /* However 782d is probably wrong. */ | ||
139 | #define W83781D_REG_PWM3 0x5E | ||
140 | #define W83781D_REG_PWM4 0x5F | ||
141 | #define W83781D_REG_PWMCLK12 0x5C | 139 | #define W83781D_REG_PWMCLK12 0x5C |
142 | #define W83781D_REG_PWMCLK34 0x45C | 140 | #define W83781D_REG_PWMCLK34 0x45C |
143 | static const u8 regpwm[] = { W83781D_REG_PWM1, W83781D_REG_PWM2, | ||
144 | W83781D_REG_PWM3, W83781D_REG_PWM4 | ||
145 | }; | ||
146 | |||
147 | #define W83781D_REG_PWM(nr) (regpwm[(nr) - 1]) | ||
148 | 141 | ||
149 | #define W83781D_REG_I2C_ADDR 0x48 | 142 | #define W83781D_REG_I2C_ADDR 0x48 |
150 | #define W83781D_REG_I2C_SUBADDR 0x4A | 143 | #define W83781D_REG_I2C_SUBADDR 0x4A |
@@ -255,7 +248,7 @@ struct w83781d_data { | |||
255 | u32 beep_mask; /* Register encoding, combined */ | 248 | u32 beep_mask; /* Register encoding, combined */ |
256 | u8 beep_enable; /* Boolean */ | 249 | u8 beep_enable; /* Boolean */ |
257 | u8 pwm[4]; /* Register value */ | 250 | u8 pwm[4]; /* Register value */ |
258 | u8 pwmenable[4]; /* Boolean */ | 251 | u8 pwm2_enable; /* Boolean */ |
259 | u16 sens[3]; /* 782D/783S only. | 252 | u16 sens[3]; /* 782D/783S only. |
260 | 1 = pentium diode; 2 = 3904 diode; | 253 | 1 = pentium diode; 2 = 3904 diode; |
261 | 3000-5000 = thermistor beta. | 254 | 3000-5000 = thermistor beta. |
@@ -297,19 +290,25 @@ static struct platform_driver w83781d_isa_driver = { | |||
297 | 290 | ||
298 | /* following are the sysfs callback functions */ | 291 | /* following are the sysfs callback functions */ |
299 | #define show_in_reg(reg) \ | 292 | #define show_in_reg(reg) \ |
300 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ | 293 | static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ |
294 | char *buf) \ | ||
301 | { \ | 295 | { \ |
296 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ | ||
302 | struct w83781d_data *data = w83781d_update_device(dev); \ | 297 | struct w83781d_data *data = w83781d_update_device(dev); \ |
303 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->reg[nr])); \ | 298 | return sprintf(buf, "%ld\n", \ |
299 | (long)IN_FROM_REG(data->reg[attr->index])); \ | ||
304 | } | 300 | } |
305 | show_in_reg(in); | 301 | show_in_reg(in); |
306 | show_in_reg(in_min); | 302 | show_in_reg(in_min); |
307 | show_in_reg(in_max); | 303 | show_in_reg(in_max); |
308 | 304 | ||
309 | #define store_in_reg(REG, reg) \ | 305 | #define store_in_reg(REG, reg) \ |
310 | static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ | 306 | static ssize_t store_in_##reg (struct device *dev, struct device_attribute \ |
307 | *da, const char *buf, size_t count) \ | ||
311 | { \ | 308 | { \ |
309 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ | ||
312 | struct w83781d_data *data = dev_get_drvdata(dev); \ | 310 | struct w83781d_data *data = dev_get_drvdata(dev); \ |
311 | int nr = attr->index; \ | ||
313 | u32 val; \ | 312 | u32 val; \ |
314 | \ | 313 | \ |
315 | val = simple_strtoul(buf, NULL, 10); \ | 314 | val = simple_strtoul(buf, NULL, 10); \ |
@@ -324,29 +323,13 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count | |||
324 | store_in_reg(MIN, min); | 323 | store_in_reg(MIN, min); |
325 | store_in_reg(MAX, max); | 324 | store_in_reg(MAX, max); |
326 | 325 | ||
327 | #define sysfs_in_offset(offset) \ | ||
328 | static ssize_t \ | ||
329 | show_regs_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
330 | { \ | ||
331 | return show_in(dev, buf, offset); \ | ||
332 | } \ | ||
333 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL); | ||
334 | |||
335 | #define sysfs_in_reg_offset(reg, offset) \ | ||
336 | static ssize_t show_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
337 | { \ | ||
338 | return show_in_##reg (dev, buf, offset); \ | ||
339 | } \ | ||
340 | static ssize_t store_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | ||
341 | { \ | ||
342 | return store_in_##reg (dev, buf, count, offset); \ | ||
343 | } \ | ||
344 | static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_in_##reg##offset, store_regs_in_##reg##offset); | ||
345 | |||
346 | #define sysfs_in_offsets(offset) \ | 326 | #define sysfs_in_offsets(offset) \ |
347 | sysfs_in_offset(offset); \ | 327 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
348 | sysfs_in_reg_offset(min, offset); \ | 328 | show_in, NULL, offset); \ |
349 | sysfs_in_reg_offset(max, offset); | 329 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
330 | show_in_min, store_in_min, offset); \ | ||
331 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
332 | show_in_max, store_in_max, offset) | ||
350 | 333 | ||
351 | sysfs_in_offsets(0); | 334 | sysfs_in_offsets(0); |
352 | sysfs_in_offsets(1); | 335 | sysfs_in_offsets(1); |
@@ -359,62 +342,56 @@ sysfs_in_offsets(7); | |||
359 | sysfs_in_offsets(8); | 342 | sysfs_in_offsets(8); |
360 | 343 | ||
361 | #define show_fan_reg(reg) \ | 344 | #define show_fan_reg(reg) \ |
362 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ | 345 | static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ |
346 | char *buf) \ | ||
363 | { \ | 347 | { \ |
348 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ | ||
364 | struct w83781d_data *data = w83781d_update_device(dev); \ | 349 | struct w83781d_data *data = w83781d_update_device(dev); \ |
365 | return sprintf(buf,"%ld\n", \ | 350 | return sprintf(buf,"%ld\n", \ |
366 | FAN_FROM_REG(data->reg[nr-1], (long)DIV_FROM_REG(data->fan_div[nr-1]))); \ | 351 | FAN_FROM_REG(data->reg[attr->index], \ |
352 | DIV_FROM_REG(data->fan_div[attr->index]))); \ | ||
367 | } | 353 | } |
368 | show_fan_reg(fan); | 354 | show_fan_reg(fan); |
369 | show_fan_reg(fan_min); | 355 | show_fan_reg(fan_min); |
370 | 356 | ||
371 | static ssize_t | 357 | static ssize_t |
372 | store_fan_min(struct device *dev, const char *buf, size_t count, int nr) | 358 | store_fan_min(struct device *dev, struct device_attribute *da, |
359 | const char *buf, size_t count) | ||
373 | { | 360 | { |
361 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
374 | struct w83781d_data *data = dev_get_drvdata(dev); | 362 | struct w83781d_data *data = dev_get_drvdata(dev); |
363 | int nr = attr->index; | ||
375 | u32 val; | 364 | u32 val; |
376 | 365 | ||
377 | val = simple_strtoul(buf, NULL, 10); | 366 | val = simple_strtoul(buf, NULL, 10); |
378 | 367 | ||
379 | mutex_lock(&data->update_lock); | 368 | mutex_lock(&data->update_lock); |
380 | data->fan_min[nr - 1] = | 369 | data->fan_min[nr] = |
381 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); | 370 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
382 | w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), | 371 | w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), |
383 | data->fan_min[nr - 1]); | 372 | data->fan_min[nr]); |
384 | 373 | ||
385 | mutex_unlock(&data->update_lock); | 374 | mutex_unlock(&data->update_lock); |
386 | return count; | 375 | return count; |
387 | } | 376 | } |
388 | 377 | ||
389 | #define sysfs_fan_offset(offset) \ | 378 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
390 | static ssize_t show_regs_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 379 | static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, |
391 | { \ | 380 | show_fan_min, store_fan_min, 0); |
392 | return show_fan(dev, buf, offset); \ | 381 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); |
393 | } \ | 382 | static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR, |
394 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL); | 383 | show_fan_min, store_fan_min, 1); |
395 | 384 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); | |
396 | #define sysfs_fan_min_offset(offset) \ | 385 | static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR, |
397 | static ssize_t show_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 386 | show_fan_min, store_fan_min, 2); |
398 | { \ | ||
399 | return show_fan_min(dev, buf, offset); \ | ||
400 | } \ | ||
401 | static ssize_t store_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | ||
402 | { \ | ||
403 | return store_fan_min(dev, buf, count, offset); \ | ||
404 | } \ | ||
405 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, show_regs_fan_min##offset, store_regs_fan_min##offset); | ||
406 | |||
407 | sysfs_fan_offset(1); | ||
408 | sysfs_fan_min_offset(1); | ||
409 | sysfs_fan_offset(2); | ||
410 | sysfs_fan_min_offset(2); | ||
411 | sysfs_fan_offset(3); | ||
412 | sysfs_fan_min_offset(3); | ||
413 | 387 | ||
414 | #define show_temp_reg(reg) \ | 388 | #define show_temp_reg(reg) \ |
415 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ | 389 | static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ |
390 | char *buf) \ | ||
416 | { \ | 391 | { \ |
392 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ | ||
417 | struct w83781d_data *data = w83781d_update_device(dev); \ | 393 | struct w83781d_data *data = w83781d_update_device(dev); \ |
394 | int nr = attr->index; \ | ||
418 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ | 395 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ |
419 | return sprintf(buf,"%d\n", \ | 396 | return sprintf(buf,"%d\n", \ |
420 | LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ | 397 | LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ |
@@ -427,9 +404,12 @@ show_temp_reg(temp_max); | |||
427 | show_temp_reg(temp_max_hyst); | 404 | show_temp_reg(temp_max_hyst); |
428 | 405 | ||
429 | #define store_temp_reg(REG, reg) \ | 406 | #define store_temp_reg(REG, reg) \ |
430 | static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ | 407 | static ssize_t store_temp_##reg (struct device *dev, \ |
408 | struct device_attribute *da, const char *buf, size_t count) \ | ||
431 | { \ | 409 | { \ |
410 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ | ||
432 | struct w83781d_data *data = dev_get_drvdata(dev); \ | 411 | struct w83781d_data *data = dev_get_drvdata(dev); \ |
412 | int nr = attr->index; \ | ||
433 | s32 val; \ | 413 | s32 val; \ |
434 | \ | 414 | \ |
435 | val = simple_strtol(buf, NULL, 10); \ | 415 | val = simple_strtol(buf, NULL, 10); \ |
@@ -452,29 +432,13 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou | |||
452 | store_temp_reg(OVER, max); | 432 | store_temp_reg(OVER, max); |
453 | store_temp_reg(HYST, max_hyst); | 433 | store_temp_reg(HYST, max_hyst); |
454 | 434 | ||
455 | #define sysfs_temp_offset(offset) \ | ||
456 | static ssize_t \ | ||
457 | show_regs_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
458 | { \ | ||
459 | return show_temp(dev, buf, offset); \ | ||
460 | } \ | ||
461 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL); | ||
462 | |||
463 | #define sysfs_temp_reg_offset(reg, offset) \ | ||
464 | static ssize_t show_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
465 | { \ | ||
466 | return show_temp_##reg (dev, buf, offset); \ | ||
467 | } \ | ||
468 | static ssize_t store_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | ||
469 | { \ | ||
470 | return store_temp_##reg (dev, buf, count, offset); \ | ||
471 | } \ | ||
472 | static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_temp_##reg##offset, store_regs_temp_##reg##offset); | ||
473 | |||
474 | #define sysfs_temp_offsets(offset) \ | 435 | #define sysfs_temp_offsets(offset) \ |
475 | sysfs_temp_offset(offset); \ | 436 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
476 | sysfs_temp_reg_offset(max, offset); \ | 437 | show_temp, NULL, offset); \ |
477 | sysfs_temp_reg_offset(max_hyst, offset); | 438 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
439 | show_temp_max, store_temp_max, offset); \ | ||
440 | static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
441 | show_temp_max_hyst, store_temp_max_hyst, offset); | ||
478 | 442 | ||
479 | sysfs_temp_offsets(1); | 443 | sysfs_temp_offsets(1); |
480 | sysfs_temp_offsets(2); | 444 | sysfs_temp_offsets(2); |
@@ -531,63 +495,64 @@ static ssize_t show_beep_enable (struct device *dev, struct device_attribute *at | |||
531 | return sprintf(buf, "%ld\n", (long)data->beep_enable); | 495 | return sprintf(buf, "%ld\n", (long)data->beep_enable); |
532 | } | 496 | } |
533 | 497 | ||
534 | #define BEEP_ENABLE 0 /* Store beep_enable */ | ||
535 | #define BEEP_MASK 1 /* Store beep_mask */ | ||
536 | |||
537 | static ssize_t | 498 | static ssize_t |
538 | store_beep_reg(struct device *dev, const char *buf, size_t count, | 499 | store_beep_mask(struct device *dev, struct device_attribute *attr, |
539 | int update_mask) | 500 | const char *buf, size_t count) |
540 | { | 501 | { |
541 | struct w83781d_data *data = dev_get_drvdata(dev); | 502 | struct w83781d_data *data = dev_get_drvdata(dev); |
542 | u32 val, val2; | 503 | u32 val; |
543 | 504 | ||
544 | val = simple_strtoul(buf, NULL, 10); | 505 | val = simple_strtoul(buf, NULL, 10); |
545 | 506 | ||
546 | mutex_lock(&data->update_lock); | 507 | mutex_lock(&data->update_lock); |
508 | data->beep_mask = BEEP_MASK_TO_REG(val, data->type); | ||
509 | w83781d_write_value(data, W83781D_REG_BEEP_INTS1, | ||
510 | data->beep_mask & 0xff); | ||
511 | w83781d_write_value(data, W83781D_REG_BEEP_INTS2, | ||
512 | ((data->beep_mask >> 8) & 0x7f) | ||
513 | | data->beep_enable << 7); | ||
514 | if (data->type != w83781d && data->type != as99127f) { | ||
515 | w83781d_write_value(data, W83781D_REG_BEEP_INTS3, | ||
516 | ((data->beep_mask) >> 16) & 0xff); | ||
517 | } | ||
518 | mutex_unlock(&data->update_lock); | ||
547 | 519 | ||
548 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ | 520 | return count; |
549 | data->beep_mask = BEEP_MASK_TO_REG(val, data->type); | 521 | } |
550 | w83781d_write_value(data, W83781D_REG_BEEP_INTS1, | ||
551 | data->beep_mask & 0xff); | ||
552 | |||
553 | if ((data->type != w83781d) && (data->type != as99127f)) { | ||
554 | w83781d_write_value(data, W83781D_REG_BEEP_INTS3, | ||
555 | ((data->beep_mask) >> 16) & 0xff); | ||
556 | } | ||
557 | 522 | ||
558 | val2 = (data->beep_mask >> 8) & 0x7f; | 523 | static ssize_t |
559 | } else { /* We are storing beep_enable */ | 524 | store_beep_enable(struct device *dev, struct device_attribute *attr, |
560 | val2 = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; | 525 | const char *buf, size_t count) |
561 | data->beep_enable = !!val; | 526 | { |
562 | } | 527 | struct w83781d_data *data = dev_get_drvdata(dev); |
528 | u32 val; | ||
563 | 529 | ||
564 | w83781d_write_value(data, W83781D_REG_BEEP_INTS2, | 530 | val = simple_strtoul(buf, NULL, 10); |
565 | val2 | data->beep_enable << 7); | 531 | if (val != 0 && val != 1) |
532 | return -EINVAL; | ||
566 | 533 | ||
534 | mutex_lock(&data->update_lock); | ||
535 | data->beep_enable = val; | ||
536 | val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; | ||
537 | val |= data->beep_enable << 7; | ||
538 | w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val); | ||
567 | mutex_unlock(&data->update_lock); | 539 | mutex_unlock(&data->update_lock); |
540 | |||
568 | return count; | 541 | return count; |
569 | } | 542 | } |
570 | 543 | ||
571 | #define sysfs_beep(REG, reg) \ | 544 | static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR, |
572 | static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ | 545 | show_beep_mask, store_beep_mask); |
573 | { \ | 546 | static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR, |
574 | return show_beep_##reg(dev, attr, buf); \ | 547 | show_beep_enable, store_beep_enable); |
575 | } \ | ||
576 | static ssize_t store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | ||
577 | { \ | ||
578 | return store_beep_reg(dev, buf, count, BEEP_##REG); \ | ||
579 | } \ | ||
580 | static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, show_regs_beep_##reg, store_regs_beep_##reg); | ||
581 | |||
582 | sysfs_beep(ENABLE, enable); | ||
583 | sysfs_beep(MASK, mask); | ||
584 | 548 | ||
585 | static ssize_t | 549 | static ssize_t |
586 | show_fan_div_reg(struct device *dev, char *buf, int nr) | 550 | show_fan_div(struct device *dev, struct device_attribute *da, char *buf) |
587 | { | 551 | { |
552 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
588 | struct w83781d_data *data = w83781d_update_device(dev); | 553 | struct w83781d_data *data = w83781d_update_device(dev); |
589 | return sprintf(buf, "%ld\n", | 554 | return sprintf(buf, "%ld\n", |
590 | (long) DIV_FROM_REG(data->fan_div[nr - 1])); | 555 | (long) DIV_FROM_REG(data->fan_div[attr->index])); |
591 | } | 556 | } |
592 | 557 | ||
593 | /* Note: we save and restore the fan minimum here, because its value is | 558 | /* Note: we save and restore the fan minimum here, because its value is |
@@ -595,10 +560,13 @@ show_fan_div_reg(struct device *dev, char *buf, int nr) | |||
595 | least surprise; the user doesn't expect the fan minimum to change just | 560 | least surprise; the user doesn't expect the fan minimum to change just |
596 | because the divisor changed. */ | 561 | because the divisor changed. */ |
597 | static ssize_t | 562 | static ssize_t |
598 | store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) | 563 | store_fan_div(struct device *dev, struct device_attribute *da, |
564 | const char *buf, size_t count) | ||
599 | { | 565 | { |
566 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
600 | struct w83781d_data *data = dev_get_drvdata(dev); | 567 | struct w83781d_data *data = dev_get_drvdata(dev); |
601 | unsigned long min; | 568 | unsigned long min; |
569 | int nr = attr->index; | ||
602 | u8 reg; | 570 | u8 reg; |
603 | unsigned long val = simple_strtoul(buf, NULL, 10); | 571 | unsigned long val = simple_strtoul(buf, NULL, 10); |
604 | 572 | ||
@@ -625,58 +593,55 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
625 | 593 | ||
626 | /* Restore fan_min */ | 594 | /* Restore fan_min */ |
627 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 595 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
628 | w83781d_write_value(data, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); | 596 | w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), data->fan_min[nr]); |
629 | 597 | ||
630 | mutex_unlock(&data->update_lock); | 598 | mutex_unlock(&data->update_lock); |
631 | return count; | 599 | return count; |
632 | } | 600 | } |
633 | 601 | ||
634 | #define sysfs_fan_div(offset) \ | 602 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, |
635 | static ssize_t show_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 603 | show_fan_div, store_fan_div, 0); |
636 | { \ | 604 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, |
637 | return show_fan_div_reg(dev, buf, offset); \ | 605 | show_fan_div, store_fan_div, 1); |
638 | } \ | 606 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, |
639 | static ssize_t store_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | 607 | show_fan_div, store_fan_div, 2); |
640 | { \ | ||
641 | return store_fan_div_reg(dev, buf, count, offset - 1); \ | ||
642 | } \ | ||
643 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, show_regs_fan_div_##offset, store_regs_fan_div_##offset); | ||
644 | |||
645 | sysfs_fan_div(1); | ||
646 | sysfs_fan_div(2); | ||
647 | sysfs_fan_div(3); | ||
648 | 608 | ||
649 | static ssize_t | 609 | static ssize_t |
650 | show_pwm_reg(struct device *dev, char *buf, int nr) | 610 | show_pwm(struct device *dev, struct device_attribute *da, char *buf) |
651 | { | 611 | { |
612 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
652 | struct w83781d_data *data = w83781d_update_device(dev); | 613 | struct w83781d_data *data = w83781d_update_device(dev); |
653 | return sprintf(buf, "%ld\n", (long)data->pwm[nr - 1]); | 614 | return sprintf(buf, "%d\n", (int)data->pwm[attr->index]); |
654 | } | 615 | } |
655 | 616 | ||
656 | static ssize_t | 617 | static ssize_t |
657 | show_pwmenable_reg(struct device *dev, char *buf, int nr) | 618 | show_pwm2_enable(struct device *dev, struct device_attribute *da, char *buf) |
658 | { | 619 | { |
659 | struct w83781d_data *data = w83781d_update_device(dev); | 620 | struct w83781d_data *data = w83781d_update_device(dev); |
660 | return sprintf(buf, "%ld\n", (long) data->pwmenable[nr - 1]); | 621 | return sprintf(buf, "%d\n", (int)data->pwm2_enable); |
661 | } | 622 | } |
662 | 623 | ||
663 | static ssize_t | 624 | static ssize_t |
664 | store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) | 625 | store_pwm(struct device *dev, struct device_attribute *da, const char *buf, |
626 | size_t count) | ||
665 | { | 627 | { |
628 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
666 | struct w83781d_data *data = dev_get_drvdata(dev); | 629 | struct w83781d_data *data = dev_get_drvdata(dev); |
630 | int nr = attr->index; | ||
667 | u32 val; | 631 | u32 val; |
668 | 632 | ||
669 | val = simple_strtoul(buf, NULL, 10); | 633 | val = simple_strtoul(buf, NULL, 10); |
670 | 634 | ||
671 | mutex_lock(&data->update_lock); | 635 | mutex_lock(&data->update_lock); |
672 | data->pwm[nr - 1] = SENSORS_LIMIT(val, 0, 255); | 636 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); |
673 | w83781d_write_value(data, W83781D_REG_PWM(nr), data->pwm[nr - 1]); | 637 | w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]); |
674 | mutex_unlock(&data->update_lock); | 638 | mutex_unlock(&data->update_lock); |
675 | return count; | 639 | return count; |
676 | } | 640 | } |
677 | 641 | ||
678 | static ssize_t | 642 | static ssize_t |
679 | store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) | 643 | store_pwm2_enable(struct device *dev, struct device_attribute *da, |
644 | const char *buf, size_t count) | ||
680 | { | 645 | { |
681 | struct w83781d_data *data = dev_get_drvdata(dev); | 646 | struct w83781d_data *data = dev_get_drvdata(dev); |
682 | u32 val, reg; | 647 | u32 val, reg; |
@@ -696,7 +661,7 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
696 | w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, | 661 | w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, |
697 | (reg & 0xef) | (!val << 4)); | 662 | (reg & 0xef) | (!val << 4)); |
698 | 663 | ||
699 | data->pwmenable[nr - 1] = val; | 664 | data->pwm2_enable = val; |
700 | break; | 665 | break; |
701 | 666 | ||
702 | default: | 667 | default: |
@@ -708,49 +673,29 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
708 | return count; | 673 | return count; |
709 | } | 674 | } |
710 | 675 | ||
711 | #define sysfs_pwm(offset) \ | 676 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0); |
712 | static ssize_t show_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 677 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 1); |
713 | { \ | 678 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 2); |
714 | return show_pwm_reg(dev, buf, offset); \ | 679 | static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 3); |
715 | } \ | 680 | /* only PWM2 can be enabled/disabled */ |
716 | static ssize_t store_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, \ | 681 | static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, |
717 | const char *buf, size_t count) \ | 682 | show_pwm2_enable, store_pwm2_enable); |
718 | { \ | ||
719 | return store_pwm_reg(dev, buf, count, offset); \ | ||
720 | } \ | ||
721 | static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | ||
722 | show_regs_pwm_##offset, store_regs_pwm_##offset); | ||
723 | |||
724 | #define sysfs_pwmenable(offset) \ | ||
725 | static ssize_t show_regs_pwmenable_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
726 | { \ | ||
727 | return show_pwmenable_reg(dev, buf, offset); \ | ||
728 | } \ | ||
729 | static ssize_t store_regs_pwmenable_##offset (struct device *dev, struct device_attribute *attr, \ | ||
730 | const char *buf, size_t count) \ | ||
731 | { \ | ||
732 | return store_pwmenable_reg(dev, buf, count, offset); \ | ||
733 | } \ | ||
734 | static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | ||
735 | show_regs_pwmenable_##offset, store_regs_pwmenable_##offset); | ||
736 | |||
737 | sysfs_pwm(1); | ||
738 | sysfs_pwm(2); | ||
739 | sysfs_pwmenable(2); /* only PWM2 can be enabled/disabled */ | ||
740 | sysfs_pwm(3); | ||
741 | sysfs_pwm(4); | ||
742 | 683 | ||
743 | static ssize_t | 684 | static ssize_t |
744 | show_sensor_reg(struct device *dev, char *buf, int nr) | 685 | show_sensor(struct device *dev, struct device_attribute *da, char *buf) |
745 | { | 686 | { |
687 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
746 | struct w83781d_data *data = w83781d_update_device(dev); | 688 | struct w83781d_data *data = w83781d_update_device(dev); |
747 | return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); | 689 | return sprintf(buf, "%d\n", (int)data->sens[attr->index]); |
748 | } | 690 | } |
749 | 691 | ||
750 | static ssize_t | 692 | static ssize_t |
751 | store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | 693 | store_sensor(struct device *dev, struct device_attribute *da, |
694 | const char *buf, size_t count) | ||
752 | { | 695 | { |
696 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
753 | struct w83781d_data *data = dev_get_drvdata(dev); | 697 | struct w83781d_data *data = dev_get_drvdata(dev); |
698 | int nr = attr->index; | ||
754 | u32 val, tmp; | 699 | u32 val, tmp; |
755 | 700 | ||
756 | val = simple_strtoul(buf, NULL, 10); | 701 | val = simple_strtoul(buf, NULL, 10); |
@@ -761,26 +706,26 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
761 | case 1: /* PII/Celeron diode */ | 706 | case 1: /* PII/Celeron diode */ |
762 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); | 707 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); |
763 | w83781d_write_value(data, W83781D_REG_SCFG1, | 708 | w83781d_write_value(data, W83781D_REG_SCFG1, |
764 | tmp | BIT_SCFG1[nr - 1]); | 709 | tmp | BIT_SCFG1[nr]); |
765 | tmp = w83781d_read_value(data, W83781D_REG_SCFG2); | 710 | tmp = w83781d_read_value(data, W83781D_REG_SCFG2); |
766 | w83781d_write_value(data, W83781D_REG_SCFG2, | 711 | w83781d_write_value(data, W83781D_REG_SCFG2, |
767 | tmp | BIT_SCFG2[nr - 1]); | 712 | tmp | BIT_SCFG2[nr]); |
768 | data->sens[nr - 1] = val; | 713 | data->sens[nr] = val; |
769 | break; | 714 | break; |
770 | case 2: /* 3904 */ | 715 | case 2: /* 3904 */ |
771 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); | 716 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); |
772 | w83781d_write_value(data, W83781D_REG_SCFG1, | 717 | w83781d_write_value(data, W83781D_REG_SCFG1, |
773 | tmp | BIT_SCFG1[nr - 1]); | 718 | tmp | BIT_SCFG1[nr]); |
774 | tmp = w83781d_read_value(data, W83781D_REG_SCFG2); | 719 | tmp = w83781d_read_value(data, W83781D_REG_SCFG2); |
775 | w83781d_write_value(data, W83781D_REG_SCFG2, | 720 | w83781d_write_value(data, W83781D_REG_SCFG2, |
776 | tmp & ~BIT_SCFG2[nr - 1]); | 721 | tmp & ~BIT_SCFG2[nr]); |
777 | data->sens[nr - 1] = val; | 722 | data->sens[nr] = val; |
778 | break; | 723 | break; |
779 | case W83781D_DEFAULT_BETA: /* thermistor */ | 724 | case W83781D_DEFAULT_BETA: /* thermistor */ |
780 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); | 725 | tmp = w83781d_read_value(data, W83781D_REG_SCFG1); |
781 | w83781d_write_value(data, W83781D_REG_SCFG1, | 726 | w83781d_write_value(data, W83781D_REG_SCFG1, |
782 | tmp & ~BIT_SCFG1[nr - 1]); | 727 | tmp & ~BIT_SCFG1[nr]); |
783 | data->sens[nr - 1] = val; | 728 | data->sens[nr] = val; |
784 | break; | 729 | break; |
785 | default: | 730 | default: |
786 | dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n", | 731 | dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n", |
@@ -792,20 +737,12 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
792 | return count; | 737 | return count; |
793 | } | 738 | } |
794 | 739 | ||
795 | #define sysfs_sensor(offset) \ | 740 | static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, |
796 | static ssize_t show_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 741 | show_sensor, store_sensor, 0); |
797 | { \ | 742 | static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, |
798 | return show_sensor_reg(dev, buf, offset); \ | 743 | show_sensor, store_sensor, 0); |
799 | } \ | 744 | static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, |
800 | static ssize_t store_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | 745 | show_sensor, store_sensor, 0); |
801 | { \ | ||
802 | return store_sensor_reg(dev, buf, count, offset); \ | ||
803 | } \ | ||
804 | static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, show_regs_sensor_##offset, store_regs_sensor_##offset); | ||
805 | |||
806 | sysfs_sensor(1); | ||
807 | sysfs_sensor(2); | ||
808 | sysfs_sensor(3); | ||
809 | 746 | ||
810 | /* I2C devices get this name attribute automatically, but for ISA devices | 747 | /* I2C devices get this name attribute automatically, but for ISA devices |
811 | we must create it by ourselves. */ | 748 | we must create it by ourselves. */ |
@@ -935,20 +872,20 @@ ERROR_SC_0: | |||
935 | return err; | 872 | return err; |
936 | } | 873 | } |
937 | 874 | ||
938 | #define IN_UNIT_ATTRS(X) \ | 875 | #define IN_UNIT_ATTRS(X) \ |
939 | &dev_attr_in##X##_input.attr, \ | 876 | &sensor_dev_attr_in##X##_input.dev_attr.attr, \ |
940 | &dev_attr_in##X##_min.attr, \ | 877 | &sensor_dev_attr_in##X##_min.dev_attr.attr, \ |
941 | &dev_attr_in##X##_max.attr | 878 | &sensor_dev_attr_in##X##_max.dev_attr.attr |
942 | 879 | ||
943 | #define FAN_UNIT_ATTRS(X) \ | 880 | #define FAN_UNIT_ATTRS(X) \ |
944 | &dev_attr_fan##X##_input.attr, \ | 881 | &sensor_dev_attr_fan##X##_input.dev_attr.attr, \ |
945 | &dev_attr_fan##X##_min.attr, \ | 882 | &sensor_dev_attr_fan##X##_min.dev_attr.attr, \ |
946 | &dev_attr_fan##X##_div.attr | 883 | &sensor_dev_attr_fan##X##_div.dev_attr.attr |
947 | 884 | ||
948 | #define TEMP_UNIT_ATTRS(X) \ | 885 | #define TEMP_UNIT_ATTRS(X) \ |
949 | &dev_attr_temp##X##_input.attr, \ | 886 | &sensor_dev_attr_temp##X##_input.dev_attr.attr, \ |
950 | &dev_attr_temp##X##_max.attr, \ | 887 | &sensor_dev_attr_temp##X##_max.dev_attr.attr, \ |
951 | &dev_attr_temp##X##_max_hyst.attr | 888 | &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr |
952 | 889 | ||
953 | static struct attribute* w83781d_attributes[] = { | 890 | static struct attribute* w83781d_attributes[] = { |
954 | IN_UNIT_ATTRS(0), | 891 | IN_UNIT_ATTRS(0), |
@@ -978,14 +915,14 @@ static struct attribute *w83781d_attributes_opt[] = { | |||
978 | IN_UNIT_ATTRS(7), | 915 | IN_UNIT_ATTRS(7), |
979 | IN_UNIT_ATTRS(8), | 916 | IN_UNIT_ATTRS(8), |
980 | TEMP_UNIT_ATTRS(3), | 917 | TEMP_UNIT_ATTRS(3), |
981 | &dev_attr_pwm1.attr, | 918 | &sensor_dev_attr_pwm1.dev_attr.attr, |
982 | &dev_attr_pwm2.attr, | 919 | &sensor_dev_attr_pwm2.dev_attr.attr, |
920 | &sensor_dev_attr_pwm3.dev_attr.attr, | ||
921 | &sensor_dev_attr_pwm4.dev_attr.attr, | ||
983 | &dev_attr_pwm2_enable.attr, | 922 | &dev_attr_pwm2_enable.attr, |
984 | &dev_attr_pwm3.attr, | 923 | &sensor_dev_attr_temp1_type.dev_attr.attr, |
985 | &dev_attr_pwm4.attr, | 924 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
986 | &dev_attr_temp1_type.attr, | 925 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
987 | &dev_attr_temp2_type.attr, | ||
988 | &dev_attr_temp3_type.attr, | ||
989 | NULL | 926 | NULL |
990 | }; | 927 | }; |
991 | static const struct attribute_group w83781d_group_opt = { | 928 | static const struct attribute_group w83781d_group_opt = { |
@@ -1002,48 +939,64 @@ w83781d_create_files(struct device *dev, int kind, int is_isa) | |||
1002 | return err; | 939 | return err; |
1003 | 940 | ||
1004 | if (kind != w83783s) { | 941 | if (kind != w83783s) { |
1005 | if ((err = device_create_file(dev, &dev_attr_in1_input)) | 942 | if ((err = device_create_file(dev, |
1006 | || (err = device_create_file(dev, &dev_attr_in1_min)) | 943 | &sensor_dev_attr_in1_input.dev_attr)) |
1007 | || (err = device_create_file(dev, &dev_attr_in1_max))) | 944 | || (err = device_create_file(dev, |
945 | &sensor_dev_attr_in1_min.dev_attr)) | ||
946 | || (err = device_create_file(dev, | ||
947 | &sensor_dev_attr_in1_max.dev_attr))) | ||
1008 | return err; | 948 | return err; |
1009 | } | 949 | } |
1010 | if (kind != as99127f && kind != w83781d && kind != w83783s) { | 950 | if (kind != as99127f && kind != w83781d && kind != w83783s) { |
1011 | if ((err = device_create_file(dev, &dev_attr_in7_input)) | 951 | if ((err = device_create_file(dev, |
1012 | || (err = device_create_file(dev, &dev_attr_in7_min)) | 952 | &sensor_dev_attr_in7_input.dev_attr)) |
1013 | || (err = device_create_file(dev, &dev_attr_in7_max)) | 953 | || (err = device_create_file(dev, |
1014 | || (err = device_create_file(dev, &dev_attr_in8_input)) | 954 | &sensor_dev_attr_in7_min.dev_attr)) |
1015 | || (err = device_create_file(dev, &dev_attr_in8_min)) | 955 | || (err = device_create_file(dev, |
1016 | || (err = device_create_file(dev, &dev_attr_in8_max))) | 956 | &sensor_dev_attr_in7_max.dev_attr)) |
957 | || (err = device_create_file(dev, | ||
958 | &sensor_dev_attr_in8_input.dev_attr)) | ||
959 | || (err = device_create_file(dev, | ||
960 | &sensor_dev_attr_in8_min.dev_attr)) | ||
961 | || (err = device_create_file(dev, | ||
962 | &sensor_dev_attr_in8_max.dev_attr))) | ||
1017 | return err; | 963 | return err; |
1018 | } | 964 | } |
1019 | if (kind != w83783s) { | 965 | if (kind != w83783s) { |
1020 | if ((err = device_create_file(dev, &dev_attr_temp3_input)) | 966 | if ((err = device_create_file(dev, |
1021 | || (err = device_create_file(dev, &dev_attr_temp3_max)) | 967 | &sensor_dev_attr_temp3_input.dev_attr)) |
1022 | || (err = device_create_file(dev, | 968 | || (err = device_create_file(dev, |
1023 | &dev_attr_temp3_max_hyst))) | 969 | &sensor_dev_attr_temp3_max.dev_attr)) |
970 | || (err = device_create_file(dev, | ||
971 | &sensor_dev_attr_temp3_max_hyst.dev_attr))) | ||
1024 | return err; | 972 | return err; |
1025 | } | 973 | } |
1026 | 974 | ||
1027 | if (kind != w83781d && kind != as99127f) { | 975 | if (kind != w83781d && kind != as99127f) { |
1028 | if ((err = device_create_file(dev, &dev_attr_pwm1)) | 976 | if ((err = device_create_file(dev, |
1029 | || (err = device_create_file(dev, &dev_attr_pwm2)) | 977 | &sensor_dev_attr_pwm1.dev_attr)) |
978 | || (err = device_create_file(dev, | ||
979 | &sensor_dev_attr_pwm2.dev_attr)) | ||
1030 | || (err = device_create_file(dev, &dev_attr_pwm2_enable))) | 980 | || (err = device_create_file(dev, &dev_attr_pwm2_enable))) |
1031 | return err; | 981 | return err; |
1032 | } | 982 | } |
1033 | if (kind == w83782d && !is_isa) { | 983 | if (kind == w83782d && !is_isa) { |
1034 | if ((err = device_create_file(dev, &dev_attr_pwm3)) | 984 | if ((err = device_create_file(dev, |
1035 | || (err = device_create_file(dev, &dev_attr_pwm4))) | 985 | &sensor_dev_attr_pwm3.dev_attr)) |
986 | || (err = device_create_file(dev, | ||
987 | &sensor_dev_attr_pwm4.dev_attr))) | ||
1036 | return err; | 988 | return err; |
1037 | } | 989 | } |
1038 | 990 | ||
1039 | if (kind != as99127f && kind != w83781d) { | 991 | if (kind != as99127f && kind != w83781d) { |
1040 | if ((err = device_create_file(dev, &dev_attr_temp1_type)) | 992 | if ((err = device_create_file(dev, |
993 | &sensor_dev_attr_temp1_type.dev_attr)) | ||
1041 | || (err = device_create_file(dev, | 994 | || (err = device_create_file(dev, |
1042 | &dev_attr_temp2_type))) | 995 | &sensor_dev_attr_temp2_type.dev_attr))) |
1043 | return err; | 996 | return err; |
1044 | if (kind != w83783s) { | 997 | if (kind != w83783s) { |
1045 | if ((err = device_create_file(dev, | 998 | if ((err = device_create_file(dev, |
1046 | &dev_attr_temp3_type))) | 999 | &sensor_dev_attr_temp3_type.dev_attr))) |
1047 | return err; | 1000 | return err; |
1048 | } | 1001 | } |
1049 | } | 1002 | } |
@@ -1571,13 +1524,10 @@ w83781d_init_device(struct device *dev) | |||
1571 | | 0x01); | 1524 | | 0x01); |
1572 | 1525 | ||
1573 | /* A few vars need to be filled upon startup */ | 1526 | /* A few vars need to be filled upon startup */ |
1574 | for (i = 1; i <= 3; i++) { | 1527 | for (i = 0; i < 3; i++) { |
1575 | data->fan_min[i - 1] = w83781d_read_value(data, | 1528 | data->fan_min[i] = w83781d_read_value(data, |
1576 | W83781D_REG_FAN_MIN(i)); | 1529 | W83781D_REG_FAN_MIN(i)); |
1577 | } | 1530 | } |
1578 | if (type != w83781d && type != as99127f) | ||
1579 | for (i = 0; i < 4; i++) | ||
1580 | data->pwmenable[i] = 1; | ||
1581 | 1531 | ||
1582 | mutex_init(&data->update_lock); | 1532 | mutex_init(&data->update_lock); |
1583 | } | 1533 | } |
@@ -1607,23 +1557,23 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) | |||
1607 | && (data->type != w83627hf) && (i == 6)) | 1557 | && (data->type != w83627hf) && (i == 6)) |
1608 | break; | 1558 | break; |
1609 | } | 1559 | } |
1610 | for (i = 1; i <= 3; i++) { | 1560 | for (i = 0; i < 3; i++) { |
1611 | data->fan[i - 1] = | 1561 | data->fan[i] = |
1612 | w83781d_read_value(data, W83781D_REG_FAN(i)); | 1562 | w83781d_read_value(data, W83781D_REG_FAN(i)); |
1613 | data->fan_min[i - 1] = | 1563 | data->fan_min[i] = |
1614 | w83781d_read_value(data, W83781D_REG_FAN_MIN(i)); | 1564 | w83781d_read_value(data, W83781D_REG_FAN_MIN(i)); |
1615 | } | 1565 | } |
1616 | if (data->type != w83781d && data->type != as99127f) { | 1566 | if (data->type != w83781d && data->type != as99127f) { |
1617 | for (i = 1; i <= 4; i++) { | 1567 | for (i = 0; i < 4; i++) { |
1618 | data->pwm[i - 1] = | 1568 | data->pwm[i] = |
1619 | w83781d_read_value(data, | 1569 | w83781d_read_value(data, |
1620 | W83781D_REG_PWM(i)); | 1570 | W83781D_REG_PWM[i]); |
1621 | if ((data->type != w83782d || !client->driver) | 1571 | if ((data->type != w83782d || !client->driver) |
1622 | && i == 2) | 1572 | && i == 1) |
1623 | break; | 1573 | break; |
1624 | } | 1574 | } |
1625 | /* Only PWM2 can be disabled */ | 1575 | /* Only PWM2 can be disabled */ |
1626 | data->pwmenable[1] = (w83781d_read_value(data, | 1576 | data->pwm2_enable = (w83781d_read_value(data, |
1627 | W83781D_REG_PWMCLK12) & 0x08) >> 3; | 1577 | W83781D_REG_PWMCLK12) & 0x08) >> 3; |
1628 | } | 1578 | } |
1629 | 1579 | ||