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.
81 return -EINVAL; in acpi_device_get_power()
83 if (!device->flags.power_manageable) { in acpi_device_get_power()
84 /* TBD: Non-recursive algorithm for walking up hierarchy. */ in acpi_device_get_power()
85 *state = device->parent ? in acpi_device_get_power()
86 device->parent->power.state : ACPI_STATE_D0; in acpi_device_get_power()
94 if (device->power.flags.power_resources) { in acpi_device_get_power()
99 if (device->power.flags.explicit_get) { in acpi_device_get_power()
125 if (!device->power.flags.ignore_parent && device->parent in acpi_device_get_power()
126 && device->parent->power.state == ACPI_STATE_UNKNOWN in acpi_device_get_power()
128 device->parent->power.state = ACPI_STATE_D0; in acpi_device_get_power()
133 dev_dbg(&device->dev, "Device power state is %s\n", in acpi_device_get_power()
141 if (adev->power.states[state].flags.explicit_set) { in acpi_dev_pm_explicit_set()
142 char method[5] = { '_', 'P', 'S', '0' + state, '\0' }; in acpi_dev_pm_explicit_set() local
145 status = acpi_evaluate_object(adev->handle, method, NULL, NULL); in acpi_dev_pm_explicit_set()
147 return -ENODEV; in acpi_dev_pm_explicit_set()
153 * acpi_device_set_power - Set power state of an ACPI device.
165 if (!device || !device->flags.power_manageable in acpi_device_set_power()
167 return -EINVAL; in acpi_device_set_power()
169 acpi_handle_debug(device->handle, "Power state change: %s -> %s\n", in acpi_device_set_power()
170 acpi_power_state_string(device->power.state), in acpi_device_set_power()
176 if (state > ACPI_STATE_D0 && state == device->power.state) { in acpi_device_set_power()
177 dev_dbg(&device->dev, "Device already in %s\n", in acpi_device_set_power()
189 if (!device->power.states[ACPI_STATE_D3_COLD].flags.valid) in acpi_device_set_power()
191 } else if (!device->power.states[state].flags.valid) { in acpi_device_set_power()
192 dev_warn(&device->dev, "Power state %s not supported\n", in acpi_device_set_power()
194 return -ENODEV; in acpi_device_set_power()
197 if (!device->power.flags.ignore_parent && in acpi_device_set_power()
198 device->parent && (state < device->parent->power.state)) { in acpi_device_set_power()
199 dev_warn(&device->dev, in acpi_device_set_power()
202 acpi_power_state_string(device->parent->power.state)); in acpi_device_set_power()
203 return -ENODEV; in acpi_device_set_power()
208 * ---------------- in acpi_device_set_power()
215 * According to ACPI 6, devices cannot go from lower-power in acpi_device_set_power()
216 * (deeper) states to higher-power (shallower) states. in acpi_device_set_power()
218 if (state < device->power.state) { in acpi_device_set_power()
219 dev_warn(&device->dev, "Cannot transition from %s to %s\n", in acpi_device_set_power()
220 acpi_power_state_string(device->power.state), in acpi_device_set_power()
222 return -ENODEV; in acpi_device_set_power()
229 if (device->power.state < ACPI_STATE_D3_HOT) { in acpi_device_set_power()
235 if (device->power.flags.power_resources) in acpi_device_set_power()
238 int cur_state = device->power.state; in acpi_device_set_power()
240 if (device->power.flags.power_resources) { in acpi_device_set_power()
250 if (!device->power.flags.explicit_get) in acpi_device_set_power()
256 * system-wide transition involving the platform in acpi_device_set_power()
274 dev_warn(&device->dev, "Failed to change power state to %s\n", in acpi_device_set_power()
277 device->power.state = target_state; in acpi_device_set_power()
278 dev_dbg(&device->dev, "Power state changed to %s\n", in acpi_device_set_power()
305 return -EINVAL; in acpi_bus_init_power()
307 device->power.state = ACPI_STATE_UNKNOWN; in acpi_bus_init_power()
309 device->flags.initialized = false; in acpi_bus_init_power()
310 return -ENXIO; in acpi_bus_init_power()
317 if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) { in acpi_bus_init_power()
341 * Toshiba P870-303 in a nasty way.] in acpi_bus_init_power()
345 device->power.state = state; in acpi_bus_init_power()
350 * acpi_device_fix_up_power - Force device with missing _PSC into D0.
361 if (!device->power.flags.power_resources in acpi_device_fix_up_power()
362 && !device->power.flags.explicit_get in acpi_device_fix_up_power()
363 && device->power.state == ACPI_STATE_D0) in acpi_device_fix_up_power()
375 if (device->power.state == ACPI_STATE_UNKNOWN) { in acpi_device_update_power()
378 *state_p = device->power.state; in acpi_device_update_power()
393 if (device->power.flags.power_resources) { in acpi_device_update_power()
402 device->power.state = state; in acpi_device_update_power()
427 return result ? false : device->flags.power_manageable; in acpi_bus_power_manageable()
456 if (adev->wakeup.flags.notifier_present) { in acpi_pm_notify_handler()
457 pm_wakeup_ws_event(adev->wakeup.ws, 0, acpi_s2idle_wakeup()); in acpi_pm_notify_handler()
458 if (adev->wakeup.context.func) { in acpi_pm_notify_handler()
460 adev->wakeup.context.func, in acpi_pm_notify_handler()
461 dev_name(adev->wakeup.context.dev)); in acpi_pm_notify_handler()
462 adev->wakeup.context.func(&adev->wakeup.context); in acpi_pm_notify_handler()
472 * acpi_add_pm_notifier - Register PM notify handler for given ACPI device.
474 * @dev: Device to generate a wakeup event for while handling the notification.
477 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of
478 * PM wakeup events. For example, wakeup events may be generated for bridges
479 * if one of the devices below the bridge is signaling wakeup, even if the
480 * bridge itself doesn't have a wakeup GPE associated with it.
492 if (adev->wakeup.flags.notifier_present) in acpi_add_pm_notifier()
495 status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY, in acpi_add_pm_notifier()
501 adev->wakeup.ws = wakeup_source_register(&adev->dev, in acpi_add_pm_notifier()
502 dev_name(&adev->dev)); in acpi_add_pm_notifier()
503 adev->wakeup.context.dev = dev; in acpi_add_pm_notifier()
504 adev->wakeup.context.func = func; in acpi_add_pm_notifier()
505 adev->wakeup.flags.notifier_present = true; in acpi_add_pm_notifier()
514 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device.
523 if (!adev->wakeup.flags.notifier_present) in acpi_remove_pm_notifier()
526 status = acpi_remove_notify_handler(adev->handle, in acpi_remove_pm_notifier()
533 adev->wakeup.context.func = NULL; in acpi_remove_pm_notifier()
534 adev->wakeup.context.dev = NULL; in acpi_remove_pm_notifier()
535 wakeup_source_unregister(adev->wakeup.ws); in acpi_remove_pm_notifier()
536 adev->wakeup.flags.notifier_present = false; in acpi_remove_pm_notifier()
550 return result ? false : device->wakeup.flags.valid; in acpi_bus_can_wakeup()
562 * acpi_dev_pm_get_state - Get preferred power state of ACPI device.
578 * Returns 0 on success or -ENODATA when one of the ACPI methods fails or
585 char method[] = { '_', 'S', '0' + target_state, 'D', '\0' }; in acpi_dev_pm_get_state() local
586 acpi_handle handle = adev->handle; in acpi_dev_pm_get_state()
589 bool wakeup = false; in acpi_dev_pm_get_state() local
596 * wakeup, in which case the return value of _S0W has to be used as the in acpi_dev_pm_get_state()
603 * If present, _SxD methods return the minimum D-state (highest power in acpi_dev_pm_get_state()
604 * state) we can use for the corresponding S-states. Otherwise, the in acpi_dev_pm_get_state()
605 * minimum D-state is D0 (ACPI 3.x). in acpi_dev_pm_get_state()
613 status = acpi_evaluate_integer(handle, method, NULL, &ret); in acpi_dev_pm_get_state()
616 return -ENODATA; in acpi_dev_pm_get_state()
623 if (!adev->power.states[ret].flags.valid) { in acpi_dev_pm_get_state()
627 return -ENODATA; in acpi_dev_pm_get_state()
634 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid in acpi_dev_pm_get_state()
635 && adev->wakeup.sleep_state >= target_state; in acpi_dev_pm_get_state()
637 wakeup = adev->wakeup.flags.valid; in acpi_dev_pm_get_state()
642 * the D-state returned by _SxD is sufficient for that (we assume a in acpi_dev_pm_get_state()
643 * wakeup-aware driver if wake is set). Still, if _SxW exists in acpi_dev_pm_get_state()
644 * (ACPI 3.x), it should return the maximum (lowest power) D-state that in acpi_dev_pm_get_state()
647 if (wakeup) { in acpi_dev_pm_get_state()
648 method[3] = 'W'; in acpi_dev_pm_get_state()
649 status = acpi_evaluate_integer(handle, method, NULL, &ret); in acpi_dev_pm_get_state()
659 if (!adev->power.states[ret].flags.valid) in acpi_dev_pm_get_state()
664 return -ENODATA; in acpi_dev_pm_get_state()
678 * acpi_pm_device_sleep_state - Get preferred power state of ACPI device.
681 * @d_max_in: Deepest low-power state to take into consideration.
682 * Return value: Preferred power state of the device on success, -ENODEV
683 * if there's no 'struct acpi_device' for @dev, -EINVAL if @d_max_in is
684 * incorrect, or -ENODATA on ACPI method failure.
694 return -EINVAL; in acpi_pm_device_sleep_state()
707 return -ENODEV; in acpi_pm_device_sleep_state()
716 return -EINVAL; in acpi_pm_device_sleep_state()
719 for (d_max = d_max_in; d_max > d_min; d_max--) { in acpi_pm_device_sleep_state()
720 if (adev->power.states[d_max].flags.valid) in acpi_pm_device_sleep_state()
733 * acpi_pm_notify_work_func - ACPI devices wakeup notification work function.
734 * @context: Device wakeup context.
738 struct device *dev = context->dev; in acpi_pm_notify_work_func()
751 struct acpi_device_wakeup *wakeup = &adev->wakeup; in __acpi_device_wakeup_enable() local
758 * If the device wakeup power is already enabled, disable it and enable in __acpi_device_wakeup_enable()
763 if (wakeup->enable_count > 0) in __acpi_device_wakeup_enable()
768 if (wakeup->enable_count > 0) { in __acpi_device_wakeup_enable()
769 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number); in __acpi_device_wakeup_enable()
770 wakeup->enable_count = 0; in __acpi_device_wakeup_enable()
775 if (wakeup->enable_count > 0) in __acpi_device_wakeup_enable()
778 status = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number); in __acpi_device_wakeup_enable()
781 error = -EIO; in __acpi_device_wakeup_enable()
785 acpi_handle_debug(adev->handle, "GPE%2X enabled for wakeup\n", in __acpi_device_wakeup_enable()
786 (unsigned int)wakeup->gpe_number); in __acpi_device_wakeup_enable()
789 if (wakeup->enable_count < INT_MAX) in __acpi_device_wakeup_enable()
790 wakeup->enable_count++; in __acpi_device_wakeup_enable()
792 acpi_handle_info(adev->handle, "Wakeup enable count out of bounds!\n"); in __acpi_device_wakeup_enable()
800 * acpi_device_wakeup_enable - Enable wakeup functionality for device.
801 * @adev: ACPI device to enable wakeup functionality for.
804 * Enable the GPE associated with @adev so that it can generate wakeup signals
805 * for the device in response to external (remote) events and enable wakeup
817 * acpi_device_wakeup_disable - Disable wakeup functionality for device.
818 * @adev: ACPI device to disable wakeup functionality for.
820 * Disable the GPE associated with @adev and disable wakeup power for it.
827 struct acpi_device_wakeup *wakeup = &adev->wakeup; in acpi_device_wakeup_disable() local
831 if (!wakeup->enable_count) in acpi_device_wakeup_disable()
834 acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number); in acpi_device_wakeup_disable()
837 wakeup->enable_count--; in acpi_device_wakeup_disable()
844 * acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device.
845 * @dev: Device to enable/disable to generate wakeup events.
846 * @enable: Whether to enable or disable the wakeup functionality.
856 return -ENODEV; in acpi_pm_set_device_wakeup()
860 return -EINVAL; in acpi_pm_set_device_wakeup()
864 dev_dbg(dev, "Wakeup disabled by ACPI\n"); in acpi_pm_set_device_wakeup()
870 dev_dbg(dev, "Wakeup enabled by ACPI\n"); in acpi_pm_set_device_wakeup()
877 * acpi_dev_pm_low_power - Put ACPI device into a low-power state.
878 * @dev: Device to put into a low-power state.
895 * acpi_dev_pm_full_power - Put ACPI device into the full-power state.
896 * @adev: ACPI device node to put into the full-power state.
905 * acpi_dev_suspend - Put device into a low-power state using ACPI.
906 * @dev: Device to put into a low-power state.
907 * @wakeup: Whether or not to enable wakeup for the device.
909 * Put the given device into a low-power state using the standard ACPI
910 * mechanism. Set up remote wakeup if desired, choose the state to put the
911 * device into (this checks if remote wakeup is expected to work too), and set
914 int acpi_dev_suspend(struct device *dev, bool wakeup) in acpi_dev_suspend() argument
923 if (wakeup && acpi_device_can_wakeup(adev)) { in acpi_dev_suspend()
926 return -EAGAIN; in acpi_dev_suspend()
928 wakeup = false; in acpi_dev_suspend()
932 if (error && wakeup) in acpi_dev_suspend()
940 * acpi_dev_resume - Put device into the full-power state using ACPI.
941 * @dev: Device to put into the full-power state.
943 * Put the given device into the full-power state using the standard ACPI
944 * mechanism. Set the power state of the device to ACPI D0 and disable wakeup.
961 * acpi_subsys_runtime_suspend - Suspend device using ACPI.
965 * it into a runtime low-power state.
976 * acpi_subsys_runtime_resume - Resume device using ACPI.
979 * Use ACPI to put the given device into the full-power state and carry out the
996 if (!pm_runtime_suspended(dev) || !adev || (adev->wakeup.flags.valid && in acpi_dev_needs_resume()
997 device_may_wakeup(dev) != !!adev->wakeup.prepare_count)) in acpi_dev_needs_resume()
1003 if (adev->power.flags.dsw_present) in acpi_dev_needs_resume()
1010 return state != adev->power.state; in acpi_dev_needs_resume()
1014 * acpi_subsys_prepare - Prepare device for system transition to a sleep state.
1021 if (dev->driver && dev->driver->pm && dev->driver->pm->prepare) { in acpi_subsys_prepare()
1022 int ret = dev->driver->pm->prepare(dev); in acpi_subsys_prepare()
1036 * acpi_subsys_complete - Finalize device's resume during system resume.
1043 * If the device had been runtime-suspended before the system went into in acpi_subsys_complete()
1053 * acpi_subsys_suspend - Run the device driver's suspend callback.
1057 * system suspend callbacks, unless the driver can cope with runtime-suspended
1058 * devices during system suspend and there are no ACPI-specific reasons for
1072 * acpi_subsys_suspend_late - Suspend device using ACPI.
1076 * it into a low-power state during system transition into a sleep state.
1091 * acpi_subsys_suspend_noirq - Run the device driver's "noirq" suspend callback.
1106 * If the target system sleep state is suspend-to-idle, it is sufficient in acpi_subsys_suspend_noirq()
1107 * to check whether or not the device's wakeup settings are good for in acpi_subsys_suspend_noirq()
1113 dev->power.may_skip_resume = false; in acpi_subsys_suspend_noirq()
1120 * acpi_subsys_resume_noirq - Run the device driver's "noirq" resume callback.
1132 * acpi_subsys_resume_early - Resume device using ACPI.
1135 * Use ACPI to put the given device into the full-power state and carry out the
1143 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; in acpi_subsys_resume_early()
1149 if (pm && !pm->resume_early) { in acpi_subsys_resume_early()
1159 * acpi_subsys_resume - Resume device using ACPI.
1162 * Use ACPI to put the given device into the full-power state if it has not been
1168 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; in acpi_subsys_resume()
1171 if (!dev_pm_skip_resume(dev) && pm && !pm->resume_early) { in acpi_subsys_resume()
1180 * acpi_subsys_freeze - Run the device driver's freeze callback.
1186 * Resume all runtime-suspended devices before creating a snapshot in acpi_subsys_freeze()
1189 * put into the runtime-active metastate during system resume anyway, in acpi_subsys_freeze()
1200 * acpi_subsys_restore_early - Restore device using ACPI.
1212 * acpi_subsys_poweroff - Run the device driver's poweroff callback.
1216 * system poweroff callbacks, unless the driver can cope with runtime-suspended
1217 * devices during system suspend and there are no ACPI-specific reasons for
1231 * acpi_subsys_poweroff_late - Run the device driver's poweroff callback.
1235 * it into a low-power state during system transition into a sleep state.
1252 * acpi_subsys_poweroff_noirq - Run the driver's "noirq" poweroff callback.
1287 * acpi_dev_pm_detach - Remove ACPI power management from the device.
1291 * Remove the device from the general ACPI PM domain and remove its wakeup
1302 if (adev && dev->pm_domain == &acpi_general_pm_domain) { in acpi_dev_pm_detach()
1310 * choice of the low-power state to put the device into. in acpi_dev_pm_detach()
1321 * acpi_dev_pm_attach - Prepare device for ACPI power management.
1326 * attached to it, install a wakeup notification handler for the device and
1367 dev->pm_domain->detach = acpi_dev_pm_detach; in acpi_dev_pm_attach()
1373 * acpi_storage_d3 - Check if D3 should be used in the suspend path
1383 * applied to the PCIe slot and plugging in a non-storage device the