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