aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-11-23 14:03:20 -0500
committerMatthew Garrett <matthew.garrett@nebula.com>2014-01-21 08:44:03 -0500
commitc2be45f09bb0b37ba1f87f39fbb04886f94e3e58 (patch)
tree6c44da69f215597a10784612c9d057a312633b4d
parent4e062581cc95cc0a12f8e48778a0d3ebb48fa980 (diff)
compal-laptop: Use devm_hwmon_device_register_with_groups
Simplify the code and create hwmon attributes as well as hwmon device in one go. With the new hwmon API, hwmon attributes are now attached to the hwmon device. Therefore, split hwmon and device attributes into two separate groups. Platform attributes are still attached to the platform device. Also use devm_kzalloc to allocate local data structures for further simplification. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
-rw-r--r--drivers/platform/x86/compal-laptop.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 9deb0350b8e6..7297df2ebf50 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -173,8 +173,7 @@
173/* ======= */ 173/* ======= */
174struct compal_data{ 174struct compal_data{
175 /* Fan control */ 175 /* Fan control */
176 struct device *hwmon_dev; 176 int pwm_enable; /* 0:full on, 1:set by pwm1, 2:control by motherboard */
177 int pwm_enable; /* 0:full on, 1:set by pwm1, 2:control by moterboard */
178 unsigned char curr_pwm; 177 unsigned char curr_pwm;
179 178
180 /* Power supply */ 179 /* Power supply */
@@ -402,15 +401,6 @@ SIMPLE_MASKED_STORE_SHOW(wake_up_wlan, WAKE_UP_ADDR, WAKE_UP_WLAN)
402SIMPLE_MASKED_STORE_SHOW(wake_up_key, WAKE_UP_ADDR, WAKE_UP_KEY) 401SIMPLE_MASKED_STORE_SHOW(wake_up_key, WAKE_UP_ADDR, WAKE_UP_KEY)
403SIMPLE_MASKED_STORE_SHOW(wake_up_mouse, WAKE_UP_ADDR, WAKE_UP_MOUSE) 402SIMPLE_MASKED_STORE_SHOW(wake_up_mouse, WAKE_UP_ADDR, WAKE_UP_MOUSE)
404 403
405
406/* General hwmon interface */
407static ssize_t hwmon_name_show(struct device *dev,
408 struct device_attribute *attr, char *buf)
409{
410 return sprintf(buf, "%s\n", DRIVER_NAME);
411}
412
413
414/* Fan control interface */ 404/* Fan control interface */
415static ssize_t pwm_enable_show(struct device *dev, 405static ssize_t pwm_enable_show(struct device *dev,
416 struct device_attribute *attr, char *buf) 406 struct device_attribute *attr, char *buf)
@@ -665,7 +655,6 @@ static DEVICE_ATTR(wake_up_key,
665static DEVICE_ATTR(wake_up_mouse, 655static DEVICE_ATTR(wake_up_mouse,
666 0644, wake_up_mouse_show, wake_up_mouse_store); 656 0644, wake_up_mouse_show, wake_up_mouse_store);
667 657
668static DEVICE_ATTR(name, S_IRUGO, hwmon_name_show, NULL);
669static DEVICE_ATTR(fan1_input, S_IRUGO, fan_show, NULL); 658static DEVICE_ATTR(fan1_input, S_IRUGO, fan_show, NULL);
670static DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu, NULL); 659static DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu, NULL);
671static DEVICE_ATTR(temp2_input, S_IRUGO, temp_cpu_local, NULL); 660static DEVICE_ATTR(temp2_input, S_IRUGO, temp_cpu_local, NULL);
@@ -683,16 +672,20 @@ static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, pwm_show, pwm_store);
683static DEVICE_ATTR(pwm1_enable, 672static DEVICE_ATTR(pwm1_enable,
684 S_IRUGO | S_IWUSR, pwm_enable_show, pwm_enable_store); 673 S_IRUGO | S_IWUSR, pwm_enable_show, pwm_enable_store);
685 674
686static struct attribute *compal_attributes[] = { 675static struct attribute *compal_platform_attrs[] = {
687 &dev_attr_wake_up_pme.attr, 676 &dev_attr_wake_up_pme.attr,
688 &dev_attr_wake_up_modem.attr, 677 &dev_attr_wake_up_modem.attr,
689 &dev_attr_wake_up_lan.attr, 678 &dev_attr_wake_up_lan.attr,
690 &dev_attr_wake_up_wlan.attr, 679 &dev_attr_wake_up_wlan.attr,
691 &dev_attr_wake_up_key.attr, 680 &dev_attr_wake_up_key.attr,
692 &dev_attr_wake_up_mouse.attr, 681 &dev_attr_wake_up_mouse.attr,
693 /* Maybe put the sensor-stuff in a separate hwmon-driver? That way, 682 NULL
694 * the hwmon sysfs won't be cluttered with the above files. */ 683};
695 &dev_attr_name.attr, 684static struct attribute_group compal_platform_attr_group = {
685 .attrs = compal_platform_attrs
686};
687
688static struct attribute *compal_hwmon_attrs[] = {
696 &dev_attr_pwm1_enable.attr, 689 &dev_attr_pwm1_enable.attr,
697 &dev_attr_pwm1.attr, 690 &dev_attr_pwm1.attr,
698 &dev_attr_fan1_input.attr, 691 &dev_attr_fan1_input.attr,
@@ -710,10 +703,7 @@ static struct attribute *compal_attributes[] = {
710 &dev_attr_temp6_label.attr, 703 &dev_attr_temp6_label.attr,
711 NULL 704 NULL
712}; 705};
713 706ATTRIBUTE_GROUPS(compal_hwmon);
714static struct attribute_group compal_attribute_group = {
715 .attrs = compal_attributes
716};
717 707
718static int compal_probe(struct platform_device *); 708static int compal_probe(struct platform_device *);
719static int compal_remove(struct platform_device *); 709static int compal_remove(struct platform_device *);
@@ -1021,6 +1011,7 @@ static int compal_probe(struct platform_device *pdev)
1021{ 1011{
1022 int err; 1012 int err;
1023 struct compal_data *data; 1013 struct compal_data *data;
1014 struct device *hwmon_dev;
1024 1015
1025 if (!extra_features) 1016 if (!extra_features)
1026 return 0; 1017 return 0;
@@ -1032,16 +1023,16 @@ static int compal_probe(struct platform_device *pdev)
1032 1023
1033 initialize_fan_control_data(data); 1024 initialize_fan_control_data(data);
1034 1025
1035 err = sysfs_create_group(&pdev->dev.kobj, &compal_attribute_group); 1026 err = sysfs_create_group(&pdev->dev.kobj, &compal_platform_attr_group);
1036 if (err) 1027 if (err)
1037 return err; 1028 return err;
1038 1029
1039 data->hwmon_dev = hwmon_device_register(&pdev->dev); 1030 hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
1040 if (IS_ERR(data->hwmon_dev)) { 1031 DRIVER_NAME, data,
1041 err = PTR_ERR(data->hwmon_dev); 1032 compal_hwmon_groups);
1042 sysfs_remove_group(&pdev->dev.kobj, 1033 if (IS_ERR(hwmon_dev)) {
1043 &compal_attribute_group); 1034 err = PTR_ERR(hwmon_dev);
1044 return err; 1035 goto remove;
1045 } 1036 }
1046 1037
1047 /* Power supply */ 1038 /* Power supply */
@@ -1051,6 +1042,10 @@ static int compal_probe(struct platform_device *pdev)
1051 platform_set_drvdata(pdev, data); 1042 platform_set_drvdata(pdev, data);
1052 1043
1053 return 0; 1044 return 0;
1045
1046remove:
1047 sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);
1048 return err;
1054} 1049}
1055 1050
1056static void __exit compal_cleanup(void) 1051static void __exit compal_cleanup(void)
@@ -1077,10 +1072,9 @@ static int compal_remove(struct platform_device *pdev)
1077 pwm_disable_control(); 1072 pwm_disable_control();
1078 1073
1079 data = platform_get_drvdata(pdev); 1074 data = platform_get_drvdata(pdev);
1080 hwmon_device_unregister(data->hwmon_dev);
1081 power_supply_unregister(&data->psy); 1075 power_supply_unregister(&data->psy);
1082 1076
1083 sysfs_remove_group(&pdev->dev.kobj, &compal_attribute_group); 1077 sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);
1084 1078
1085 return 0; 1079 return 0;
1086} 1080}