blob: efa008d6bbeb26c5994bde1c171b62a470905dfa [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5c354b92019-04-22 14:55:16 -06002
Martin Roth5c354b92019-04-22 14:55:16 -06003#include <device/mmio.h>
4#include <bootstate.h>
5#include <cpu/x86/smm.h>
6#include <device/device.h>
7#include <device/pci.h>
Martin Roth5c354b92019-04-22 14:55:16 -06008#include <device/pci_ops.h>
Martin Roth5c354b92019-04-22 14:55:16 -06009#include <amdblocks/amd_pci_util.h>
Varshit Pandyaef513772024-02-09 18:26:32 +053010#include <amdblocks/pci_clk_req.h>
Martin Roth5c354b92019-04-22 14:55:16 -060011#include <amdblocks/reset.h>
12#include <amdblocks/acpimmio.h>
Martin Roth5c354b92019-04-22 14:55:16 -060013#include <amdblocks/acpi.h>
Felix Helddea4e0f2021-09-22 20:05:53 +020014#include <amdblocks/gpio.h>
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060015#include <amdblocks/i2c.h>
Felix Helda5a52952020-12-01 18:14:01 +010016#include <amdblocks/smi.h>
Marshall Dawson39a4ac12019-06-20 16:28:33 -060017#include <soc/cpu.h>
Felix Held5b01f2b2020-05-20 16:01:43 +020018#include <soc/i2c.h>
Felix Heldda5553c2021-02-03 14:42:42 +010019#include <soc/iomap.h>
Martin Roth5c354b92019-04-22 14:55:16 -060020#include <soc/southbridge.h>
Martin Roth5c354b92019-04-22 14:55:16 -060021#include <soc/smi.h>
22#include <soc/amd_pci_int_defs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060023#include <soc/pci_devs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060024#include <types.h>
Furquan Shaikh69c28112020-04-28 18:57:52 -070025#include "chip.h"
Martin Roth5c354b92019-04-22 14:55:16 -060026
Martin Roth5c354b92019-04-22 14:55:16 -060027/*
28 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
29 * provides a visible association with the index, therefore helping
30 * maintainability of table. If a new index/name is defined in
31 * amd_pci_int_defs.h, just add the pair at the end of this table.
32 * Order is not important.
33 */
Elyes Haouas24769422023-01-12 06:21:42 +010034static const struct irq_idx_name irq_association[] = {
Martin Roth5c354b92019-04-22 14:55:16 -060035 { PIRQ_A, "INTA#" },
36 { PIRQ_B, "INTB#" },
37 { PIRQ_C, "INTC#" },
38 { PIRQ_D, "INTD#" },
39 { PIRQ_E, "INTE#" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060040 { PIRQ_F, "INTF#/GENINT2" },
Martin Roth5c354b92019-04-22 14:55:16 -060041 { PIRQ_G, "INTG#" },
42 { PIRQ_H, "INTH#" },
43 { PIRQ_MISC, "Misc" },
44 { PIRQ_MISC0, "Misc0" },
45 { PIRQ_MISC1, "Misc1" },
46 { PIRQ_MISC2, "Misc2" },
47 { PIRQ_SIRQA, "Ser IRQ INTA" },
48 { PIRQ_SIRQB, "Ser IRQ INTB" },
49 { PIRQ_SIRQC, "Ser IRQ INTC" },
50 { PIRQ_SIRQD, "Ser IRQ INTD" },
51 { PIRQ_SCI, "SCI" },
52 { PIRQ_SMBUS, "SMBUS" },
53 { PIRQ_ASF, "ASF" },
Martin Roth5c354b92019-04-22 14:55:16 -060054 { PIRQ_PMON, "PerMon" },
55 { PIRQ_SD, "SD" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060056 { PIRQ_SDIO, "SDIO" },
57 { PIRQ_CIR, "CIR" },
58 { PIRQ_GPIOA, "GPIOa" },
59 { PIRQ_GPIOB, "GPIOb" },
60 { PIRQ_GPIOC, "GPIOc" },
Martin Roth5c354b92019-04-22 14:55:16 -060061 { PIRQ_SATA, "SATA" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060062 { PIRQ_EMMC, "eMMC" },
63 { PIRQ_GPP0, "GPP0" },
64 { PIRQ_GPP1, "GPP1" },
65 { PIRQ_GPP2, "GPP2" },
66 { PIRQ_GPP3, "GPP3" },
Martin Roth5c354b92019-04-22 14:55:16 -060067 { PIRQ_GPIO, "GPIO" },
68 { PIRQ_I2C0, "I2C0" },
69 { PIRQ_I2C1, "I2C1" },
70 { PIRQ_I2C2, "I2C2" },
71 { PIRQ_I2C3, "I2C3" },
72 { PIRQ_UART0, "UART0" },
73 { PIRQ_UART1, "UART1" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060074 { PIRQ_I2C4, "I2C4" },
75 { PIRQ_I2C5, "I2C5" },
76 { PIRQ_UART2, "UART2" },
77 { PIRQ_UART3, "UART3" },
Martin Roth5c354b92019-04-22 14:55:16 -060078};
79
80const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
81{
82 *size = ARRAY_SIZE(irq_association);
83 return irq_association;
84}
85
Felix Heldf66e7812021-07-22 17:38:27 +020086static void fch_clk_output_48Mhz(void)
Martin Roth5c354b92019-04-22 14:55:16 -060087{
88 u32 ctrl;
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060089 const struct soc_amd_picasso_config *cfg = config_of_soc();
Martin Roth5c354b92019-04-22 14:55:16 -060090
Martin Roth5c354b92019-04-22 14:55:16 -060091 ctrl = misc_read32(MISC_CLK_CNTL1);
Eric Laidd32e652020-12-15 14:51:50 +080092 /* If used external clock source for I2S, disable the internal clock output */
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060093 if (cfg->acp_i2s_use_external_48mhz_osc &&
94 cfg->common_config.acp_config.acp_pin_cfg == I2S_PINS_I2S_TDM)
Eric Laidd32e652020-12-15 14:51:50 +080095 ctrl &= ~BP_X48M0_OUTPUT_EN;
96 else
97 ctrl |= BP_X48M0_OUTPUT_EN;
Martin Roth5c354b92019-04-22 14:55:16 -060098 misc_write32(MISC_CLK_CNTL1, ctrl);
99}
100
Chris Wangad4f6d72021-01-26 20:09:34 +0800101static void sb_rfmux_config_override(void)
102{
103 u8 port;
104 const struct soc_amd_picasso_config *cfg;
105
106 cfg = config_of_soc();
107
108 for (port = 0; port < USB_PD_PORT_COUNT; port++) {
109 if (cfg->usb_pd_config_override[port].rfmux_override_en) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200110 write32p(USB_PD_PORT_CONTROL + PD_PORT_MUX_OFFSET(port),
Chris Wangad4f6d72021-01-26 20:09:34 +0800111 cfg->usb_pd_config_override[port].rfmux_config
112 | USB_PD_RFMUX_OVERRIDE);
113 }
114 }
115}
116
Felix Heldee1fb0a2021-02-02 01:10:59 +0100117static void fch_init_acpi_ports(void)
Martin Roth5c354b92019-04-22 14:55:16 -0600118{
119 u32 reg;
120
121 /* We use some of these ports in SMM regardless of whether or not
122 * ACPI tables are generated. Enable these ports indiscriminately.
123 */
124
125 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
126 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
127 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
128 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Marshall Dawson39a4ac12019-06-20 16:28:33 -0600129
Martin Roth5c354b92019-04-22 14:55:16 -0600130 if (CONFIG(HAVE_SMI_HANDLER)) {
131 /* APMC - SMI Command Port */
132 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
133 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
134
135 /* SMI on SlpTyp requires sending SMI before completion
Felix Held5dd52c72021-02-10 19:53:38 +0100136 response of the I/O write. */
Martin Roth5c354b92019-04-22 14:55:16 -0600137 reg = pm_read32(PM_PCI_CTRL);
138 reg |= FORCE_SLPSTATE_RETRY;
Martin Roth5c354b92019-04-22 14:55:16 -0600139 pm_write32(PM_PCI_CTRL, reg);
140
141 /* Disable SlpTyp feature */
142 reg = pm_read8(PM_RST_CTRL1);
143 reg &= ~SLPTYPE_CONTROL_EN;
144 pm_write8(PM_RST_CTRL1, reg);
145
146 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
147 } else {
148 pm_write16(PM_ACPI_SMI_CMD, 0);
149 }
150
151 /* Decode ACPI registers and enable standard features */
152 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
153 PM_ACPI_GLOBAL_EN |
154 PM_ACPI_RTC_EN_EN |
155 PM_ACPI_TIMER_EN_EN);
156}
157
Matt Papageorgeab83b432020-06-26 08:47:00 -0500158/*
159 * A-Link to AHB bridge, part of the AMBA fabric. These are internal clocks
160 * and unneeded for Raven/Picasso so gate them to save power.
161 */
162static void al2ahb_clock_gate(void)
163{
164 uint8_t al2ahb_val;
165 uintptr_t al2ahb_base = ALINK_AHB_ADDRESS;
166
Felix Heldf69cb292022-09-29 16:05:41 +0200167 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500168 al2ahb_val |= AL2AHB_CLK_GATE_EN;
Felix Heldf69cb292022-09-29 16:05:41 +0200169 write8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET, al2ahb_val);
170 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500171 al2ahb_val |= AL2AHB_HCLK_GATE_EN;
Felix Heldf69cb292022-09-29 16:05:41 +0200172 write8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET, al2ahb_val);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500173}
174
Martin Roth26f97f92021-10-01 14:53:22 -0600175/* configure the general purpose PCIe clock outputs according to the devicetree settings */
Felix Held82a0a632020-08-28 01:40:20 +0200176static void gpp_clk_setup(void)
177{
Varshit Pandyaef513772024-02-09 18:26:32 +0530178 struct soc_amd_picasso_config *cfg = config_of_soc();
Felix Held82a0a632020-08-28 01:40:20 +0200179
180 /* look-up table to be able to iterate over the PCIe clock output settings */
181 const uint8_t gpp_clk_shift_lut[GPP_CLK_OUTPUT_COUNT] = {
182 GPP_CLK0_REQ_SHIFT,
183 GPP_CLK1_REQ_SHIFT,
184 GPP_CLK2_REQ_SHIFT,
185 GPP_CLK3_REQ_SHIFT,
186 GPP_CLK4_REQ_SHIFT,
187 GPP_CLK5_REQ_SHIFT,
188 GPP_CLK6_REQ_SHIFT,
189 };
190
191 uint32_t gpp_clk_ctl = misc_read32(GPP_CLK_CNTRL);
192
Varshit Pandyaef513772024-02-09 18:26:32 +0530193 pcie_gpp_dxio_update_clk_req_config(&cfg->gpp_clk_config[0],
194 ARRAY_SIZE(cfg->gpp_clk_config));
Felix Held82a0a632020-08-28 01:40:20 +0200195 for (int i = 0; i < GPP_CLK_OUTPUT_COUNT; i++) {
196 gpp_clk_ctl &= ~GPP_CLK_REQ_MASK(gpp_clk_shift_lut[i]);
197 /*
198 * The remapping of values is done so that the default of the enum used for the
199 * devicetree settings is the clock being enabled, so that a missing devicetree
200 * configuration for this will result in an always active clock and not an
201 * inactive PCIe clock output.
202 */
203 switch (cfg->gpp_clk_config[i]) {
204 case GPP_CLK_REQ:
205 gpp_clk_ctl |= GPP_CLK_REQ_EXT(gpp_clk_shift_lut[i]);
206 break;
207 case GPP_CLK_OFF:
208 gpp_clk_ctl |= GPP_CLK_REQ_OFF(gpp_clk_shift_lut[i]);
209 break;
210 case GPP_CLK_ON:
211 default:
212 gpp_clk_ctl |= GPP_CLK_REQ_ON(gpp_clk_shift_lut[i]);
213 }
214 }
215
216 misc_write32(GPP_CLK_CNTRL, gpp_clk_ctl);
217}
218
Felix Heldfaaafb42021-01-28 23:19:40 +0100219void fch_init(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600220{
Aaron Durbin09f60ff2020-04-09 15:24:50 -0600221 i2c_soc_init();
Felix Heldee1fb0a2021-02-02 01:10:59 +0100222 fch_init_acpi_ports();
Aaron Durbin404a5c32020-08-14 16:27:27 -0600223
Kyösti Mälkkib0db8132021-01-21 16:34:43 +0200224 acpi_pm_gpe_add_events_print_events();
225 gpio_add_events();
226
Matt Papageorgeab83b432020-06-26 08:47:00 -0500227 al2ahb_clock_gate();
Felix Held82a0a632020-08-28 01:40:20 +0200228
229 gpp_clk_setup();
Eric Lai3b648ba2020-12-18 10:51:46 +0800230
Felix Heldf66e7812021-07-22 17:38:27 +0200231 fch_clk_output_48Mhz();
Chris Wangad4f6d72021-01-26 20:09:34 +0800232
233 sb_rfmux_config_override();
Martin Roth5c354b92019-04-22 14:55:16 -0600234}
235
Felix Heldfaaafb42021-01-28 23:19:40 +0100236void fch_final(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600237{
Martin Roth5c354b92019-04-22 14:55:16 -0600238}
239
240/*
241 * Update the PCI devices with a valid IRQ number
242 * that is set in the mainboard PCI_IRQ structures.
243 */
244static void set_pci_irqs(void *unused)
245{
246 /* Write PCI_INTR regs 0xC00/0xC01 */
247 write_pci_int_table();
248
Raul E Rangel4e80fae2020-12-16 10:08:41 -0700249 /* pirq_data is consumed by `write_pci_cfg_irqs` */
250 populate_pirq_data();
251
Martin Roth5c354b92019-04-22 14:55:16 -0600252 /* Write IRQs for all devicetree enabled devices */
253 write_pci_cfg_irqs();
254}
255
256/*
257 * Hook this function into the PCI state machine
258 * on entry into BS_DEV_ENABLE.
259 */
260BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);