diff options
author | Lv Zheng <lv.zheng@intel.com> | 2016-06-01 06:10:42 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-06-21 20:10:15 -0400 |
commit | ee7e22653f5077169ec706b5a140a3be9db381e7 (patch) | |
tree | 8d5498bbdac559ca4c3fa681c04b16219a3e0cf8 /drivers/acpi/button.c | |
parent | c2dd420034f24f356b86f90222ef19148b82a5c1 (diff) |
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>
Diffstat (limited to 'drivers/acpi/button.c')
-rw-r--r-- | drivers/acpi/button.c | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 9863278eb089..6e291c17e43a 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c | |||
@@ -113,16 +113,52 @@ static struct acpi_device *lid_device; | |||
113 | static struct proc_dir_entry *acpi_button_dir; | 113 | static struct proc_dir_entry *acpi_button_dir; |
114 | static struct proc_dir_entry *acpi_lid_dir; | 114 | static struct proc_dir_entry *acpi_lid_dir; |
115 | 115 | ||
116 | static int acpi_lid_evaluate_state(struct acpi_device *device) | ||
117 | { | ||
118 | unsigned long long lid_state; | ||
119 | acpi_status status; | ||
120 | |||
121 | status = acpi_evaluate_integer(device->handle, "_LID", NULL, &lid_state); | ||
122 | if (ACPI_FAILURE(status)) | ||
123 | return -ENODEV; | ||
124 | |||
125 | return lid_state ? 1 : 0; | ||
126 | } | ||
127 | |||
128 | static int acpi_lid_notify_state(struct acpi_device *device, int state) | ||
129 | { | ||
130 | struct acpi_button *button = acpi_driver_data(device); | ||
131 | int ret; | ||
132 | |||
133 | /* input layer checks if event is redundant */ | ||
134 | input_report_switch(button->input, SW_LID, !state); | ||
135 | input_sync(button->input); | ||
136 | |||
137 | if (state) | ||
138 | pm_wakeup_event(&device->dev, 0); | ||
139 | |||
140 | ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device); | ||
141 | if (ret == NOTIFY_DONE) | ||
142 | ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, | ||
143 | device); | ||
144 | if (ret == NOTIFY_DONE || ret == NOTIFY_OK) { | ||
145 | /* | ||
146 | * It is also regarded as success if the notifier_chain | ||
147 | * returns NOTIFY_OK or NOTIFY_DONE. | ||
148 | */ | ||
149 | ret = 0; | ||
150 | } | ||
151 | return ret; | ||
152 | } | ||
153 | |||
116 | static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) | 154 | static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) |
117 | { | 155 | { |
118 | struct acpi_device *device = seq->private; | 156 | struct acpi_device *device = seq->private; |
119 | acpi_status status; | 157 | int state; |
120 | unsigned long long state; | ||
121 | 158 | ||
122 | status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state); | 159 | state = acpi_lid_evaluate_state(device); |
123 | seq_printf(seq, "state: %s\n", | 160 | seq_printf(seq, "state: %s\n", |
124 | ACPI_FAILURE(status) ? "unsupported" : | 161 | state < 0 ? "unsupported" : (state ? "open" : "closed")); |
125 | (state ? "open" : "closed")); | ||
126 | return 0; | 162 | return 0; |
127 | } | 163 | } |
128 | 164 | ||
@@ -231,51 +267,22 @@ EXPORT_SYMBOL(acpi_lid_notifier_unregister); | |||
231 | 267 | ||
232 | int acpi_lid_open(void) | 268 | int acpi_lid_open(void) |
233 | { | 269 | { |
234 | acpi_status status; | ||
235 | unsigned long long state; | ||
236 | |||
237 | if (!lid_device) | 270 | if (!lid_device) |
238 | return -ENODEV; | 271 | return -ENODEV; |
239 | 272 | ||
240 | status = acpi_evaluate_integer(lid_device->handle, "_LID", NULL, | 273 | return acpi_lid_evaluate_state(lid_device); |
241 | &state); | ||
242 | if (ACPI_FAILURE(status)) | ||
243 | return -ENODEV; | ||
244 | |||
245 | return !!state; | ||
246 | } | 274 | } |
247 | EXPORT_SYMBOL(acpi_lid_open); | 275 | EXPORT_SYMBOL(acpi_lid_open); |
248 | 276 | ||
249 | static int acpi_lid_send_state(struct acpi_device *device) | 277 | static int acpi_lid_update_state(struct acpi_device *device) |
250 | { | 278 | { |
251 | struct acpi_button *button = acpi_driver_data(device); | 279 | int state; |
252 | unsigned long long state; | ||
253 | acpi_status status; | ||
254 | int ret; | ||
255 | |||
256 | status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state); | ||
257 | if (ACPI_FAILURE(status)) | ||
258 | return -ENODEV; | ||
259 | 280 | ||
260 | /* input layer checks if event is redundant */ | 281 | state = acpi_lid_evaluate_state(device); |
261 | input_report_switch(button->input, SW_LID, !state); | 282 | if (state < 0) |
262 | input_sync(button->input); | 283 | return state; |
263 | 284 | ||
264 | if (state) | 285 | return acpi_lid_notify_state(device, state); |
265 | pm_wakeup_event(&device->dev, 0); | ||
266 | |||
267 | ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device); | ||
268 | if (ret == NOTIFY_DONE) | ||
269 | ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, | ||
270 | device); | ||
271 | if (ret == NOTIFY_DONE || ret == NOTIFY_OK) { | ||
272 | /* | ||
273 | * It is also regarded as success if the notifier_chain | ||
274 | * returns NOTIFY_OK or NOTIFY_DONE. | ||
275 | */ | ||
276 | ret = 0; | ||
277 | } | ||
278 | return ret; | ||
279 | } | 286 | } |
280 | 287 | ||
281 | static void acpi_button_notify(struct acpi_device *device, u32 event) | 288 | 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) | |||
290 | case ACPI_BUTTON_NOTIFY_STATUS: | 297 | case ACPI_BUTTON_NOTIFY_STATUS: |
291 | input = button->input; | 298 | input = button->input; |
292 | if (button->type == ACPI_BUTTON_TYPE_LID) { | 299 | if (button->type == ACPI_BUTTON_TYPE_LID) { |
293 | acpi_lid_send_state(device); | 300 | acpi_lid_update_state(device); |
294 | } else { | 301 | } else { |
295 | int keycode; | 302 | int keycode; |
296 | 303 | ||