blob: dd19c310bc57c70f83ac99e8f1fa61d13bff7243 [file] [log] [blame]
Felix Held230dbd62021-01-28 23:40:52 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Felix Held72b78912021-04-13 00:08:33 +02003#include <amdblocks/acpi.h>
Felix Held7e703d72021-02-03 21:38:14 +01004#include <amdblocks/acpimmio.h>
Raul E Rangela6529e72021-02-09 14:38:36 -07005#include <amdblocks/amd_pci_util.h>
Felix Helddea4e0f2021-09-22 20:05:53 +02006#include <amdblocks/gpio.h>
Felix Helde094b1f2021-02-09 22:55:04 +01007#include <amdblocks/smi.h>
Felix Held7e703d72021-02-03 21:38:14 +01008#include <assert.h>
Raul E Rangela6529e72021-02-09 14:38:36 -07009#include <bootstate.h>
Felix Helde094b1f2021-02-09 22:55:04 +010010#include <cpu/x86/smm.h>
Zheng Bao7b13e4e2021-03-16 16:13:56 +080011#include <amdblocks/i2c.h>
Raul E Rangela6529e72021-02-09 14:38:36 -070012#include <soc/amd_pci_int_defs.h>
Felix Held7e703d72021-02-03 21:38:14 +010013#include <soc/iomap.h>
Zheng Bao7b13e4e2021-03-16 16:13:56 +080014#include <soc/i2c.h>
Felix Helde094b1f2021-02-09 22:55:04 +010015#include <soc/smi.h>
Felix Held230dbd62021-01-28 23:40:52 +010016#include <soc/southbridge.h>
Felix Held224b5782021-05-18 01:25:51 +020017#include "chip.h"
Felix Held230dbd62021-01-28 23:40:52 +010018
Raul E Rangela6529e72021-02-09 14:38:36 -070019/*
20 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
21 * provides a visible association with the index, therefore helping
22 * maintainability of table. If a new index/name is defined in
23 * amd_pci_int_defs.h, just add the pair at the end of this table.
24 * Order is not important.
25 */
26const static struct irq_idx_name irq_association[] = {
27 { PIRQ_A, "INTA#" },
28 { PIRQ_B, "INTB#" },
29 { PIRQ_C, "INTC#" },
30 { PIRQ_D, "INTD#" },
31 { PIRQ_E, "INTE#" },
32 { PIRQ_F, "INTF#/GENINT2" },
33 { PIRQ_G, "INTG#" },
34 { PIRQ_H, "INTH#" },
35 { PIRQ_MISC, "Misc" },
36 { PIRQ_MISC0, "Misc0" },
37 { PIRQ_HPET_L, "HPET_L" },
38 { PIRQ_HPET_H, "HPET_H" },
39 { PIRQ_SIRQA, "Ser IRQ INTA" },
40 { PIRQ_SIRQB, "Ser IRQ INTB" },
41 { PIRQ_SIRQC, "Ser IRQ INTC" },
42 { PIRQ_SIRQD, "Ser IRQ INTD" },
43 { PIRQ_SCI, "SCI" },
44 { PIRQ_SMBUS, "SMBUS" },
45 { PIRQ_ASF, "ASF" },
46 { PIRQ_PMON, "PerMon" },
47 { PIRQ_SD, "SD" },
48 { PIRQ_SDIO, "SDIO" },
49 { PIRQ_CIR, "CIR" },
50 { PIRQ_GPIOA, "GPIOa" },
51 { PIRQ_GPIOB, "GPIOb" },
52 { PIRQ_GPIOC, "GPIOc" },
53 { PIRQ_SATA, "SATA" },
54 { PIRQ_EMMC, "eMMC" },
55 { PIRQ_GPP0, "GPP0" },
56 { PIRQ_GPP1, "GPP1" },
57 { PIRQ_GPP2, "GPP2" },
58 { PIRQ_GPP3, "GPP3" },
59 { PIRQ_GPIO, "GPIO" },
60 { PIRQ_I2C0, "I2C0" },
61 { PIRQ_I2C1, "I2C1" },
62 { PIRQ_I2C2, "I2C2" },
63 { PIRQ_I2C3, "I2C3" },
64 { PIRQ_UART0, "UART0" },
65 { PIRQ_UART1, "UART1" },
66 { PIRQ_I2C4, "I2C4" },
67 { PIRQ_I2C5, "I2C5" },
68};
69
70const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
71{
72 *size = ARRAY_SIZE(irq_association);
73 return irq_association;
74}
75
Felix Heldfd2982e2021-07-22 17:41:38 +020076static void fch_clk_output_48Mhz(void)
77{
78 uint32_t ctrl = misc_read32(MISC_CLK_CNTL0);
79 /* Enable BP_X48M0 Clock Output */
80 ctrl |= BP_X48M0_OUTPUT_EN;
81 misc_write32(MISC_CLK_CNTL0, ctrl);
82}
83
Felix Held7e703d72021-02-03 21:38:14 +010084static void fch_init_acpi_ports(void)
85{
Felix Helde094b1f2021-02-09 22:55:04 +010086 u32 reg;
87
Felix Held7e703d72021-02-03 21:38:14 +010088 /* We use some of these ports in SMM regardless of whether or not
89 * ACPI tables are generated. Enable these ports indiscriminately.
90 */
91
92 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
93 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
94 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
95 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
96
97 if (CONFIG(HAVE_SMI_HANDLER)) {
Felix Helde094b1f2021-02-09 22:55:04 +010098 /* APMC - SMI Command Port */
99 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
100 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
101
102 /* SMI on SlpTyp requires sending SMI before completion
103 response of the I/O write. */
104 reg = pm_read32(PM_PCI_CTRL);
105 reg |= FORCE_SLPSTATE_RETRY;
106 pm_write32(PM_PCI_CTRL, reg);
107
108 /* Disable SlpTyp feature */
109 reg = pm_read8(PM_RST_CTRL1);
110 reg &= ~SLPTYPE_CONTROL_EN;
111 pm_write8(PM_RST_CTRL1, reg);
112
113 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
Felix Held7e703d72021-02-03 21:38:14 +0100114 } else {
115 pm_write16(PM_ACPI_SMI_CMD, 0);
116 }
117
118 /* Decode ACPI registers and enable standard features */
119 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
120 PM_ACPI_GLOBAL_EN |
121 PM_ACPI_RTC_EN_EN |
122 PM_ACPI_TIMER_EN_EN);
123}
124
Marshall Dawson3e1943e2021-05-06 16:08:09 -0600125static void fch_init_resets(void)
126{
127 pm_write16(PWR_RESET_CFG, pm_read16(PWR_RESET_CFG) | TOGGLE_ALL_PWR_GOOD);
128}
129
Martin Roth26f97f92021-10-01 14:53:22 -0600130/* configure the general purpose PCIe clock outputs according to the devicetree settings */
Felix Held224b5782021-05-18 01:25:51 +0200131static void gpp_clk_setup(void)
132{
133 const struct soc_amd_cezanne_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.
155 */
156 switch (cfg->gpp_clk_config[i]) {
157 case GPP_CLK_REQ:
158 gpp_clk_ctl |= GPP_CLK_REQ_EXT(gpp_clk_shift_lut[i]);
159 break;
160 case GPP_CLK_OFF:
161 gpp_clk_ctl |= GPP_CLK_REQ_OFF(gpp_clk_shift_lut[i]);
162 break;
163 case GPP_CLK_ON:
164 default:
165 gpp_clk_ctl |= GPP_CLK_REQ_ON(gpp_clk_shift_lut[i]);
166 }
167 }
168
169 misc_write32(GPP_CLK_CNTRL, gpp_clk_ctl);
170}
171
Julian Schroeder5412a812021-10-12 10:58:49 -0500172static void cgpll_clock_gate_init(void)
173{
174 uint32_t t;
175
176 t = misc_read32(MISC_CLKGATEDCNTL);
177 t |= ALINKCLK_GATEOFFEN;
178 t |= BLINKCLK_GATEOFFEN;
179 t |= XTAL_PAD_S3_TURNOFF_EN;
180 t |= XTAL_PAD_S5_TURNOFF_EN;
181 misc_write32(MISC_CLKGATEDCNTL, t);
182
183 t = misc_read32(MISC_CGPLL_CONFIGURATION0);
184 t |= USB_PHY_CMCLK_S3_DIS;
185 t |= USB_PHY_CMCLK_S0I3_DIS;
186 t |= USB_PHY_CMCLK_S5_DIS;
187 misc_write32(MISC_CGPLL_CONFIGURATION0, t);
188
189 t = pm_read32(PM_ISACONTROL);
190 t |= ABCLKGATEEN;
191 pm_write32(PM_ISACONTROL, t);
192}
193
Felix Held230dbd62021-01-28 23:40:52 +0100194void fch_init(void *chip_info)
195{
Marshall Dawson3e1943e2021-05-06 16:08:09 -0600196 fch_init_resets();
Zheng Bao7b13e4e2021-03-16 16:13:56 +0800197 i2c_soc_init();
Felix Held7e703d72021-02-03 21:38:14 +0100198 fch_init_acpi_ports();
Felix Held72b78912021-04-13 00:08:33 +0200199
200 acpi_pm_gpe_add_events_print_events();
201 gpio_add_events();
202 acpi_clear_pm_gpe_status();
Felix Held224b5782021-05-18 01:25:51 +0200203
204 gpp_clk_setup();
Felix Heldfd2982e2021-07-22 17:41:38 +0200205 fch_clk_output_48Mhz();
Julian Schroeder5412a812021-10-12 10:58:49 -0500206 cgpll_clock_gate_init();
Felix Held230dbd62021-01-28 23:40:52 +0100207}
208
209void fch_final(void *chip_info)
210{
211}
Raul E Rangela6529e72021-02-09 14:38:36 -0700212
213static void set_pci_irqs(void *unused)
214{
215 /* Write PCI_INTR regs 0xC00/0xC01 */
216 write_pci_int_table();
Raul E Rangelfd7ed872021-05-04 15:42:09 -0600217
218 /* pirq_data is consumed by `write_pci_cfg_irqs` */
219 populate_pirq_data();
220
221 /* Write IRQs for all devicetree enabled devices */
222 write_pci_cfg_irqs();
Raul E Rangela6529e72021-02-09 14:38:36 -0700223}
224
225/*
226 * Hook this function into the PCI state machine
227 * on entry into BS_DEV_ENABLE.
228 */
229BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);