Commit 0b0b5dff authored by Henrik Rydberg's avatar Henrik Rydberg Committed by Guenter Roeck

hwmon: (applesmc) Simplify feature sysfs handling

Given the dynamic node construction method, the setup of the
accelerometer, light sensor and keyboard backlight sysfs nodes
can be simplified. This patch does not contain any logic changes.
Signed-off-by: default avatarHenrik Rydberg <rydberg@euromail.se>
Signed-off-by: default avatarGuenter Roeck <guenter.roeck@ericsson.com>
parent 3eba2bf7
...@@ -992,47 +992,27 @@ static struct led_classdev applesmc_backlight = { ...@@ -992,47 +992,27 @@ static struct led_classdev applesmc_backlight = {
.brightness_set = applesmc_brightness_set, .brightness_set = applesmc_brightness_set,
}; };
static DEVICE_ATTR(name, 0444, applesmc_name_show, NULL); static struct applesmc_node_group info_group[] = {
{ "name", applesmc_name_show },
static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL); { "key_count", applesmc_key_count_show },
static DEVICE_ATTR(calibrate, 0644, { "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store },
applesmc_calibrate_show, applesmc_calibrate_store); { "key_at_index_name", applesmc_key_at_index_name_show },
{ "key_at_index_type", applesmc_key_at_index_type_show },
static struct attribute *accelerometer_attributes[] = { { "key_at_index_data_length", applesmc_key_at_index_data_length_show },
&dev_attr_position.attr, { "key_at_index_data", applesmc_key_at_index_read_show },
&dev_attr_calibrate.attr, { }
NULL
}; };
static const struct attribute_group accelerometer_attributes_group = static struct applesmc_node_group accelerometer_group[] = {
{ .attrs = accelerometer_attributes }; { "position", applesmc_position_show },
{ "calibrate", applesmc_calibrate_show, applesmc_calibrate_store },
static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL); { }
static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL);
static DEVICE_ATTR(key_at_index, 0644,
applesmc_key_at_index_show, applesmc_key_at_index_store);
static DEVICE_ATTR(key_at_index_name, 0444,
applesmc_key_at_index_name_show, NULL);
static DEVICE_ATTR(key_at_index_type, 0444,
applesmc_key_at_index_type_show, NULL);
static DEVICE_ATTR(key_at_index_data_length, 0444,
applesmc_key_at_index_data_length_show, NULL);
static DEVICE_ATTR(key_at_index_data, 0444,
applesmc_key_at_index_read_show, NULL);
static struct attribute *key_enumeration_attributes[] = {
&dev_attr_key_count.attr,
&dev_attr_key_at_index.attr,
&dev_attr_key_at_index_name.attr,
&dev_attr_key_at_index_type.attr,
&dev_attr_key_at_index_data_length.attr,
&dev_attr_key_at_index_data.attr,
NULL
}; };
static const struct attribute_group key_enumeration_group = static struct applesmc_node_group light_sensor_group[] = {
{ .attrs = key_enumeration_attributes }; { "light", applesmc_light_show },
{ }
};
static struct applesmc_node_group fan_group[] = { static struct applesmc_node_group fan_group[] = {
{ "fan%d_label", applesmc_show_fan_position }, { "fan%d_label", applesmc_show_fan_position },
...@@ -1115,8 +1095,10 @@ static int applesmc_create_accelerometer(void) ...@@ -1115,8 +1095,10 @@ static int applesmc_create_accelerometer(void)
struct input_dev *idev; struct input_dev *idev;
int ret; int ret;
ret = sysfs_create_group(&pdev->dev.kobj, if (!smcreg.has_accelerometer)
&accelerometer_attributes_group); return 0;
ret = applesmc_create_nodes(accelerometer_group, 1);
if (ret) if (ret)
goto out; goto out;
...@@ -1153,7 +1135,7 @@ static int applesmc_create_accelerometer(void) ...@@ -1153,7 +1135,7 @@ static int applesmc_create_accelerometer(void)
input_free_polled_device(applesmc_idev); input_free_polled_device(applesmc_idev);
out_sysfs: out_sysfs:
sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); applesmc_destroy_nodes(accelerometer_group);
out: out:
pr_warn("driver init failed (ret=%d)!\n", ret); pr_warn("driver init failed (ret=%d)!\n", ret);
...@@ -1163,10 +1145,45 @@ static int applesmc_create_accelerometer(void) ...@@ -1163,10 +1145,45 @@ static int applesmc_create_accelerometer(void)
/* Release all ressources used by the accelerometer */ /* Release all ressources used by the accelerometer */
static void applesmc_release_accelerometer(void) static void applesmc_release_accelerometer(void)
{ {
if (!smcreg.has_accelerometer)
return;
input_unregister_polled_device(applesmc_idev); input_unregister_polled_device(applesmc_idev);
input_free_polled_device(applesmc_idev); input_free_polled_device(applesmc_idev);
sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); applesmc_destroy_nodes(accelerometer_group);
}
static int applesmc_create_light_sensor(void)
{
if (!smcreg.num_light_sensors)
return 0;
return applesmc_create_nodes(light_sensor_group, 1);
}
static void applesmc_release_light_sensor(void)
{
if (!smcreg.num_light_sensors)
return;
applesmc_destroy_nodes(light_sensor_group);
}
static int applesmc_create_key_backlight(void)
{
if (!smcreg.has_key_backlight)
return 0;
applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
if (!applesmc_led_wq)
return -ENOMEM;
return led_classdev_register(&pdev->dev, &applesmc_backlight);
} }
static void applesmc_release_key_backlight(void)
{
if (!smcreg.has_key_backlight)
return;
led_classdev_unregister(&applesmc_backlight);
destroy_workqueue(applesmc_led_wq);
}
static int applesmc_dmi_match(const struct dmi_system_id *id) static int applesmc_dmi_match(const struct dmi_system_id *id)
{ {
return 1; return 1;
...@@ -1234,15 +1251,10 @@ static int __init applesmc_init(void) ...@@ -1234,15 +1251,10 @@ static int __init applesmc_init(void)
if (ret) if (ret)
goto out_device; goto out_device;
ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_name.attr); ret = applesmc_create_nodes(info_group, 1);
if (ret) if (ret)
goto out_smcreg; goto out_smcreg;
/* Create key enumeration sysfs files */
ret = sysfs_create_group(&pdev->dev.kobj, &key_enumeration_group);
if (ret)
goto out_name;
ret = applesmc_create_nodes(fan_group, smcreg.fan_count); ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
if (ret) if (ret)
goto out_info; goto out_info;
...@@ -1251,32 +1263,17 @@ static int __init applesmc_init(void) ...@@ -1251,32 +1263,17 @@ static int __init applesmc_init(void)
if (ret) if (ret)
goto out_fans; goto out_fans;
if (smcreg.has_accelerometer) {
ret = applesmc_create_accelerometer(); ret = applesmc_create_accelerometer();
if (ret) if (ret)
goto out_temperature; goto out_temperature;
}
if (smcreg.num_light_sensors) { ret = applesmc_create_light_sensor();
/* Add light sensor file */
ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr);
if (ret) if (ret)
goto out_accelerometer; goto out_accelerometer;
}
if (smcreg.has_key_backlight) { ret = applesmc_create_key_backlight();
/* Create the workqueue */ if (ret)
applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
if (!applesmc_led_wq) {
ret = -ENOMEM;
goto out_light_sysfs; goto out_light_sysfs;
}
/* register as a led device */
ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
if (ret < 0)
goto out_light_wq;
}
hwmon_dev = hwmon_device_register(&pdev->dev); hwmon_dev = hwmon_device_register(&pdev->dev);
if (IS_ERR(hwmon_dev)) { if (IS_ERR(hwmon_dev)) {
...@@ -1289,25 +1286,17 @@ static int __init applesmc_init(void) ...@@ -1289,25 +1286,17 @@ static int __init applesmc_init(void)
return 0; return 0;
out_light_ledclass: out_light_ledclass:
if (smcreg.has_key_backlight) applesmc_release_key_backlight();
led_classdev_unregister(&applesmc_backlight);
out_light_wq:
if (smcreg.has_key_backlight)
destroy_workqueue(applesmc_led_wq);
out_light_sysfs: out_light_sysfs:
if (smcreg.num_light_sensors) applesmc_release_light_sensor();
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
out_accelerometer: out_accelerometer:
if (smcreg.has_accelerometer)
applesmc_release_accelerometer(); applesmc_release_accelerometer();
out_temperature: out_temperature:
applesmc_destroy_nodes(temp_group); applesmc_destroy_nodes(temp_group);
out_fans: out_fans:
applesmc_destroy_nodes(fan_group); applesmc_destroy_nodes(fan_group);
out_info: out_info:
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); applesmc_destroy_nodes(info_group);
out_name:
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
out_smcreg: out_smcreg:
applesmc_destroy_smcreg(); applesmc_destroy_smcreg();
out_device: out_device:
...@@ -1324,18 +1313,12 @@ static int __init applesmc_init(void) ...@@ -1324,18 +1313,12 @@ static int __init applesmc_init(void)
static void __exit applesmc_exit(void) static void __exit applesmc_exit(void)
{ {
hwmon_device_unregister(hwmon_dev); hwmon_device_unregister(hwmon_dev);
if (smcreg.has_key_backlight) { applesmc_release_key_backlight();
led_classdev_unregister(&applesmc_backlight); applesmc_release_light_sensor();
destroy_workqueue(applesmc_led_wq);
}
if (smcreg.num_light_sensors)
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
if (smcreg.has_accelerometer)
applesmc_release_accelerometer(); applesmc_release_accelerometer();
applesmc_destroy_nodes(temp_group); applesmc_destroy_nodes(temp_group);
applesmc_destroy_nodes(fan_group); applesmc_destroy_nodes(fan_group);
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); applesmc_destroy_nodes(info_group);
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
applesmc_destroy_smcreg(); applesmc_destroy_smcreg();
platform_device_unregister(pdev); platform_device_unregister(pdev);
platform_driver_unregister(&applesmc_driver); platform_driver_unregister(&applesmc_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment