aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/dock.c
diff options
context:
space:
mode:
authorJiang Liu <jiang.liu@huawei.com>2013-06-28 12:24:42 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-07-14 19:33:10 -0400
commitc9b5471f8866956919955b70ab27b4737b8bce30 (patch)
treee3dc01f55036556bc345a12bc7e118e849d06ccc /drivers/acpi/dock.c
parentebf4df8db0e7e5db9f7fca5fcd0c2b90ac954385 (diff)
ACPI: simplify dock driver with new helper functions
Use helper functions introduced previously to simplify the ACPI dock driver. [rjw: Changelog] Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/dock.c')
-rw-r--r--drivers/acpi/dock.c122
1 files changed, 12 insertions, 110 deletions
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 1bdb1facc17b..810d1d720b1f 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -226,48 +226,6 @@ find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
226/***************************************************************************** 226/*****************************************************************************
227 * Dock functions * 227 * Dock functions *
228 *****************************************************************************/ 228 *****************************************************************************/
229/**
230 * is_dock - see if a device is a dock station
231 * @handle: acpi handle of the device
232 *
233 * If an acpi object has a _DCK method, then it is by definition a dock
234 * station, so return true.
235 */
236static int is_dock(acpi_handle handle)
237{
238 acpi_status status;
239 acpi_handle tmp;
240
241 status = acpi_get_handle(handle, "_DCK", &tmp);
242 if (ACPI_FAILURE(status))
243 return 0;
244 return 1;
245}
246
247static int __init is_ejectable(acpi_handle handle)
248{
249 acpi_status status;
250 acpi_handle tmp;
251
252 status = acpi_get_handle(handle, "_EJ0", &tmp);
253 if (ACPI_FAILURE(status))
254 return 0;
255 return 1;
256}
257
258static int __init is_ata(acpi_handle handle)
259{
260 acpi_handle tmp;
261
262 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
263 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
264 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
265 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
266 return 1;
267
268 return 0;
269}
270
271static int __init is_battery(acpi_handle handle) 229static int __init is_battery(acpi_handle handle)
272{ 230{
273 struct acpi_device_info *info; 231 struct acpi_device_info *info;
@@ -284,17 +242,13 @@ static int __init is_battery(acpi_handle handle)
284 return ret; 242 return ret;
285} 243}
286 244
287static int __init is_ejectable_bay(acpi_handle handle) 245/* Check whether ACPI object is an ejectable battery or disk bay */
246static bool __init is_ejectable_bay(acpi_handle handle)
288{ 247{
289 acpi_handle phandle; 248 if (acpi_has_method(handle, "_EJ0") && is_battery(handle))
249 return true;
290 250
291 if (!is_ejectable(handle)) 251 return acpi_bay_match(handle);
292 return 0;
293 if (is_battery(handle) || is_ata(handle))
294 return 1;
295 if (!acpi_get_parent(handle, &phandle) && is_ata(phandle))
296 return 1;
297 return 0;
298} 252}
299 253
300/** 254/**
@@ -312,7 +266,7 @@ int is_dock_device(acpi_handle handle)
312 if (!dock_station_count) 266 if (!dock_station_count)
313 return 0; 267 return 0;
314 268
315 if (is_dock(handle)) 269 if (acpi_dock_match(handle))
316 return 1; 270 return 1;
317 271
318 list_for_each_entry(dock_station, &dock_stations, sibling) 272 list_for_each_entry(dock_station, &dock_stations, sibling)
@@ -447,37 +401,6 @@ static void dock_event(struct dock_station *ds, u32 event, int num)
447} 401}
448 402
449/** 403/**
450 * eject_dock - respond to a dock eject request
451 * @ds: the dock station
452 *
453 * This is called after _DCK is called, to execute the dock station's
454 * _EJ0 method.
455 */
456static void eject_dock(struct dock_station *ds)
457{
458 struct acpi_object_list arg_list;
459 union acpi_object arg;
460 acpi_status status;
461 acpi_handle tmp;
462
463 /* all dock devices should have _EJ0, but check anyway */
464 status = acpi_get_handle(ds->handle, "_EJ0", &tmp);
465 if (ACPI_FAILURE(status)) {
466 pr_debug("No _EJ0 support for dock device\n");
467 return;
468 }
469
470 arg_list.count = 1;
471 arg_list.pointer = &arg;
472 arg.type = ACPI_TYPE_INTEGER;
473 arg.integer.value = 1;
474
475 status = acpi_evaluate_object(ds->handle, "_EJ0", &arg_list, NULL);
476 if (ACPI_FAILURE(status))
477 pr_debug("Failed to evaluate _EJ0!\n");
478}
479
480/**
481 * handle_dock - handle a dock event 404 * handle_dock - handle a dock event
482 * @ds: the dock station 405 * @ds: the dock station
483 * @dock: to dock, or undock - that is the question 406 * @dock: to dock, or undock - that is the question
@@ -537,27 +460,6 @@ static inline void complete_undock(struct dock_station *ds)
537 ds->flags &= ~(DOCK_UNDOCKING); 460 ds->flags &= ~(DOCK_UNDOCKING);
538} 461}
539 462
540static void dock_lock(struct dock_station *ds, int lock)
541{
542 struct acpi_object_list arg_list;
543 union acpi_object arg;
544 acpi_status status;
545
546 arg_list.count = 1;
547 arg_list.pointer = &arg;
548 arg.type = ACPI_TYPE_INTEGER;
549 arg.integer.value = !!lock;
550 status = acpi_evaluate_object(ds->handle, "_LCK", &arg_list, NULL);
551 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
552 if (lock)
553 acpi_handle_warn(ds->handle,
554 "Locking device failed (0x%x)\n", status);
555 else
556 acpi_handle_warn(ds->handle,
557 "Unlocking device failed (0x%x)\n", status);
558 }
559}
560
561/** 463/**
562 * dock_in_progress - see if we are in the middle of handling a dock event 464 * dock_in_progress - see if we are in the middle of handling a dock event
563 * @ds: the dock station 465 * @ds: the dock station
@@ -692,8 +594,8 @@ static int handle_eject_request(struct dock_station *ds, u32 event)
692 594
693 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); 595 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
694 undock(ds); 596 undock(ds);
695 dock_lock(ds, 0); 597 acpi_evaluate_lck(ds->handle, 0);
696 eject_dock(ds); 598 acpi_evaluate_ej0(ds->handle);
697 if (dock_present(ds)) { 599 if (dock_present(ds)) {
698 acpi_handle_err(ds->handle, "Unable to undock!\n"); 600 acpi_handle_err(ds->handle, "Unable to undock!\n");
699 return -EBUSY; 601 return -EBUSY;
@@ -752,7 +654,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
752 hotplug_dock_devices(ds, event); 654 hotplug_dock_devices(ds, event);
753 complete_dock(ds); 655 complete_dock(ds);
754 dock_event(ds, event, DOCK_EVENT); 656 dock_event(ds, event, DOCK_EVENT);
755 dock_lock(ds, 1); 657 acpi_evaluate_lck(ds->handle, 1);
756 acpi_update_all_gpes(); 658 acpi_update_all_gpes();
757 break; 659 break;
758 } 660 }
@@ -998,9 +900,9 @@ static int __init dock_add(acpi_handle handle)
998 /* we want the dock device to send uevents */ 900 /* we want the dock device to send uevents */
999 dev_set_uevent_suppress(&dd->dev, 0); 901 dev_set_uevent_suppress(&dd->dev, 0);
1000 902
1001 if (is_dock(handle)) 903 if (acpi_dock_match(handle))
1002 dock_station->flags |= DOCK_IS_DOCK; 904 dock_station->flags |= DOCK_IS_DOCK;
1003 if (is_ata(handle)) 905 if (acpi_ata_match(handle))
1004 dock_station->flags |= DOCK_IS_ATA; 906 dock_station->flags |= DOCK_IS_ATA;
1005 if (is_battery(handle)) 907 if (is_battery(handle))
1006 dock_station->flags |= DOCK_IS_BAT; 908 dock_station->flags |= DOCK_IS_BAT;
@@ -1043,7 +945,7 @@ err_unregister:
1043static __init acpi_status 945static __init acpi_status
1044find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv) 946find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
1045{ 947{
1046 if (is_dock(handle) || is_ejectable_bay(handle)) 948 if (acpi_dock_match(handle) || is_ejectable_bay(handle))
1047 dock_add(handle); 949 dock_add(handle);
1048 950
1049 return AE_OK; 951 return AE_OK;