aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/device_pm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/device_pm.c')
-rw-r--r--drivers/acpi/device_pm.c126
1 files changed, 64 insertions, 62 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 96de787e6104..bc493aa3af19 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -37,68 +37,6 @@
37#define _COMPONENT ACPI_POWER_COMPONENT 37#define _COMPONENT ACPI_POWER_COMPONENT
38ACPI_MODULE_NAME("device_pm"); 38ACPI_MODULE_NAME("device_pm");
39 39
40static DEFINE_MUTEX(acpi_pm_notifier_lock);
41
42/**
43 * acpi_add_pm_notifier - Register PM notifier for given ACPI device.
44 * @adev: ACPI device to add the notifier for.
45 * @context: Context information to pass to the notifier routine.
46 *
47 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of
48 * PM wakeup events. For example, wakeup events may be generated for bridges
49 * if one of the devices below the bridge is signaling wakeup, even if the
50 * bridge itself doesn't have a wakeup GPE associated with it.
51 */
52acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
53 acpi_notify_handler handler, void *context)
54{
55 acpi_status status = AE_ALREADY_EXISTS;
56
57 mutex_lock(&acpi_pm_notifier_lock);
58
59 if (adev->wakeup.flags.notifier_present)
60 goto out;
61
62 status = acpi_install_notify_handler(adev->handle,
63 ACPI_SYSTEM_NOTIFY,
64 handler, context);
65 if (ACPI_FAILURE(status))
66 goto out;
67
68 adev->wakeup.flags.notifier_present = true;
69
70 out:
71 mutex_unlock(&acpi_pm_notifier_lock);
72 return status;
73}
74
75/**
76 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device.
77 * @adev: ACPI device to remove the notifier from.
78 */
79acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
80 acpi_notify_handler handler)
81{
82 acpi_status status = AE_BAD_PARAMETER;
83
84 mutex_lock(&acpi_pm_notifier_lock);
85
86 if (!adev->wakeup.flags.notifier_present)
87 goto out;
88
89 status = acpi_remove_notify_handler(adev->handle,
90 ACPI_SYSTEM_NOTIFY,
91 handler);
92 if (ACPI_FAILURE(status))
93 goto out;
94
95 adev->wakeup.flags.notifier_present = false;
96
97 out:
98 mutex_unlock(&acpi_pm_notifier_lock);
99 return status;
100}
101
102/** 40/**
103 * acpi_power_state_string - String representation of ACPI device power state. 41 * acpi_power_state_string - String representation of ACPI device power state.
104 * @state: ACPI device power state to return the string representation of. 42 * @state: ACPI device power state to return the string representation of.
@@ -385,6 +323,69 @@ bool acpi_bus_power_manageable(acpi_handle handle)
385} 323}
386EXPORT_SYMBOL(acpi_bus_power_manageable); 324EXPORT_SYMBOL(acpi_bus_power_manageable);
387 325
326#ifdef CONFIG_PM
327static DEFINE_MUTEX(acpi_pm_notifier_lock);
328
329/**
330 * acpi_add_pm_notifier - Register PM notifier for given ACPI device.
331 * @adev: ACPI device to add the notifier for.
332 * @context: Context information to pass to the notifier routine.
333 *
334 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of
335 * PM wakeup events. For example, wakeup events may be generated for bridges
336 * if one of the devices below the bridge is signaling wakeup, even if the
337 * bridge itself doesn't have a wakeup GPE associated with it.
338 */
339acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
340 acpi_notify_handler handler, void *context)
341{
342 acpi_status status = AE_ALREADY_EXISTS;
343
344 mutex_lock(&acpi_pm_notifier_lock);
345
346 if (adev->wakeup.flags.notifier_present)
347 goto out;
348
349 status = acpi_install_notify_handler(adev->handle,
350 ACPI_SYSTEM_NOTIFY,
351 handler, context);
352 if (ACPI_FAILURE(status))
353 goto out;
354
355 adev->wakeup.flags.notifier_present = true;
356
357 out:
358 mutex_unlock(&acpi_pm_notifier_lock);
359 return status;
360}
361
362/**
363 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device.
364 * @adev: ACPI device to remove the notifier from.
365 */
366acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
367 acpi_notify_handler handler)
368{
369 acpi_status status = AE_BAD_PARAMETER;
370
371 mutex_lock(&acpi_pm_notifier_lock);
372
373 if (!adev->wakeup.flags.notifier_present)
374 goto out;
375
376 status = acpi_remove_notify_handler(adev->handle,
377 ACPI_SYSTEM_NOTIFY,
378 handler);
379 if (ACPI_FAILURE(status))
380 goto out;
381
382 adev->wakeup.flags.notifier_present = false;
383
384 out:
385 mutex_unlock(&acpi_pm_notifier_lock);
386 return status;
387}
388
388bool acpi_bus_can_wakeup(acpi_handle handle) 389bool acpi_bus_can_wakeup(acpi_handle handle)
389{ 390{
390 struct acpi_device *device; 391 struct acpi_device *device;
@@ -1023,3 +1024,4 @@ void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev)
1023 mutex_unlock(&adev->physical_node_lock); 1024 mutex_unlock(&adev->physical_node_lock);
1024} 1025}
1025EXPORT_SYMBOL_GPL(acpi_dev_pm_remove_dependent); 1026EXPORT_SYMBOL_GPL(acpi_dev_pm_remove_dependent);
1027#endif /* CONFIG_PM */