blob: e7b79a0a68b56fa6070c78ca12cf143c5ebaabdf [file] [log] [blame]
Andrey Petrovf35804b2017-06-05 13:22:41 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Usha P33ff4cc2019-11-28 10:05:45 +05305 * Copyright (C) 2017-2019 Intel Corporation.
Andrey Petrovf35804b2017-06-05 13:22:41 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053017#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070019#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070021#include <intelblocks/fast_spi.h>
Furquan Shaikh1876f3a2017-12-07 18:39:34 -080022#include <intelblocks/gspi.h>
Caveh Jalali1428f012018-01-23 22:15:24 -080023#include <intelblocks/lpc_lib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053024#include <intelblocks/p2sb.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070025#include <intelblocks/pcr.h>
Lijian Zhao031020e2017-12-15 12:58:07 -080026#include <intelblocks/pmclib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053027#include <intelblocks/rtc.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070028#include <soc/bootblock.h>
Subrata Banik73b1bd72019-11-28 13:56:24 +053029#include <soc/gpio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070030#include <soc/iomap.h>
31#include <soc/lpc.h>
32#include <soc/p2sb.h>
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053033#include <soc/pch.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070034#include <soc/pci_devs.h>
35#include <soc/pcr_ids.h>
Lijian Zhaob3dfcb82017-08-16 22:18:52 -070036#include <soc/pm.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070037
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053038#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP 0x1400
39#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H 0x0980
40
Andrey Petrovf35804b2017-06-05 13:22:41 -070041#define PCR_PSFX_TO_SHDW_BAR0 0
42#define PCR_PSFX_TO_SHDW_BAR1 0x4
43#define PCR_PSFX_TO_SHDW_BAR2 0x8
44#define PCR_PSFX_TO_SHDW_BAR3 0xC
45#define PCR_PSFX_TO_SHDW_BAR4 0x10
46#define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01
47#define PCR_PSFX_T0_SHDW_PCIEN 0x1C
48
Duncan Laurie2aef7f32018-11-17 12:13:59 -070049#define PCR_DMI_DMICTL 0x2234
50#define PCR_DMI_DMICTL_SRLOCK (1 << 31)
51
Andrey Petrovf35804b2017-06-05 13:22:41 -070052#define PCR_DMI_ACPIBA 0x27B4
53#define PCR_DMI_ACPIBDID 0x27B8
54#define PCR_DMI_PMBASEA 0x27AC
55#define PCR_DMI_PMBASEC 0x27B0
Andrey Petrovf35804b2017-06-05 13:22:41 -070056
57#define PCR_DMI_LPCIOD 0x2770
58#define PCR_DMI_LPCIOE 0x2774
59
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053060static uint32_t get_pmc_reg_base(void)
61{
62 uint8_t pch_series;
63
64 pch_series = get_pch_series();
65
66 if (pch_series == PCH_H)
67 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H;
68 else if (pch_series == PCH_LP)
69 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP;
70 else
71 return 0;
72}
73
Andrey Petrovf35804b2017-06-05 13:22:41 -070074static void soc_config_pwrmbase(void)
75{
76 uint32_t reg32;
77
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053078 /*
79 * Assign Resources to PWRMBASE
80 * Clear BIT 1-2 Command Register
81 */
Andrey Petrovf35804b2017-06-05 13:22:41 -070082 reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND);
83 reg32 &= ~(PCI_COMMAND_MEMORY);
84 pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32);
85
86 /* Program PWRM Base */
87 pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS);
88
89 /* Enable Bus Master and MMIO Space */
90 reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND);
Subrata Banik154024d2019-10-30 17:22:33 +053091 reg32 |= PCI_COMMAND_MEMORY;
Andrey Petrovf35804b2017-06-05 13:22:41 -070092 pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32);
93
94 /* Enable PWRM in PMC */
95 reg32 = read32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL));
96 write32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL), reg32 | PWRM_EN);
97}
98
99void bootblock_pch_early_init(void)
100{
101 fast_spi_early_init(SPI_BASE_ADDRESS);
Furquan Shaikh1876f3a2017-12-07 18:39:34 -0800102 gspi_early_bar_init();
Subrata Banik7837c202018-05-07 17:13:40 +0530103 p2sb_enable_bar();
104 p2sb_configure_hpet();
Subrata Banikafa07f72018-05-24 12:21:06 +0530105
Andrey Petrovf35804b2017-06-05 13:22:41 -0700106 /*
107 * Enabling PWRM Base for accessing
108 * Global Reset Cause Register.
109 */
110 soc_config_pwrmbase();
111}
112
113
114static void soc_config_acpibase(void)
115{
116 uint32_t pmc_reg_value;
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530117 uint32_t pmc_base_reg;
Andrey Petrovf35804b2017-06-05 13:22:41 -0700118
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530119 pmc_base_reg = get_pmc_reg_base();
120 if (!pmc_base_reg)
Keith Short15588b02019-05-09 11:40:34 -0600121 die_with_post_code(POST_HW_INIT_FAILURE,
122 "Invalid PMC base address\n");
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530123
124 pmc_reg_value = pcr_read32(PID_PSF3, pmc_base_reg +
125 PCR_PSFX_TO_SHDW_BAR4);
Andrey Petrovf35804b2017-06-05 13:22:41 -0700126
127 if (pmc_reg_value != 0xFFFFFFFF)
128 {
129 /* Disable Io Space before changing the address */
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530130 pcr_rmw32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700131 PCR_PSFX_T0_SHDW_PCIEN,
132 ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0);
133 /* Program ABASE in PSF3 PMC space BAR4*/
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530134 pcr_write32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700135 PCR_PSFX_TO_SHDW_BAR4,
136 ACPI_BASE_ADDRESS);
137 /* Enable IO Space */
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530138 pcr_rmw32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700139 PCR_PSFX_T0_SHDW_PCIEN,
140 ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN);
141 }
142}
143
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700144static int pch_check_decode_enable(void)
145{
146 uint32_t dmi_control;
147
148 /*
149 * This cycle decoding is only allowed to set when
150 * DMICTL.SRLOCK is 0.
151 */
152 dmi_control = pcr_read32(PID_DMI, PCR_DMI_DMICTL);
153 if (dmi_control & PCR_DMI_DMICTL_SRLOCK)
154 return -1;
155 return 0;
156}
157
Andrey Petrovf35804b2017-06-05 13:22:41 -0700158void pch_early_iorange_init(void)
159{
Christian Walterf4aa5012019-08-13 15:09:10 +0200160 uint16_t io_enables = LPC_IOE_EC_4E_4F | LPC_IOE_SUPERIO_2E_2F | LPC_IOE_KBC_60_64 |
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700161 LPC_IOE_EC_62_66 | LPC_IOE_LGE_200;
Andrey Petrovf35804b2017-06-05 13:22:41 -0700162
163 /* IO Decode Range */
Julius Wernercd49cce2019-03-05 16:53:33 -0800164 if (CONFIG(DRIVERS_UART_8250IO))
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700165 lpc_io_setup_comm_a_b();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700166
167 /* IO Decode Enable */
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700168 if (pch_check_decode_enable() == 0) {
169 io_enables = lpc_enable_fixed_io_ranges(io_enables);
170 /*
171 * Set up LPC IO Enables PCR[DMI] + 2774h [15:0] to the same
172 * value program in LPC PCI offset 82h.
173 */
174 pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables);
Wim Vervoorn84400182020-02-03 15:20:46 +0100175 /*
176 * Set LPC IO Decode Ranges PCR[DMI] + 2770h [15:0] to the same
177 * value programmed in LPC PCI offset 80h.
178 */
179 pcr_write16(PID_DMI, PCR_DMI_LPCIOD, lpc_get_fixed_io_decode());
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700180 }
Caveh Jalali1428f012018-01-23 22:15:24 -0800181
182 /* Program generic IO Decode Range */
183 pch_enable_lpc();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700184}
185
Usha P33ff4cc2019-11-28 10:05:45 +0530186void bootblock_pch_init(void)
Andrey Petrovf35804b2017-06-05 13:22:41 -0700187{
188 /*
189 * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT,
190 * GPE0_STS, GPE0_EN registers.
191 */
192 soc_config_acpibase();
193
Lijian Zhao031020e2017-12-15 12:58:07 -0800194 /* Set up GPE configuration */
195 pmc_gpe_init();
196
Andrey Petrovf35804b2017-06-05 13:22:41 -0700197 enable_rtc_upper_bank();
Subrata Banik73b1bd72019-11-28 13:56:24 +0530198
199 /* GPIO community PM configuration */
200 soc_gpio_pm_configuration();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700201}