Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 227770
b: refs/heads/master
c: 0b0b5df
h: refs/heads/master
v: v3
  • Loading branch information
Henrik Rydberg authored and Guenter Roeck committed Jan 8, 2011
1 parent 8dbef86 commit df68feb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 94 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3eba2bf7c5fb7863412554cd73646cb80ac293ff
refs/heads/master: 0b0b5dff8967a4468f05174d0d74e1ed6e369776
169 changes: 76 additions & 93 deletions trunk/drivers/hwmon/applesmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,47 +992,27 @@ static struct led_classdev applesmc_backlight = {
.brightness_set = applesmc_brightness_set,
};

static DEVICE_ATTR(name, 0444, applesmc_name_show, NULL);

static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL);
static DEVICE_ATTR(calibrate, 0644,
applesmc_calibrate_show, applesmc_calibrate_store);

static struct attribute *accelerometer_attributes[] = {
&dev_attr_position.attr,
&dev_attr_calibrate.attr,
NULL
static struct applesmc_node_group info_group[] = {
{ "name", applesmc_name_show },
{ "key_count", applesmc_key_count_show },
{ "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store },
{ "key_at_index_name", applesmc_key_at_index_name_show },
{ "key_at_index_type", applesmc_key_at_index_type_show },
{ "key_at_index_data_length", applesmc_key_at_index_data_length_show },
{ "key_at_index_data", applesmc_key_at_index_read_show },
{ }
};

static const struct attribute_group accelerometer_attributes_group =
{ .attrs = accelerometer_attributes };

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 struct applesmc_node_group accelerometer_group[] = {
{ "position", applesmc_position_show },
{ "calibrate", applesmc_calibrate_show, applesmc_calibrate_store },
{ }
};

static const struct attribute_group key_enumeration_group =
{ .attrs = key_enumeration_attributes };
static struct applesmc_node_group light_sensor_group[] = {
{ "light", applesmc_light_show },
{ }
};

static struct applesmc_node_group fan_group[] = {
{ "fan%d_label", applesmc_show_fan_position },
Expand Down Expand Up @@ -1115,8 +1095,10 @@ static int applesmc_create_accelerometer(void)
struct input_dev *idev;
int ret;

ret = sysfs_create_group(&pdev->dev.kobj,
&accelerometer_attributes_group);
if (!smcreg.has_accelerometer)
return 0;

ret = applesmc_create_nodes(accelerometer_group, 1);
if (ret)
goto out;

Expand Down Expand Up @@ -1153,7 +1135,7 @@ static int applesmc_create_accelerometer(void)
input_free_polled_device(applesmc_idev);

out_sysfs:
sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group);
applesmc_destroy_nodes(accelerometer_group);

out:
pr_warn("driver init failed (ret=%d)!\n", ret);
Expand All @@ -1163,10 +1145,45 @@ static int applesmc_create_accelerometer(void)
/* Release all ressources used by the accelerometer */
static void applesmc_release_accelerometer(void)
{
if (!smcreg.has_accelerometer)
return;
input_unregister_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)
{
return 1;
Expand Down Expand Up @@ -1234,15 +1251,10 @@ static int __init applesmc_init(void)
if (ret)
goto out_device;

ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_name.attr);
ret = applesmc_create_nodes(info_group, 1);
if (ret)
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);
if (ret)
goto out_info;
Expand All @@ -1251,32 +1263,17 @@ static int __init applesmc_init(void)
if (ret)
goto out_fans;

if (smcreg.has_accelerometer) {
ret = applesmc_create_accelerometer();
if (ret)
goto out_temperature;
}

if (smcreg.num_light_sensors) {
/* Add light sensor file */
ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr);
if (ret)
goto out_accelerometer;
}
ret = applesmc_create_accelerometer();
if (ret)
goto out_temperature;

if (smcreg.has_key_backlight) {
/* Create the workqueue */
applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
if (!applesmc_led_wq) {
ret = -ENOMEM;
goto out_light_sysfs;
}
ret = applesmc_create_light_sensor();
if (ret)
goto out_accelerometer;

/* register as a led device */
ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
if (ret < 0)
goto out_light_wq;
}
ret = applesmc_create_key_backlight();
if (ret)
goto out_light_sysfs;

hwmon_dev = hwmon_device_register(&pdev->dev);
if (IS_ERR(hwmon_dev)) {
Expand All @@ -1289,25 +1286,17 @@ static int __init applesmc_init(void)
return 0;

out_light_ledclass:
if (smcreg.has_key_backlight)
led_classdev_unregister(&applesmc_backlight);
out_light_wq:
if (smcreg.has_key_backlight)
destroy_workqueue(applesmc_led_wq);
applesmc_release_key_backlight();
out_light_sysfs:
if (smcreg.num_light_sensors)
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
applesmc_release_light_sensor();
out_accelerometer:
if (smcreg.has_accelerometer)
applesmc_release_accelerometer();
applesmc_release_accelerometer();
out_temperature:
applesmc_destroy_nodes(temp_group);
out_fans:
applesmc_destroy_nodes(fan_group);
out_info:
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
out_name:
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
applesmc_destroy_nodes(info_group);
out_smcreg:
applesmc_destroy_smcreg();
out_device:
Expand All @@ -1324,18 +1313,12 @@ static int __init applesmc_init(void)
static void __exit applesmc_exit(void)
{
hwmon_device_unregister(hwmon_dev);
if (smcreg.has_key_backlight) {
led_classdev_unregister(&applesmc_backlight);
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_key_backlight();
applesmc_release_light_sensor();
applesmc_release_accelerometer();
applesmc_destroy_nodes(temp_group);
applesmc_destroy_nodes(fan_group);
sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
applesmc_destroy_nodes(info_group);
applesmc_destroy_smcreg();
platform_device_unregister(pdev);
platform_driver_unregister(&applesmc_driver);
Expand Down

0 comments on commit df68feb

Please sign in to comment.