blob: 86aec0abe0f670e045c68d4284b99d9b98881c53 [file] [log] [blame]
Bin Mengab702be2017-04-21 07:24:28 -07001/*
2 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#ifndef __ASM_ACPI_S3_H__
8#define __ASM_ACPI_S3_H__
9
Bin Meng215596c2017-04-21 07:24:35 -070010#define WAKEUP_BASE 0x600
11
Bin Mengab702be2017-04-21 07:24:28 -070012/* PM1_STATUS register */
13#define WAK_STS (1 << 15)
14#define PCIEXPWAK_STS (1 << 14)
15#define RTC_STS (1 << 10)
16#define SLPBTN_STS (1 << 9)
17#define PWRBTN_STS (1 << 8)
18#define GBL_STS (1 << 5)
19#define BM_STS (1 << 4)
20#define TMR_STS (1 << 0)
21
22/* PM1_CNT register */
23#define SLP_EN (1 << 13)
24#define SLP_TYP_SHIFT 10
25#define SLP_TYP (7 << SLP_TYP_SHIFT)
26#define SLP_TYP_S0 0
27#define SLP_TYP_S1 1
28#define SLP_TYP_S3 5
29#define SLP_TYP_S4 6
30#define SLP_TYP_S5 7
31
Bin Meng353f5cb2017-04-21 07:24:47 -070032/* Memory size reserved for S3 resume */
33#define S3_RESERVE_SIZE 0x1000
34
Bin Meng215596c2017-04-21 07:24:35 -070035#ifndef __ASSEMBLY__
36
37extern char __wakeup[];
38extern int __wakeup_size;
39
Bin Mengab702be2017-04-21 07:24:28 -070040enum acpi_sleep_state {
41 ACPI_S0,
42 ACPI_S1,
43 ACPI_S2,
44 ACPI_S3,
45 ACPI_S4,
46 ACPI_S5,
47};
48
49/**
Bin Mengef61f772017-04-21 07:24:32 -070050 * acpi_ss_string() - get ACPI-defined sleep state string
51 *
52 * @pm1_cnt: ACPI-defined sleep state
53 * @return: a pointer to the sleep state string.
54 */
55static inline char *acpi_ss_string(enum acpi_sleep_state state)
56{
57 char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"};
58
59 return ss_string[state];
60}
61
62/**
Bin Mengab702be2017-04-21 07:24:28 -070063 * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register
64 *
65 * @pm1_cnt: PM1_CNT register value
66 * @return: ACPI-defined sleep state if given valid PM1_CNT register value,
67 * -EINVAL otherwise.
68 */
69static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt)
70{
71 switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
72 case SLP_TYP_S0:
73 return ACPI_S0;
74 case SLP_TYP_S1:
75 return ACPI_S1;
76 case SLP_TYP_S3:
77 return ACPI_S3;
78 case SLP_TYP_S4:
79 return ACPI_S4;
80 case SLP_TYP_S5:
81 return ACPI_S5;
82 }
83
84 return -EINVAL;
85}
86
Bin Mengacb4bf92017-04-21 07:24:31 -070087/**
88 * chipset_prev_sleep_state() - Get chipset previous sleep state
89 *
90 * This returns chipset previous sleep state from ACPI registers.
91 * Platform codes must supply this routine in order to support ACPI S3.
92 *
93 * @return ACPI_S0/S1/S2/S3/S4/S5.
94 */
95enum acpi_sleep_state chipset_prev_sleep_state(void);
96
97/**
98 * chipset_clear_sleep_state() - Clear chipset sleep state
99 *
100 * This clears chipset sleep state in ACPI registers.
101 * Platform codes must supply this routine in order to support ACPI S3.
102 */
103void chipset_clear_sleep_state(void);
104
Bin Meng280aebe2017-04-21 07:24:44 -0700105struct acpi_fadt;
Bin Meng710d2152017-04-21 07:24:37 -0700106/**
107 * acpi_resume() - Do ACPI S3 resume
108 *
109 * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector.
110 *
Bin Meng280aebe2017-04-21 07:24:44 -0700111 * @fadt: FADT table pointer in the ACPI table
Bin Meng710d2152017-04-21 07:24:37 -0700112 * @return: Never returns
113 */
Bin Meng280aebe2017-04-21 07:24:44 -0700114void acpi_resume(struct acpi_fadt *fadt);
Bin Meng710d2152017-04-21 07:24:37 -0700115
Bin Meng353f5cb2017-04-21 07:24:47 -0700116/**
117 * acpi_s3_reserve() - Reserve memory for ACPI S3 resume
118 *
119 * This copies memory where real mode interrupt handler stubs reside to the
120 * reserved place on the stack.
121 *
122 * This routine should be called by reserve_arch() before U-Boot is relocated
123 * when ACPI S3 resume is enabled.
124 *
125 * @return: 0 always
126 */
127int acpi_s3_reserve(void);
128
Bin Meng215596c2017-04-21 07:24:35 -0700129#endif /* __ASSEMBLY__ */
130
Bin Mengab702be2017-04-21 07:24:28 -0700131#endif /* __ASM_ACPI_S3_H__ */