Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 6 | * Copyright (C) 2017-2019 Intel Corporation. |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 18 | #include <bootstate.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 19 | #include <chip.h> |
| 20 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame^] | 21 | #include <device/mmio.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 22 | #include <device/device.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 23 | #include <device/pci_ops.h> |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 24 | #include <intelblocks/pmc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 25 | #include <intelblocks/pmclib.h> |
| 26 | #include <intelblocks/rtc.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 27 | #include <soc/pci_devs.h> |
| 28 | #include <soc/pm.h> |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 29 | |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 30 | /* |
| 31 | * Set which power state system will be after reapplying |
| 32 | * the power (from G3 State) |
| 33 | */ |
Duncan Laurie | 26bc328 | 2019-01-23 14:58:23 -0800 | [diff] [blame] | 34 | void pmc_set_afterg3(struct device *dev, int s5pwr) |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 35 | { |
| 36 | uint8_t reg8; |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 37 | uint8_t *pmcbase = pmc_mmio_regs(); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 38 | |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 39 | reg8 = read8(pmcbase + GEN_PMCON_A); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 40 | |
| 41 | switch (s5pwr) { |
| 42 | case MAINBOARD_POWER_STATE_OFF: |
| 43 | reg8 |= 1; |
| 44 | break; |
| 45 | case MAINBOARD_POWER_STATE_ON: |
| 46 | reg8 &= ~1; |
| 47 | break; |
| 48 | case MAINBOARD_POWER_STATE_PREVIOUS: |
| 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | |
Lijian Zhao | c3e75b4 | 2019-01-15 17:37:50 -0800 | [diff] [blame] | 53 | write8(pmcbase + GEN_PMCON_A, reg8); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Set PMC register to know which state system should be after |
| 58 | * power reapplied |
| 59 | */ |
| 60 | void pmc_soc_restore_power_failure(void) |
| 61 | { |
Nico Huber | a70ed00 | 2018-11-17 23:43:24 +0100 | [diff] [blame] | 62 | pmc_set_afterg3(PCH_DEV_PMC, CONFIG_MAINBOARD_POWER_FAILURE_STATE); |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 63 | } |
| 64 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 65 | static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable) |
| 66 | { |
| 67 | uint32_t reg; |
| 68 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 69 | |
| 70 | printk(BIOS_DEBUG, "%sabling Deep S%c\n", |
| 71 | enable ? "En" : "Dis", sx + '0'); |
| 72 | reg = read32(pmcbase + offset); |
| 73 | if (enable) |
| 74 | reg |= mask; |
| 75 | else |
| 76 | reg &= ~mask; |
| 77 | write32(pmcbase + offset, reg); |
| 78 | } |
| 79 | |
| 80 | static void config_deep_s5(int on_ac, int on_dc) |
| 81 | { |
| 82 | /* Treat S4 the same as S5. */ |
| 83 | config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac); |
| 84 | config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc); |
| 85 | config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac); |
| 86 | config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc); |
| 87 | } |
| 88 | |
| 89 | static void config_deep_s3(int on_ac, int on_dc) |
| 90 | { |
| 91 | config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac); |
| 92 | config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc); |
| 93 | } |
| 94 | |
| 95 | static void config_deep_sx(uint32_t deepsx_config) |
| 96 | { |
| 97 | uint32_t reg; |
| 98 | uint8_t *pmcbase = pmc_mmio_regs(); |
| 99 | |
| 100 | reg = read32(pmcbase + DSX_CFG); |
| 101 | reg &= ~DSX_CFG_MASK; |
| 102 | reg |= deepsx_config; |
| 103 | write32(pmcbase + DSX_CFG, reg); |
| 104 | } |
| 105 | |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 106 | static void pch_power_options(struct device *dev) |
| 107 | { |
| 108 | const char *state; |
| 109 | |
Nico Huber | a70ed00 | 2018-11-17 23:43:24 +0100 | [diff] [blame] | 110 | const int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 111 | |
| 112 | /* |
| 113 | * Which state do we want to goto after g3 (power restored)? |
| 114 | * 0 == S5 Soft Off |
| 115 | * 1 == S0 Full On |
| 116 | * 2 == Keep Previous State |
| 117 | */ |
| 118 | switch (pwr_on) { |
| 119 | case MAINBOARD_POWER_STATE_OFF: |
| 120 | state = "off"; |
| 121 | break; |
| 122 | case MAINBOARD_POWER_STATE_ON: |
| 123 | state = "on"; |
| 124 | break; |
| 125 | case MAINBOARD_POWER_STATE_PREVIOUS: |
| 126 | state = "state keep"; |
| 127 | break; |
| 128 | default: |
| 129 | state = "undefined"; |
| 130 | } |
| 131 | pmc_set_afterg3(dev, pwr_on); |
| 132 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 133 | |
| 134 | /* Set up GPE configuration. */ |
| 135 | pmc_gpe_init(); |
| 136 | } |
| 137 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 138 | static void pmc_init(void *unused) |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 139 | { |
Elyes HAOUAS | 3c8b5d0 | 2018-05-27 16:57:24 +0200 | [diff] [blame] | 140 | struct device *dev = PCH_DEV_PMC; |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 141 | config_t *config = dev->chip_info; |
| 142 | |
| 143 | rtc_init(); |
| 144 | |
| 145 | /* Initialize power management */ |
Subrata Banik | 33cd28e | 2017-12-19 12:33:59 +0530 | [diff] [blame] | 146 | pch_power_options(dev); |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 147 | |
Lijian Zhao | ac87a98 | 2017-08-28 17:46:55 -0700 | [diff] [blame] | 148 | config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc); |
| 149 | config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc); |
| 150 | config_deep_sx(config->deep_sx_config); |
| 151 | } |
| 152 | |
Subrata Banik | 0baad61 | 2017-11-23 13:58:34 +0530 | [diff] [blame] | 153 | /* |
| 154 | * Initialize PMC controller. |
| 155 | * |
| 156 | * PMC controller gets hidden from PCI bus during FSP-Silicon init call. |
| 157 | * Hence PCI enumeration can't be used to initialize bus device and |
| 158 | * allocate resources. |
| 159 | */ |
| 160 | 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] | 161 | |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 162 | static void soc_acpi_mode_init(void *unused) |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 163 | { |
| 164 | /* |
| 165 | * PMC initialization happens earlier for this SoC because FSP-Silicon |
| 166 | * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which |
| 167 | * 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] | 168 | * delayed till typical BS_DEV_INIT. This ensures that ACPI mode |
| 169 | * disabling happens the same way for all SoCs and hence the ordering of |
| 170 | * events is the same. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 171 | * |
| 172 | * This is important to ensure that the ordering does not break the |
| 173 | * assumptions of any other drivers (e.g. ChromeEC) which could be |
| 174 | * taking different actions based on disabling of ACPI (e.g. flushing of |
| 175 | * all EC hostevent bits). |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 176 | * |
| 177 | * P.S.: This cannot be done as part of pmc_soc_init as PMC device is |
| 178 | * hidden and hence the PMC driver never gets enumerated and so init is |
| 179 | * not called for it. |
Furquan Shaikh | ac8c60e | 2019-02-25 16:01:25 -0800 | [diff] [blame] | 180 | */ |
| 181 | pmc_set_acpi_mode(); |
| 182 | } |
Furquan Shaikh | 67a489f | 2019-02-27 00:59:06 -0800 | [diff] [blame] | 183 | |
| 184 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, soc_acpi_mode_init, NULL); |