Angel Pons | 16f6aa8 | 2020-04-05 15:47:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * This file is created based on Intel Tiger Lake Processor PCH Datasheet |
| 5 | * Document number: 575857 |
| 6 | * Chapter number: 4 |
| 7 | */ |
| 8 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 9 | #include <acpi/acpigen.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 10 | #include <console/console.h> |
| 11 | #include <device/mmio.h> |
| 12 | #include <device/device.h> |
Tim Wawrzynczak | c7854b0 | 2020-05-18 13:43:19 -0600 | [diff] [blame] | 13 | #include <drivers/intel/pmc_mux/chip.h> |
Tim Wawrzynczak | 72d9402 | 2021-07-01 08:25:11 -0600 | [diff] [blame^] | 14 | #include <intelblocks/acpi.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 15 | #include <intelblocks/pmc.h> |
| 16 | #include <intelblocks/pmclib.h> |
Duncan Laurie | e997d85 | 2020-10-10 00:18:08 +0000 | [diff] [blame] | 17 | #include <intelblocks/pmc_ipc.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 18 | #include <intelblocks/rtc.h> |
Tim Wawrzynczak | 72d9402 | 2021-07-01 08:25:11 -0600 | [diff] [blame^] | 19 | #include <soc/lpm.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
| 21 | #include <soc/pm.h> |
| 22 | #include <soc/soc_chip.h> |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 23 | #include <bootstate.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 24 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 25 | #define PMC_HID "INTC1026" |
| 26 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 27 | static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 28 | { |
| 29 | uint32_t reg; |
| 30 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 31 | |
| 32 | printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 33 | enable ? "En" : "Dis", sx + '0'); |
| 34 | reg = read32(pmcbase + offset); |
| 35 | if (enable) |
| 36 | reg |= mask; |
| 37 | else |
| 38 | reg &= ~mask; |
| 39 | write32(pmcbase + offset, reg); |
| 40 | } |
| 41 | |
| 42 | static void config_deep_s5(int on_ac, int on_dc) |
| 43 | { |
| 44 | /* Treat S4 the same as S5. */ |
| 45 | config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 46 | config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 47 | config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 48 | config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 49 | } |
| 50 | |
| 51 | static void config_deep_s3(int on_ac, int on_dc) |
| 52 | { |
| 53 | config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 54 | config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 55 | } |
| 56 | |
| 57 | static void config_deep_sx(uint32_t deepsx_config) |
| 58 | { |
| 59 | uint32_t reg; |
| 60 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 61 | |
| 62 | reg = read32(pmcbase + DSX_CFG); |
| 63 | reg &= ~DSX_CFG_MASK; |
| 64 | reg |= deepsx_config; |
| 65 | write32(pmcbase + DSX_CFG, reg); |
| 66 | } |
| 67 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 68 | static void pmc_init(struct device *dev) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 69 | { |
| 70 | const config_t *config = config_of_soc(); |
| 71 | |
| 72 | rtc_init(); |
| 73 | |
| 74 | pmc_set_power_failure_state(true); |
| 75 | pmc_gpe_init(); |
| 76 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 77 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 78 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 79 | config_deep_sx(config->deep_sx_config); |
| 80 | } |
| 81 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 82 | static void soc_pmc_read_resources(struct device *dev) |
| 83 | { |
| 84 | struct resource *res; |
| 85 | |
| 86 | /* Add the fixed MMIO resource */ |
| 87 | mmio_resource(dev, 0, PCH_PWRM_BASE_ADDRESS / KiB, PCH_PWRM_BASE_SIZE / KiB); |
| 88 | |
| 89 | /* Add the fixed I/O resource */ |
| 90 | res = new_resource(dev, 1); |
| 91 | res->base = (resource_t)ACPI_BASE_ADDRESS; |
| 92 | res->size = (resource_t)ACPI_BASE_SIZE; |
| 93 | res->limit = res->base + res->size - 1; |
| 94 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 95 | } |
| 96 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 97 | static void soc_pmc_fill_ssdt(const struct device *dev) |
| 98 | { |
John Zhao | 3d6066e | 2020-06-26 09:38:04 -0700 | [diff] [blame] | 99 | const char *scope = acpi_device_scope(dev); |
| 100 | const char *name = acpi_device_name(dev); |
| 101 | if (!scope || !name) |
| 102 | return; |
| 103 | |
| 104 | acpigen_write_scope(scope); |
| 105 | acpigen_write_device(name); |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 106 | |
| 107 | acpigen_write_name_string("_HID", PMC_HID); |
| 108 | acpigen_write_name_string("_DDN", "Intel(R) Tiger Lake IPC Controller"); |
| 109 | |
| 110 | /* |
| 111 | * Part of the PCH's reserved 32 MB MMIO range (0xFC800000 - 0xFE7FFFFF). |
| 112 | * The PMC gets 0xFE000000 - 0xFE00FFFF. |
| 113 | */ |
| 114 | acpigen_write_name("_CRS"); |
| 115 | acpigen_write_resourcetemplate_header(); |
| 116 | acpigen_write_mem32fixed(1, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE); |
| 117 | acpigen_write_resourcetemplate_footer(); |
| 118 | |
Duncan Laurie | e997d85 | 2020-10-10 00:18:08 +0000 | [diff] [blame] | 119 | /* Define IPC Write Method */ |
| 120 | if (CONFIG(PMC_IPC_ACPI_INTERFACE)) |
| 121 | pmc_ipc_acpi_fill_ssdt(); |
| 122 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 123 | acpigen_pop_len(); /* PMC Device */ |
| 124 | acpigen_pop_len(); /* Scope */ |
| 125 | |
Tim Wawrzynczak | 72d9402 | 2021-07-01 08:25:11 -0600 | [diff] [blame^] | 126 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_PEP)) { |
| 127 | const struct soc_pmc_lpm tgl_pmc_lpm = { |
| 128 | .num_substates = 8, |
| 129 | .num_req_regs = 6, |
| 130 | .lpm_ipc_offset = 0x1000, |
| 131 | .req_reg_stride = 0x30, |
| 132 | .lpm_enable_mask = get_supported_lpm_mask(config_of_soc()), |
| 133 | }; |
| 134 | |
| 135 | generate_acpi_power_engine_with_lpm(&tgl_pmc_lpm); |
| 136 | } |
| 137 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 138 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), dev->chip_ops->name, |
| 139 | dev_path(dev)); |
| 140 | } |
| 141 | |
William Wei | 9f6622f | 2020-06-22 13:30:37 +0800 | [diff] [blame] | 142 | static void soc_acpi_mode_init(struct device *dev) |
| 143 | { |
| 144 | /* |
| 145 | * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order |
| 146 | * to ensure the ordering does not break the assumptions that other |
| 147 | * drivers make about ACPI mode (e.g. Chrome EC). Since it disables |
| 148 | * ACPI mode, other drivers may take different actions based on this |
| 149 | * (e.g. Chrome EC will flush any pending hostevent bits). Because |
| 150 | * TGL has its PMC device available for device_operations, it can be |
| 151 | * done from the "ops->init" callback. |
| 152 | */ |
| 153 | pmc_set_acpi_mode(); |
| 154 | } |
| 155 | |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 156 | static void pm1_enable_pwrbtn_smi(void *unused) |
| 157 | { |
| 158 | /* Enable power button SMI after BS_DEV_INIT_CHIPS (FSP-S) is done. */ |
| 159 | pmc_update_pm1_enable(PWRBTN_EN); |
| 160 | } |
| 161 | |
| 162 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL); |
| 163 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 164 | struct device_operations pmc_ops = { |
| 165 | .read_resources = soc_pmc_read_resources, |
| 166 | .set_resources = noop_set_resources, |
William Wei | 9f6622f | 2020-06-22 13:30:37 +0800 | [diff] [blame] | 167 | .init = soc_acpi_mode_init, |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 168 | .enable = pmc_init, |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 169 | #if CONFIG(HAVE_ACPI_TABLES) |
| 170 | .acpi_fill_ssdt = soc_pmc_fill_ssdt, |
| 171 | #endif |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 172 | .scan_bus = scan_static_bus, |
| 173 | }; |