Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __ASM_ACPI_S3_H__ |
| 7 | #define __ASM_ACPI_S3_H__ |
| 8 | |
Bin Meng | 215596c | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 9 | #define WAKEUP_BASE 0x600 |
| 10 | |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 11 | /* PM1_STATUS register */ |
| 12 | #define WAK_STS (1 << 15) |
| 13 | #define PCIEXPWAK_STS (1 << 14) |
| 14 | #define RTC_STS (1 << 10) |
| 15 | #define SLPBTN_STS (1 << 9) |
| 16 | #define PWRBTN_STS (1 << 8) |
| 17 | #define GBL_STS (1 << 5) |
| 18 | #define BM_STS (1 << 4) |
| 19 | #define TMR_STS (1 << 0) |
| 20 | |
| 21 | /* PM1_CNT register */ |
| 22 | #define SLP_EN (1 << 13) |
| 23 | #define SLP_TYP_SHIFT 10 |
| 24 | #define SLP_TYP (7 << SLP_TYP_SHIFT) |
| 25 | #define SLP_TYP_S0 0 |
| 26 | #define SLP_TYP_S1 1 |
| 27 | #define SLP_TYP_S3 5 |
| 28 | #define SLP_TYP_S4 6 |
| 29 | #define SLP_TYP_S5 7 |
| 30 | |
Simon Glass | b16dbec | 2020-09-22 12:45:19 -0600 | [diff] [blame] | 31 | /* PM1_STS register */ |
| 32 | #define RTC_EN BIT(10) |
| 33 | #define PWRBTN_EN BIT(8) |
| 34 | |
Bin Meng | 353f5cb | 2017-04-21 07:24:47 -0700 | [diff] [blame] | 35 | /* Memory size reserved for S3 resume */ |
| 36 | #define S3_RESERVE_SIZE 0x1000 |
| 37 | |
Bin Meng | 215596c | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 38 | #ifndef __ASSEMBLY__ |
| 39 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 40 | #include <linux/errno.h> |
| 41 | #include <linux/types.h> |
| 42 | |
Bin Meng | 215596c | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 43 | extern char __wakeup[]; |
| 44 | extern int __wakeup_size; |
| 45 | |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 46 | enum acpi_sleep_state { |
| 47 | ACPI_S0, |
| 48 | ACPI_S1, |
| 49 | ACPI_S2, |
| 50 | ACPI_S3, |
| 51 | ACPI_S4, |
| 52 | ACPI_S5, |
| 53 | }; |
| 54 | |
| 55 | /** |
Bin Meng | ef61f77 | 2017-04-21 07:24:32 -0700 | [diff] [blame] | 56 | * acpi_ss_string() - get ACPI-defined sleep state string |
| 57 | * |
| 58 | * @pm1_cnt: ACPI-defined sleep state |
| 59 | * @return: a pointer to the sleep state string. |
| 60 | */ |
| 61 | static inline char *acpi_ss_string(enum acpi_sleep_state state) |
| 62 | { |
| 63 | char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"}; |
| 64 | |
| 65 | return ss_string[state]; |
| 66 | } |
| 67 | |
| 68 | /** |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 69 | * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register |
| 70 | * |
| 71 | * @pm1_cnt: PM1_CNT register value |
| 72 | * @return: ACPI-defined sleep state if given valid PM1_CNT register value, |
| 73 | * -EINVAL otherwise. |
| 74 | */ |
| 75 | static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt) |
| 76 | { |
| 77 | switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) { |
| 78 | case SLP_TYP_S0: |
| 79 | return ACPI_S0; |
| 80 | case SLP_TYP_S1: |
| 81 | return ACPI_S1; |
| 82 | case SLP_TYP_S3: |
| 83 | return ACPI_S3; |
| 84 | case SLP_TYP_S4: |
| 85 | return ACPI_S4; |
| 86 | case SLP_TYP_S5: |
| 87 | return ACPI_S5; |
| 88 | } |
| 89 | |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 93 | /** |
| 94 | * chipset_prev_sleep_state() - Get chipset previous sleep state |
| 95 | * |
| 96 | * This returns chipset previous sleep state from ACPI registers. |
| 97 | * Platform codes must supply this routine in order to support ACPI S3. |
| 98 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 99 | * Return: ACPI_S0/S1/S2/S3/S4/S5. |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 100 | */ |
| 101 | enum acpi_sleep_state chipset_prev_sleep_state(void); |
| 102 | |
| 103 | /** |
| 104 | * chipset_clear_sleep_state() - Clear chipset sleep state |
| 105 | * |
| 106 | * This clears chipset sleep state in ACPI registers. |
| 107 | * Platform codes must supply this routine in order to support ACPI S3. |
| 108 | */ |
| 109 | void chipset_clear_sleep_state(void); |
| 110 | |
Bin Meng | 280aebe | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 111 | struct acpi_fadt; |
Bin Meng | 710d215 | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 112 | /** |
| 113 | * acpi_resume() - Do ACPI S3 resume |
| 114 | * |
| 115 | * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector. |
| 116 | * |
Bin Meng | 280aebe | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 117 | * @fadt: FADT table pointer in the ACPI table |
Bin Meng | 710d215 | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 118 | * @return: Never returns |
| 119 | */ |
Bin Meng | 280aebe | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 120 | void acpi_resume(struct acpi_fadt *fadt); |
Bin Meng | 710d215 | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 121 | |
Bin Meng | 353f5cb | 2017-04-21 07:24:47 -0700 | [diff] [blame] | 122 | /** |
| 123 | * acpi_s3_reserve() - Reserve memory for ACPI S3 resume |
| 124 | * |
| 125 | * This copies memory where real mode interrupt handler stubs reside to the |
| 126 | * reserved place on the stack. |
| 127 | * |
| 128 | * This routine should be called by reserve_arch() before U-Boot is relocated |
| 129 | * when ACPI S3 resume is enabled. |
| 130 | * |
| 131 | * @return: 0 always |
| 132 | */ |
| 133 | int acpi_s3_reserve(void); |
| 134 | |
Bin Meng | 215596c | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 135 | #endif /* __ASSEMBLY__ */ |
| 136 | |
Bin Meng | ab702be | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 137 | #endif /* __ASM_ACPI_S3_H__ */ |