blob: e1f054857abb821d0f46959057ea4d6f6e043d1c [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Andrey Petrovf35804b2017-06-05 13:22:41 -07002
Maulik V Vaghela9b08a182018-07-17 21:52:27 +05303#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -07005#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -07007#include <intelblocks/fast_spi.h>
Furquan Shaikh1876f3a2017-12-07 18:39:34 -08008#include <intelblocks/gspi.h>
Caveh Jalali1428f012018-01-23 22:15:24 -08009#include <intelblocks/lpc_lib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053010#include <intelblocks/p2sb.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070011#include <intelblocks/pcr.h>
Lijian Zhao031020e2017-12-15 12:58:07 -080012#include <intelblocks/pmclib.h>
Subrata Banik7837c202018-05-07 17:13:40 +053013#include <intelblocks/rtc.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070014#include <soc/bootblock.h>
Subrata Banik73b1bd72019-11-28 13:56:24 +053015#include <soc/gpio.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070016#include <soc/iomap.h>
17#include <soc/lpc.h>
18#include <soc/p2sb.h>
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053019#include <soc/pch.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070020#include <soc/pci_devs.h>
21#include <soc/pcr_ids.h>
Lijian Zhaob3dfcb82017-08-16 22:18:52 -070022#include <soc/pm.h>
Andrey Petrovf35804b2017-06-05 13:22:41 -070023
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053024#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP 0x1400
25#define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H 0x0980
26
Andrey Petrovf35804b2017-06-05 13:22:41 -070027#define PCR_PSFX_TO_SHDW_BAR0 0
28#define PCR_PSFX_TO_SHDW_BAR1 0x4
29#define PCR_PSFX_TO_SHDW_BAR2 0x8
30#define PCR_PSFX_TO_SHDW_BAR3 0xC
31#define PCR_PSFX_TO_SHDW_BAR4 0x10
32#define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01
33#define PCR_PSFX_T0_SHDW_PCIEN 0x1C
34
Duncan Laurie2aef7f32018-11-17 12:13:59 -070035#define PCR_DMI_DMICTL 0x2234
36#define PCR_DMI_DMICTL_SRLOCK (1 << 31)
37
Andrey Petrovf35804b2017-06-05 13:22:41 -070038#define PCR_DMI_ACPIBA 0x27B4
39#define PCR_DMI_ACPIBDID 0x27B8
40#define PCR_DMI_PMBASEA 0x27AC
41#define PCR_DMI_PMBASEC 0x27B0
Andrey Petrovf35804b2017-06-05 13:22:41 -070042
43#define PCR_DMI_LPCIOD 0x2770
44#define PCR_DMI_LPCIOE 0x2774
45
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053046static uint32_t get_pmc_reg_base(void)
47{
48 uint8_t pch_series;
49
50 pch_series = get_pch_series();
51
52 if (pch_series == PCH_H)
53 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H;
54 else if (pch_series == PCH_LP)
55 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP;
56 else
57 return 0;
58}
59
Andrey Petrovf35804b2017-06-05 13:22:41 -070060static void soc_config_pwrmbase(void)
61{
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053062 /*
63 * Assign Resources to PWRMBASE
Subrata Banik45caf972020-08-05 13:30:30 +053064 * Clear BIT 1-2 Command Register
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053065 */
Subrata Banik45caf972020-08-05 13:30:30 +053066 pci_and_config16(PCH_DEV_PMC, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
Andrey Petrovf35804b2017-06-05 13:22:41 -070067
68 /* Program PWRM Base */
69 pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS);
70
71 /* Enable Bus Master and MMIO Space */
Subrata Banik45caf972020-08-05 13:30:30 +053072 pci_or_config16(PCH_DEV_PMC, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
Andrey Petrovf35804b2017-06-05 13:22:41 -070073
74 /* Enable PWRM in PMC */
Subrata Banik45caf972020-08-05 13:30:30 +053075 setbits32((void *) PCH_PWRM_BASE_ADDRESS + ACTL, PWRM_EN);
Andrey Petrovf35804b2017-06-05 13:22:41 -070076}
77
78void bootblock_pch_early_init(void)
79{
80 fast_spi_early_init(SPI_BASE_ADDRESS);
Furquan Shaikh1876f3a2017-12-07 18:39:34 -080081 gspi_early_bar_init();
Subrata Banik7837c202018-05-07 17:13:40 +053082 p2sb_enable_bar();
83 p2sb_configure_hpet();
Subrata Banikafa07f72018-05-24 12:21:06 +053084
Andrey Petrovf35804b2017-06-05 13:22:41 -070085 /*
86 * Enabling PWRM Base for accessing
87 * Global Reset Cause Register.
88 */
89 soc_config_pwrmbase();
90}
91
92
93static void soc_config_acpibase(void)
94{
95 uint32_t pmc_reg_value;
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053096 uint32_t pmc_base_reg;
Andrey Petrovf35804b2017-06-05 13:22:41 -070097
Maulik V Vaghela9b08a182018-07-17 21:52:27 +053098 pmc_base_reg = get_pmc_reg_base();
99 if (!pmc_base_reg)
Keith Short15588b02019-05-09 11:40:34 -0600100 die_with_post_code(POST_HW_INIT_FAILURE,
101 "Invalid PMC base address\n");
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530102
103 pmc_reg_value = pcr_read32(PID_PSF3, pmc_base_reg +
104 PCR_PSFX_TO_SHDW_BAR4);
Andrey Petrovf35804b2017-06-05 13:22:41 -0700105
106 if (pmc_reg_value != 0xFFFFFFFF)
107 {
108 /* Disable Io Space before changing the address */
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530109 pcr_rmw32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700110 PCR_PSFX_T0_SHDW_PCIEN,
111 ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0);
112 /* Program ABASE in PSF3 PMC space BAR4*/
Maulik V Vaghela9b08a182018-07-17 21:52:27 +0530113 pcr_write32(PID_PSF3, pmc_base_reg +
Andrey Petrovf35804b2017-06-05 13:22:41 -0700114 PCR_PSFX_TO_SHDW_BAR4,
115 ACPI_BASE_ADDRESS);
116 /* Enable IO Space */
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 ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN);
120 }
121}
122
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700123static int pch_check_decode_enable(void)
124{
125 uint32_t dmi_control;
126
127 /*
128 * This cycle decoding is only allowed to set when
129 * DMICTL.SRLOCK is 0.
130 */
131 dmi_control = pcr_read32(PID_DMI, PCR_DMI_DMICTL);
132 if (dmi_control & PCR_DMI_DMICTL_SRLOCK)
133 return -1;
134 return 0;
135}
136
Andrey Petrovf35804b2017-06-05 13:22:41 -0700137void pch_early_iorange_init(void)
138{
Christian Walterf4aa5012019-08-13 15:09:10 +0200139 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 -0700140 LPC_IOE_EC_62_66 | LPC_IOE_LGE_200;
Andrey Petrovf35804b2017-06-05 13:22:41 -0700141
142 /* IO Decode Range */
Julius Wernercd49cce2019-03-05 16:53:33 -0800143 if (CONFIG(DRIVERS_UART_8250IO))
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700144 lpc_io_setup_comm_a_b();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700145
146 /* IO Decode Enable */
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700147 if (pch_check_decode_enable() == 0) {
148 io_enables = lpc_enable_fixed_io_ranges(io_enables);
149 /*
Wim Vervoornee38b992020-02-03 15:25:49 +0100150 * Set LPC IO Enables PCR[DMI] + 2774h [15:0] to the same
151 * value programmed in LPC PCI offset 82h.
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700152 */
153 pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables);
Wim Vervoorn84400182020-02-03 15:20:46 +0100154 /*
155 * Set LPC IO Decode Ranges PCR[DMI] + 2770h [15:0] to the same
156 * value programmed in LPC PCI offset 80h.
157 */
158 pcr_write16(PID_DMI, PCR_DMI_LPCIOD, lpc_get_fixed_io_decode());
Duncan Laurie2aef7f32018-11-17 12:13:59 -0700159 }
Caveh Jalali1428f012018-01-23 22:15:24 -0800160
161 /* Program generic IO Decode Range */
162 pch_enable_lpc();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700163}
164
Usha P33ff4cc2019-11-28 10:05:45 +0530165void bootblock_pch_init(void)
Andrey Petrovf35804b2017-06-05 13:22:41 -0700166{
167 /*
168 * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT,
169 * GPE0_STS, GPE0_EN registers.
170 */
171 soc_config_acpibase();
172
Lijian Zhao031020e2017-12-15 12:58:07 -0800173 /* Set up GPE configuration */
174 pmc_gpe_init();
175
Andrey Petrovf35804b2017-06-05 13:22:41 -0700176 enable_rtc_upper_bank();
Subrata Banik73b1bd72019-11-28 13:56:24 +0530177
178 /* GPIO community PM configuration */
179 soc_gpio_pm_configuration();
Andrey Petrovf35804b2017-06-05 13:22:41 -0700180}