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> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 14 | #include <intelblocks/pmc.h> |
| 15 | #include <intelblocks/pmclib.h> |
| 16 | #include <intelblocks/rtc.h> |
| 17 | #include <soc/pci_devs.h> |
| 18 | #include <soc/pm.h> |
| 19 | #include <soc/soc_chip.h> |
| 20 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 21 | #define PMC_HID "INTC1026" |
| 22 | |
Duncan Laurie | 5268807 | 2020-04-29 12:19:50 -0700 | [diff] [blame] | 23 | enum pch_pmc_xtal pmc_get_xtal_freq(void) |
| 24 | { |
| 25 | uint8_t *const pmcbase = pmc_mmio_regs(); |
| 26 | |
| 27 | return PCH_EPOC_XTAL_FREQ(read32(pmcbase + PCH_PMC_EPOC)); |
| 28 | } |
| 29 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 30 | static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 31 | { |
| 32 | uint32_t reg; |
| 33 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 34 | |
| 35 | printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 36 | enable ? "En" : "Dis", sx + '0'); |
| 37 | reg = read32(pmcbase + offset); |
| 38 | if (enable) |
| 39 | reg |= mask; |
| 40 | else |
| 41 | reg &= ~mask; |
| 42 | write32(pmcbase + offset, reg); |
| 43 | } |
| 44 | |
| 45 | static void config_deep_s5(int on_ac, int on_dc) |
| 46 | { |
| 47 | /* Treat S4 the same as S5. */ |
| 48 | config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 49 | config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 50 | config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 51 | config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 52 | } |
| 53 | |
| 54 | static void config_deep_s3(int on_ac, int on_dc) |
| 55 | { |
| 56 | config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 57 | config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 58 | } |
| 59 | |
| 60 | static void config_deep_sx(uint32_t deepsx_config) |
| 61 | { |
| 62 | uint32_t reg; |
| 63 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 64 | |
| 65 | reg = read32(pmcbase + DSX_CFG); |
| 66 | reg &= ~DSX_CFG_MASK; |
| 67 | reg |= deepsx_config; |
| 68 | write32(pmcbase + DSX_CFG, reg); |
| 69 | } |
| 70 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 71 | static void pmc_init(struct device *dev) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 72 | { |
| 73 | const config_t *config = config_of_soc(); |
| 74 | |
| 75 | rtc_init(); |
| 76 | |
| 77 | pmc_set_power_failure_state(true); |
| 78 | pmc_gpe_init(); |
| 79 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 80 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 81 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 82 | config_deep_sx(config->deep_sx_config); |
| 83 | } |
| 84 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 85 | static void soc_pmc_read_resources(struct device *dev) |
| 86 | { |
| 87 | struct resource *res; |
| 88 | |
| 89 | /* Add the fixed MMIO resource */ |
| 90 | mmio_resource(dev, 0, PCH_PWRM_BASE_ADDRESS / KiB, PCH_PWRM_BASE_SIZE / KiB); |
| 91 | |
| 92 | /* Add the fixed I/O resource */ |
| 93 | res = new_resource(dev, 1); |
| 94 | res->base = (resource_t)ACPI_BASE_ADDRESS; |
| 95 | res->size = (resource_t)ACPI_BASE_SIZE; |
| 96 | res->limit = res->base + res->size - 1; |
| 97 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 98 | } |
| 99 | |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 100 | static void soc_pmc_fill_ssdt(const struct device *dev) |
| 101 | { |
John Zhao | 3d6066e | 2020-06-26 09:38:04 -0700 | [diff] [blame^] | 102 | const char *scope = acpi_device_scope(dev); |
| 103 | const char *name = acpi_device_name(dev); |
| 104 | if (!scope || !name) |
| 105 | return; |
| 106 | |
| 107 | acpigen_write_scope(scope); |
| 108 | acpigen_write_device(name); |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 109 | |
| 110 | acpigen_write_name_string("_HID", PMC_HID); |
| 111 | acpigen_write_name_string("_DDN", "Intel(R) Tiger Lake IPC Controller"); |
| 112 | |
| 113 | /* |
| 114 | * Part of the PCH's reserved 32 MB MMIO range (0xFC800000 - 0xFE7FFFFF). |
| 115 | * The PMC gets 0xFE000000 - 0xFE00FFFF. |
| 116 | */ |
| 117 | acpigen_write_name("_CRS"); |
| 118 | acpigen_write_resourcetemplate_header(); |
| 119 | acpigen_write_mem32fixed(1, PCH_PWRM_BASE_ADDRESS, PCH_PWRM_BASE_SIZE); |
| 120 | acpigen_write_resourcetemplate_footer(); |
| 121 | |
| 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 | |
Tim Wawrzynczak | c7854b0 | 2020-05-18 13:43:19 -0600 | [diff] [blame] | 129 | /* By default, TGL uses the PMC MUX for all ports, so port_number is unused */ |
| 130 | const struct device *soc_get_pmc_mux_device(int port_number) |
| 131 | { |
| 132 | const struct device *pmc; |
| 133 | struct device *child; |
| 134 | |
| 135 | child = NULL; |
| 136 | pmc = pcidev_path_on_root(PCH_DEVFN_PMC); |
| 137 | if (!pmc || !pmc->link_list) |
| 138 | return NULL; |
| 139 | |
| 140 | while ((child = dev_bus_each_child(pmc->link_list, child)) != NULL) |
| 141 | if (child->chip_ops == &drivers_intel_pmc_mux_ops) |
| 142 | break; |
| 143 | |
| 144 | /* child will either be the correct device or NULL if not found */ |
| 145 | return child; |
| 146 | } |
| 147 | |
William Wei | 9f6622f | 2020-06-22 13:30:37 +0800 | [diff] [blame] | 148 | static void soc_acpi_mode_init(struct device *dev) |
| 149 | { |
| 150 | /* |
| 151 | * pmc_set_acpi_mode() should be delayed until BS_DEV_INIT in order |
| 152 | * to ensure the ordering does not break the assumptions that other |
| 153 | * drivers make about ACPI mode (e.g. Chrome EC). Since it disables |
| 154 | * ACPI mode, other drivers may take different actions based on this |
| 155 | * (e.g. Chrome EC will flush any pending hostevent bits). Because |
| 156 | * TGL has its PMC device available for device_operations, it can be |
| 157 | * done from the "ops->init" callback. |
| 158 | */ |
| 159 | pmc_set_acpi_mode(); |
| 160 | } |
| 161 | |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 162 | struct device_operations pmc_ops = { |
| 163 | .read_resources = soc_pmc_read_resources, |
| 164 | .set_resources = noop_set_resources, |
William Wei | 9f6622f | 2020-06-22 13:30:37 +0800 | [diff] [blame] | 165 | .init = soc_acpi_mode_init, |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 166 | .enable = pmc_init, |
Tim Wawrzynczak | 7729b29 | 2020-05-14 16:21:09 -0600 | [diff] [blame] | 167 | #if CONFIG(HAVE_ACPI_TABLES) |
| 168 | .acpi_fill_ssdt = soc_pmc_fill_ssdt, |
| 169 | #endif |
Tim Wawrzynczak | 6d20d0c | 2020-05-13 17:00:33 -0600 | [diff] [blame] | 170 | .scan_bus = scan_static_bus, |
| 171 | }; |