blob: d67edea21cd4cc994d507d1b0825804ba83ecee2 [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Andrey Petrovf35804b2017-06-05 13:22:41 -07003
Maulik V Vaghela9b08a182018-07-17 21:52:27 +05304#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -07006#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -07008#include <intelblocks/fast_spi.h>
Furquan Shaikh1876f3a2017-12-07 18:39:34 -08009#include <intelblocks/gspi.h>
Caveh Jalali1428f012018-01-23 22:15:24 -080010#include <intelblocks/lpc_lib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053011#include <intelblocks/p2sb.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070012#include <intelblocks/pcr.h>
Lijian Zhao031020e2017-12-15 12:58:07 -080013#include <intelblocks/pmclib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053014#include <intelblocks/rtc.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070015#include <soc/bootblock.h>
Subrata Banik73b1bd72019-11-28 13:56:24 +053016#include <soc/gpio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070017#include <soc/iomap.h>
18#include <soc/lpc.h>
19#include <soc/p2sb.h>
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053020#include <soc/pch.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070021#include <soc/pci_devs.h>
22#include <soc/pcr_ids.h>
Lijian Zhaob3dfcb82017-08-16 22:18:52 -070023#include <soc/pm.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070024
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053025#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP 0x1400
26#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H 0x0980
27
Andrey Petrovf35804b2017-06-05 13:22:41 -070028#define PCR_PSFX_TO_SHDW_BAR0 0
29#define PCR_PSFX_TO_SHDW_BAR1 0x4
30#define PCR_PSFX_TO_SHDW_BAR2 0x8
31#define PCR_PSFX_TO_SHDW_BAR3 0xC
32#define PCR_PSFX_TO_SHDW_BAR4 0x10
33#define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01
34#define PCR_PSFX_T0_SHDW_PCIEN 0x1C
35
Duncan Laurie2aef7f32018-11-17 12:13:59 -070036#define PCR_DMI_DMICTL 0x2234
37#define PCR_DMI_DMICTL_SRLOCK (1 << 31)
38
Andrey Petrovf35804b2017-06-05 13:22:41 -070039#define PCR_DMI_ACPIBA 0x27B4
40#define PCR_DMI_ACPIBDID 0x27B8
41#define PCR_DMI_PMBASEA 0x27AC
42#define PCR_DMI_PMBASEC 0x27B0
Andrey Petrovf35804b2017-06-05 13:22:41 -070043
44#define PCR_DMI_LPCIOD 0x2770
45#define PCR_DMI_LPCIOE 0x2774
46
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053047static uint32_t get_pmc_reg_base(void)
48{
49 uint8_t pch_series;
50
51 pch_series = get_pch_series();
52
53 if (pch_series == PCH_H)
54 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H;
55 else if (pch_series == PCH_LP)
56 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP;
57 else
58 return 0;
59}
60
Andrey Petrovf35804b2017-06-05 13:22:41 -070061static void soc_config_pwrmbase(void)
62{
63 uint32_t reg32;
64
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053065 /*
66 * Assign Resources to PWRMBASE
67 * Clear BIT 1-2 Command Register
68 */
Andrey Petrovf35804b2017-06-05 13:22:41 -070069 reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND);
70 reg32 &= ~(PCI_COMMAND_MEMORY);
71 pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32);
72
73 /* Program PWRM Base */
74 pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS);
75
76 /* Enable Bus Master and MMIO Space */
77 reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND);
Subrata Banik154024d2019-10-30 17:22:33 +053078 reg32 |= PCI_COMMAND_MEMORY;
Andrey Petrovf35804b2017-06-05 13:22:41 -070079 pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32);
80
81 /* Enable PWRM in PMC */
82 reg32 = read32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL));
83 write32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL), reg32 | PWRM_EN);
84}
85
86void bootblock_pch_early_init(void)
87{
88 fast_spi_early_init(SPI_BASE_ADDRESS);
Furquan Shaikh1876f3a2017-12-07 18:39:34 -080089 gspi_early_bar_init();
Subrata Banik7837c202018-05-07 17:13:40 +053090 p2sb_enable_bar();
91 p2sb_configure_hpet();
Subrata Banikafa07f72018-05-24 12:21:06 +053092
Andrey Petrovf35804b2017-06-05 13:22:41 -070093 /*
94 * Enabling PWRM Base for accessing
95 * Global Reset Cause Register.
96 */
97 soc_config_pwrmbase();
98}
99
100
101static void soc_config_acpibase(void)
102{
103 uint32_t pmc_reg_value;
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530104 uint32_t pmc_base_reg;
Andrey Petrovf35804b2017-06-05 13:22:41 -0700105
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530106 pmc_base_reg = get_pmc_reg_base();
107 if (!pmc_base_reg)
Keith Short15588b02019-05-09 11:40:34 -0600108 die_with_post_code(POST_HW_INIT_FAILURE,
109 "Invalid PMC base address\n");
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530110
111 pmc_reg_value = pcr_read32(PID_PSF3, pmc_base_reg +
112 PCR_PSFX_TO_SHDW_BAR4);
Andrey Petrovf35804b2017-06-05 13:22:41 -0700113
114 if (pmc_reg_value != 0xFFFFFFFF)
115 {
116 /* Disable Io Space before changing the address */
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530117 pcr_rmw32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700118 PCR_PSFX_T0_SHDW_PCIEN,
119 ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0);
120 /* Program ABASE in PSF3 PMC space BAR4*/
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530121 pcr_write32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700122 PCR_PSFX_TO_SHDW_BAR4,
123 ACPI_BASE_ADDRESS);
124 /* Enable IO Space */
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530125 pcr_rmw32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700126 PCR_PSFX_T0_SHDW_PCIEN,
127 ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN);
128 }
129}
130
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700131static int pch_check_decode_enable(void)
132{
133 uint32_t dmi_control;
134
135 /*
136 * This cycle decoding is only allowed to set when
137 * DMICTL.SRLOCK is 0.
138 */
139 dmi_control = pcr_read32(PID_DMI, PCR_DMI_DMICTL);
140 if (dmi_control & PCR_DMI_DMICTL_SRLOCK)
141 return -1;
142 return 0;
143}
144
Andrey Petrovf35804b2017-06-05 13:22:41 -0700145void pch_early_iorange_init(void)
146{
Christian Walterf4aa5012019-08-13 15:09:10 +0200147 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 -0700148 LPC_IOE_EC_62_66 | LPC_IOE_LGE_200;
Andrey Petrovf35804b2017-06-05 13:22:41 -0700149
150 /* IO Decode Range */
Julius Wernercd49cce2019-03-05 16:53:33 -0800151 if (CONFIG(DRIVERS_UART_8250IO))
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700152 lpc_io_setup_comm_a_b();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700153
154 /* IO Decode Enable */
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700155 if (pch_check_decode_enable() == 0) {
156 io_enables = lpc_enable_fixed_io_ranges(io_enables);
157 /*
Wim Vervoornee38b992020-02-03 15:25:49 +0100158 * Set LPC IO Enables PCR[DMI] + 2774h [15:0] to the same
159 * value programmed in LPC PCI offset 82h.
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700160 */
161 pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables);
Wim Vervoorn84400182020-02-03 15:20:46 +0100162 /*
163 * Set LPC IO Decode Ranges PCR[DMI] + 2770h [15:0] to the same
164 * value programmed in LPC PCI offset 80h.
165 */
166 pcr_write16(PID_DMI, PCR_DMI_LPCIOD, lpc_get_fixed_io_decode());
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700167 }
Caveh Jalali1428f012018-01-23 22:15:24 -0800168
169 /* Program generic IO Decode Range */
170 pch_enable_lpc();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700171}
172
Usha P33ff4cc2019-11-28 10:05:45 +0530173void bootblock_pch_init(void)
Andrey Petrovf35804b2017-06-05 13:22:41 -0700174{
175 /*
176 * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT,
177 * GPE0_STS, GPE0_EN registers.
178 */
179 soc_config_acpibase();
180
Lijian Zhao031020e2017-12-15 12:58:07 -0800181 /* Set up GPE configuration */
182 pmc_gpe_init();
183
Andrey Petrovf35804b2017-06-05 13:22:41 -0700184 enable_rtc_upper_bank();
Subrata Banik73b1bd72019-11-28 13:56:24 +0530185
186 /* GPIO community PM configuration */
187 soc_gpio_pm_configuration();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700188}