Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | ebe7874 | 2016-06-17 02:13:14 -0700 | [diff] [blame] | 7 | #include <cpu.h> |
| 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 5046109 | 2020-04-08 16:57:35 -0600 | [diff] [blame] | 10 | #include <acpi/acpi_s3.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 11 | #include <acpi/acpi_table.h> |
Bin Meng | 4c762a6 | 2017-04-21 07:24:29 -0700 | [diff] [blame] | 12 | #include <asm/io.h> |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 13 | #include <asm/tables.h> |
Bin Meng | ebe7874 | 2016-06-17 02:13:14 -0700 | [diff] [blame] | 14 | #include <asm/arch/global_nvs.h> |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 15 | #include <asm/arch/iomap.h> |
Simon Glass | 5046109 | 2020-04-08 16:57:35 -0600 | [diff] [blame] | 16 | #include <dm/uclass-internal.h> |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 17 | |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 18 | static int baytrail_write_fadt(struct acpi_ctx *ctx, |
| 19 | const struct acpi_writer *entry) |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 20 | { |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 21 | struct acpi_table_header *header; |
| 22 | struct acpi_fadt *fadt; |
| 23 | |
| 24 | fadt = ctx->current; |
| 25 | header = &fadt->header; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 26 | u16 pmbase = ACPI_BASE_ADDRESS; |
| 27 | |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 28 | memset(fadt, '\0', sizeof(struct acpi_fadt)); |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 29 | |
| 30 | acpi_fill_header(header, "FACP"); |
| 31 | header->length = sizeof(struct acpi_fadt); |
| 32 | header->revision = 4; |
| 33 | |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 34 | fadt->firmware_ctrl = (u32)ctx->facs; |
| 35 | fadt->dsdt = (u32)ctx->dsdt; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 36 | fadt->preferred_pm_profile = ACPI_PM_MOBILE; |
| 37 | fadt->sci_int = 9; |
| 38 | fadt->smi_cmd = 0; |
| 39 | fadt->acpi_enable = 0; |
| 40 | fadt->acpi_disable = 0; |
| 41 | fadt->s4bios_req = 0; |
| 42 | fadt->pstate_cnt = 0; |
| 43 | fadt->pm1a_evt_blk = pmbase; |
| 44 | fadt->pm1b_evt_blk = 0x0; |
| 45 | fadt->pm1a_cnt_blk = pmbase + 0x4; |
| 46 | fadt->pm1b_cnt_blk = 0x0; |
| 47 | fadt->pm2_cnt_blk = pmbase + 0x50; |
| 48 | fadt->pm_tmr_blk = pmbase + 0x8; |
| 49 | fadt->gpe0_blk = pmbase + 0x20; |
| 50 | fadt->gpe1_blk = 0; |
| 51 | fadt->pm1_evt_len = 4; |
| 52 | fadt->pm1_cnt_len = 2; |
| 53 | fadt->pm2_cnt_len = 1; |
| 54 | fadt->pm_tmr_len = 4; |
| 55 | fadt->gpe0_blk_len = 8; |
| 56 | fadt->gpe1_blk_len = 0; |
| 57 | fadt->gpe1_base = 0; |
| 58 | fadt->cst_cnt = 0; |
| 59 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 60 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 61 | fadt->flush_size = 0; |
| 62 | fadt->flush_stride = 0; |
| 63 | fadt->duty_offset = 1; |
| 64 | fadt->duty_width = 0; |
| 65 | fadt->day_alrm = 0x0d; |
| 66 | fadt->mon_alrm = 0x00; |
| 67 | fadt->century = 0x00; |
| 68 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 69 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 70 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 71 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_RESET_REGISTER | |
| 72 | ACPI_FADT_PLATFORM_CLOCK; |
| 73 | |
| 74 | fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO; |
| 75 | fadt->reset_reg.bit_width = 8; |
| 76 | fadt->reset_reg.bit_offset = 0; |
| 77 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 78 | fadt->reset_reg.addrl = IO_PORT_RESET; |
| 79 | fadt->reset_reg.addrh = 0; |
Bin Meng | 62e16c5 | 2017-08-28 22:09:11 -0700 | [diff] [blame] | 80 | fadt->reset_value = SYS_RST | RST_CPU | FULL_RST; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 81 | |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 82 | fadt->x_firmware_ctl_l = (u32)ctx->facs; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 83 | fadt->x_firmware_ctl_h = 0; |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 84 | fadt->x_dsdt_l = (u32)ctx->dsdt; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 85 | fadt->x_dsdt_h = 0; |
| 86 | |
| 87 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 88 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 89 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 90 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 91 | fadt->x_pm1a_evt_blk.addrl = fadt->pm1a_evt_blk; |
| 92 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 93 | |
| 94 | fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 95 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 96 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 97 | fadt->x_pm1b_evt_blk.access_size = 0; |
| 98 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 99 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 100 | |
| 101 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 102 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 103 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 104 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 105 | fadt->x_pm1a_cnt_blk.addrl = fadt->pm1a_cnt_blk; |
| 106 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 107 | |
| 108 | fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 109 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 110 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 111 | fadt->x_pm1b_cnt_blk.access_size = 0; |
| 112 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 113 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 114 | |
| 115 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 116 | fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8; |
| 117 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 118 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 119 | fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk; |
| 120 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 121 | |
| 122 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 123 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 124 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 125 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 126 | fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk; |
| 127 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 128 | |
| 129 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 130 | fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8; |
| 131 | fadt->x_gpe0_blk.bit_offset = 0; |
| 132 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 133 | fadt->x_gpe0_blk.addrl = fadt->gpe0_blk; |
| 134 | fadt->x_gpe0_blk.addrh = 0x0; |
| 135 | |
| 136 | fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 137 | fadt->x_gpe1_blk.bit_width = 0; |
| 138 | fadt->x_gpe1_blk.bit_offset = 0; |
| 139 | fadt->x_gpe1_blk.access_size = 0; |
| 140 | fadt->x_gpe1_blk.addrl = 0x0; |
| 141 | fadt->x_gpe1_blk.addrh = 0x0; |
| 142 | |
| 143 | header->checksum = table_compute_checksum(fadt, header->length); |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 144 | |
| 145 | acpi_add_table(ctx, fadt); |
| 146 | |
| 147 | acpi_inc(ctx, sizeof(struct acpi_fadt)); |
| 148 | |
| 149 | return 0; |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 150 | } |
Simon Glass | c4b5b02 | 2021-12-01 09:02:55 -0700 | [diff] [blame] | 151 | ACPI_WRITER(5fadt, "FACP", baytrail_write_fadt, 0); |
Bin Meng | e9f5a79 | 2016-05-07 07:46:32 -0700 | [diff] [blame] | 152 | |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 153 | int acpi_create_gnvs(struct acpi_global_nvs *gnvs) |
Bin Meng | ebe7874 | 2016-06-17 02:13:14 -0700 | [diff] [blame] | 154 | { |
| 155 | struct udevice *dev; |
| 156 | int ret; |
| 157 | |
| 158 | /* at least we have one processor */ |
| 159 | gnvs->pcnt = 1; |
| 160 | /* override the processor count with actual number */ |
| 161 | ret = uclass_find_first_device(UCLASS_CPU, &dev); |
| 162 | if (ret == 0 && dev != NULL) { |
| 163 | ret = cpu_get_count(dev); |
| 164 | if (ret > 0) |
| 165 | gnvs->pcnt = ret; |
| 166 | } |
| 167 | |
| 168 | /* determine whether internal uart is on */ |
| 169 | if (IS_ENABLED(CONFIG_INTERNAL_UART)) |
| 170 | gnvs->iuart_en = 1; |
| 171 | else |
| 172 | gnvs->iuart_en = 0; |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 173 | |
| 174 | return 0; |
Bin Meng | ebe7874 | 2016-06-17 02:13:14 -0700 | [diff] [blame] | 175 | } |
Bin Meng | 4c762a6 | 2017-04-21 07:24:29 -0700 | [diff] [blame] | 176 | |
Bin Meng | 4c762a6 | 2017-04-21 07:24:29 -0700 | [diff] [blame] | 177 | /* |
| 178 | * The following two routines are called at a very early stage, even before |
| 179 | * FSP 2nd phase API fsp_init() is called. Registers off ACPI_BASE_ADDRESS |
| 180 | * and PMC_BASE_ADDRESS are accessed, so we need make sure the base addresses |
| 181 | * of these two blocks are programmed by either U-Boot or FSP. |
| 182 | * |
Simon Glass | 6c34fc1 | 2019-09-25 08:00:11 -0600 | [diff] [blame] | 183 | * It has been verified that 1st phase API (see arch/x86/lib/fsp1/fsp_car.S) |
Bin Meng | 4c762a6 | 2017-04-21 07:24:29 -0700 | [diff] [blame] | 184 | * on Intel BayTrail SoC already initializes these two base addresses so |
| 185 | * we are safe to access these registers here. |
| 186 | */ |
| 187 | |
| 188 | enum acpi_sleep_state chipset_prev_sleep_state(void) |
| 189 | { |
| 190 | u32 pm1_sts; |
| 191 | u32 pm1_cnt; |
| 192 | u32 gen_pmcon1; |
| 193 | enum acpi_sleep_state prev_sleep_state = ACPI_S0; |
| 194 | |
| 195 | /* Read Power State */ |
| 196 | pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS); |
| 197 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 198 | gen_pmcon1 = readl(PMC_BASE_ADDRESS + GEN_PMCON1); |
| 199 | |
| 200 | debug("PM1_STS = 0x%x PM1_CNT = 0x%x GEN_PMCON1 = 0x%x\n", |
| 201 | pm1_sts, pm1_cnt, gen_pmcon1); |
| 202 | |
| 203 | if (pm1_sts & WAK_STS) |
| 204 | prev_sleep_state = acpi_sleep_from_pm1(pm1_cnt); |
| 205 | |
| 206 | if (gen_pmcon1 & (PWR_FLR | SUS_PWR_FLR)) |
| 207 | prev_sleep_state = ACPI_S5; |
| 208 | |
| 209 | return prev_sleep_state; |
| 210 | } |
| 211 | |
| 212 | void chipset_clear_sleep_state(void) |
| 213 | { |
| 214 | u32 pm1_cnt; |
| 215 | |
| 216 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 217 | outl(pm1_cnt & ~(SLP_TYP), ACPI_BASE_ADDRESS + PM1_CNT); |
| 218 | } |