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