blob: dcae1adff689ab15ef9433382c6fee1d07b8525d [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
3#include <console/console.h>
4#include <device/mmio.h>
5#include <bootstate.h>
Raul E Rangelbe2b5ac2020-06-04 16:36:33 -06006#include <cpu/amd/msr.h>
Martin Roth5c354b92019-04-22 14:55:16 -06007#include <cpu/x86/smm.h>
Marshall Dawson39a4ac12019-06-20 16:28:33 -06008#include <cpu/x86/msr.h>
Martin Roth5c354b92019-04-22 14:55:16 -06009#include <device/device.h>
10#include <device/pci.h>
Martin Roth5c354b92019-04-22 14:55:16 -060011#include <device/pci_ops.h>
Martin Roth5c354b92019-04-22 14:55:16 -060012#include <amdblocks/amd_pci_util.h>
Martin Roth5c354b92019-04-22 14:55:16 -060013#include <amdblocks/reset.h>
14#include <amdblocks/acpimmio.h>
Martin Roth5c354b92019-04-22 14:55:16 -060015#include <amdblocks/acpi.h>
Felix Helddf9549e2021-04-13 00:11:14 +020016#include <amdblocks/gpio_banks.h>
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060017#include <amdblocks/i2c.h>
Felix Helda5a52952020-12-01 18:14:01 +010018#include <amdblocks/smi.h>
Aaron Durbinaa8f1652020-08-17 17:41:28 -060019#include <soc/acpi.h>
Marshall Dawson39a4ac12019-06-20 16:28:33 -060020#include <soc/cpu.h>
Felix Held5b01f2b2020-05-20 16:01:43 +020021#include <soc/i2c.h>
Felix Heldda5553c2021-02-03 14:42:42 +010022#include <soc/iomap.h>
Martin Roth5c354b92019-04-22 14:55:16 -060023#include <soc/southbridge.h>
Martin Roth5c354b92019-04-22 14:55:16 -060024#include <soc/smi.h>
25#include <soc/amd_pci_int_defs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060026#include <soc/pci_devs.h>
Martin Roth5c354b92019-04-22 14:55:16 -060027#include <types.h>
Furquan Shaikh69c28112020-04-28 18:57:52 -070028#include "chip.h"
Martin Roth5c354b92019-04-22 14:55:16 -060029
Martin Roth5c354b92019-04-22 14:55:16 -060030/*
31 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
32 * provides a visible association with the index, therefore helping
33 * maintainability of table. If a new index/name is defined in
34 * amd_pci_int_defs.h, just add the pair at the end of this table.
35 * Order is not important.
36 */
37const static struct irq_idx_name irq_association[] = {
38 { PIRQ_A, "INTA#" },
39 { PIRQ_B, "INTB#" },
40 { PIRQ_C, "INTC#" },
41 { PIRQ_D, "INTD#" },
42 { PIRQ_E, "INTE#" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060043 { PIRQ_F, "INTF#/GENINT2" },
Martin Roth5c354b92019-04-22 14:55:16 -060044 { PIRQ_G, "INTG#" },
45 { PIRQ_H, "INTH#" },
46 { PIRQ_MISC, "Misc" },
47 { PIRQ_MISC0, "Misc0" },
48 { PIRQ_MISC1, "Misc1" },
49 { PIRQ_MISC2, "Misc2" },
50 { PIRQ_SIRQA, "Ser IRQ INTA" },
51 { PIRQ_SIRQB, "Ser IRQ INTB" },
52 { PIRQ_SIRQC, "Ser IRQ INTC" },
53 { PIRQ_SIRQD, "Ser IRQ INTD" },
54 { PIRQ_SCI, "SCI" },
55 { PIRQ_SMBUS, "SMBUS" },
56 { PIRQ_ASF, "ASF" },
Martin Roth5c354b92019-04-22 14:55:16 -060057 { PIRQ_PMON, "PerMon" },
58 { PIRQ_SD, "SD" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060059 { PIRQ_SDIO, "SDIO" },
60 { PIRQ_CIR, "CIR" },
61 { PIRQ_GPIOA, "GPIOa" },
62 { PIRQ_GPIOB, "GPIOb" },
63 { PIRQ_GPIOC, "GPIOc" },
Martin Roth5c354b92019-04-22 14:55:16 -060064 { PIRQ_SATA, "SATA" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060065 { PIRQ_EMMC, "eMMC" },
66 { PIRQ_GPP0, "GPP0" },
67 { PIRQ_GPP1, "GPP1" },
68 { PIRQ_GPP2, "GPP2" },
69 { PIRQ_GPP3, "GPP3" },
Martin Roth5c354b92019-04-22 14:55:16 -060070 { PIRQ_GPIO, "GPIO" },
71 { PIRQ_I2C0, "I2C0" },
72 { PIRQ_I2C1, "I2C1" },
73 { PIRQ_I2C2, "I2C2" },
74 { PIRQ_I2C3, "I2C3" },
75 { PIRQ_UART0, "UART0" },
76 { PIRQ_UART1, "UART1" },
Marshall Dawson39a4ac12019-06-20 16:28:33 -060077 { PIRQ_I2C4, "I2C4" },
78 { PIRQ_I2C5, "I2C5" },
79 { PIRQ_UART2, "UART2" },
80 { PIRQ_UART3, "UART3" },
Martin Roth5c354b92019-04-22 14:55:16 -060081};
82
83const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
84{
85 *size = ARRAY_SIZE(irq_association);
86 return irq_association;
87}
88
Marshall Dawson0bd08062019-06-20 11:03:06 -060089void sb_clk_output_48Mhz(void)
Martin Roth5c354b92019-04-22 14:55:16 -060090{
91 u32 ctrl;
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060092 const struct soc_amd_picasso_config *cfg = config_of_soc();
Martin Roth5c354b92019-04-22 14:55:16 -060093
Martin Roth5c354b92019-04-22 14:55:16 -060094 ctrl = misc_read32(MISC_CLK_CNTL1);
Eric Laidd32e652020-12-15 14:51:50 +080095 /* If used external clock source for I2S, disable the internal clock output */
Karthikeyan Ramasubramanian39b7afa2021-04-29 16:50:51 -060096 if (cfg->acp_i2s_use_external_48mhz_osc &&
97 cfg->common_config.acp_config.acp_pin_cfg == I2S_PINS_I2S_TDM)
Eric Laidd32e652020-12-15 14:51:50 +080098 ctrl &= ~BP_X48M0_OUTPUT_EN;
99 else
100 ctrl |= BP_X48M0_OUTPUT_EN;
Martin Roth5c354b92019-04-22 14:55:16 -0600101 misc_write32(MISC_CLK_CNTL1, ctrl);
102}
103
Chris Wangad4f6d72021-01-26 20:09:34 +0800104static void sb_rfmux_config_override(void)
105{
106 u8 port;
107 const struct soc_amd_picasso_config *cfg;
108
109 cfg = config_of_soc();
110
111 for (port = 0; port < USB_PD_PORT_COUNT; port++) {
112 if (cfg->usb_pd_config_override[port].rfmux_override_en) {
113 write32((void *)(USB_PD_PORT_CONTROL + PD_PORT_MUX_OFFSET(port)),
114 cfg->usb_pd_config_override[port].rfmux_config
115 | USB_PD_RFMUX_OVERRIDE);
116 }
117 }
118}
119
Felix Heldee1fb0a2021-02-02 01:10:59 +0100120static void fch_init_acpi_ports(void)
Martin Roth5c354b92019-04-22 14:55:16 -0600121{
122 u32 reg;
123
124 /* We use some of these ports in SMM regardless of whether or not
125 * ACPI tables are generated. Enable these ports indiscriminately.
126 */
127
128 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
129 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
130 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
131 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Marshall Dawson39a4ac12019-06-20 16:28:33 -0600132
Martin Roth5c354b92019-04-22 14:55:16 -0600133 if (CONFIG(HAVE_SMI_HANDLER)) {
134 /* APMC - SMI Command Port */
135 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
136 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
137
138 /* SMI on SlpTyp requires sending SMI before completion
Felix Held5dd52c72021-02-10 19:53:38 +0100139 response of the I/O write. */
Martin Roth5c354b92019-04-22 14:55:16 -0600140 reg = pm_read32(PM_PCI_CTRL);
141 reg |= FORCE_SLPSTATE_RETRY;
Martin Roth5c354b92019-04-22 14:55:16 -0600142 pm_write32(PM_PCI_CTRL, reg);
143
144 /* Disable SlpTyp feature */
145 reg = pm_read8(PM_RST_CTRL1);
146 reg &= ~SLPTYPE_CONTROL_EN;
147 pm_write8(PM_RST_CTRL1, reg);
148
149 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
150 } else {
151 pm_write16(PM_ACPI_SMI_CMD, 0);
152 }
153
154 /* Decode ACPI registers and enable standard features */
155 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
156 PM_ACPI_GLOBAL_EN |
157 PM_ACPI_RTC_EN_EN |
158 PM_ACPI_TIMER_EN_EN);
159}
160
Matt Papageorgeab83b432020-06-26 08:47:00 -0500161/*
162 * A-Link to AHB bridge, part of the AMBA fabric. These are internal clocks
163 * and unneeded for Raven/Picasso so gate them to save power.
164 */
165static void al2ahb_clock_gate(void)
166{
167 uint8_t al2ahb_val;
168 uintptr_t al2ahb_base = ALINK_AHB_ADDRESS;
169
170 al2ahb_val = read8((void *)(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET));
171 al2ahb_val |= AL2AHB_CLK_GATE_EN;
172 write8((void *)(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET), al2ahb_val);
173 al2ahb_val = read8((void *)(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET));
174 al2ahb_val |= AL2AHB_HCLK_GATE_EN;
175 write8((void *)(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET), al2ahb_val);
176}
177
Felix Held82a0a632020-08-28 01:40:20 +0200178/* configure the genral purpose PCIe clock outputs according to the devicetree settings */
179static void gpp_clk_setup(void)
180{
181 const struct soc_amd_picasso_config *cfg = config_of_soc();
182
183 /* look-up table to be able to iterate over the PCIe clock output settings */
184 const uint8_t gpp_clk_shift_lut[GPP_CLK_OUTPUT_COUNT] = {
185 GPP_CLK0_REQ_SHIFT,
186 GPP_CLK1_REQ_SHIFT,
187 GPP_CLK2_REQ_SHIFT,
188 GPP_CLK3_REQ_SHIFT,
189 GPP_CLK4_REQ_SHIFT,
190 GPP_CLK5_REQ_SHIFT,
191 GPP_CLK6_REQ_SHIFT,
192 };
193
194 uint32_t gpp_clk_ctl = misc_read32(GPP_CLK_CNTRL);
195
196 for (int i = 0; i < GPP_CLK_OUTPUT_COUNT; i++) {
197 gpp_clk_ctl &= ~GPP_CLK_REQ_MASK(gpp_clk_shift_lut[i]);
198 /*
199 * The remapping of values is done so that the default of the enum used for the
200 * devicetree settings is the clock being enabled, so that a missing devicetree
201 * configuration for this will result in an always active clock and not an
202 * inactive PCIe clock output.
203 */
204 switch (cfg->gpp_clk_config[i]) {
205 case GPP_CLK_REQ:
206 gpp_clk_ctl |= GPP_CLK_REQ_EXT(gpp_clk_shift_lut[i]);
207 break;
208 case GPP_CLK_OFF:
209 gpp_clk_ctl |= GPP_CLK_REQ_OFF(gpp_clk_shift_lut[i]);
210 break;
211 case GPP_CLK_ON:
212 default:
213 gpp_clk_ctl |= GPP_CLK_REQ_ON(gpp_clk_shift_lut[i]);
214 }
215 }
216
217 misc_write32(GPP_CLK_CNTRL, gpp_clk_ctl);
218}
219
Felix Heldfaaafb42021-01-28 23:19:40 +0100220void fch_init(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600221{
Aaron Durbin09f60ff2020-04-09 15:24:50 -0600222 i2c_soc_init();
Felix Heldee1fb0a2021-02-02 01:10:59 +0100223 fch_init_acpi_ports();
Aaron Durbin404a5c32020-08-14 16:27:27 -0600224
Kyösti Mälkkib0db8132021-01-21 16:34:43 +0200225 acpi_pm_gpe_add_events_print_events();
226 gpio_add_events();
227
Aaron Durbin404a5c32020-08-14 16:27:27 -0600228 acpi_clear_pm_gpe_status();
229
Matt Papageorgeab83b432020-06-26 08:47:00 -0500230 al2ahb_clock_gate();
Felix Held82a0a632020-08-28 01:40:20 +0200231
232 gpp_clk_setup();
Eric Lai3b648ba2020-12-18 10:51:46 +0800233
234 sb_clk_output_48Mhz();
Chris Wangad4f6d72021-01-26 20:09:34 +0800235
236 sb_rfmux_config_override();
Martin Roth5c354b92019-04-22 14:55:16 -0600237}
238
Felix Heldfaaafb42021-01-28 23:19:40 +0100239void fch_final(void *chip_info)
Martin Roth5c354b92019-04-22 14:55:16 -0600240{
Martin Roth5c354b92019-04-22 14:55:16 -0600241}
242
243/*
244 * Update the PCI devices with a valid IRQ number
245 * that is set in the mainboard PCI_IRQ structures.
246 */
247static void set_pci_irqs(void *unused)
248{
249 /* Write PCI_INTR regs 0xC00/0xC01 */
250 write_pci_int_table();
251
Raul E Rangel4e80fae2020-12-16 10:08:41 -0700252 /* pirq_data is consumed by `write_pci_cfg_irqs` */
253 populate_pirq_data();
254
Martin Roth5c354b92019-04-22 14:55:16 -0600255 /* Write IRQs for all devicetree enabled devices */
256 write_pci_cfg_irqs();
257}
258
259/*
260 * Hook this function into the PCI state machine
261 * on entry into BS_DEV_ENABLE.
262 */
263BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);