Debian Codegraph @

src/soc/intel/cannonlake/bootblock/pch.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <device/mmio.h>
5 #include <device/device.h>
6 #include <device/pci_ops.h>
7 #include <gpio.h>
8 #include <intelblocks/fast_spi.h>
9 #include <intelblocks/gspi.h>
10 #include <intelblocks/lpc_lib.h>
11 #include <intelblocks/p2sb.h>
12 #include <intelblocks/pcr.h>
13 #include <intelblocks/pmclib.h>
14 #include <intelblocks/rtc.h>
15 #include <soc/bootblock.h>
16 #include <soc/iomap.h>
17 #include <soc/lpc.h>
18 #include <soc/p2sb.h>
19 #include <soc/pch.h>
20 #include <soc/pci_devs.h>
21 #include <soc/pcr_ids.h>
22 #include <soc/pm.h>
23
24 #define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP 0x1400
25 #define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H 0x0980
26
27 #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
35 static uint32_t get_pmc_reg_base(void)
36 {
37 if (CONFIG(SOC_INTEL_CANNONLAKE_PCH_H))
38 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H;
39 else
40 return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP;
41 }
42
43 static void soc_config_pwrmbase(void)
44 {
45 /*
46 * Assign Resources to PWRMBASE
47 * Clear BIT 1-2 Command Register
48 */
49 pci_and_config16(PCH_DEV_PMC, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
50
51 /* Program PWRM Base */
52 pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS);
53
54 /* Enable Bus Master and MMIO Space */
55 pci_or_config16(PCH_DEV_PMC, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
56
57 /* Enable PWRM in PMC */
58 setbits32((void *)PCH_PWRM_BASE_ADDRESS + ACTL, PWRM_EN);
59 }
60
61 void bootblock_pch_early_init(void)
62 {
63 /*
64 * Perform P2SB configuration before any another controller initialization as the
65 * controller might want to perform PCR settings.
66 */
67 p2sb_enable_bar();
68 p2sb_configure_hpet();
69
70 fast_spi_early_init(SPI_BASE_ADDRESS);
71 gspi_early_bar_init();
72
73 /*
74 * Enabling PWRM Base for accessing
75 * Global Reset Cause Register.
76 */
77 soc_config_pwrmbase();
78 }
79
80 static void soc_config_acpibase(void)
81 {
82 uint32_t pmc_reg_value;
83 uint32_t pmc_base_reg;
84
85 pmc_base_reg = get_pmc_reg_base();
86 if (!pmc_base_reg)
87 die_with_post_code(POSTCODE_HW_INIT_FAILURE,
88 "Invalid PMC base address\n");
89
90 pmc_reg_value = pcr_read32(PID_PSF3, pmc_base_reg +
91 PCR_PSFX_TO_SHDW_BAR4);
92
93 if (pmc_reg_value != 0xFFFFFFFF)
94 {
95 /* Disable Io Space before changing the address */
96 pcr_rmw32(PID_PSF3, pmc_base_reg +
97 PCR_PSFX_T0_SHDW_PCIEN,
98 ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0);
99 /* Program ABASE in PSF3 PMC space BAR4*/
100 pcr_write32(PID_PSF3, pmc_base_reg +
101 PCR_PSFX_TO_SHDW_BAR4,
102 ACPI_BASE_ADDRESS);
103 /* Enable IO Space */
104 pcr_rmw32(PID_PSF3, pmc_base_reg +
105 PCR_PSFX_T0_SHDW_PCIEN,
106 ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN);
107 }
108 }
109
110 void pch_early_iorange_init(void)
111 {
112 uint16_t io_enables = LPC_IOE_EC_4E_4F | LPC_IOE_SUPERIO_2E_2F | LPC_IOE_KBC_60_64 |
113 LPC_IOE_EC_62_66 | LPC_IOE_LGE_200;
114
115 /* IO Decode Range */
116 if (CONFIG(DRIVERS_UART_8250IO))
117 lpc_io_setup_comm_a_b();
118
119 /* IO Decode Enable */
120 lpc_enable_fixed_io_ranges(io_enables);
121
122 /* Program generic IO Decode Range */
123 pch_enable_lpc();
124 }
125
126 void bootblock_pch_init(void)
127 {
128 /*
129 * Clear the GPI interrupt status and enable registers. These
130 * registers do not get reset to default state when booting from S5.
131 */
132 gpi_clear_int_cfg();
133
134 /*
135 * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT,
136 * GPE0_STS, GPE0_EN registers.
137 */
138 soc_config_acpibase();
139
140 /* Set up GPE configuration */
141 pmc_gpe_init();
142
143 enable_rtc_upper_bank();
144
145 /* GPIO community PM configuration */
146 soc_gpio_pm_configuration();
147 }