blob: bfe65a2b9e49c2e308f2ee7d9cb792b516bce51b [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>
Martin Roth5c354b92019-04-22 14:55:16 -060010#include <amdblocks/reset.h>
11#include <amdblocks/acpimmio.h>
Martin Roth5c354b92019-04-22 14:55:16 -060012#include <amdblocks/acpi.h>
Felix Helddea4e0f2021-09-22 20:05:53 +020013#include <amdblocks/gpio.h>
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060014#include <amdblocks/i2c.h>
Felix Helda5a52952020-12-01 18:14:01 +010015#include <amdblocks/smi.h>
Marshall Dawson39a4ac12019-06-20 16:28:33 -060016#include <soc/cpu.h>
Felix Held5b01f2b2020-05-20 16:01:43 +020017#include <soc/i2c.h>
Felix Heldda5553c2021-02-03 14:42:42 +010018#include <soc/iomap.h>
Martin Roth5c354b92019-04-22 14:55:16 -060019#include <soc/southbridge.h>
Martin Roth5c354b92019-04-22 14:55:16 -060020#include <soc/smi.h>
21#include <soc/amd_pci_int_defs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060022#include <soc/pci_devs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060023#include <types.h>
Furquan Shaikh69c28112020-04-28 18:57:52 -070024#include "chip.h"
Martin Roth5c354b92019-04-22 14:55:16 -060025
Martin Roth5c354b92019-04-22 14:55:16 -060026/*
27 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
28 * provides a visible association with the index, therefore helping
29 * maintainability of table. If a new index/name is defined in
30 * amd_pci_int_defs.h, just add the pair at the end of this table.
31 * Order is not important.
32 */
Elyes Haouas24769422023-01-12 06:21:42 +010033static const struct irq_idx_name irq_association[] = {
Martin Roth5c354b92019-04-22 14:55:16 -060034 { PIRQ_A, "INTA#" },
35 { PIRQ_B, "INTB#" },
36 { PIRQ_C, "INTC#" },
37 { PIRQ_D, "INTD#" },
38 { PIRQ_E, "INTE#" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060039 { PIRQ_F, "INTF#/GENINT2" },
Martin Roth5c354b92019-04-22 14:55:16 -060040 { PIRQ_G, "INTG#" },
41 { PIRQ_H, "INTH#" },
42 { PIRQ_MISC, "Misc" },
43 { PIRQ_MISC0, "Misc0" },
44 { PIRQ_MISC1, "Misc1" },
45 { PIRQ_MISC2, "Misc2" },
46 { PIRQ_SIRQA, "Ser IRQ INTA" },
47 { PIRQ_SIRQB, "Ser IRQ INTB" },
48 { PIRQ_SIRQC, "Ser IRQ INTC" },
49 { PIRQ_SIRQD, "Ser IRQ INTD" },
50 { PIRQ_SCI, "SCI" },
51 { PIRQ_SMBUS, "SMBUS" },
52 { PIRQ_ASF, "ASF" },
Martin Roth5c354b92019-04-22 14:55:16 -060053 { PIRQ_PMON, "PerMon" },
54 { PIRQ_SD, "SD" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060055 { PIRQ_SDIO, "SDIO" },
56 { PIRQ_CIR, "CIR" },
57 { PIRQ_GPIOA, "GPIOa" },
58 { PIRQ_GPIOB, "GPIOb" },
59 { PIRQ_GPIOC, "GPIOc" },
Martin Roth5c354b92019-04-22 14:55:16 -060060 { PIRQ_SATA, "SATA" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060061 { PIRQ_EMMC, "eMMC" },
62 { PIRQ_GPP0, "GPP0" },
63 { PIRQ_GPP1, "GPP1" },
64 { PIRQ_GPP2, "GPP2" },
65 { PIRQ_GPP3, "GPP3" },
Martin Roth5c354b92019-04-22 14:55:16 -060066 { PIRQ_GPIO, "GPIO" },
67 { PIRQ_I2C0, "I2C0" },
68 { PIRQ_I2C1, "I2C1" },
69 { PIRQ_I2C2, "I2C2" },
70 { PIRQ_I2C3, "I2C3" },
71 { PIRQ_UART0, "UART0" },
72 { PIRQ_UART1, "UART1" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060073 { PIRQ_I2C4, "I2C4" },
74 { PIRQ_I2C5, "I2C5" },
75 { PIRQ_UART2, "UART2" },
76 { PIRQ_UART3, "UART3" },
Martin Roth5c354b92019-04-22 14:55:16 -060077};
78
79const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
80{
81 *size = ARRAY_SIZE(irq_association);
82 return irq_association;
83}
84
Felix Heldf66e7812021-07-22 17:38:27 +020085static void fch_clk_output_48Mhz(void)
Martin Roth5c354b92019-04-22 14:55:16 -060086{
87 u32 ctrl;
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060088 const struct soc_amd_picasso_config *cfg = config_of_soc();
Martin Roth5c354b92019-04-22 14:55:16 -060089
Martin Roth5c354b92019-04-22 14:55:16 -060090 ctrl = misc_read32(MISC_CLK_CNTL1);
Eric Laidd32e652020-12-15 14:51:50 +080091 /* If used external clock source for I2S, disable the internal clock output */
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060092 if (cfg->acp_i2s_use_external_48mhz_osc &&
93 cfg->common_config.acp_config.acp_pin_cfg == I2S_PINS_I2S_TDM)
Eric Laidd32e652020-12-15 14:51:50 +080094 ctrl &= ~BP_X48M0_OUTPUT_EN;
95 else
96 ctrl |= BP_X48M0_OUTPUT_EN;
Martin Roth5c354b92019-04-22 14:55:16 -060097 misc_write32(MISC_CLK_CNTL1, ctrl);
98}
99
Chris Wangad4f6d72021-01-26 20:09:34 +0800100static void sb_rfmux_config_override(void)
101{
102 u8 port;
103 const struct soc_amd_picasso_config *cfg;
104
105 cfg = config_of_soc();
106
107 for (port = 0; port < USB_PD_PORT_COUNT; port++) {
108 if (cfg->usb_pd_config_override[port].rfmux_override_en) {
Arthur Heymans4c684872022-04-19 21:44:22 +0200109 write32p(USB_PD_PORT_CONTROL + PD_PORT_MUX_OFFSET(port),
Chris Wangad4f6d72021-01-26 20:09:34 +0800110 cfg->usb_pd_config_override[port].rfmux_config
111 | USB_PD_RFMUX_OVERRIDE);
112 }
113 }
114}
115
Felix Heldee1fb0a2021-02-02 01:10:59 +0100116static void fch_init_acpi_ports(void)
Martin Roth5c354b92019-04-22 14:55:16 -0600117{
118 u32 reg;
119
120 /* We use some of these ports in SMM regardless of whether or not
121 * ACPI tables are generated. Enable these ports indiscriminately.
122 */
123
124 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
125 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
126 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
127 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Marshall Dawson39a4ac12019-06-20 16:28:33 -0600128
Martin Roth5c354b92019-04-22 14:55:16 -0600129 if (CONFIG(HAVE_SMI_HANDLER)) {
130 /* APMC - SMI Command Port */
131 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
132 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
133
134 /* SMI on SlpTyp requires sending SMI before completion
Felix Held5dd52c72021-02-10 19:53:38 +0100135 response of the I/O write. */
Martin Roth5c354b92019-04-22 14:55:16 -0600136 reg = pm_read32(PM_PCI_CTRL);
137 reg |= FORCE_SLPSTATE_RETRY;
Martin Roth5c354b92019-04-22 14:55:16 -0600138 pm_write32(PM_PCI_CTRL, reg);
139
140 /* Disable SlpTyp feature */
141 reg = pm_read8(PM_RST_CTRL1);
142 reg &= ~SLPTYPE_CONTROL_EN;
143 pm_write8(PM_RST_CTRL1, reg);
144
145 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
146 } else {
147 pm_write16(PM_ACPI_SMI_CMD, 0);
148 }
149
150 /* Decode ACPI registers and enable standard features */
151 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
152 PM_ACPI_GLOBAL_EN |
153 PM_ACPI_RTC_EN_EN |
154 PM_ACPI_TIMER_EN_EN);
155}
156
Matt Papageorgeab83b432020-06-26 08:47:00 -0500157/*
158 * A-Link to AHB bridge, part of the AMBA fabric. These are internal clocks
159 * and unneeded for Raven/Picasso so gate them to save power.
160 */
161static void al2ahb_clock_gate(void)
162{
163 uint8_t al2ahb_val;
164 uintptr_t al2ahb_base = ALINK_AHB_ADDRESS;
165
Felix Heldf69cb292022-09-29 16:05:41 +0200166 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500167 al2ahb_val |= AL2AHB_CLK_GATE_EN;
Felix Heldf69cb292022-09-29 16:05:41 +0200168 write8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET, al2ahb_val);
169 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500170 al2ahb_val |= AL2AHB_HCLK_GATE_EN;
Felix Heldf69cb292022-09-29 16:05:41 +0200171 write8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET, al2ahb_val);
Matt Papageorgeab83b432020-06-26 08:47:00 -0500172}
173
Martin Roth26f97f92021-10-01 14:53:22 -0600174/* configure the general purpose PCIe clock outputs according to the devicetree settings */
Felix Held82a0a632020-08-28 01:40:20 +0200175static void gpp_clk_setup(void)
176{
177 const struct soc_amd_picasso_config *cfg = config_of_soc();
178
179 /* look-up table to be able to iterate over the PCIe clock output settings */
180 const uint8_t gpp_clk_shift_lut[GPP_CLK_OUTPUT_COUNT] = {
181 GPP_CLK0_REQ_SHIFT,
182 GPP_CLK1_REQ_SHIFT,
183 GPP_CLK2_REQ_SHIFT,
184 GPP_CLK3_REQ_SHIFT,
185 GPP_CLK4_REQ_SHIFT,
186 GPP_CLK5_REQ_SHIFT,
187 GPP_CLK6_REQ_SHIFT,
188 };
189
190 uint32_t gpp_clk_ctl = misc_read32(GPP_CLK_CNTRL);
191
192 for (int i = 0; i < GPP_CLK_OUTPUT_COUNT; i++) {
193 gpp_clk_ctl &= ~GPP_CLK_REQ_MASK(gpp_clk_shift_lut[i]);
194 /*
195 * The remapping of values is done so that the default of the enum used for the
196 * devicetree settings is the clock being enabled, so that a missing devicetree
197 * configuration for this will result in an always active clock and not an
198 * inactive PCIe clock output.
199 */
200 switch (cfg->gpp_clk_config[i]) {
201 case GPP_CLK_REQ:
202 gpp_clk_ctl |= GPP_CLK_REQ_EXT(gpp_clk_shift_lut[i]);
203 break;
204 case GPP_CLK_OFF:
205 gpp_clk_ctl |= GPP_CLK_REQ_OFF(gpp_clk_shift_lut[i]);
206 break;
207 case GPP_CLK_ON:
208 default:
209 gpp_clk_ctl |= GPP_CLK_REQ_ON(gpp_clk_shift_lut[i]);
210 }
211 }
212
213 misc_write32(GPP_CLK_CNTRL, gpp_clk_ctl);
214}
215
Felix Heldfaaafb42021-01-28 23:19:40 +0100216void fch_init(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600217{
Aaron Durbin09f60ff2020-04-09 15:24:50 -0600218 i2c_soc_init();
Felix Heldee1fb0a2021-02-02 01:10:59 +0100219 fch_init_acpi_ports();
Aaron Durbin404a5c32020-08-14 16:27:27 -0600220
Kyösti Mälkkib0db8132021-01-21 16:34:43 +0200221 acpi_pm_gpe_add_events_print_events();
222 gpio_add_events();
223
Matt Papageorgeab83b432020-06-26 08:47:00 -0500224 al2ahb_clock_gate();
Felix Held82a0a632020-08-28 01:40:20 +0200225
226 gpp_clk_setup();
Eric Lai3b648ba2020-12-18 10:51:46 +0800227
Felix Heldf66e7812021-07-22 17:38:27 +0200228 fch_clk_output_48Mhz();
Chris Wangad4f6d72021-01-26 20:09:34 +0800229
230 sb_rfmux_config_override();
Martin Roth5c354b92019-04-22 14:55:16 -0600231}
232
Felix Heldfaaafb42021-01-28 23:19:40 +0100233void fch_final(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600234{
Martin Roth5c354b92019-04-22 14:55:16 -0600235}
236
237/*
238 * Update the PCI devices with a valid IRQ number
239 * that is set in the mainboard PCI_IRQ structures.
240 */
241static void set_pci_irqs(void *unused)
242{
243 /* Write PCI_INTR regs 0xC00/0xC01 */
244 write_pci_int_table();
245
Raul E Rangel4e80fae2020-12-16 10:08:41 -0700246 /* pirq_data is consumed by `write_pci_cfg_irqs` */
247 populate_pirq_data();
248
Martin Roth5c354b92019-04-22 14:55:16 -0600249 /* Write IRQs for all devicetree enabled devices */
250 write_pci_cfg_irqs();
251}
252
253/*
254 * Hook this function into the PCI state machine
255 * on entry into BS_DEV_ENABLE.
256 */
257BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);