Lines Matching +full:wakeup +full:- +full:method

1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/acpi/device_pm.c - ACPI device power management routines.
27 * acpi_power_state_string - String representation of ACPI device power state.
53 status = acpi_evaluate_integer(device->handle, "_PSC", NULL, &psc); in acpi_dev_pm_explicit_get()
55 return -ENODEV; in acpi_dev_pm_explicit_get()
62 * acpi_device_get_power - Get power state of an ACPI device.
82 return -EINVAL; in acpi_device_get_power()
86 if (!device->flags.power_manageable) { in acpi_device_get_power()
87 /* TBD: Non-recursive algorithm for walking up hierarchy. */ in acpi_device_get_power()
88 *state = parent ? parent->power.state : ACPI_STATE_D0; in acpi_device_get_power()
96 if (device->power.flags.power_resources) { in acpi_device_get_power()
101 if (device->power.flags.explicit_get) { in acpi_device_get_power()
127 if (!device->power.flags.ignore_parent && parent && in acpi_device_get_power()
128 parent->power.state == ACPI_STATE_UNKNOWN && in acpi_device_get_power()
130 parent->power.state = ACPI_STATE_D0; in acpi_device_get_power()
135 acpi_handle_debug(device->handle, "Power state: %s\n", in acpi_device_get_power()
143 if (adev->power.states[state].flags.explicit_set) { in acpi_dev_pm_explicit_set()
144 char method[5] = { '_', 'P', 'S', '0' + state, '\0' }; in acpi_dev_pm_explicit_set() local
147 status = acpi_evaluate_object(adev->handle, method, NULL, NULL); in acpi_dev_pm_explicit_set()
149 return -ENODEV; in acpi_dev_pm_explicit_set()
155 * acpi_device_set_power - Set power state of an ACPI device.
167 if (!device || !device->flags.power_manageable in acpi_device_set_power()
169 return -EINVAL; in acpi_device_set_power()
171 acpi_handle_debug(device->handle, "Power state change: %s -> %s\n", in acpi_device_set_power()
172 acpi_power_state_string(device->power.state), in acpi_device_set_power()
178 if (state > ACPI_STATE_D0 && state == device->power.state) in acpi_device_set_power()
188 if (!device->power.states[ACPI_STATE_D3_COLD].flags.valid) in acpi_device_set_power()
190 } else if (!device->power.states[state].flags.valid) { in acpi_device_set_power()
191 acpi_handle_debug(device->handle, "Power state %s not supported\n", in acpi_device_set_power()
193 return -ENODEV; in acpi_device_set_power()
196 if (!device->power.flags.ignore_parent) { in acpi_device_set_power()
200 if (parent && state < parent->power.state) { in acpi_device_set_power()
201 acpi_handle_debug(device->handle, in acpi_device_set_power()
204 acpi_power_state_string(parent->power.state)); in acpi_device_set_power()
205 return -ENODEV; in acpi_device_set_power()
211 * ---------------- in acpi_device_set_power()
218 * According to ACPI 6, devices cannot go from lower-power in acpi_device_set_power()
219 * (deeper) states to higher-power (shallower) states. in acpi_device_set_power()
221 if (state < device->power.state) { in acpi_device_set_power()
222 acpi_handle_debug(device->handle, in acpi_device_set_power()
224 acpi_power_state_string(device->power.state), in acpi_device_set_power()
226 return -ENODEV; in acpi_device_set_power()
233 if (device->power.state < ACPI_STATE_D3_HOT) { in acpi_device_set_power()
239 if (device->power.flags.power_resources) in acpi_device_set_power()
242 int cur_state = device->power.state; in acpi_device_set_power()
244 if (device->power.flags.power_resources) { in acpi_device_set_power()
254 if (!device->power.flags.explicit_get) in acpi_device_set_power()
260 * system-wide transition involving the platform in acpi_device_set_power()
278 acpi_handle_debug(device->handle, in acpi_device_set_power()
282 device->power.state = target_state; in acpi_device_set_power()
283 acpi_handle_debug(device->handle, "Power state changed to %s\n", in acpi_device_set_power()
290 acpi_handle_debug(device->handle, "Already in %s\n", in acpi_device_set_power()
303 return -ENODEV; in acpi_bus_set_power()
313 return -EINVAL; in acpi_bus_init_power()
315 device->power.state = ACPI_STATE_UNKNOWN; in acpi_bus_init_power()
317 device->flags.initialized = false; in acpi_bus_init_power()
318 return -ENXIO; in acpi_bus_init_power()
325 if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) { in acpi_bus_init_power()
349 * Toshiba P870-303 in a nasty way.] in acpi_bus_init_power()
353 device->power.state = state; in acpi_bus_init_power()
358 * acpi_device_fix_up_power - Force device with missing _PSC into D0.
369 if (!device->power.flags.power_resources in acpi_device_fix_up_power()
370 && !device->power.flags.explicit_get in acpi_device_fix_up_power()
371 && device->power.state == ACPI_STATE_D0) in acpi_device_fix_up_power()
380 if (adev->status.present && adev->status.enabled) in fix_up_power_if_applicable()
387 * acpi_device_fix_up_power_extended - Force device and its children into D0.
405 if (device->power.state == ACPI_STATE_UNKNOWN) { in acpi_device_update_power()
408 *state_p = device->power.state; in acpi_device_update_power()
423 if (device->power.flags.power_resources) { in acpi_device_update_power()
432 device->power.state = state; in acpi_device_update_power()
448 return -ENODEV; in acpi_bus_update_power()
456 return device && device->flags.power_manageable; in acpi_bus_power_manageable()
462 if (!(adev->flags.power_manageable && adev->pnp.type.bus_address)) in acpi_power_up_if_adr_present()
465 acpi_handle_debug(adev->handle, "Power state: %s\n", in acpi_power_up_if_adr_present()
466 acpi_power_state_string(adev->power.state)); in acpi_power_up_if_adr_present()
468 if (adev->power.state == ACPI_STATE_D3_COLD) in acpi_power_up_if_adr_present()
475 * acpi_dev_power_up_children_with_adr - Power up childres with valid _ADR
512 if (adev->wakeup.flags.notifier_present) { in acpi_pm_notify_handler()
513 pm_wakeup_ws_event(adev->wakeup.ws, 0, acpi_s2idle_wakeup()); in acpi_pm_notify_handler()
514 if (adev->wakeup.context.func) { in acpi_pm_notify_handler()
516 adev->wakeup.context.func, in acpi_pm_notify_handler()
517 dev_name(adev->wakeup.context.dev)); in acpi_pm_notify_handler()
518 adev->wakeup.context.func(&adev->wakeup.context); in acpi_pm_notify_handler()
528 * acpi_add_pm_notifier - Register PM notify handler for given ACPI device.
530 * @dev: Device to generate a wakeup event for while handling the notification.
533 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of
534 * PM wakeup events. For example, wakeup events may be generated for bridges
535 * if one of the devices below the bridge is signaling wakeup, even if the
536 * bridge itself doesn't have a wakeup GPE associated with it.
548 if (adev->wakeup.flags.notifier_present) in acpi_add_pm_notifier()
551 status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY, in acpi_add_pm_notifier()
557 adev->wakeup.ws = wakeup_source_register(&adev->dev, in acpi_add_pm_notifier()
558 dev_name(&adev->dev)); in acpi_add_pm_notifier()
559 adev->wakeup.context.dev = dev; in acpi_add_pm_notifier()
560 adev->wakeup.context.func = func; in acpi_add_pm_notifier()
561 adev->wakeup.flags.notifier_present = true; in acpi_add_pm_notifier()
570 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device.
579 if (!adev->wakeup.flags.notifier_present) in acpi_remove_pm_notifier()
582 status = acpi_remove_notify_handler(adev->handle, in acpi_remove_pm_notifier()
589 adev->wakeup.context.func = NULL; in acpi_remove_pm_notifier()
590 adev->wakeup.context.dev = NULL; in acpi_remove_pm_notifier()
591 wakeup_source_unregister(adev->wakeup.ws); in acpi_remove_pm_notifier()
592 adev->wakeup.flags.notifier_present = false; in acpi_remove_pm_notifier()
604 return device && device->wakeup.flags.valid; in acpi_bus_can_wakeup()
616 * acpi_dev_pm_get_state - Get preferred power state of ACPI device.
632 * Returns 0 on success or -ENODATA when one of the ACPI methods fails or
639 char method[] = { '_', 'S', '0' + target_state, 'D', '\0' }; in acpi_dev_pm_get_state() local
640 acpi_handle handle = adev->handle; in acpi_dev_pm_get_state()
643 bool wakeup = false; in acpi_dev_pm_get_state() local
650 * wakeup, in which case the return value of _S0W has to be used as the in acpi_dev_pm_get_state()
657 * If present, _SxD methods return the minimum D-state (highest power in acpi_dev_pm_get_state()
658 * state) we can use for the corresponding S-states. Otherwise, the in acpi_dev_pm_get_state()
659 * minimum D-state is D0 (ACPI 3.x). in acpi_dev_pm_get_state()
667 status = acpi_evaluate_integer(handle, method, NULL, &ret); in acpi_dev_pm_get_state()
670 return -ENODATA; in acpi_dev_pm_get_state()
677 if (!adev->power.states[ret].flags.valid) { in acpi_dev_pm_get_state()
681 return -ENODATA; in acpi_dev_pm_get_state()
688 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid in acpi_dev_pm_get_state()
689 && adev->wakeup.sleep_state >= target_state; in acpi_dev_pm_get_state()
690 } else if (device_may_wakeup(dev) && dev->power.wakeirq) { in acpi_dev_pm_get_state()
699 * _S0W method to get the correct wake D-state. Otherwise we in acpi_dev_pm_get_state()
703 wakeup = true; in acpi_dev_pm_get_state()
706 wakeup = adev->wakeup.flags.valid; in acpi_dev_pm_get_state()
711 * the D-state returned by _SxD is sufficient for that (we assume a in acpi_dev_pm_get_state()
712 * wakeup-aware driver if wake is set). Still, if _SxW exists in acpi_dev_pm_get_state()
713 * (ACPI 3.x), it should return the maximum (lowest power) D-state that in acpi_dev_pm_get_state()
716 if (wakeup) { in acpi_dev_pm_get_state()
717 method[3] = 'W'; in acpi_dev_pm_get_state()
718 status = acpi_evaluate_integer(handle, method, NULL, &ret); in acpi_dev_pm_get_state()
728 if (!adev->power.states[ret].flags.valid) in acpi_dev_pm_get_state()
733 return -ENODATA; in acpi_dev_pm_get_state()
747 * acpi_pm_device_sleep_state - Get preferred power state of ACPI device.
750 * @d_max_in: Deepest low-power state to take into consideration.
751 * Return value: Preferred power state of the device on success, -ENODEV
752 * if there's no 'struct acpi_device' for @dev, -EINVAL if @d_max_in is
753 * incorrect, or -ENODATA on ACPI method failure.
763 return -EINVAL; in acpi_pm_device_sleep_state()
776 return -ENODEV; in acpi_pm_device_sleep_state()
785 return -EINVAL; in acpi_pm_device_sleep_state()
788 for (d_max = d_max_in; d_max > d_min; d_max--) { in acpi_pm_device_sleep_state()
789 if (adev->power.states[d_max].flags.valid) in acpi_pm_device_sleep_state()
802 * acpi_pm_notify_work_func - ACPI devices wakeup notification work function.
803 * @context: Device wakeup context.
807 struct device *dev = context->dev; in acpi_pm_notify_work_func()
820 struct acpi_device_wakeup *wakeup = &adev->wakeup; in __acpi_device_wakeup_enable() local
827 * If the device wakeup power is already enabled, disable it and enable in __acpi_device_wakeup_enable()
832 if (wakeup->enable_count > 0) in __acpi_device_wakeup_enable()
837 if (wakeup->enable_count > 0) { in __acpi_device_wakeup_enable()
838 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number); in __acpi_device_wakeup_enable()
839 wakeup->enable_count = 0; in __acpi_device_wakeup_enable()
844 if (wakeup->enable_count > 0) in __acpi_device_wakeup_enable()
847 status = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number); in __acpi_device_wakeup_enable()
850 error = -EIO; in __acpi_device_wakeup_enable()
854 acpi_handle_debug(adev->handle, "GPE%2X enabled for wakeup\n", in __acpi_device_wakeup_enable()
855 (unsigned int)wakeup->gpe_number); in __acpi_device_wakeup_enable()
858 if (wakeup->enable_count < INT_MAX) in __acpi_device_wakeup_enable()
859 wakeup->enable_count++; in __acpi_device_wakeup_enable()
861 acpi_handle_info(adev->handle, "Wakeup enable count out of bounds!\n"); in __acpi_device_wakeup_enable()
869 * acpi_device_wakeup_enable - Enable wakeup functionality for device.
870 * @adev: ACPI device to enable wakeup functionality for.
873 * Enable the GPE associated with @adev so that it can generate wakeup signals
874 * for the device in response to external (remote) events and enable wakeup
886 * acpi_device_wakeup_disable - Disable wakeup functionality for device.
887 * @adev: ACPI device to disable wakeup functionality for.
889 * Disable the GPE associated with @adev and disable wakeup power for it.
896 struct acpi_device_wakeup *wakeup = &adev->wakeup; in acpi_device_wakeup_disable() local
900 if (!wakeup->enable_count) in acpi_device_wakeup_disable()
903 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number); in acpi_device_wakeup_disable()
906 wakeup->enable_count--; in acpi_device_wakeup_disable()
913 * acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device.
914 * @dev: Device to enable/disable to generate wakeup events.
915 * @enable: Whether to enable or disable the wakeup functionality.
925 return -ENODEV; in acpi_pm_set_device_wakeup()
929 return -EINVAL; in acpi_pm_set_device_wakeup()
933 dev_dbg(dev, "Wakeup disabled by ACPI\n"); in acpi_pm_set_device_wakeup()
939 dev_dbg(dev, "Wakeup enabled by ACPI\n"); in acpi_pm_set_device_wakeup()
946 * acpi_dev_pm_low_power - Put ACPI device into a low-power state.
947 * @dev: Device to put into a low-power state.
964 * acpi_dev_pm_full_power - Put ACPI device into the full-power state.
965 * @adev: ACPI device node to put into the full-power state.
974 * acpi_dev_suspend - Put device into a low-power state using ACPI.
975 * @dev: Device to put into a low-power state.
976 * @wakeup: Whether or not to enable wakeup for the device.
978 * Put the given device into a low-power state using the standard ACPI
979 * mechanism. Set up remote wakeup if desired, choose the state to put the
980 * device into (this checks if remote wakeup is expected to work too), and set
983 int acpi_dev_suspend(struct device *dev, bool wakeup) in acpi_dev_suspend() argument
992 if (wakeup && acpi_device_can_wakeup(adev)) { in acpi_dev_suspend()
995 return -EAGAIN; in acpi_dev_suspend()
997 wakeup = false; in acpi_dev_suspend()
1001 if (error && wakeup) in acpi_dev_suspend()
1009 * acpi_dev_resume - Put device into the full-power state using ACPI.
1010 * @dev: Device to put into the full-power state.
1012 * Put the given device into the full-power state using the standard ACPI
1013 * mechanism. Set the power state of the device to ACPI D0 and disable wakeup.
1030 * acpi_subsys_runtime_suspend - Suspend device using ACPI.
1034 * it into a runtime low-power state.
1045 * acpi_subsys_runtime_resume - Resume device using ACPI.
1048 * Use ACPI to put the given device into the full-power state and carry out the
1065 if (!pm_runtime_suspended(dev) || !adev || (adev->wakeup.flags.valid && in acpi_dev_needs_resume()
1066 device_may_wakeup(dev) != !!adev->wakeup.prepare_count)) in acpi_dev_needs_resume()
1072 if (adev->power.flags.dsw_present) in acpi_dev_needs_resume()
1079 return state != adev->power.state; in acpi_dev_needs_resume()
1083 * acpi_subsys_prepare - Prepare device for system transition to a sleep state.
1090 if (dev->driver && dev->driver->pm && dev->driver->pm->prepare) { in acpi_subsys_prepare()
1091 int ret = dev->driver->pm->prepare(dev); in acpi_subsys_prepare()
1105 * acpi_subsys_complete - Finalize device's resume during system resume.
1112 * If the device had been runtime-suspended before the system went into in acpi_subsys_complete()
1122 * acpi_subsys_suspend - Run the device driver's suspend callback.
1126 * system suspend callbacks, unless the driver can cope with runtime-suspended
1127 * devices during system suspend and there are no ACPI-specific reasons for
1141 * acpi_subsys_suspend_late - Suspend device using ACPI.
1145 * it into a low-power state during system transition into a sleep state.
1160 * acpi_subsys_suspend_noirq - Run the device driver's "noirq" suspend callback.
1175 * If the target system sleep state is suspend-to-idle, it is sufficient in acpi_subsys_suspend_noirq()
1176 * to check whether or not the device's wakeup settings are good for in acpi_subsys_suspend_noirq()
1182 dev->power.may_skip_resume = false; in acpi_subsys_suspend_noirq()
1189 * acpi_subsys_resume_noirq - Run the device driver's "noirq" resume callback.
1201 * acpi_subsys_resume_early - Resume device using ACPI.
1204 * Use ACPI to put the given device into the full-power state and carry out the
1212 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; in acpi_subsys_resume_early()
1218 if (pm && !pm->resume_early) { in acpi_subsys_resume_early()
1228 * acpi_subsys_resume - Resume device using ACPI.
1231 * Use ACPI to put the given device into the full-power state if it has not been
1237 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; in acpi_subsys_resume()
1240 if (!dev_pm_skip_resume(dev) && pm && !pm->resume_early) { in acpi_subsys_resume()
1249 * acpi_subsys_freeze - Run the device driver's freeze callback.
1255 * Resume all runtime-suspended devices before creating a snapshot in acpi_subsys_freeze()
1258 * put into the runtime-active metastate during system resume anyway, in acpi_subsys_freeze()
1269 * acpi_subsys_restore_early - Restore device using ACPI.
1281 * acpi_subsys_poweroff - Run the device driver's poweroff callback.
1285 * system poweroff callbacks, unless the driver can cope with runtime-suspended
1286 * devices during system suspend and there are no ACPI-specific reasons for
1300 * acpi_subsys_poweroff_late - Run the device driver's poweroff callback.
1304 * it into a low-power state during system transition into a sleep state.
1321 * acpi_subsys_poweroff_noirq - Run the driver's "noirq" poweroff callback.
1356 * acpi_dev_pm_detach - Remove ACPI power management from the device.
1360 * Remove the device from the general ACPI PM domain and remove its wakeup
1371 if (adev && dev->pm_domain == &acpi_general_pm_domain) { in acpi_dev_pm_detach()
1379 * choice of the low-power state to put the device into. in acpi_dev_pm_detach()
1390 * acpi_dev_pm_attach - Prepare device for ACPI power management.
1395 * attached to it, install a wakeup notification handler for the device and
1436 dev->pm_domain->detach = acpi_dev_pm_detach; in acpi_dev_pm_attach()
1442 * acpi_storage_d3 - Check if D3 should be used in the suspend path
1452 * applied to the PCIe slot and plugging in a non-storage device the
1473 * acpi_dev_state_d0 - Tell if the device is in D0 power state
1479 * Note that the power state of a device is not well-defined after it has been
1484 * function. See Documentation/firmware-guide/acpi/non-d0-probe.rst for
1494 return adev->power.state == ACPI_STATE_D0; in acpi_dev_state_d0()