Angel Pons | f5627e8 | 2020-04-05 15:46:52 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 2 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 3 | #include <bootstate.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 6 | #include <device/device.h> |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 7 | #include <intelblocks/pmc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 8 | #include <intelblocks/pmclib.h> |
| 9 | #include <intelblocks/rtc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 10 | #include <soc/pci_devs.h> |
| 11 | #include <soc/pm.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 12 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 13 | #include "chip.h" |
| 14 | |
Krzysztof Sywula | 42a66fb | 2019-03-13 16:48:56 -0700 | [diff] [blame] | 15 | static void pm1_enable_pwrbtn_smi(void *unused) |
| 16 | { |
| 17 | /* |
| 18 | * Enable power button SMI only before jumping to payload. This ensures |
| 19 | * that: |
| 20 | * 1. Power button SMI is enabled only after coreboot is done. |
| 21 | * 2. On resume path, power button SMI is not enabled and thus avoids |
| 22 | * any shutdowns because of power button presses due to power button |
| 23 | * press in resume path. |
| 24 | */ |
| 25 | pmc_update_pm1_enable(PWRBTN_EN); |
| 26 | } |
| 27 | |
| 28 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL); |
| 29 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [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 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 71 | static void pmc_init(void *unused) |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 72 | { |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 73 | const config_t *config = config_of_soc(); |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 74 | |
| 75 | rtc_init(); |
| 76 | |
Nico Huber | 733c28f | 2019-08-05 19:33:09 +0200 | [diff] [blame] | 77 | pmc_set_power_failure_state(true); |
| 78 | pmc_gpe_init(); |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 79 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [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 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 85 | /* |
| 86 | * Initialize PMC controller. |
| 87 | * |
| 88 | * PMC controller gets hidden from PCI bus during FSP-Silicon init call. |
| 89 | * Hence PCI enumeration can't be used to initialize bus device and |
| 90 | * allocate resources. |
| 91 | */ |
| 92 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pmc_init, NULL); |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 93 | |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 94 | static void soc_acpi_mode_init(void *unused) |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 95 | { |
| 96 | /* |
| 97 | * PMC initialization happens earlier for this SoC because FSP-Silicon |
| 98 | * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which |
| 99 | * disables ACPI mode doesn't need to happen that early and can be |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 100 | * delayed till typical BS_DEV_INIT. This ensures that ACPI mode |
| 101 | * disabling happens the same way for all SoCs and hence the ordering of |
| 102 | * events is the same. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 103 | * |
| 104 | * This is important to ensure that the ordering does not break the |
| 105 | * assumptions of any other drivers (e.g. ChromeEC) which could be |
| 106 | * taking different actions based on disabling of ACPI (e.g. flushing of |
| 107 | * all EC hostevent bits). |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 108 | * |
| 109 | * P.S.: This cannot be done as part of pmc_soc_init as PMC device is |
| 110 | * hidden and hence the PMC driver never gets enumerated and so init is |
| 111 | * not called for it. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 112 | */ |
| 113 | pmc_set_acpi_mode(); |
| 114 | } |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 115 | |
| 116 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, soc_acpi_mode_init, NULL); |