blob: 7821964f1fca96c385140b3dc48808c47c4609a9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Menge9f5a792016-05-07 07:46:32 -07002/*
3 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
Bin Menge9f5a792016-05-07 07:46:32 -07004 */
5
Bin Mengebe78742016-06-17 02:13:14 -07006#include <cpu.h>
7#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Heinrich Schuchardtec958062023-12-16 09:11:57 +01009#include <mapmem.h>
Simon Glass50461092020-04-08 16:57:35 -060010#include <acpi/acpi_s3.h>
Simon Glass858fed12020-04-08 16:57:36 -060011#include <acpi/acpi_table.h>
Bin Meng4c762a62017-04-21 07:24:29 -070012#include <asm/io.h>
Bin Menge9f5a792016-05-07 07:46:32 -070013#include <asm/tables.h>
Bin Mengebe78742016-06-17 02:13:14 -070014#include <asm/arch/global_nvs.h>
Bin Menge9f5a792016-05-07 07:46:32 -070015#include <asm/arch/iomap.h>
Simon Glass50461092020-04-08 16:57:35 -060016#include <dm/uclass-internal.h>
Bin Menge9f5a792016-05-07 07:46:32 -070017
Simon Glass9bd6b622023-09-01 11:27:09 -060018static int baytrail_write_fadt(struct acpi_ctx *ctx,
19 const struct acpi_writer *entry)
Bin Menge9f5a792016-05-07 07:46:32 -070020{
Simon Glass9bd6b622023-09-01 11:27:09 -060021 struct acpi_table_header *header;
22 struct acpi_fadt *fadt;
23
24 fadt = ctx->current;
25 header = &fadt->header;
Bin Menge9f5a792016-05-07 07:46:32 -070026 u16 pmbase = ACPI_BASE_ADDRESS;
27
Simon Glass9bd6b622023-09-01 11:27:09 -060028 memset(fadt, '\0', sizeof(struct acpi_fadt));
Bin Menge9f5a792016-05-07 07:46:32 -070029
30 acpi_fill_header(header, "FACP");
31 header->length = sizeof(struct acpi_fadt);
32 header->revision = 4;
33
Bin Menge9f5a792016-05-07 07:46:32 -070034 fadt->preferred_pm_profile = ACPI_PM_MOBILE;
35 fadt->sci_int = 9;
36 fadt->smi_cmd = 0;
37 fadt->acpi_enable = 0;
38 fadt->acpi_disable = 0;
39 fadt->s4bios_req = 0;
40 fadt->pstate_cnt = 0;
41 fadt->pm1a_evt_blk = pmbase;
42 fadt->pm1b_evt_blk = 0x0;
43 fadt->pm1a_cnt_blk = pmbase + 0x4;
44 fadt->pm1b_cnt_blk = 0x0;
45 fadt->pm2_cnt_blk = pmbase + 0x50;
46 fadt->pm_tmr_blk = pmbase + 0x8;
47 fadt->gpe0_blk = pmbase + 0x20;
48 fadt->gpe1_blk = 0;
49 fadt->pm1_evt_len = 4;
50 fadt->pm1_cnt_len = 2;
51 fadt->pm2_cnt_len = 1;
52 fadt->pm_tmr_len = 4;
53 fadt->gpe0_blk_len = 8;
54 fadt->gpe1_blk_len = 0;
55 fadt->gpe1_base = 0;
56 fadt->cst_cnt = 0;
57 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
58 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
59 fadt->flush_size = 0;
60 fadt->flush_stride = 0;
61 fadt->duty_offset = 1;
62 fadt->duty_width = 0;
63 fadt->day_alrm = 0x0d;
64 fadt->mon_alrm = 0x00;
65 fadt->century = 0x00;
66 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
67 fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
68 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
69 ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_RESET_REGISTER |
70 ACPI_FADT_PLATFORM_CLOCK;
71
72 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
73 fadt->reset_reg.bit_width = 8;
74 fadt->reset_reg.bit_offset = 0;
75 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
76 fadt->reset_reg.addrl = IO_PORT_RESET;
77 fadt->reset_reg.addrh = 0;
Bin Meng62e16c52017-08-28 22:09:11 -070078 fadt->reset_value = SYS_RST | RST_CPU | FULL_RST;
Bin Menge9f5a792016-05-07 07:46:32 -070079
Heinrich Schuchardtec958062023-12-16 09:11:57 +010080 fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs);
81 fadt->x_dsdt = map_to_sysmem(ctx->dsdt);
Bin Menge9f5a792016-05-07 07:46:32 -070082
83 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
84 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
85 fadt->x_pm1a_evt_blk.bit_offset = 0;
86 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
87 fadt->x_pm1a_evt_blk.addrl = fadt->pm1a_evt_blk;
88 fadt->x_pm1a_evt_blk.addrh = 0x0;
89
90 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
91 fadt->x_pm1b_evt_blk.bit_width = 0;
92 fadt->x_pm1b_evt_blk.bit_offset = 0;
93 fadt->x_pm1b_evt_blk.access_size = 0;
94 fadt->x_pm1b_evt_blk.addrl = 0x0;
95 fadt->x_pm1b_evt_blk.addrh = 0x0;
96
97 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
98 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
99 fadt->x_pm1a_cnt_blk.bit_offset = 0;
100 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
101 fadt->x_pm1a_cnt_blk.addrl = fadt->pm1a_cnt_blk;
102 fadt->x_pm1a_cnt_blk.addrh = 0x0;
103
104 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
105 fadt->x_pm1b_cnt_blk.bit_width = 0;
106 fadt->x_pm1b_cnt_blk.bit_offset = 0;
107 fadt->x_pm1b_cnt_blk.access_size = 0;
108 fadt->x_pm1b_cnt_blk.addrl = 0x0;
109 fadt->x_pm1b_cnt_blk.addrh = 0x0;
110
111 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
112 fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
113 fadt->x_pm2_cnt_blk.bit_offset = 0;
114 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
115 fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk;
116 fadt->x_pm2_cnt_blk.addrh = 0x0;
117
118 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
119 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
120 fadt->x_pm_tmr_blk.bit_offset = 0;
121 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
122 fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk;
123 fadt->x_pm_tmr_blk.addrh = 0x0;
124
125 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
126 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
127 fadt->x_gpe0_blk.bit_offset = 0;
128 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
129 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
130 fadt->x_gpe0_blk.addrh = 0x0;
131
132 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
133 fadt->x_gpe1_blk.bit_width = 0;
134 fadt->x_gpe1_blk.bit_offset = 0;
135 fadt->x_gpe1_blk.access_size = 0;
136 fadt->x_gpe1_blk.addrl = 0x0;
137 fadt->x_gpe1_blk.addrh = 0x0;
138
139 header->checksum = table_compute_checksum(fadt, header->length);
Simon Glass9bd6b622023-09-01 11:27:09 -0600140
Andy Shevchenko6f15ab72023-09-01 11:27:10 -0600141 return acpi_add_fadt(ctx, fadt);
Bin Menge9f5a792016-05-07 07:46:32 -0700142}
Simon Glass9bd6b622023-09-01 11:27:09 -0600143ACPI_WRITER(5fadt, "FADT", baytrail_write_fadt, 0);
Bin Menge9f5a792016-05-07 07:46:32 -0700144
Simon Glass9ed41e72020-07-07 21:32:05 -0600145int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Bin Mengebe78742016-06-17 02:13:14 -0700146{
147 struct udevice *dev;
148 int ret;
149
150 /* at least we have one processor */
151 gnvs->pcnt = 1;
152 /* override the processor count with actual number */
153 ret = uclass_find_first_device(UCLASS_CPU, &dev);
154 if (ret == 0 && dev != NULL) {
155 ret = cpu_get_count(dev);
156 if (ret > 0)
157 gnvs->pcnt = ret;
158 }
159
160 /* determine whether internal uart is on */
161 if (IS_ENABLED(CONFIG_INTERNAL_UART))
162 gnvs->iuart_en = 1;
163 else
164 gnvs->iuart_en = 0;
Simon Glass9ed41e72020-07-07 21:32:05 -0600165
166 return 0;
Bin Mengebe78742016-06-17 02:13:14 -0700167}
Bin Meng4c762a62017-04-21 07:24:29 -0700168
Bin Meng4c762a62017-04-21 07:24:29 -0700169/*
170 * The following two routines are called at a very early stage, even before
171 * FSP 2nd phase API fsp_init() is called. Registers off ACPI_BASE_ADDRESS
172 * and PMC_BASE_ADDRESS are accessed, so we need make sure the base addresses
173 * of these two blocks are programmed by either U-Boot or FSP.
174 *
Simon Glass6c34fc12019-09-25 08:00:11 -0600175 * It has been verified that 1st phase API (see arch/x86/lib/fsp1/fsp_car.S)
Bin Meng4c762a62017-04-21 07:24:29 -0700176 * on Intel BayTrail SoC already initializes these two base addresses so
177 * we are safe to access these registers here.
178 */
179
180enum acpi_sleep_state chipset_prev_sleep_state(void)
181{
182 u32 pm1_sts;
183 u32 pm1_cnt;
184 u32 gen_pmcon1;
185 enum acpi_sleep_state prev_sleep_state = ACPI_S0;
186
187 /* Read Power State */
188 pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS);
189 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
190 gen_pmcon1 = readl(PMC_BASE_ADDRESS + GEN_PMCON1);
191
192 debug("PM1_STS = 0x%x PM1_CNT = 0x%x GEN_PMCON1 = 0x%x\n",
193 pm1_sts, pm1_cnt, gen_pmcon1);
194
195 if (pm1_sts & WAK_STS)
196 prev_sleep_state = acpi_sleep_from_pm1(pm1_cnt);
197
198 if (gen_pmcon1 & (PWR_FLR | SUS_PWR_FLR))
199 prev_sleep_state = ACPI_S5;
200
201 return prev_sleep_state;
202}
203
204void chipset_clear_sleep_state(void)
205{
206 u32 pm1_cnt;
207
208 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
209 outl(pm1_cnt & ~(SLP_TYP), ACPI_BASE_ADDRESS + PM1_CNT);
210}