blob: 84bfba06c031858ca454d3f72834dba1094f5780 [file] [log] [blame]
Lijian Zhaoac87a982017-08-28 17:46:55 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
Lijian Zhaoc3e75b42019-01-15 17:37:50 -08006 * Copyright (C) 2017-2019 Intel Corporation.
Lijian Zhaoac87a982017-08-28 17:46:55 -07007 *
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 Banik0baad612017-11-23 13:58:34 +053018#include <bootstate.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070019#include <chip.h>
20#include <console/console.h>
21#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020022#include <device/pci_ops.h>
Subrata Banik0baad612017-11-23 13:58:34 +053023#include <intelblocks/pmc.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070024#include <intelblocks/pmclib.h>
25#include <intelblocks/rtc.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070026#include <soc/pci_devs.h>
27#include <soc/pm.h>
Lijian Zhaoac87a982017-08-28 17:46:55 -070028
Subrata Banik33cd28e2017-12-19 12:33:59 +053029/*
30 * Set which power state system will be after reapplying
31 * the power (from G3 State)
32 */
Duncan Laurie26bc3282019-01-23 14:58:23 -080033void pmc_set_afterg3(struct device *dev, int s5pwr)
Subrata Banik33cd28e2017-12-19 12:33:59 +053034{
35 uint8_t reg8;
Lijian Zhaoc3e75b42019-01-15 17:37:50 -080036 uint8_t *pmcbase = pmc_mmio_regs();
Subrata Banik33cd28e2017-12-19 12:33:59 +053037
Lijian Zhaoc3e75b42019-01-15 17:37:50 -080038 reg8 = read8(pmcbase + GEN_PMCON_A);
Subrata Banik33cd28e2017-12-19 12:33:59 +053039
40 switch (s5pwr) {
41 case MAINBOARD_POWER_STATE_OFF:
42 reg8 |= 1;
43 break;
44 case MAINBOARD_POWER_STATE_ON:
45 reg8 &= ~1;
46 break;
47 case MAINBOARD_POWER_STATE_PREVIOUS:
48 default:
49 break;
50 }
51
Lijian Zhaoc3e75b42019-01-15 17:37:50 -080052 write8(pmcbase + GEN_PMCON_A, reg8);
Subrata Banik33cd28e2017-12-19 12:33:59 +053053}
54
55/*
56 * Set PMC register to know which state system should be after
57 * power reapplied
58 */
59void pmc_soc_restore_power_failure(void)
60{
Nico Hubera70ed002018-11-17 23:43:24 +010061 pmc_set_afterg3(PCH_DEV_PMC, CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Subrata Banik33cd28e2017-12-19 12:33:59 +053062}
63
Lijian Zhaoac87a982017-08-28 17:46:55 -070064static void config_deep_sX(uint32_t offset, uint32_t mask, int sx, int enable)
65{
66 uint32_t reg;
67 uint8_t *pmcbase = pmc_mmio_regs();
68
69 printk(BIOS_DEBUG, "%sabling Deep S%c\n",
70 enable ? "En" : "Dis", sx + '0');
71 reg = read32(pmcbase + offset);
72 if (enable)
73 reg |= mask;
74 else
75 reg &= ~mask;
76 write32(pmcbase + offset, reg);
77}
78
79static void config_deep_s5(int on_ac, int on_dc)
80{
81 /* Treat S4 the same as S5. */
82 config_deep_sX(S4_PWRGATE_POL, S4AC_GATE_SUS, 4, on_ac);
83 config_deep_sX(S4_PWRGATE_POL, S4DC_GATE_SUS, 4, on_dc);
84 config_deep_sX(S5_PWRGATE_POL, S5AC_GATE_SUS, 5, on_ac);
85 config_deep_sX(S5_PWRGATE_POL, S5DC_GATE_SUS, 5, on_dc);
86}
87
88static void config_deep_s3(int on_ac, int on_dc)
89{
90 config_deep_sX(S3_PWRGATE_POL, S3AC_GATE_SUS, 3, on_ac);
91 config_deep_sX(S3_PWRGATE_POL, S3DC_GATE_SUS, 3, on_dc);
92}
93
94static void config_deep_sx(uint32_t deepsx_config)
95{
96 uint32_t reg;
97 uint8_t *pmcbase = pmc_mmio_regs();
98
99 reg = read32(pmcbase + DSX_CFG);
100 reg &= ~DSX_CFG_MASK;
101 reg |= deepsx_config;
102 write32(pmcbase + DSX_CFG, reg);
103}
104
Subrata Banik33cd28e2017-12-19 12:33:59 +0530105static void pch_power_options(struct device *dev)
106{
107 const char *state;
108
Nico Hubera70ed002018-11-17 23:43:24 +0100109 const int pwr_on = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Subrata Banik33cd28e2017-12-19 12:33:59 +0530110
111 /*
112 * Which state do we want to goto after g3 (power restored)?
113 * 0 == S5 Soft Off
114 * 1 == S0 Full On
115 * 2 == Keep Previous State
116 */
117 switch (pwr_on) {
118 case MAINBOARD_POWER_STATE_OFF:
119 state = "off";
120 break;
121 case MAINBOARD_POWER_STATE_ON:
122 state = "on";
123 break;
124 case MAINBOARD_POWER_STATE_PREVIOUS:
125 state = "state keep";
126 break;
127 default:
128 state = "undefined";
129 }
130 pmc_set_afterg3(dev, pwr_on);
131 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
132
133 /* Set up GPE configuration. */
134 pmc_gpe_init();
135}
136
Subrata Banik0baad612017-11-23 13:58:34 +0530137static void pmc_init(void *unused)
Lijian Zhaoac87a982017-08-28 17:46:55 -0700138{
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200139 struct device *dev = PCH_DEV_PMC;
Lijian Zhaoac87a982017-08-28 17:46:55 -0700140 config_t *config = dev->chip_info;
141
142 rtc_init();
143
144 /* Initialize power management */
Subrata Banik33cd28e2017-12-19 12:33:59 +0530145 pch_power_options(dev);
Lijian Zhaoac87a982017-08-28 17:46:55 -0700146
Lijian Zhaoac87a982017-08-28 17:46:55 -0700147 config_deep_s3(config->deep_s3_enable_ac, config->deep_s3_enable_dc);
148 config_deep_s5(config->deep_s5_enable_ac, config->deep_s5_enable_dc);
149 config_deep_sx(config->deep_sx_config);
150}
151
Subrata Banik0baad612017-11-23 13:58:34 +0530152/*
153* Initialize PMC controller.
154*
155* PMC controller gets hidden from PCI bus during FSP-Silicon init call.
156* Hence PCI enumeration can't be used to initialize bus device and
157* allocate resources.
158*/
159BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, pmc_init, NULL);
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800160
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800161static void soc_acpi_mode_init(void *unused)
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800162{
163 /*
164 * PMC initialization happens earlier for this SoC because FSP-Silicon
165 * init hides PMC from PCI bus. However, pmc_set_acpi_mode, which
166 * disables ACPI mode doesn't need to happen that early and can be
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800167 * delayed till typical BS_DEV_INIT. This ensures that ACPI mode
168 * disabling happens the same way for all SoCs and hence the ordering of
169 * events is the same.
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800170 *
171 * This is important to ensure that the ordering does not break the
172 * assumptions of any other drivers (e.g. ChromeEC) which could be
173 * taking different actions based on disabling of ACPI (e.g. flushing of
174 * all EC hostevent bits).
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800175 *
176 * P.S.: This cannot be done as part of pmc_soc_init as PMC device is
177 * hidden and hence the PMC driver never gets enumerated and so init is
178 * not called for it.
Furquan Shaikhac8c60e2019-02-25 16:01:25 -0800179 */
180 pmc_set_acpi_mode();
181}
Furquan Shaikh67a489f2019-02-27 00:59:06 -0800182
183BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, soc_acpi_mode_init, NULL);