Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * ACPI - create the Fixed ACPI Description Tables (FADT) |
| 5 | */ |
| 6 | |
| 7 | #include <string.h> |
| 8 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 9 | #include <acpi/acpi.h> |
| 10 | #include <acpi/acpigen.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Marc Jones | 5ebc865 | 2017-06-19 23:34:04 -0600 | [diff] [blame] | 12 | #include <arch/ioapic.h> |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 13 | #include <cpu/x86/smm.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 14 | #include <cbmem.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 15 | #include <device/device.h> |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 16 | #include <device/pci.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 17 | #include <amdblocks/acpimmio.h> |
Marshall Dawson | 4ee83b2 | 2019-05-03 11:44:22 -0600 | [diff] [blame] | 18 | #include <amdblocks/acpi.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 19 | #include <soc/acpi.h> |
Chris Ching | 6a35fab | 2017-10-19 11:45:30 -0600 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 21 | #include <soc/southbridge.h> |
Patrick Georgi | 4fbefc5 | 2018-10-23 14:35:37 +0200 | [diff] [blame] | 22 | #include <soc/northbridge.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 23 | #include <soc/nvs.h> |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 24 | #include <soc/gpio.h> |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 25 | #include <version.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 26 | |
Marc Jones | 5ebc865 | 2017-06-19 23:34:04 -0600 | [diff] [blame] | 27 | unsigned long acpi_fill_madt(unsigned long current) |
| 28 | { |
| 29 | /* create all subtables for processors */ |
| 30 | current = acpi_create_madt_lapics(current); |
| 31 | |
| 32 | /* Write Kern IOAPIC, only one */ |
| 33 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, |
| 34 | CONFIG_MAX_CPUS, IO_APIC_ADDR, 0); |
| 35 | |
| 36 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, |
| 37 | CONFIG_MAX_CPUS+1, IO_APIC2_ADDR, 24); |
| 38 | |
| 39 | /* 0: mean bus 0--->ISA */ |
| 40 | /* 0: PIC 0 */ |
| 41 | /* 2: APIC 2 */ |
| 42 | /* 5 mean: 0101 --> Edge-triggered, Active high */ |
| 43 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 44 | current, 0, 0, 2, 0); |
| 45 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
Marshall Dawson | ecce847 | 2018-10-05 15:41:03 -0600 | [diff] [blame] | 46 | current, 0, 9, 9, 0xf); |
Marc Jones | 5ebc865 | 2017-06-19 23:34:04 -0600 | [diff] [blame] | 47 | |
| 48 | /* create all subtables for processors */ |
| 49 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, |
| 50 | 0xff, 5, 1); |
| 51 | /* 1: LINT1 connect to NMI */ |
| 52 | |
| 53 | return current; |
| 54 | } |
| 55 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 56 | /* |
| 57 | * Reference section 5.2.9 Fixed ACPI Description Table (FADT) |
| 58 | * in the ACPI 3.0b specification. |
| 59 | */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 60 | void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 61 | { |
| 62 | acpi_header_t *header = &(fadt->header); |
| 63 | |
| 64 | printk(BIOS_DEBUG, "pm_base: 0x%04x\n", STONEYRIDGE_ACPI_IO_BASE); |
| 65 | |
| 66 | /* Prepare the header */ |
| 67 | memset((void *)fadt, 0, sizeof(acpi_fadt_t)); |
| 68 | memcpy(header->signature, "FACP", 4); |
| 69 | header->length = sizeof(acpi_fadt_t); |
Marc Jones | f9ea7ed | 2018-08-22 18:59:26 -0600 | [diff] [blame] | 70 | header->revision = get_acpi_table_revision(FADT); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 71 | memcpy(header->oem_id, OEM_ID, 6); |
| 72 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 73 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 74 | header->asl_compiler_revision = asl_revision; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 75 | |
| 76 | fadt->firmware_ctrl = (u32) facs; |
| 77 | fadt->dsdt = (u32) dsdt; |
Elyes HAOUAS | 0d4de2a | 2019-02-28 13:04:29 +0100 | [diff] [blame] | 78 | fadt->reserved = 0; /* reserved, should be 0 ACPI 3.0 */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 79 | fadt->preferred_pm_profile = FADT_PM_PROFILE; |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 80 | fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 81 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame^] | 82 | if (permanent_smi_handler()) { |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 83 | fadt->smi_cmd = APM_CNT; |
| 84 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 85 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK; |
| 89 | fadt->pm1b_evt_blk = 0x0000; |
| 90 | fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK; |
| 91 | fadt->pm1b_cnt_blk = 0x0000; |
| 92 | fadt->pm2_cnt_blk = 0x0000; |
| 93 | fadt->pm_tmr_blk = ACPI_PM_TMR_BLK; |
| 94 | fadt->gpe0_blk = ACPI_GPE0_BLK; |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 95 | fadt->gpe1_blk = 0x0000; /* No gpe1 block */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 96 | |
| 97 | fadt->pm1_evt_len = 4; /* 32 bits */ |
| 98 | fadt->pm1_cnt_len = 2; /* 16 bits */ |
| 99 | fadt->pm2_cnt_len = 0; |
| 100 | fadt->pm_tmr_len = 4; /* 32 bits */ |
| 101 | fadt->gpe0_blk_len = 8; /* 64 bits */ |
| 102 | fadt->gpe1_blk_len = 0; |
| 103 | fadt->gpe1_base = 0; |
| 104 | |
| 105 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 106 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 107 | fadt->flush_size = 0; /* set to 0 if WBINVD is 1 in flags */ |
| 108 | fadt->flush_stride = 0; /* set to 0 if WBINVD is 1 in flags */ |
| 109 | fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */ |
| 110 | fadt->duty_width = 3; /* CLK_VAL bits 3:1 */ |
| 111 | fadt->day_alrm = 0; /* 0x7d these have to be */ |
| 112 | fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */ |
| 113 | fadt->century = 0; /* 0x7f to make rtc alarm work */ |
| 114 | fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */ |
| 115 | fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
| 116 | fadt->flags = ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */ |
| 117 | ACPI_FADT_C1_SUPPORTED | |
| 118 | ACPI_FADT_SLEEP_BUTTON | |
| 119 | ACPI_FADT_S4_RTC_WAKE | |
| 120 | ACPI_FADT_32BIT_TIMER | |
| 121 | ACPI_FADT_RESET_REGISTER | |
| 122 | ACPI_FADT_PCI_EXPRESS_WAKE | |
| 123 | ACPI_FADT_PLATFORM_CLOCK | |
| 124 | ACPI_FADT_S4_RTC_VALID | |
| 125 | ACPI_FADT_REMOTE_POWER_ON; |
| 126 | |
| 127 | /* Format is from 5.2.3.1: Generic Address Structure */ |
| 128 | /* reset_reg: see section 4.7.3.6 ACPI 3.0a spec */ |
| 129 | /* 8 bit write of value 0x06 to 0xCF9 in IO space */ |
| 130 | fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO; |
| 131 | fadt->reset_reg.bit_width = 8; |
| 132 | fadt->reset_reg.bit_offset = 0; |
| 133 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 134 | fadt->reset_reg.addrl = SYS_RESET; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 135 | fadt->reset_reg.addrh = 0x0; |
| 136 | |
| 137 | fadt->reset_value = 6; |
| 138 | |
Elyes HAOUAS | f5b974e | 2018-11-10 20:29:08 +0100 | [diff] [blame] | 139 | fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */ |
| 140 | fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 141 | |
| 142 | fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */ |
| 143 | fadt->x_firmware_ctl_h = 0; |
| 144 | fadt->x_dsdt_l = (u32) dsdt; |
| 145 | fadt->x_dsdt_h = 0; |
| 146 | |
| 147 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 148 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 149 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 150 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 151 | fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK; |
| 152 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 153 | |
| 154 | fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 155 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 156 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 157 | fadt->x_pm1b_evt_blk.access_size = 0; |
| 158 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 159 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 160 | |
| 161 | |
| 162 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 163 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 164 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 165 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 166 | fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK; |
| 167 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 168 | |
| 169 | fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 170 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 171 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 172 | fadt->x_pm1b_cnt_blk.access_size = 0; |
| 173 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 174 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 175 | |
| 176 | /* |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 177 | * Note: Under this current AMD C state implementation, this is no |
| 178 | * longer used and should not be reported to OS. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 179 | */ |
| 180 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 181 | fadt->x_pm2_cnt_blk.bit_width = 0; |
| 182 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 183 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 184 | fadt->x_pm2_cnt_blk.addrl = 0; |
| 185 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 186 | |
| 187 | |
| 188 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 189 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 190 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 191 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 192 | fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK; |
| 193 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 194 | |
| 195 | |
| 196 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 197 | fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */ |
| 198 | fadt->x_gpe0_blk.bit_offset = 0; |
| 199 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 200 | fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK; |
| 201 | fadt->x_gpe0_blk.addrh = 0x0; |
| 202 | |
| 203 | |
| 204 | fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 205 | fadt->x_gpe1_blk.bit_width = 0; |
| 206 | fadt->x_gpe1_blk.bit_offset = 0; |
| 207 | fadt->x_gpe1_blk.access_size = 0; |
| 208 | fadt->x_gpe1_blk.addrl = 0; |
| 209 | fadt->x_gpe1_blk.addrh = 0x0; |
| 210 | |
| 211 | header->checksum = acpi_checksum((void *)fadt, sizeof(acpi_fadt_t)); |
| 212 | } |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 213 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 214 | void generate_cpu_entries(const struct device *device) |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 215 | { |
Richard Spiegel | 3f16a0f | 2018-08-06 11:06:08 -0700 | [diff] [blame] | 216 | int cores, cpu; |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 217 | |
| 218 | /* Stoney Ridge is single node, just report # of cores */ |
Patrick Georgi | 4fbefc5 | 2018-10-23 14:35:37 +0200 | [diff] [blame] | 219 | cores = pci_read_config32(SOC_NB_DEV, NB_CAPABILITIES2) & CMP_CAP_MASK; |
| 220 | cores++; /* number of cores is CmpCap+1 */ |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 221 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 222 | printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores); |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 223 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 224 | /* Generate BSP \_SB.P000 */ |
Richard Spiegel | 3f16a0f | 2018-08-06 11:06:08 -0700 | [diff] [blame] | 225 | acpigen_write_processor(0, ACPI_GPE0_BLK, 6); |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 226 | acpigen_pop_len(); |
| 227 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 228 | /* Generate AP \_SB.Pxxx */ |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 229 | for (cpu = 1; cpu < cores; cpu++) { |
Richard Spiegel | 3f16a0f | 2018-08-06 11:06:08 -0700 | [diff] [blame] | 230 | acpigen_write_processor(cpu, 0, 0); |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 231 | acpigen_pop_len(); |
| 232 | } |
| 233 | } |
| 234 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 235 | unsigned long southbridge_write_acpi_tables(const struct device *device, |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 236 | unsigned long current, |
| 237 | struct acpi_rsdp *rsdp) |
| 238 | { |
| 239 | return acpi_write_hpet(device, current, rsdp); |
| 240 | } |
| 241 | |
| 242 | static void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 243 | { |
| 244 | /* Clear out GNVS. */ |
| 245 | memset(gnvs, 0, sizeof(*gnvs)); |
| 246 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 247 | if (CONFIG(CONSOLE_CBMEM)) |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 248 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 249 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 250 | if (CONFIG(CHROMEOS)) { |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 251 | /* Initialize Verified Boot data */ |
Joel Kitching | 6fbd874 | 2018-08-23 14:56:25 +0800 | [diff] [blame] | 252 | chromeos_init_chromeos_acpi(&gnvs->chromeos); |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 253 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 254 | } |
| 255 | |
| 256 | /* Set unknown wake source */ |
| 257 | gnvs->pm1i = ~0ULL; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 258 | gnvs->gpei = ~0ULL; |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 259 | |
| 260 | /* CPU core count */ |
| 261 | gnvs->pcnt = dev_count_cpu(); |
| 262 | } |
| 263 | |
Furquan Shaikh | 338fd9a | 2020-04-24 22:57:05 -0700 | [diff] [blame] | 264 | void southbridge_inject_dsdt(const struct device *device) |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 265 | { |
| 266 | struct global_nvs_t *gnvs; |
| 267 | |
| 268 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 269 | |
| 270 | if (gnvs) { |
| 271 | acpi_create_gnvs(gnvs); |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 272 | |
| 273 | /* Add it to DSDT */ |
| 274 | acpigen_write_scope("\\"); |
| 275 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
| 276 | acpigen_pop_len(); |
| 277 | } |
| 278 | } |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 279 | |
| 280 | static void acpigen_soc_get_gpio_in_local5(uintptr_t addr) |
| 281 | { |
| 282 | /* |
| 283 | * Store (\_SB.GPR2 (addr), Local5) |
| 284 | * \_SB.GPR2 is used to read control byte 2 from control register. |
| 285 | * / It is defined in gpio_lib.asl. |
| 286 | */ |
| 287 | acpigen_write_store(); |
| 288 | acpigen_emit_namestring("\\_SB.GPR2"); |
| 289 | acpigen_write_integer(addr); |
| 290 | acpigen_emit_byte(LOCAL5_OP); |
| 291 | } |
| 292 | |
| 293 | static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask) |
| 294 | { |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 295 | if (gpio_num >= SOC_GPIO_TOTAL_PINS) { |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 296 | printk(BIOS_WARNING, "Warning: Pin %d should be smaller than" |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 297 | " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS); |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 298 | return -1; |
| 299 | } |
| 300 | uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num); |
| 301 | |
| 302 | acpigen_soc_get_gpio_in_local5(addr); |
| 303 | |
| 304 | /* If (And (Local5, mask)) */ |
| 305 | acpigen_write_if_and(LOCAL5_OP, mask); |
| 306 | |
| 307 | /* Store (One, Local0) */ |
| 308 | acpigen_write_store_ops(ONE_OP, LOCAL0_OP); |
| 309 | |
| 310 | acpigen_pop_len(); /* If */ |
| 311 | |
| 312 | /* Else */ |
| 313 | acpigen_write_else(); |
| 314 | |
| 315 | /* Store (Zero, Local0) */ |
| 316 | acpigen_write_store_ops(ZERO_OP, LOCAL0_OP); |
| 317 | |
| 318 | acpigen_pop_len(); /* Else */ |
| 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val) |
| 324 | { |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 325 | if (gpio_num >= SOC_GPIO_TOTAL_PINS) { |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 326 | printk(BIOS_WARNING, "Warning: Pin %d should be smaller than" |
Marshall Dawson | 251d305 | 2019-05-02 17:27:57 -0600 | [diff] [blame] | 327 | " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS); |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 328 | return -1; |
| 329 | } |
| 330 | uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num); |
| 331 | |
Kevin Chiu | d837e66 | 2018-07-03 19:13:34 +0800 | [diff] [blame] | 332 | /* Store (0x40, Local0) */ |
| 333 | acpigen_write_store(); |
| 334 | acpigen_write_integer(GPIO_PIN_OUT); |
| 335 | acpigen_emit_byte(LOCAL0_OP); |
| 336 | |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 337 | acpigen_soc_get_gpio_in_local5(addr); |
| 338 | |
| 339 | if (val) { |
| 340 | /* Or (Local5, GPIO_PIN_OUT, Local5) */ |
Kevin Chiu | d837e66 | 2018-07-03 19:13:34 +0800 | [diff] [blame] | 341 | acpigen_write_or(LOCAL5_OP, LOCAL0_OP, LOCAL5_OP); |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 342 | } else { |
| 343 | /* Not (GPIO_PIN_OUT, Local6) */ |
Kevin Chiu | d837e66 | 2018-07-03 19:13:34 +0800 | [diff] [blame] | 344 | acpigen_write_not(LOCAL0_OP, LOCAL6_OP); |
Richard Spiegel | 93459d6 | 2018-05-16 14:08:33 -0700 | [diff] [blame] | 345 | |
| 346 | /* And (Local5, Local6, Local5) */ |
| 347 | acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP); |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * SB.GPW2 (addr, Local5) |
| 352 | * \_SB.GPW2 is used to write control byte in control register |
| 353 | * / byte 2. It is defined in gpio_lib.asl. |
| 354 | */ |
| 355 | acpigen_emit_namestring("\\_SB.GPW2"); |
| 356 | acpigen_write_integer(addr); |
| 357 | acpigen_emit_byte(LOCAL5_OP); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | int acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 363 | { |
| 364 | return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_IN); |
| 365 | } |
| 366 | |
| 367 | int acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 368 | { |
| 369 | return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_OUT); |
| 370 | } |
| 371 | |
| 372 | int acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 373 | { |
| 374 | return acpigen_soc_set_gpio_val(gpio_num, 1); |
| 375 | } |
| 376 | |
| 377 | int acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 378 | { |
| 379 | return acpigen_soc_set_gpio_val(gpio_num, 0); |
| 380 | } |