aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-03-27 11:58:46 -0400
committerGuenter Roeck <linux@roeck-us.net>2013-04-14 07:47:06 -0400
commitb4e665c78023ee4e4821f8e602e3b403c49ef70f (patch)
treed7e64e944803b06ecfe4784c9ba640f3d327e42c /drivers/hwmon
parent947e92719db4163da6985afcc9ed3cf4147adbd4 (diff)
hwmon: (tmp401) Use sysfs_create_group / sysfs_remove_group
instead of creating and removing sysfs attribute files individually. Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/tmp401.c154
1 files changed, 91 insertions, 63 deletions
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index 04cf0c63a2ea..f9c492e35fe4 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -465,38 +465,64 @@ static ssize_t reset_temp_history(struct device *dev,
465 return count; 465 return count;
466} 466}
467 467
468static struct sensor_device_attribute tmp401_attr[] = { 468static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0);
469 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0), 469static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
470 SENSOR_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, 470 store_temp_min, 0);
471 store_temp_min, 0), 471static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
472 SENSOR_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 472 store_temp_max, 0);
473 store_temp_max, 0), 473static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit,
474 SENSOR_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit, 474 store_temp_crit, 0);
475 store_temp_crit, 0), 475static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
476 SENSOR_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_crit_hyst, 476 show_temp_crit_hyst, store_temp_crit_hyst, 0);
477 store_temp_crit_hyst, 0), 477static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL,
478 SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, 478 TMP401_STATUS_LOCAL_LOW);
479 TMP401_STATUS_LOCAL_LOW), 479static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL,
480 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL, 480 TMP401_STATUS_LOCAL_HIGH);
481 TMP401_STATUS_LOCAL_HIGH), 481static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL,
482 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, 482 TMP401_STATUS_LOCAL_CRIT);
483 TMP401_STATUS_LOCAL_CRIT), 483static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1);
484 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1), 484static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
485 SENSOR_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, 485 store_temp_min, 1);
486 store_temp_min, 1), 486static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
487 SENSOR_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, 487 store_temp_max, 1);
488 store_temp_max, 1), 488static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit,
489 SENSOR_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit, 489 store_temp_crit, 1);
490 store_temp_crit, 1), 490static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst,
491 SENSOR_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, 1), 491 NULL, 1);
492 SENSOR_ATTR(temp2_fault, S_IRUGO, show_status, NULL, 492static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_status, NULL,
493 TMP401_STATUS_REMOTE_OPEN), 493 TMP401_STATUS_REMOTE_OPEN);
494 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL, 494static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL,
495 TMP401_STATUS_REMOTE_LOW), 495 TMP401_STATUS_REMOTE_LOW);
496 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL, 496static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL,
497 TMP401_STATUS_REMOTE_HIGH), 497 TMP401_STATUS_REMOTE_HIGH);
498 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL, 498static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL,
499 TMP401_STATUS_REMOTE_CRIT), 499 TMP401_STATUS_REMOTE_CRIT);
500
501static struct attribute *tmp401_attributes[] = {
502 &sensor_dev_attr_temp1_input.dev_attr.attr,
503 &sensor_dev_attr_temp1_min.dev_attr.attr,
504 &sensor_dev_attr_temp1_max.dev_attr.attr,
505 &sensor_dev_attr_temp1_crit.dev_attr.attr,
506 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
507 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
508 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
509 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
510
511 &sensor_dev_attr_temp2_input.dev_attr.attr,
512 &sensor_dev_attr_temp2_min.dev_attr.attr,
513 &sensor_dev_attr_temp2_max.dev_attr.attr,
514 &sensor_dev_attr_temp2_crit.dev_attr.attr,
515 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
516 &sensor_dev_attr_temp2_fault.dev_attr.attr,
517 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
518 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
519 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
520
521 NULL
522};
523
524static const struct attribute_group tmp401_group = {
525 .attrs = tmp401_attributes,
500}; 526};
501 527
502/* 528/*
@@ -506,12 +532,24 @@ static struct sensor_device_attribute tmp401_attr[] = {
506 * minimum and maximum register reset for both the local 532 * minimum and maximum register reset for both the local
507 * and remote channels. 533 * and remote channels.
508 */ 534 */
509static struct sensor_device_attribute tmp411_attr[] = { 535static SENSOR_DEVICE_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0);
510 SENSOR_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0), 536static SENSOR_DEVICE_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0);
511 SENSOR_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0), 537static SENSOR_DEVICE_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1);
512 SENSOR_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1), 538static SENSOR_DEVICE_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1);
513 SENSOR_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1), 539static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history,
514 SENSOR_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, 0), 540 0);
541
542static struct attribute *tmp411_attributes[] = {
543 &sensor_dev_attr_temp1_highest.dev_attr.attr,
544 &sensor_dev_attr_temp1_lowest.dev_attr.attr,
545 &sensor_dev_attr_temp2_highest.dev_attr.attr,
546 &sensor_dev_attr_temp2_lowest.dev_attr.attr,
547 &sensor_dev_attr_temp_reset_history.dev_attr.attr,
548 NULL
549};
550
551static const struct attribute_group tmp411_group = {
552 .attrs = tmp411_attributes,
515}; 553};
516 554
517/* 555/*
@@ -602,20 +640,16 @@ static int tmp401_detect(struct i2c_client *client,
602 640
603static int tmp401_remove(struct i2c_client *client) 641static int tmp401_remove(struct i2c_client *client)
604{ 642{
643 struct device *dev = &client->dev;
605 struct tmp401_data *data = i2c_get_clientdata(client); 644 struct tmp401_data *data = i2c_get_clientdata(client);
606 int i;
607 645
608 if (data->hwmon_dev) 646 if (data->hwmon_dev)
609 hwmon_device_unregister(data->hwmon_dev); 647 hwmon_device_unregister(data->hwmon_dev);
610 648
611 for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) 649 sysfs_remove_group(&dev->kobj, &tmp401_group);
612 device_remove_file(&client->dev, &tmp401_attr[i].dev_attr);
613 650
614 if (data->kind == tmp411) { 651 if (data->kind == tmp411)
615 for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) 652 sysfs_remove_group(&dev->kobj, &tmp411_group);
616 device_remove_file(&client->dev,
617 &tmp411_attr[i].dev_attr);
618 }
619 653
620 return 0; 654 return 0;
621} 655}
@@ -623,12 +657,12 @@ static int tmp401_remove(struct i2c_client *client)
623static int tmp401_probe(struct i2c_client *client, 657static int tmp401_probe(struct i2c_client *client,
624 const struct i2c_device_id *id) 658 const struct i2c_device_id *id)
625{ 659{
626 int i, err = 0; 660 struct device *dev = &client->dev;
661 int err;
627 struct tmp401_data *data; 662 struct tmp401_data *data;
628 const char *names[] = { "TMP401", "TMP411", "TMP431" }; 663 const char *names[] = { "TMP401", "TMP411", "TMP431" };
629 664
630 data = devm_kzalloc(&client->dev, sizeof(struct tmp401_data), 665 data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
631 GFP_KERNEL);
632 if (!data) 666 if (!data)
633 return -ENOMEM; 667 return -ENOMEM;
634 668
@@ -640,31 +674,25 @@ static int tmp401_probe(struct i2c_client *client,
640 tmp401_init_client(client); 674 tmp401_init_client(client);
641 675
642 /* Register sysfs hooks */ 676 /* Register sysfs hooks */
643 for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) { 677 err = sysfs_create_group(&dev->kobj, &tmp401_group);
644 err = device_create_file(&client->dev, 678 if (err)
645 &tmp401_attr[i].dev_attr); 679 return err;
646 if (err)
647 goto exit_remove;
648 }
649 680
650 /* Register additional tmp411 sysfs hooks */ 681 /* Register additional tmp411 sysfs hooks */
651 if (data->kind == tmp411) { 682 if (data->kind == tmp411) {
652 for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) { 683 err = sysfs_create_group(&dev->kobj, &tmp411_group);
653 err = device_create_file(&client->dev, 684 if (err)
654 &tmp411_attr[i].dev_attr); 685 goto exit_remove;
655 if (err)
656 goto exit_remove;
657 }
658 } 686 }
659 687
660 data->hwmon_dev = hwmon_device_register(&client->dev); 688 data->hwmon_dev = hwmon_device_register(dev);
661 if (IS_ERR(data->hwmon_dev)) { 689 if (IS_ERR(data->hwmon_dev)) {
662 err = PTR_ERR(data->hwmon_dev); 690 err = PTR_ERR(data->hwmon_dev);
663 data->hwmon_dev = NULL; 691 data->hwmon_dev = NULL;
664 goto exit_remove; 692 goto exit_remove;
665 } 693 }
666 694
667 dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]); 695 dev_info(dev, "Detected TI %s chip\n", names[data->kind]);
668 696
669 return 0; 697 return 0;
670 698