aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-06-09 10:11:16 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-07-19 14:22:13 -0400
commit1e71a5a2ce40425e3bf1bbce021a443ec8a24043 (patch)
tree2c4dc6f5699008907da652d9e6de2331b4b50718 /drivers/hwmon
parent2ec342e68453d9f3a1ac28ab80ffa8faacf58710 (diff)
hwmon/via686a: Use dynamic sysfs callbacks
This lets us get rid of macro-generated functions and shrinks the driver size by about 9%. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/via686a.c250
1 files changed, 111 insertions, 139 deletions
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 0ee9a278537a..24a6851491d0 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -36,6 +36,7 @@
36#include <linux/jiffies.h> 36#include <linux/jiffies.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/hwmon.h> 38#include <linux/hwmon.h>
39#include <linux/hwmon-sysfs.h>
39#include <linux/err.h> 40#include <linux/err.h>
40#include <linux/init.h> 41#include <linux/init.h>
41#include <linux/mutex.h> 42#include <linux/mutex.h>
@@ -332,24 +333,35 @@ static void via686a_init_device(struct via686a_data *data);
332/* following are the sysfs callback functions */ 333/* following are the sysfs callback functions */
333 334
334/* 7 voltage sensors */ 335/* 7 voltage sensors */
335static ssize_t show_in(struct device *dev, char *buf, int nr) { 336static ssize_t show_in(struct device *dev, struct device_attribute *da,
337 char *buf) {
336 struct via686a_data *data = via686a_update_device(dev); 338 struct via686a_data *data = via686a_update_device(dev);
339 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
340 int nr = attr->index;
337 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); 341 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr));
338} 342}
339 343
340static ssize_t show_in_min(struct device *dev, char *buf, int nr) { 344static ssize_t show_in_min(struct device *dev, struct device_attribute *da,
345 char *buf) {
341 struct via686a_data *data = via686a_update_device(dev); 346 struct via686a_data *data = via686a_update_device(dev);
347 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
348 int nr = attr->index;
342 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); 349 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr));
343} 350}
344 351
345static ssize_t show_in_max(struct device *dev, char *buf, int nr) { 352static ssize_t show_in_max(struct device *dev, struct device_attribute *da,
353 char *buf) {
346 struct via686a_data *data = via686a_update_device(dev); 354 struct via686a_data *data = via686a_update_device(dev);
355 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
356 int nr = attr->index;
347 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); 357 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr));
348} 358}
349 359
350static ssize_t set_in_min(struct device *dev, const char *buf, 360static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
351 size_t count, int nr) { 361 const char *buf, size_t count) {
352 struct via686a_data *data = dev_get_drvdata(dev); 362 struct via686a_data *data = dev_get_drvdata(dev);
363 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
364 int nr = attr->index;
353 unsigned long val = simple_strtoul(buf, NULL, 10); 365 unsigned long val = simple_strtoul(buf, NULL, 10);
354 366
355 mutex_lock(&data->update_lock); 367 mutex_lock(&data->update_lock);
@@ -359,9 +371,11 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
359 mutex_unlock(&data->update_lock); 371 mutex_unlock(&data->update_lock);
360 return count; 372 return count;
361} 373}
362static ssize_t set_in_max(struct device *dev, const char *buf, 374static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
363 size_t count, int nr) { 375 const char *buf, size_t count) {
364 struct via686a_data *data = dev_get_drvdata(dev); 376 struct via686a_data *data = dev_get_drvdata(dev);
377 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
378 int nr = attr->index;
365 unsigned long val = simple_strtoul(buf, NULL, 10); 379 unsigned long val = simple_strtoul(buf, NULL, 10);
366 380
367 mutex_lock(&data->update_lock); 381 mutex_lock(&data->update_lock);
@@ -372,36 +386,12 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
372 return count; 386 return count;
373} 387}
374#define show_in_offset(offset) \ 388#define show_in_offset(offset) \
375static ssize_t \ 389static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
376 show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 390 show_in, NULL, offset); \
377{ \ 391static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
378 return show_in(dev, buf, offset); \ 392 show_in_min, set_in_min, offset); \
379} \ 393static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
380static ssize_t \ 394 show_in_max, set_in_max, offset);
381 show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
382{ \
383 return show_in_min(dev, buf, offset); \
384} \
385static ssize_t \
386 show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
387{ \
388 return show_in_max(dev, buf, offset); \
389} \
390static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
391 const char *buf, size_t count) \
392{ \
393 return set_in_min(dev, buf, count, offset); \
394} \
395static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
396 const char *buf, size_t count) \
397{ \
398 return set_in_max(dev, buf, count, offset); \
399} \
400static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);\
401static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
402 show_in##offset##_min, set_in##offset##_min); \
403static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
404 show_in##offset##_max, set_in##offset##_max);
405 395
406show_in_offset(0); 396show_in_offset(0);
407show_in_offset(1); 397show_in_offset(1);
@@ -410,21 +400,32 @@ show_in_offset(3);
410show_in_offset(4); 400show_in_offset(4);
411 401
412/* 3 temperatures */ 402/* 3 temperatures */
413static ssize_t show_temp(struct device *dev, char *buf, int nr) { 403static ssize_t show_temp(struct device *dev, struct device_attribute *da,
404 char *buf) {
414 struct via686a_data *data = via686a_update_device(dev); 405 struct via686a_data *data = via686a_update_device(dev);
406 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
407 int nr = attr->index;
415 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); 408 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr]));
416} 409}
417static ssize_t show_temp_over(struct device *dev, char *buf, int nr) { 410static ssize_t show_temp_over(struct device *dev, struct device_attribute *da,
411 char *buf) {
418 struct via686a_data *data = via686a_update_device(dev); 412 struct via686a_data *data = via686a_update_device(dev);
413 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
414 int nr = attr->index;
419 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); 415 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr]));
420} 416}
421static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) { 417static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da,
418 char *buf) {
422 struct via686a_data *data = via686a_update_device(dev); 419 struct via686a_data *data = via686a_update_device(dev);
420 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
421 int nr = attr->index;
423 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); 422 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr]));
424} 423}
425static ssize_t set_temp_over(struct device *dev, const char *buf, 424static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
426 size_t count, int nr) { 425 const char *buf, size_t count) {
427 struct via686a_data *data = dev_get_drvdata(dev); 426 struct via686a_data *data = dev_get_drvdata(dev);
427 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
428 int nr = attr->index;
428 int val = simple_strtol(buf, NULL, 10); 429 int val = simple_strtol(buf, NULL, 10);
429 430
430 mutex_lock(&data->update_lock); 431 mutex_lock(&data->update_lock);
@@ -434,9 +435,11 @@ static ssize_t set_temp_over(struct device *dev, const char *buf,
434 mutex_unlock(&data->update_lock); 435 mutex_unlock(&data->update_lock);
435 return count; 436 return count;
436} 437}
437static ssize_t set_temp_hyst(struct device *dev, const char *buf, 438static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
438 size_t count, int nr) { 439 const char *buf, size_t count) {
439 struct via686a_data *data = dev_get_drvdata(dev); 440 struct via686a_data *data = dev_get_drvdata(dev);
441 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
442 int nr = attr->index;
440 int val = simple_strtol(buf, NULL, 10); 443 int val = simple_strtol(buf, NULL, 10);
441 444
442 mutex_lock(&data->update_lock); 445 mutex_lock(&data->update_lock);
@@ -447,58 +450,46 @@ static ssize_t set_temp_hyst(struct device *dev, const char *buf,
447 return count; 450 return count;
448} 451}
449#define show_temp_offset(offset) \ 452#define show_temp_offset(offset) \
450static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 453static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
451{ \ 454 show_temp, NULL, offset - 1); \
452 return show_temp(dev, buf, offset - 1); \ 455static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
453} \ 456 show_temp_over, set_temp_over, offset - 1); \
454static ssize_t \ 457static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
455show_temp_##offset##_over (struct device *dev, struct device_attribute *attr, char *buf) \ 458 show_temp_hyst, set_temp_hyst, offset - 1);
456{ \
457 return show_temp_over(dev, buf, offset - 1); \
458} \
459static ssize_t \
460show_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, char *buf) \
461{ \
462 return show_temp_hyst(dev, buf, offset - 1); \
463} \
464static ssize_t set_temp_##offset##_over (struct device *dev, struct device_attribute *attr, \
465 const char *buf, size_t count) \
466{ \
467 return set_temp_over(dev, buf, count, offset - 1); \
468} \
469static ssize_t set_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, \
470 const char *buf, size_t count) \
471{ \
472 return set_temp_hyst(dev, buf, count, offset - 1); \
473} \
474static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL);\
475static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
476 show_temp_##offset##_over, set_temp_##offset##_over); \
477static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
478 show_temp_##offset##_hyst, set_temp_##offset##_hyst);
479 459
480show_temp_offset(1); 460show_temp_offset(1);
481show_temp_offset(2); 461show_temp_offset(2);
482show_temp_offset(3); 462show_temp_offset(3);
483 463
484/* 2 Fans */ 464/* 2 Fans */
485static ssize_t show_fan(struct device *dev, char *buf, int nr) { 465static ssize_t show_fan(struct device *dev, struct device_attribute *da,
466 char *buf) {
486 struct via686a_data *data = via686a_update_device(dev); 467 struct via686a_data *data = via686a_update_device(dev);
468 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
469 int nr = attr->index;
487 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 470 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
488 DIV_FROM_REG(data->fan_div[nr])) ); 471 DIV_FROM_REG(data->fan_div[nr])) );
489} 472}
490static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { 473static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
474 char *buf) {
491 struct via686a_data *data = via686a_update_device(dev); 475 struct via686a_data *data = via686a_update_device(dev);
476 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
477 int nr = attr->index;
492 return sprintf(buf, "%d\n", 478 return sprintf(buf, "%d\n",
493 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); 479 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) );
494} 480}
495static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { 481static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
482 char *buf) {
496 struct via686a_data *data = via686a_update_device(dev); 483 struct via686a_data *data = via686a_update_device(dev);
484 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
485 int nr = attr->index;
497 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 486 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
498} 487}
499static ssize_t set_fan_min(struct device *dev, const char *buf, 488static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
500 size_t count, int nr) { 489 const char *buf, size_t count) {
501 struct via686a_data *data = dev_get_drvdata(dev); 490 struct via686a_data *data = dev_get_drvdata(dev);
491 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
492 int nr = attr->index;
502 int val = simple_strtol(buf, NULL, 10); 493 int val = simple_strtol(buf, NULL, 10);
503 494
504 mutex_lock(&data->update_lock); 495 mutex_lock(&data->update_lock);
@@ -507,9 +498,11 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
507 mutex_unlock(&data->update_lock); 498 mutex_unlock(&data->update_lock);
508 return count; 499 return count;
509} 500}
510static ssize_t set_fan_div(struct device *dev, const char *buf, 501static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
511 size_t count, int nr) { 502 const char *buf, size_t count) {
512 struct via686a_data *data = dev_get_drvdata(dev); 503 struct via686a_data *data = dev_get_drvdata(dev);
504 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
505 int nr = attr->index;
513 int val = simple_strtol(buf, NULL, 10); 506 int val = simple_strtol(buf, NULL, 10);
514 int old; 507 int old;
515 508
@@ -523,33 +516,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
523} 516}
524 517
525#define show_fan_offset(offset) \ 518#define show_fan_offset(offset) \
526static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 519static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
527{ \ 520 show_fan, NULL, offset - 1); \
528 return show_fan(dev, buf, offset - 1); \ 521static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
529} \ 522 show_fan_min, set_fan_min, offset - 1); \
530static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 523static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
531{ \ 524 show_fan_div, set_fan_div, offset - 1);
532 return show_fan_min(dev, buf, offset - 1); \
533} \
534static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
535{ \
536 return show_fan_div(dev, buf, offset - 1); \
537} \
538static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
539 const char *buf, size_t count) \
540{ \
541 return set_fan_min(dev, buf, count, offset - 1); \
542} \
543static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \
544 const char *buf, size_t count) \
545{ \
546 return set_fan_div(dev, buf, count, offset - 1); \
547} \
548static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
549static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
550 show_fan_##offset##_min, set_fan_##offset##_min); \
551static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
552 show_fan_##offset##_div, set_fan_##offset##_div);
553 525
554show_fan_offset(1); 526show_fan_offset(1);
555show_fan_offset(2); 527show_fan_offset(2);
@@ -570,38 +542,38 @@ static ssize_t show_name(struct device *dev, struct device_attribute
570static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 542static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
571 543
572static struct attribute *via686a_attributes[] = { 544static struct attribute *via686a_attributes[] = {
573 &dev_attr_in0_input.attr, 545 &sensor_dev_attr_in0_input.dev_attr.attr,
574 &dev_attr_in1_input.attr, 546 &sensor_dev_attr_in1_input.dev_attr.attr,
575 &dev_attr_in2_input.attr, 547 &sensor_dev_attr_in2_input.dev_attr.attr,
576 &dev_attr_in3_input.attr, 548 &sensor_dev_attr_in3_input.dev_attr.attr,
577 &dev_attr_in4_input.attr, 549 &sensor_dev_attr_in4_input.dev_attr.attr,
578 &dev_attr_in0_min.attr, 550 &sensor_dev_attr_in0_min.dev_attr.attr,
579 &dev_attr_in1_min.attr, 551 &sensor_dev_attr_in1_min.dev_attr.attr,
580 &dev_attr_in2_min.attr, 552 &sensor_dev_attr_in2_min.dev_attr.attr,
581 &dev_attr_in3_min.attr, 553 &sensor_dev_attr_in3_min.dev_attr.attr,
582 &dev_attr_in4_min.attr, 554 &sensor_dev_attr_in4_min.dev_attr.attr,
583 &dev_attr_in0_max.attr, 555 &sensor_dev_attr_in0_max.dev_attr.attr,
584 &dev_attr_in1_max.attr, 556 &sensor_dev_attr_in1_max.dev_attr.attr,
585 &dev_attr_in2_max.attr, 557 &sensor_dev_attr_in2_max.dev_attr.attr,
586 &dev_attr_in3_max.attr, 558 &sensor_dev_attr_in3_max.dev_attr.attr,
587 &dev_attr_in4_max.attr, 559 &sensor_dev_attr_in4_max.dev_attr.attr,
588 560
589 &dev_attr_temp1_input.attr, 561 &sensor_dev_attr_temp1_input.dev_attr.attr,
590 &dev_attr_temp2_input.attr, 562 &sensor_dev_attr_temp2_input.dev_attr.attr,
591 &dev_attr_temp3_input.attr, 563 &sensor_dev_attr_temp3_input.dev_attr.attr,
592 &dev_attr_temp1_max.attr, 564 &sensor_dev_attr_temp1_max.dev_attr.attr,
593 &dev_attr_temp2_max.attr, 565 &sensor_dev_attr_temp2_max.dev_attr.attr,
594 &dev_attr_temp3_max.attr, 566 &sensor_dev_attr_temp3_max.dev_attr.attr,
595 &dev_attr_temp1_max_hyst.attr, 567 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
596 &dev_attr_temp2_max_hyst.attr, 568 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
597 &dev_attr_temp3_max_hyst.attr, 569 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
598 570
599 &dev_attr_fan1_input.attr, 571 &sensor_dev_attr_fan1_input.dev_attr.attr,
600 &dev_attr_fan2_input.attr, 572 &sensor_dev_attr_fan2_input.dev_attr.attr,
601 &dev_attr_fan1_min.attr, 573 &sensor_dev_attr_fan1_min.dev_attr.attr,
602 &dev_attr_fan2_min.attr, 574 &sensor_dev_attr_fan2_min.dev_attr.attr,
603 &dev_attr_fan1_div.attr, 575 &sensor_dev_attr_fan1_div.dev_attr.attr,
604 &dev_attr_fan2_div.attr, 576 &sensor_dev_attr_fan2_div.dev_attr.attr,
605 577
606 &dev_attr_alarms.attr, 578 &dev_attr_alarms.attr,
607 &dev_attr_name.attr, 579 &dev_attr_name.attr,