blob: 93597c9a3b527a3f1bf55ff1657a3b695902691a [file] [log] [blame]
Martin Rothf95a11e2022-10-21 16:43:08 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3/* TODO: Update for Glinda */
4
5#include <amdblocks/acpi.h>
6#include <amdblocks/acpimmio.h>
7#include <amdblocks/amd_pci_util.h>
8#include <amdblocks/gpio.h>
Martin Roth10c43a22023-02-02 17:21:37 -07009#include <amdblocks/reset.h>
Martin Rothf95a11e2022-10-21 16:43:08 -060010#include <amdblocks/smi.h>
11#include <assert.h>
12#include <bootstate.h>
13#include <cpu/x86/smm.h>
14#include <amdblocks/i2c.h>
15#include <soc/amd_pci_int_defs.h>
16#include <soc/iomap.h>
17#include <soc/i2c.h>
18#include <soc/smi.h>
19#include <soc/southbridge.h>
20#include "chip.h"
21
22/*
23 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
24 * provides a visible association with the index, therefore helping
25 * maintainability of table. If a new index/name is defined in
26 * amd_pci_int_defs.h, just add the pair at the end of this table.
27 * Order is not important.
28 */
Elyes Haouas24769422023-01-12 06:21:42 +010029static const struct irq_idx_name irq_association[] = {
Martin Rothf95a11e2022-10-21 16:43:08 -060030 { PIRQ_A, "INTA#" },
31 { PIRQ_B, "INTB#" },
32 { PIRQ_C, "INTC#" },
33 { PIRQ_D, "INTD#" },
34 { PIRQ_E, "INTE#" },
35 { PIRQ_F, "INTF#/GENINT2" },
36 { PIRQ_G, "INTG#" },
37 { PIRQ_H, "INTH#" },
38 { PIRQ_MISC, "Misc" },
39 { PIRQ_MISC0, "Misc0" },
40 { PIRQ_HPET_L, "HPET_L" },
41 { PIRQ_HPET_H, "HPET_H" },
42 { PIRQ_SIRQA, "Ser IRQ INTA" },
43 { PIRQ_SIRQB, "Ser IRQ INTB" },
44 { PIRQ_SIRQC, "Ser IRQ INTC" },
45 { PIRQ_SIRQD, "Ser IRQ INTD" },
46 { PIRQ_SCI, "SCI" },
47 { PIRQ_SMBUS, "SMBUS" },
48 { PIRQ_ASF, "ASF" },
49 { PIRQ_PMON, "PerMon" },
50 { PIRQ_SD, "SD" },
51 { PIRQ_SDIO, "SDIO" },
52 { PIRQ_CIR, "CIR" },
53 { PIRQ_GPIOA, "GPIOa" },
54 { PIRQ_GPIOB, "GPIOb" },
55 { PIRQ_GPIOC, "GPIOc" },
Martin Rothf95a11e2022-10-21 16:43:08 -060056 { PIRQ_GPP0, "GPP0" },
57 { PIRQ_GPP1, "GPP1" },
58 { PIRQ_GPP2, "GPP2" },
59 { PIRQ_GPP3, "GPP3" },
60 { PIRQ_GPIO, "GPIO" },
61 { PIRQ_I2C0, "I2C0" },
62 { PIRQ_I2C1, "I2C1" },
63 { PIRQ_I2C2, "I2C2" },
64 { PIRQ_I2C3, "I2C3" },
65 { PIRQ_UART0, "UART0" },
66 { PIRQ_UART1, "UART1" },
67 { PIRQ_I2C4, "I2C4" },
68 { PIRQ_UART4, "UART4" },
69 { PIRQ_UART2, "UART2" },
70 { PIRQ_UART3, "UART3" },
71};
72
73const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
74{
75 *size = ARRAY_SIZE(irq_association);
76 return irq_association;
77}
78
79static void fch_clk_output_48Mhz(void)
80{
81 uint32_t ctrl = misc_read32(MISC_CLK_CNTL0);
82 /* Enable BP_X48M0 Clock Output */
83 ctrl |= BP_X48M0_OUTPUT_EN;
84 /* Disable clock output in S0i3 */
85 ctrl |= BP_X48M0_S0I3_DIS;
86 misc_write32(MISC_CLK_CNTL0, ctrl);
87}
88
89static void fch_init_acpi_ports(void)
90{
91 u32 reg;
92
93 /* We use some of these ports in SMM regardless of whether or not
94 * ACPI tables are generated. Enable these ports indiscriminately.
95 */
96
97 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
98 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
99 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
100 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
101
102 if (CONFIG(HAVE_SMI_HANDLER)) {
103 /* APMC - SMI Command Port */
104 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
105 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
106
107 /* SMI on SlpTyp requires sending SMI before completion
108 response of the I/O write. */
109 reg = pm_read32(PM_PCI_CTRL);
110 reg |= FORCE_SLPSTATE_RETRY;
111 pm_write32(PM_PCI_CTRL, reg);
112
113 /* Disable SlpTyp feature */
114 reg = pm_read8(PM_RST_CTRL1);
115 reg &= ~SLPTYPE_CONTROL_EN;
116 pm_write8(PM_RST_CTRL1, reg);
117
118 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
119 } else {
120 pm_write16(PM_ACPI_SMI_CMD, 0);
121 }
122
123 /* Decode ACPI registers and enable standard features */
124 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
125 PM_ACPI_GLOBAL_EN |
126 PM_ACPI_RTC_EN_EN |
127 PM_ACPI_TIMER_EN_EN);
128}
129
130/* configure the general purpose PCIe clock outputs according to the devicetree settings */
131static void gpp_clk_setup(void)
132{
133 const struct soc_amd_glinda_config *cfg = config_of_soc();
134
135 /* look-up table to be able to iterate over the PCIe clock output settings */
136 const uint8_t gpp_clk_shift_lut[GPP_CLK_OUTPUT_COUNT] = {
137 GPP_CLK0_REQ_SHIFT,
138 GPP_CLK1_REQ_SHIFT,
139 GPP_CLK2_REQ_SHIFT,
140 GPP_CLK3_REQ_SHIFT,
141 GPP_CLK4_REQ_SHIFT,
142 GPP_CLK5_REQ_SHIFT,
143 GPP_CLK6_REQ_SHIFT,
144 };
145
146 uint32_t gpp_clk_ctl = misc_read32(GPP_CLK_CNTRL);
147
148 for (int i = 0; i < GPP_CLK_OUTPUT_COUNT; i++) {
149 gpp_clk_ctl &= ~GPP_CLK_REQ_MASK(gpp_clk_shift_lut[i]);
150 /*
151 * The remapping of values is done so that the default of the enum used for the
152 * devicetree settings is the clock being enabled, so that a missing devicetree
153 * configuration for this will result in an always active clock and not an
154 * inactive PCIe clock output. Only the configuration for the clock outputs
155 * available on the package is provided via the devicetree; the rest is
156 * switched off unconditionally.
157 */
158 switch (i < GPP_CLK_OUTPUT_AVAILABLE ? cfg->gpp_clk_config[i] : GPP_CLK_OFF) {
159 case GPP_CLK_REQ:
160 gpp_clk_ctl |= GPP_CLK_REQ_EXT(gpp_clk_shift_lut[i]);
161 break;
162 case GPP_CLK_OFF:
163 gpp_clk_ctl |= GPP_CLK_REQ_OFF(gpp_clk_shift_lut[i]);
164 break;
165 case GPP_CLK_ON:
166 default:
167 gpp_clk_ctl |= GPP_CLK_REQ_ON(gpp_clk_shift_lut[i]);
168 }
169 }
170
171 misc_write32(GPP_CLK_CNTRL, gpp_clk_ctl);
172}
173
174static void cgpll_clock_gate_init(void)
175{
176 uint32_t t;
177
178 t = misc_read32(MISC_CLKGATEDCNTL);
179 t |= ALINKCLK_GATEOFFEN;
180 t |= BLINKCLK_GATEOFFEN;
181 t |= XTAL_PAD_S0I3_TURNOFF_EN;
182 t |= XTAL_PAD_S3_TURNOFF_EN;
183 t |= XTAL_PAD_S5_TURNOFF_EN;
184 misc_write32(MISC_CLKGATEDCNTL, t);
185
186 t = misc_read32(MISC_CGPLL_CONFIGURATION0);
187 t |= USB_PHY_CMCLK_S3_DIS;
188 t |= USB_PHY_CMCLK_S0I3_DIS;
189 t |= USB_PHY_CMCLK_S5_DIS;
190 misc_write32(MISC_CGPLL_CONFIGURATION0, t);
191
192 t = pm_read32(PM_ISACONTROL);
193 t |= ABCLKGATEEN;
194 pm_write32(PM_ISACONTROL, t);
195}
196
197void fch_init(void *chip_info)
198{
Martin Roth10c43a22023-02-02 17:21:37 -0700199 set_resets_to_cold();
Martin Rothf95a11e2022-10-21 16:43:08 -0600200 i2c_soc_init();
201 fch_init_acpi_ports();
202
203 acpi_pm_gpe_add_events_print_events();
204 gpio_add_events();
205
206 gpp_clk_setup();
207 fch_clk_output_48Mhz();
208 cgpll_clock_gate_init();
209}
210
211void fch_final(void *chip_info)
212{
213}
214
215static void set_pci_irqs(void *unused)
216{
217 /* Write PCI_INTR regs 0xC00/0xC01 */
218 write_pci_int_table();
219
220 /* pirq_data is consumed by `write_pci_cfg_irqs` */
221 populate_pirq_data();
222
223 /* Write IRQs for all devicetree enabled devices */
224 write_pci_cfg_irqs();
225}
226
227/*
228 * Hook this function into the PCI state machine
229 * on entry into BS_DEV_ENABLE.
230 */
231BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);