hp_accel: do not call ACPI from invalid context
The LED on HP notebooks is connected through ACPI. That unfortunately means that it needs to be delayed by using schedule_work() to avoid calling the ACPI interpreter from an invalid context. [akpm@linux-foundation.org: use flush_work() rather than sort-of reimplementing it] Signed-off-by: Pavel Machek <pavel@suse.cz> Cc: Éric Piel <eric.piel@tremplin-utc.net> Cc: Len Brown <lenb@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
219beb291b
Коммит
9e1c9d8655
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2008 Yan Burman
|
* Copyright (C) 2007-2008 Yan Burman
|
||||||
* Copyright (C) 2008 Eric Piel
|
* Copyright (C) 2008 Eric Piel
|
||||||
* Copyright (C) 2008 Pavel Machek
|
* Copyright (C) 2008-2009 Pavel Machek
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -44,6 +44,36 @@
|
||||||
#define DRIVER_NAME "lis3lv02d"
|
#define DRIVER_NAME "lis3lv02d"
|
||||||
#define ACPI_MDPS_CLASS "accelerometer"
|
#define ACPI_MDPS_CLASS "accelerometer"
|
||||||
|
|
||||||
|
/* Delayed LEDs infrastructure ------------------------------------ */
|
||||||
|
|
||||||
|
/* Special LED class that can defer work */
|
||||||
|
struct delayed_led_classdev {
|
||||||
|
struct led_classdev led_classdev;
|
||||||
|
struct work_struct work;
|
||||||
|
enum led_brightness new_brightness;
|
||||||
|
|
||||||
|
unsigned int led; /* For driver */
|
||||||
|
void (*set_brightness)(struct delayed_led_classdev *data, enum led_brightness value);
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void delayed_set_status_worker(struct work_struct *work)
|
||||||
|
{
|
||||||
|
struct delayed_led_classdev *data =
|
||||||
|
container_of(work, struct delayed_led_classdev, work);
|
||||||
|
|
||||||
|
data->set_brightness(data, data->new_brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void delayed_sysfs_set(struct led_classdev *led_cdev,
|
||||||
|
enum led_brightness brightness)
|
||||||
|
{
|
||||||
|
struct delayed_led_classdev *data = container_of(led_cdev,
|
||||||
|
struct delayed_led_classdev, led_classdev);
|
||||||
|
data->new_brightness = brightness;
|
||||||
|
schedule_work(&data->work);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* HP-specific accelerometer driver ------------------------------------ */
|
||||||
|
|
||||||
/* For automatic insertion of the module */
|
/* For automatic insertion of the module */
|
||||||
static struct acpi_device_id lis3lv02d_device_ids[] = {
|
static struct acpi_device_id lis3lv02d_device_ids[] = {
|
||||||
|
@ -155,28 +185,27 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
static acpi_status hpled_acpi_write(acpi_handle handle, int reg)
|
static void hpled_set(struct delayed_led_classdev *led_cdev, enum led_brightness value)
|
||||||
{
|
{
|
||||||
|
acpi_handle handle = adev.device->handle;
|
||||||
unsigned long long ret; /* Not used when writing */
|
unsigned long long ret; /* Not used when writing */
|
||||||
union acpi_object in_obj[1];
|
union acpi_object in_obj[1];
|
||||||
struct acpi_object_list args = { 1, in_obj };
|
struct acpi_object_list args = { 1, in_obj };
|
||||||
|
|
||||||
in_obj[0].type = ACPI_TYPE_INTEGER;
|
in_obj[0].type = ACPI_TYPE_INTEGER;
|
||||||
in_obj[0].integer.value = reg;
|
in_obj[0].integer.value = !!value;
|
||||||
|
|
||||||
return acpi_evaluate_integer(handle, "ALED", &args, &ret);
|
acpi_evaluate_integer(handle, "ALED", &args, &ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hpled_set(struct led_classdev *led_cdev,
|
static struct delayed_led_classdev hpled_led = {
|
||||||
enum led_brightness value)
|
.led_classdev = {
|
||||||
{
|
.name = "hp::hddprotect",
|
||||||
hpled_acpi_write(adev.device->handle, !!value);
|
.default_trigger = "none",
|
||||||
}
|
.brightness_set = delayed_sysfs_set,
|
||||||
|
.flags = LED_CORE_SUSPENDRESUME,
|
||||||
static struct led_classdev hpled_led = {
|
},
|
||||||
.name = "hp:red:hddprotection",
|
.set_brightness = hpled_set,
|
||||||
.default_trigger = "none",
|
|
||||||
.brightness_set = hpled_set,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int lis3lv02d_add(struct acpi_device *device)
|
static int lis3lv02d_add(struct acpi_device *device)
|
||||||
|
@ -208,13 +237,15 @@ static int lis3lv02d_add(struct acpi_device *device)
|
||||||
adev.ac = lis3lv02d_axis_normal;
|
adev.ac = lis3lv02d_axis_normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = led_classdev_register(NULL, &hpled_led);
|
INIT_WORK(&hpled_led.work, delayed_set_status_worker);
|
||||||
|
ret = led_classdev_register(NULL, &hpled_led.led_classdev);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = lis3lv02d_init_device(&adev);
|
ret = lis3lv02d_init_device(&adev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
led_classdev_unregister(&hpled_led);
|
flush_work(&hpled_led.work);
|
||||||
|
led_classdev_unregister(&hpled_led.led_classdev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +260,8 @@ static int lis3lv02d_remove(struct acpi_device *device, int type)
|
||||||
lis3lv02d_joystick_disable();
|
lis3lv02d_joystick_disable();
|
||||||
lis3lv02d_poweroff(device->handle);
|
lis3lv02d_poweroff(device->handle);
|
||||||
|
|
||||||
led_classdev_unregister(&hpled_led);
|
flush_work(&hpled_led.work);
|
||||||
|
led_classdev_unregister(&hpled_led.led_classdev);
|
||||||
|
|
||||||
return lis3lv02d_remove_fs();
|
return lis3lv02d_remove_fs();
|
||||||
}
|
}
|
||||||
|
@ -240,7 +272,6 @@ static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state)
|
||||||
{
|
{
|
||||||
/* make sure the device is off when we suspend */
|
/* make sure the device is off when we suspend */
|
||||||
lis3lv02d_poweroff(device->handle);
|
lis3lv02d_poweroff(device->handle);
|
||||||
led_classdev_suspend(&hpled_led);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +284,6 @@ static int lis3lv02d_resume(struct acpi_device *device)
|
||||||
else
|
else
|
||||||
lis3lv02d_poweroff(device->handle);
|
lis3lv02d_poweroff(device->handle);
|
||||||
mutex_unlock(&adev.lock);
|
mutex_unlock(&adev.lock);
|
||||||
led_classdev_resume(&hpled_led);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Загрузка…
Ссылка в новой задаче