Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 15 | #include <bootstate.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 16 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 17 | #include <device/mmio.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 18 | #include <device/device.h> |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 19 | #include <intelblocks/pmc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 20 | #include <intelblocks/pmclib.h> |
| 21 | #include <intelblocks/rtc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 22 | #include <soc/pci_devs.h> |
| 23 | #include <soc/pm.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 24 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 25 | #include "chip.h" |
| 26 | |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 27 | /* |
| 28 | * Set which power state system will be after reapplying |
| 29 | * the power (from G3 State) |
| 30 | */ |
Nico Huber | 733c28f | 2019-08-05 19:33:09 +0200 | [diff] [blame] | 31 | void pmc_soc_set_afterg3_en(const bool on) |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 32 | { |
| 33 | uint8_t reg8; |
Nico Huber | 733c28f | 2019-08-05 19:33:09 +0200 | [diff] [blame] | 34 | uint8_t *const pmcbase = pmc_mmio_regs(); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 35 | |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 36 | reg8 = read8(pmcbase + GEN_PMCON_A); |
Nico Huber | 733c28f | 2019-08-05 19:33:09 +0200 | [diff] [blame] | 37 | if (on) |
| 38 | reg8 &= ~SLEEP_AFTER_POWER_FAIL; |
| 39 | else |
| 40 | reg8 |= SLEEP_AFTER_POWER_FAIL; |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 41 | write8(pmcbase + GEN_PMCON_A, reg8); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 42 | } |
| 43 | |
Krzysztof Sywula | 42a66fb | 2019-03-13 16:48:56 -0700 | [diff] [blame] | 44 | static void pm1_enable_pwrbtn_smi(void *unused) |
| 45 | { |
| 46 | /* |
| 47 | * Enable power button SMI only before jumping to payload. This ensures |
| 48 | * that: |
| 49 | * 1. Power button SMI is enabled only after coreboot is done. |
| 50 | * 2. On resume path, power button SMI is not enabled and thus avoids |
| 51 | * any shutdowns because of power button presses due to power button |
| 52 | * press in resume path. |
| 53 | */ |
| 54 | pmc_update_pm1_enable(PWRBTN_EN); |
| 55 | } |
| 56 | |
| 57 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, pm1_enable_pwrbtn_smi, NULL); |
| 58 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 59 | static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 60 | { |
| 61 | uint32_t reg; |
| 62 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 63 | |
| 64 | printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 65 | enable ? "En" : "Dis", sx + '0'); |
| 66 | reg = read32(pmcbase + offset); |
| 67 | if (enable) |
| 68 | reg |= mask; |
| 69 | else |
| 70 | reg &= ~mask; |
| 71 | write32(pmcbase + offset, reg); |
| 72 | } |
| 73 | |
| 74 | static void config_deep_s5(int on_ac, int on_dc) |
| 75 | { |
| 76 | /* Treat S4 the same as S5. */ |
| 77 | config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 78 | config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 79 | config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 80 | config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 81 | } |
| 82 | |
| 83 | static void config_deep_s3(int on_ac, int on_dc) |
| 84 | { |
| 85 | config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 86 | config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 87 | } |
| 88 | |
| 89 | static void config_deep_sx(uint32_t deepsx_config) |
| 90 | { |
| 91 | uint32_t reg; |
| 92 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 93 | |
| 94 | reg = read32(pmcbase + DSX_CFG); |
| 95 | reg &= ~DSX_CFG_MASK; |
| 96 | reg |= deepsx_config; |
| 97 | write32(pmcbase + DSX_CFG, reg); |
| 98 | } |
| 99 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 100 | static void pmc_init(void *unused) |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 101 | { |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 102 | const config_t *config = config_of_soc(); |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 103 | |
| 104 | rtc_init(); |
| 105 | |
Nico Huber | 733c28f | 2019-08-05 19:33:09 +0200 | [diff] [blame] | 106 | pmc_set_power_failure_state(true); |
| 107 | pmc_gpe_init(); |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 108 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 109 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 110 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 111 | config_deep_sx(config->deep_sx_config); |
| 112 | } |
| 113 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 114 | /* |
| 115 | * Initialize PMC controller. |
| 116 | * |
| 117 | * PMC controller gets hidden from PCI bus during FSP-Silicon init call. |
| 118 | * Hence PCI enumeration can't be used to initialize bus device and |
| 119 | * allocate resources. |
| 120 | */ |
| 121 | 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] | 122 | |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 123 | static void soc_acpi_mode_init(void *unused) |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 124 | { |
| 125 | /* |
| 126 | * PMC initialization happens earlier for this SoC because FSP-Silicon |
| 127 | * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which |
| 128 | * 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] | 129 | * delayed till typical BS_DEV_INIT. This ensures that ACPI mode |
| 130 | * disabling happens the same way for all SoCs and hence the ordering of |
| 131 | * events is the same. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 132 | * |
| 133 | * This is important to ensure that the ordering does not break the |
| 134 | * assumptions of any other drivers (e.g. ChromeEC) which could be |
| 135 | * taking different actions based on disabling of ACPI (e.g. flushing of |
| 136 | * all EC hostevent bits). |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 137 | * |
| 138 | * P.S.: This cannot be done as part of pmc_soc_init as PMC device is |
| 139 | * hidden and hence the PMC driver never gets enumerated and so init is |
| 140 | * not called for it. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 141 | */ |
| 142 | pmc_set_acpi_mode(); |
| 143 | } |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 144 | |
| 145 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, soc_acpi_mode_init, NULL); |