blob: 847139baa0cc4da5c2a6ff2c64a2450497c325ca [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Bin Mengab702be2017-04-21 07:24:28 -07002/*
3 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
Bin Mengab702be2017-04-21 07:24:28 -07004 */
5
6#ifndef __ASM_ACPI_S3_H__
7#define __ASM_ACPI_S3_H__
8
Bin Meng215596c2017-04-21 07:24:35 -07009#define WAKEUP_BASE 0x600
10
Bin Mengab702be2017-04-21 07:24:28 -070011/* 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 Glassb16dbec2020-09-22 12:45:19 -060031/* PM1_STS register */
32#define RTC_EN BIT(10)
33#define PWRBTN_EN BIT(8)
34
Bin Meng353f5cb2017-04-21 07:24:47 -070035/* Memory size reserved for S3 resume */
36#define S3_RESERVE_SIZE 0x1000
37
Bin Meng215596c2017-04-21 07:24:35 -070038#ifndef __ASSEMBLY__
39
40extern char __wakeup[];
41extern int __wakeup_size;
42
Bin Mengab702be2017-04-21 07:24:28 -070043enum acpi_sleep_state {
44 ACPI_S0,
45 ACPI_S1,
46 ACPI_S2,
47 ACPI_S3,
48 ACPI_S4,
49 ACPI_S5,
50};
51
52/**
Bin Mengef61f772017-04-21 07:24:32 -070053 * acpi_ss_string() - get ACPI-defined sleep state string
54 *
55 * @pm1_cnt: ACPI-defined sleep state
56 * @return: a pointer to the sleep state string.
57 */
58static inline char *acpi_ss_string(enum acpi_sleep_state state)
59{
60 char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"};
61
62 return ss_string[state];
63}
64
65/**
Bin Mengab702be2017-04-21 07:24:28 -070066 * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register
67 *
68 * @pm1_cnt: PM1_CNT register value
69 * @return: ACPI-defined sleep state if given valid PM1_CNT register value,
70 * -EINVAL otherwise.
71 */
72static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt)
73{
74 switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
75 case SLP_TYP_S0:
76 return ACPI_S0;
77 case SLP_TYP_S1:
78 return ACPI_S1;
79 case SLP_TYP_S3:
80 return ACPI_S3;
81 case SLP_TYP_S4:
82 return ACPI_S4;
83 case SLP_TYP_S5:
84 return ACPI_S5;
85 }
86
87 return -EINVAL;
88}
89
Bin Mengacb4bf92017-04-21 07:24:31 -070090/**
91 * chipset_prev_sleep_state() - Get chipset previous sleep state
92 *
93 * This returns chipset previous sleep state from ACPI registers.
94 * Platform codes must supply this routine in order to support ACPI S3.
95 *
96 * @return ACPI_S0/S1/S2/S3/S4/S5.
97 */
98enum acpi_sleep_state chipset_prev_sleep_state(void);
99
100/**
101 * chipset_clear_sleep_state() - Clear chipset sleep state
102 *
103 * This clears chipset sleep state in ACPI registers.
104 * Platform codes must supply this routine in order to support ACPI S3.
105 */
106void chipset_clear_sleep_state(void);
107
Bin Meng280aebe2017-04-21 07:24:44 -0700108struct acpi_fadt;
Bin Meng710d2152017-04-21 07:24:37 -0700109/**
110 * acpi_resume() - Do ACPI S3 resume
111 *
112 * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector.
113 *
Bin Meng280aebe2017-04-21 07:24:44 -0700114 * @fadt: FADT table pointer in the ACPI table
Bin Meng710d2152017-04-21 07:24:37 -0700115 * @return: Never returns
116 */
Bin Meng280aebe2017-04-21 07:24:44 -0700117void acpi_resume(struct acpi_fadt *fadt);
Bin Meng710d2152017-04-21 07:24:37 -0700118
Bin Meng353f5cb2017-04-21 07:24:47 -0700119/**
120 * acpi_s3_reserve() - Reserve memory for ACPI S3 resume
121 *
122 * This copies memory where real mode interrupt handler stubs reside to the
123 * reserved place on the stack.
124 *
125 * This routine should be called by reserve_arch() before U-Boot is relocated
126 * when ACPI S3 resume is enabled.
127 *
128 * @return: 0 always
129 */
130int acpi_s3_reserve(void);
131
Bin Meng215596c2017-04-21 07:24:35 -0700132#endif /* __ASSEMBLY__ */
133
Bin Mengab702be2017-04-21 07:24:28 -0700134#endif /* __ASM_ACPI_S3_H__ */