aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/acpi_power_meter.c
diff options
context:
space:
mode:
authorKyle McMartin <kyle@mcmartin.ca>2012-04-02 14:19:00 -0400
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-05-20 22:41:48 -0400
commit81194cd24051eb3476f3ae853cc892e6d3a77bd7 (patch)
tree5afa22ddfdea4ce63c2251a25802c5ed74f5cfd1 /drivers/hwmon/acpi_power_meter.c
parentf71f5a550a43a81943efbe0032190ec381006b53 (diff)
acpi_power_meter: use the same struct {rw,ro}_sensor_template for both
We don't need both, when we can just key the read/write off of the presence of the .set member. Signed-off-by: Kyle McMartin <kyle@redhat.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/acpi_power_meter.c')
-rw-r--r--drivers/hwmon/acpi_power_meter.c153
1 files changed, 110 insertions, 43 deletions
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 9140236a0182..f9111561a30e 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -107,15 +107,7 @@ struct acpi_power_meter_resource {
107 struct kobject *holders_dir; 107 struct kobject *holders_dir;
108}; 108};
109 109
110struct ro_sensor_template { 110struct sensor_template {
111 char *label;
112 ssize_t (*show)(struct device *dev,
113 struct device_attribute *devattr,
114 char *buf);
115 int index;
116};
117
118struct rw_sensor_template {
119 char *label; 111 char *label;
120 ssize_t (*show)(struct device *dev, 112 ssize_t (*show)(struct device *dev,
121 struct device_attribute *devattr, 113 struct device_attribute *devattr,
@@ -470,50 +462,125 @@ static ssize_t show_name(struct device *dev,
470} 462}
471 463
472/* Sensor descriptions. If you add a sensor, update NUM_SENSORS above! */ 464/* Sensor descriptions. If you add a sensor, update NUM_SENSORS above! */
473static struct ro_sensor_template meter_ro_attrs[] = { 465static struct sensor_template meter_ro_attrs[] = {
474{POWER_AVERAGE_NAME, show_power, 0}, 466 {
475{"power1_accuracy", show_accuracy, 0}, 467 .label = POWER_AVERAGE_NAME,
476{"power1_average_interval_min", show_val, 0}, 468 .show = show_power,
477{"power1_average_interval_max", show_val, 1}, 469 .index = 0,
478{"power1_is_battery", show_val, 5}, 470 },
479{NULL, NULL, 0}, 471 {
472 .label = "power1_accuracy",
473 .show = show_accuracy,
474 .index = 0,
475 },
476 { .label = "power1_average_interval_min",
477 .show = show_val,
478 .index = 0
479 },
480 {
481 .label = "power1_average_interval_max",
482 .show = show_val,
483 .index = 1,
484 },
485 {
486 .label = "power1_is_battery",
487 .show = show_val,
488 .index = 5,
489 },
490 {},
480}; 491};
481 492
482static struct rw_sensor_template meter_rw_attrs[] = { 493static struct sensor_template meter_rw_attrs[] = {
483{POWER_AVG_INTERVAL_NAME, show_avg_interval, set_avg_interval, 0}, 494 {
484{NULL, NULL, NULL, 0}, 495 .label = POWER_AVG_INTERVAL_NAME,
496 .show = show_avg_interval,
497 .set = set_avg_interval,
498 .index = 0,
499 },
500 {},
485}; 501};
486 502
487static struct ro_sensor_template misc_cap_attrs[] = { 503static struct sensor_template misc_cap_attrs[] = {
488{"power1_cap_min", show_val, 2}, 504 {
489{"power1_cap_max", show_val, 3}, 505 .label = "power1_cap_min",
490{"power1_cap_hyst", show_val, 4}, 506 .show = show_val,
491{POWER_ALARM_NAME, show_val, 6}, 507 .index = 2,
492{NULL, NULL, 0}, 508 },
509 {
510 .label = "power1_cap_max",
511 .show = show_val,
512 .index = 3,
513 },
514 {
515 .label = "power1_cap_hyst",
516 .show = show_val,
517 .index = 4,
518 },
519 {
520 .label = POWER_ALARM_NAME,
521 .show = show_val,
522 .index = 6,
523 },
524 {},
493}; 525};
494 526
495static struct ro_sensor_template ro_cap_attrs[] = { 527static struct sensor_template ro_cap_attrs[] = {
496{POWER_CAP_NAME, show_cap, 0}, 528 {
497{NULL, NULL, 0}, 529 .label = POWER_CAP_NAME,
530 .show = show_cap,
531 .index = 0,
532 },
533 {},
498}; 534};
499 535
500static struct rw_sensor_template rw_cap_attrs[] = { 536static struct sensor_template rw_cap_attrs[] = {
501{POWER_CAP_NAME, show_cap, set_cap, 0}, 537 {
502{NULL, NULL, NULL, 0}, 538 .label = POWER_CAP_NAME,
539 .show = show_cap,
540 .set = set_cap,
541 .index = 0,
542 },
543 {},
503}; 544};
504 545
505static struct rw_sensor_template trip_attrs[] = { 546static struct sensor_template trip_attrs[] = {
506{"power1_average_min", show_val, set_trip, 7}, 547 {
507{"power1_average_max", show_val, set_trip, 8}, 548 .label = "power1_average_min",
508{NULL, NULL, NULL, 0}, 549 .show = show_val,
550 .set = set_trip,
551 .index = 7,
552 },
553 {
554 .label = "power1_average_max",
555 .show = show_val,
556 .set = set_trip,
557 .index = 8,
558 },
559 {},
509}; 560};
510 561
511static struct ro_sensor_template misc_attrs[] = { 562static struct sensor_template misc_attrs[] = {
512{"name", show_name, 0}, 563 {
513{"power1_model_number", show_str, 0}, 564 .label = "name",
514{"power1_oem_info", show_str, 2}, 565 .show = show_name,
515{"power1_serial_number", show_str, 1}, 566 .index = 0,
516{NULL, NULL, 0}, 567 },
568 {
569 .label = "power1_model_number",
570 .show = show_str,
571 .index = 0,
572 },
573 {
574 .label = "power1_oem_info",
575 .show = show_str,
576 .index = 2,
577 },
578 {
579 .label = "power1_serial_number",
580 .show = show_str,
581 .index = 1,
582 },
583 {},
517}; 584};
518 585
519/* Read power domain data */ 586/* Read power domain data */
@@ -620,7 +687,7 @@ end:
620 687
621/* Registration and deregistration */ 688/* Registration and deregistration */
622static int register_ro_attrs(struct acpi_power_meter_resource *resource, 689static int register_ro_attrs(struct acpi_power_meter_resource *resource,
623 struct ro_sensor_template *ro) 690 struct sensor_template *ro)
624{ 691{
625 struct device *dev = &resource->acpi_dev->dev; 692 struct device *dev = &resource->acpi_dev->dev;
626 struct sensor_device_attribute *sensors = 693 struct sensor_device_attribute *sensors =
@@ -649,7 +716,7 @@ error:
649} 716}
650 717
651static int register_rw_attrs(struct acpi_power_meter_resource *resource, 718static int register_rw_attrs(struct acpi_power_meter_resource *resource,
652 struct rw_sensor_template *rw) 719 struct sensor_template *rw)
653{ 720{
654 struct device *dev = &resource->acpi_dev->dev; 721 struct device *dev = &resource->acpi_dev->dev;
655 struct sensor_device_attribute *sensors = 722 struct sensor_device_attribute *sensors =