ACPI / button: Refactor functions to eliminate redundant code
(Correct a wrong macro usage.) This patch simplies the code by merging some redundant code. No functional changes. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
c2dd420034
commit
ee7e22653f
@@ -113,16 +113,52 @@ static struct acpi_device *lid_device;
|
|||||||
static struct proc_dir_entry *acpi_button_dir;
|
static struct proc_dir_entry *acpi_button_dir;
|
||||||
static struct proc_dir_entry *acpi_lid_dir;
|
static struct proc_dir_entry *acpi_lid_dir;
|
||||||
|
|
||||||
|
static int acpi_lid_evaluate_state(struct acpi_device *device)
|
||||||
|
{
|
||||||
|
unsigned long long lid_state;
|
||||||
|
acpi_status status;
|
||||||
|
|
||||||
|
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &lid_state);
|
||||||
|
if (ACPI_FAILURE(status))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return lid_state ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int acpi_lid_notify_state(struct acpi_device *device, int state)
|
||||||
|
{
|
||||||
|
struct acpi_button *button = acpi_driver_data(device);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* input layer checks if event is redundant */
|
||||||
|
input_report_switch(button->input, SW_LID, !state);
|
||||||
|
input_sync(button->input);
|
||||||
|
|
||||||
|
if (state)
|
||||||
|
pm_wakeup_event(&device->dev, 0);
|
||||||
|
|
||||||
|
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
|
||||||
|
if (ret == NOTIFY_DONE)
|
||||||
|
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
|
||||||
|
device);
|
||||||
|
if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
|
||||||
|
/*
|
||||||
|
* It is also regarded as success if the notifier_chain
|
||||||
|
* returns NOTIFY_OK or NOTIFY_DONE.
|
||||||
|
*/
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
|
static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
|
||||||
{
|
{
|
||||||
struct acpi_device *device = seq->private;
|
struct acpi_device *device = seq->private;
|
||||||
acpi_status status;
|
int state;
|
||||||
unsigned long long state;
|
|
||||||
|
|
||||||
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
|
state = acpi_lid_evaluate_state(device);
|
||||||
seq_printf(seq, "state: %s\n",
|
seq_printf(seq, "state: %s\n",
|
||||||
ACPI_FAILURE(status) ? "unsupported" :
|
state < 0 ? "unsupported" : (state ? "open" : "closed"));
|
||||||
(state ? "open" : "closed"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,51 +267,22 @@ EXPORT_SYMBOL(acpi_lid_notifier_unregister);
|
|||||||
|
|
||||||
int acpi_lid_open(void)
|
int acpi_lid_open(void)
|
||||||
{
|
{
|
||||||
acpi_status status;
|
|
||||||
unsigned long long state;
|
|
||||||
|
|
||||||
if (!lid_device)
|
if (!lid_device)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
status = acpi_evaluate_integer(lid_device->handle, "_LID", NULL,
|
return acpi_lid_evaluate_state(lid_device);
|
||||||
&state);
|
|
||||||
if (ACPI_FAILURE(status))
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return !!state;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(acpi_lid_open);
|
EXPORT_SYMBOL(acpi_lid_open);
|
||||||
|
|
||||||
static int acpi_lid_send_state(struct acpi_device *device)
|
static int acpi_lid_update_state(struct acpi_device *device)
|
||||||
{
|
{
|
||||||
struct acpi_button *button = acpi_driver_data(device);
|
int state;
|
||||||
unsigned long long state;
|
|
||||||
acpi_status status;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
|
state = acpi_lid_evaluate_state(device);
|
||||||
if (ACPI_FAILURE(status))
|
if (state < 0)
|
||||||
return -ENODEV;
|
return state;
|
||||||
|
|
||||||
/* input layer checks if event is redundant */
|
return acpi_lid_notify_state(device, state);
|
||||||
input_report_switch(button->input, SW_LID, !state);
|
|
||||||
input_sync(button->input);
|
|
||||||
|
|
||||||
if (state)
|
|
||||||
pm_wakeup_event(&device->dev, 0);
|
|
||||||
|
|
||||||
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
|
|
||||||
if (ret == NOTIFY_DONE)
|
|
||||||
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
|
|
||||||
device);
|
|
||||||
if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
|
|
||||||
/*
|
|
||||||
* It is also regarded as success if the notifier_chain
|
|
||||||
* returns NOTIFY_OK or NOTIFY_DONE.
|
|
||||||
*/
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void acpi_button_notify(struct acpi_device *device, u32 event)
|
static void acpi_button_notify(struct acpi_device *device, u32 event)
|
||||||
@@ -290,7 +297,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
|
|||||||
case ACPI_BUTTON_NOTIFY_STATUS:
|
case ACPI_BUTTON_NOTIFY_STATUS:
|
||||||
input = button->input;
|
input = button->input;
|
||||||
if (button->type == ACPI_BUTTON_TYPE_LID) {
|
if (button->type == ACPI_BUTTON_TYPE_LID) {
|
||||||
acpi_lid_send_state(device);
|
acpi_lid_update_state(device);
|
||||||
} else {
|
} else {
|
||||||
int keycode;
|
int keycode;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user