| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * pm.h - Power management interface |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2000 Andrew Henroid |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | 6 | */ |
|---|
| 20 | 7 | |
|---|
| 21 | 8 | #ifndef _LINUX_PM_H |
|---|
| .. | .. |
|---|
| 26 | 13 | #include <linux/spinlock.h> |
|---|
| 27 | 14 | #include <linux/wait.h> |
|---|
| 28 | 15 | #include <linux/timer.h> |
|---|
| 16 | +#include <linux/hrtimer.h> |
|---|
| 29 | 17 | #include <linux/completion.h> |
|---|
| 18 | +#include <linux/android_kabi.h> |
|---|
| 30 | 19 | |
|---|
| 31 | 20 | /* |
|---|
| 32 | 21 | * Callbacks for platform drivers to implement. |
|---|
| .. | .. |
|---|
| 283 | 272 | * actions to be performed by a device driver's callbacks generally depend on |
|---|
| 284 | 273 | * the platform and subsystem the device belongs to. |
|---|
| 285 | 274 | * |
|---|
| 286 | | - * Refer to Documentation/power/runtime_pm.txt for more information about the |
|---|
| 275 | + * Refer to Documentation/power/runtime_pm.rst for more information about the |
|---|
| 287 | 276 | * role of the @runtime_suspend(), @runtime_resume() and @runtime_idle() |
|---|
| 288 | 277 | * callbacks in device runtime power management. |
|---|
| 289 | 278 | */ |
|---|
| .. | .. |
|---|
| 311 | 300 | int (*runtime_suspend)(struct device *dev); |
|---|
| 312 | 301 | int (*runtime_resume)(struct device *dev); |
|---|
| 313 | 302 | int (*runtime_idle)(struct device *dev); |
|---|
| 303 | + |
|---|
| 304 | + ANDROID_KABI_RESERVE(1); |
|---|
| 314 | 305 | }; |
|---|
| 315 | 306 | |
|---|
| 316 | 307 | #ifdef CONFIG_PM_SLEEP |
|---|
| .. | .. |
|---|
| 363 | 354 | * to RAM and hibernation. |
|---|
| 364 | 355 | */ |
|---|
| 365 | 356 | #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ |
|---|
| 366 | | -const struct dev_pm_ops name = { \ |
|---|
| 357 | +const struct dev_pm_ops __maybe_unused name = { \ |
|---|
| 367 | 358 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ |
|---|
| 368 | 359 | } |
|---|
| 369 | 360 | |
|---|
| .. | .. |
|---|
| 381 | 372 | * .runtime_resume(), respectively (and analogously for hibernation). |
|---|
| 382 | 373 | */ |
|---|
| 383 | 374 | #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \ |
|---|
| 384 | | -const struct dev_pm_ops name = { \ |
|---|
| 375 | +const struct dev_pm_ops __maybe_unused name = { \ |
|---|
| 385 | 376 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ |
|---|
| 386 | 377 | SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ |
|---|
| 387 | 378 | } |
|---|
| 379 | + |
|---|
| 380 | +#ifdef CONFIG_PM |
|---|
| 381 | +#define pm_ptr(_ptr) (_ptr) |
|---|
| 382 | +#else |
|---|
| 383 | +#define pm_ptr(_ptr) NULL |
|---|
| 384 | +#endif |
|---|
| 388 | 385 | |
|---|
| 389 | 386 | /* |
|---|
| 390 | 387 | * PM_EVENT_ messages |
|---|
| .. | .. |
|---|
| 556 | 553 | * These flags can be set by device drivers at the probe time. They need not be |
|---|
| 557 | 554 | * cleared by the drivers as the driver core will take care of that. |
|---|
| 558 | 555 | * |
|---|
| 559 | | - * NEVER_SKIP: Do not skip all system suspend/resume callbacks for the device. |
|---|
| 560 | | - * SMART_PREPARE: Check the return value of the driver's ->prepare callback. |
|---|
| 561 | | - * SMART_SUSPEND: No need to resume the device from runtime suspend. |
|---|
| 562 | | - * LEAVE_SUSPENDED: Avoid resuming the device during system resume if possible. |
|---|
| 556 | + * NO_DIRECT_COMPLETE: Do not apply direct-complete optimization to the device. |
|---|
| 557 | + * SMART_PREPARE: Take the driver ->prepare callback return value into account. |
|---|
| 558 | + * SMART_SUSPEND: Avoid resuming the device from runtime suspend. |
|---|
| 559 | + * MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipped. |
|---|
| 563 | 560 | * |
|---|
| 564 | | - * Setting SMART_PREPARE instructs bus types and PM domains which may want |
|---|
| 565 | | - * system suspend/resume callbacks to be skipped for the device to return 0 from |
|---|
| 566 | | - * their ->prepare callbacks if the driver's ->prepare callback returns 0 (in |
|---|
| 567 | | - * other words, the system suspend/resume callbacks can only be skipped for the |
|---|
| 568 | | - * device if its driver doesn't object against that). This flag has no effect |
|---|
| 569 | | - * if NEVER_SKIP is set. |
|---|
| 570 | | - * |
|---|
| 571 | | - * Setting SMART_SUSPEND instructs bus types and PM domains which may want to |
|---|
| 572 | | - * runtime resume the device upfront during system suspend that doing so is not |
|---|
| 573 | | - * necessary from the driver's perspective. It also may cause them to skip |
|---|
| 574 | | - * invocations of the ->suspend_late and ->suspend_noirq callbacks provided by |
|---|
| 575 | | - * the driver if they decide to leave the device in runtime suspend. |
|---|
| 576 | | - * |
|---|
| 577 | | - * Setting LEAVE_SUSPENDED informs the PM core and middle-layer code that the |
|---|
| 578 | | - * driver prefers the device to be left in suspend after system resume. |
|---|
| 561 | + * See Documentation/driver-api/pm/devices.rst for details. |
|---|
| 579 | 562 | */ |
|---|
| 580 | | -#define DPM_FLAG_NEVER_SKIP BIT(0) |
|---|
| 563 | +#define DPM_FLAG_NO_DIRECT_COMPLETE BIT(0) |
|---|
| 581 | 564 | #define DPM_FLAG_SMART_PREPARE BIT(1) |
|---|
| 582 | 565 | #define DPM_FLAG_SMART_SUSPEND BIT(2) |
|---|
| 583 | | -#define DPM_FLAG_LEAVE_SUSPENDED BIT(3) |
|---|
| 566 | +#define DPM_FLAG_MAY_SKIP_RESUME BIT(3) |
|---|
| 584 | 567 | |
|---|
| 585 | 568 | struct dev_pm_info { |
|---|
| 586 | 569 | pm_message_t power_state; |
|---|
| .. | .. |
|---|
| 609 | 592 | unsigned int should_wakeup:1; |
|---|
| 610 | 593 | #endif |
|---|
| 611 | 594 | #ifdef CONFIG_PM |
|---|
| 612 | | - struct timer_list suspend_timer; |
|---|
| 613 | | - unsigned long timer_expires; |
|---|
| 595 | + struct hrtimer suspend_timer; |
|---|
| 596 | + u64 timer_expires; |
|---|
| 614 | 597 | struct work_struct work; |
|---|
| 615 | 598 | wait_queue_head_t wait_queue; |
|---|
| 616 | 599 | struct wake_irq *wakeirq; |
|---|
| .. | .. |
|---|
| 620 | 603 | unsigned int idle_notification:1; |
|---|
| 621 | 604 | unsigned int request_pending:1; |
|---|
| 622 | 605 | unsigned int deferred_resume:1; |
|---|
| 606 | + unsigned int needs_force_resume:1; |
|---|
| 623 | 607 | unsigned int runtime_auto:1; |
|---|
| 624 | 608 | bool ignore_children:1; |
|---|
| 625 | 609 | unsigned int no_callbacks:1; |
|---|
| .. | .. |
|---|
| 632 | 616 | enum rpm_status runtime_status; |
|---|
| 633 | 617 | int runtime_error; |
|---|
| 634 | 618 | int autosuspend_delay; |
|---|
| 635 | | - unsigned long last_busy; |
|---|
| 636 | | - unsigned long active_jiffies; |
|---|
| 637 | | - unsigned long suspended_jiffies; |
|---|
| 638 | | - unsigned long accounting_timestamp; |
|---|
| 619 | + u64 last_busy; |
|---|
| 620 | + u64 active_time; |
|---|
| 621 | + u64 suspended_time; |
|---|
| 622 | + u64 accounting_timestamp; |
|---|
| 639 | 623 | #endif |
|---|
| 640 | 624 | struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ |
|---|
| 641 | 625 | void (*set_latency_tolerance)(struct device *, s32); |
|---|
| 642 | 626 | struct dev_pm_qos *qos; |
|---|
| 627 | + |
|---|
| 628 | + ANDROID_KABI_RESERVE(1); |
|---|
| 629 | + ANDROID_KABI_RESERVE(2); |
|---|
| 643 | 630 | }; |
|---|
| 644 | 631 | |
|---|
| 645 | | -extern void update_pm_runtime_accounting(struct device *dev); |
|---|
| 646 | 632 | extern int dev_pm_get_subsys_data(struct device *dev); |
|---|
| 647 | 633 | extern void dev_pm_put_subsys_data(struct device *dev); |
|---|
| 648 | 634 | |
|---|
| .. | .. |
|---|
| 650 | 636 | * struct dev_pm_domain - power management domain representation. |
|---|
| 651 | 637 | * |
|---|
| 652 | 638 | * @ops: Power management operations associated with this domain. |
|---|
| 639 | + * @start: Called when a user needs to start the device via the domain. |
|---|
| 653 | 640 | * @detach: Called when removing a device from the domain. |
|---|
| 654 | 641 | * @activate: Called before executing probe routines for bus types and drivers. |
|---|
| 655 | 642 | * @sync: Called after successful driver probe. |
|---|
| .. | .. |
|---|
| 661 | 648 | */ |
|---|
| 662 | 649 | struct dev_pm_domain { |
|---|
| 663 | 650 | struct dev_pm_ops ops; |
|---|
| 651 | + int (*start)(struct device *dev); |
|---|
| 664 | 652 | void (*detach)(struct device *dev, bool power_off); |
|---|
| 665 | 653 | int (*activate)(struct device *dev); |
|---|
| 666 | 654 | void (*sync)(struct device *dev); |
|---|
| 667 | 655 | void (*dismiss)(struct device *dev); |
|---|
| 656 | + |
|---|
| 657 | + ANDROID_KABI_RESERVE(1); |
|---|
| 668 | 658 | }; |
|---|
| 669 | 659 | |
|---|
| 670 | 660 | /* |
|---|
| .. | .. |
|---|
| 725 | 715 | extern void device_pm_lock(void); |
|---|
| 726 | 716 | extern void dpm_resume_start(pm_message_t state); |
|---|
| 727 | 717 | extern void dpm_resume_end(pm_message_t state); |
|---|
| 728 | | -extern void dpm_noirq_resume_devices(pm_message_t state); |
|---|
| 729 | | -extern void dpm_noirq_end(void); |
|---|
| 730 | 718 | extern void dpm_resume_noirq(pm_message_t state); |
|---|
| 731 | 719 | extern void dpm_resume_early(pm_message_t state); |
|---|
| 732 | 720 | extern void dpm_resume(pm_message_t state); |
|---|
| .. | .. |
|---|
| 735 | 723 | extern void device_pm_unlock(void); |
|---|
| 736 | 724 | extern int dpm_suspend_end(pm_message_t state); |
|---|
| 737 | 725 | extern int dpm_suspend_start(pm_message_t state); |
|---|
| 738 | | -extern void dpm_noirq_begin(void); |
|---|
| 739 | | -extern int dpm_noirq_suspend_devices(pm_message_t state); |
|---|
| 740 | 726 | extern int dpm_suspend_noirq(pm_message_t state); |
|---|
| 741 | 727 | extern int dpm_suspend_late(pm_message_t state); |
|---|
| 742 | 728 | extern int dpm_suspend(pm_message_t state); |
|---|
| .. | .. |
|---|
| 773 | 759 | extern int pm_generic_poweroff(struct device *dev); |
|---|
| 774 | 760 | extern void pm_generic_complete(struct device *dev); |
|---|
| 775 | 761 | |
|---|
| 776 | | -extern void dev_pm_skip_next_resume_phases(struct device *dev); |
|---|
| 777 | | -extern bool dev_pm_may_skip_resume(struct device *dev); |
|---|
| 778 | | -extern bool dev_pm_smart_suspend_and_suspended(struct device *dev); |
|---|
| 762 | +extern bool dev_pm_skip_resume(struct device *dev); |
|---|
| 763 | +extern bool dev_pm_skip_suspend(struct device *dev); |
|---|
| 779 | 764 | |
|---|
| 780 | 765 | #else /* !CONFIG_PM_SLEEP */ |
|---|
| 781 | 766 | |
|---|