Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Bin Meng | 4372c11 | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 4372c11 | 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 | 2b2d666 | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 9 | #define WAKEUP_BASE 0x600 |
| 10 | |
Bin Meng | 4372c11 | 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 | |
Bin Meng | 5ae5aa9 | 2017-04-21 07:24:47 -0700 | [diff] [blame] | 31 | /* Memory size reserved for S3 resume */ |
| 32 | #define S3_RESERVE_SIZE 0x1000 |
| 33 | |
Bin Meng | 2b2d666 | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 34 | #ifndef __ASSEMBLY__ |
| 35 | |
| 36 | extern char __wakeup[]; |
| 37 | extern int __wakeup_size; |
| 38 | |
Bin Meng | 4372c11 | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 39 | enum acpi_sleep_state { |
| 40 | ACPI_S0, |
| 41 | ACPI_S1, |
| 42 | ACPI_S2, |
| 43 | ACPI_S3, |
| 44 | ACPI_S4, |
| 45 | ACPI_S5, |
| 46 | }; |
| 47 | |
| 48 | /** |
Bin Meng | b727961 | 2017-04-21 07:24:32 -0700 | [diff] [blame] | 49 | * acpi_ss_string() - get ACPI-defined sleep state string |
| 50 | * |
| 51 | * @pm1_cnt: ACPI-defined sleep state |
| 52 | * @return: a pointer to the sleep state string. |
| 53 | */ |
| 54 | static inline char *acpi_ss_string(enum acpi_sleep_state state) |
| 55 | { |
| 56 | char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"}; |
| 57 | |
| 58 | return ss_string[state]; |
| 59 | } |
| 60 | |
| 61 | /** |
Bin Meng | 4372c11 | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 62 | * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register |
| 63 | * |
| 64 | * @pm1_cnt: PM1_CNT register value |
| 65 | * @return: ACPI-defined sleep state if given valid PM1_CNT register value, |
| 66 | * -EINVAL otherwise. |
| 67 | */ |
| 68 | static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt) |
| 69 | { |
| 70 | switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) { |
| 71 | case SLP_TYP_S0: |
| 72 | return ACPI_S0; |
| 73 | case SLP_TYP_S1: |
| 74 | return ACPI_S1; |
| 75 | case SLP_TYP_S3: |
| 76 | return ACPI_S3; |
| 77 | case SLP_TYP_S4: |
| 78 | return ACPI_S4; |
| 79 | case SLP_TYP_S5: |
| 80 | return ACPI_S5; |
| 81 | } |
| 82 | |
| 83 | return -EINVAL; |
| 84 | } |
| 85 | |
Bin Meng | 1206723 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 86 | /** |
| 87 | * chipset_prev_sleep_state() - Get chipset previous sleep state |
| 88 | * |
| 89 | * This returns chipset previous sleep state from ACPI registers. |
| 90 | * Platform codes must supply this routine in order to support ACPI S3. |
| 91 | * |
| 92 | * @return ACPI_S0/S1/S2/S3/S4/S5. |
| 93 | */ |
| 94 | enum acpi_sleep_state chipset_prev_sleep_state(void); |
| 95 | |
| 96 | /** |
| 97 | * chipset_clear_sleep_state() - Clear chipset sleep state |
| 98 | * |
| 99 | * This clears chipset sleep state in ACPI registers. |
| 100 | * Platform codes must supply this routine in order to support ACPI S3. |
| 101 | */ |
| 102 | void chipset_clear_sleep_state(void); |
| 103 | |
Bin Meng | 0f4e258 | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 104 | struct acpi_fadt; |
Bin Meng | 3a34cae | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 105 | /** |
| 106 | * acpi_resume() - Do ACPI S3 resume |
| 107 | * |
| 108 | * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector. |
| 109 | * |
Bin Meng | 0f4e258 | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 110 | * @fadt: FADT table pointer in the ACPI table |
Bin Meng | 3a34cae | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 111 | * @return: Never returns |
| 112 | */ |
Bin Meng | 0f4e258 | 2017-04-21 07:24:44 -0700 | [diff] [blame] | 113 | void acpi_resume(struct acpi_fadt *fadt); |
Bin Meng | 3a34cae | 2017-04-21 07:24:37 -0700 | [diff] [blame] | 114 | |
Bin Meng | 5ae5aa9 | 2017-04-21 07:24:47 -0700 | [diff] [blame] | 115 | /** |
| 116 | * acpi_s3_reserve() - Reserve memory for ACPI S3 resume |
| 117 | * |
| 118 | * This copies memory where real mode interrupt handler stubs reside to the |
| 119 | * reserved place on the stack. |
| 120 | * |
| 121 | * This routine should be called by reserve_arch() before U-Boot is relocated |
| 122 | * when ACPI S3 resume is enabled. |
| 123 | * |
| 124 | * @return: 0 always |
| 125 | */ |
| 126 | int acpi_s3_reserve(void); |
| 127 | |
Bin Meng | 2b2d666 | 2017-04-21 07:24:35 -0700 | [diff] [blame] | 128 | #endif /* __ASSEMBLY__ */ |
| 129 | |
Bin Meng | 4372c11 | 2017-04-21 07:24:28 -0700 | [diff] [blame] | 130 | #endif /* __ASM_ACPI_S3_H__ */ |