Debian Codegraph @

src/soc/amd/picasso/fch.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <device/mmio.h>
4 #include <bootstate.h>
5 #include <cpu/x86/smm.h>
6 #include <device/device.h>
7 #include <device/pci.h>
8 #include <device/pci_ops.h>
9 #include <amdblocks/amd_pci_util.h>
10 #include <amdblocks/pci_clk_req.h>
11 #include <amdblocks/reset.h>
12 #include <amdblocks/acpimmio.h>
13 #include <amdblocks/acpi.h>
14 #include <amdblocks/gpio.h>
15 #include <amdblocks/i2c.h>
16 #include <amdblocks/smi.h>
17 #include <soc/cpu.h>
18 #include <soc/i2c.h>
19 #include <soc/iomap.h>
20 #include <soc/southbridge.h>
21 #include <soc/smi.h>
22 #include <soc/amd_pci_int_defs.h>
23 #include <soc/pci_devs.h>
24 #include <static.h>
25 #include <types.h>
26 #include "chip.h"
27
28 /*
29 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
30 * provides a visible association with the index, therefore helping
31 * maintainability of table. If a new index/name is defined in
32 * amd_pci_int_defs.h, just add the pair at the end of this table.
33 * Order is not important.
34 */
35 static const struct irq_idx_name irq_association[] = {
36 { PIRQ_A, "INTA#" },
37 { PIRQ_B, "INTB#" },
38 { PIRQ_C, "INTC#" },
39 { PIRQ_D, "INTD#" },
40 { PIRQ_E, "INTE#" },
41 { PIRQ_F, "INTF#/GENINT2" },
42 { PIRQ_G, "INTG#" },
43 { PIRQ_H, "INTH#" },
44 { PIRQ_MISC, "Misc" },
45 { PIRQ_MISC0, "Misc0" },
46 { PIRQ_MISC1, "Misc1" },
47 { PIRQ_MISC2, "Misc2" },
48 { PIRQ_SIRQA, "Ser IRQ INTA" },
49 { PIRQ_SIRQB, "Ser IRQ INTB" },
50 { PIRQ_SIRQC, "Ser IRQ INTC" },
51 { PIRQ_SIRQD, "Ser IRQ INTD" },
52 { PIRQ_SCI, "SCI" },
53 { PIRQ_SMBUS, "SMBUS" },
54 { PIRQ_ASF, "ASF" },
55 { PIRQ_PMON, "PerMon" },
56 { PIRQ_SD, "SD" },
57 { PIRQ_SDIO, "SDIO" },
58 { PIRQ_CIR, "CIR" },
59 { PIRQ_GPIOA, "GPIOa" },
60 { PIRQ_GPIOB, "GPIOb" },
61 { PIRQ_GPIOC, "GPIOc" },
62 { PIRQ_SATA, "SATA" },
63 { PIRQ_EMMC, "eMMC" },
64 { PIRQ_GPP0, "GPP0" },
65 { PIRQ_GPP1, "GPP1" },
66 { PIRQ_GPP2, "GPP2" },
67 { PIRQ_GPP3, "GPP3" },
68 { PIRQ_GPIO, "GPIO" },
69 { PIRQ_I2C0, "I2C0" },
70 { PIRQ_I2C1, "I2C1" },
71 { PIRQ_I2C2, "I2C2" },
72 { PIRQ_I2C3, "I2C3" },
73 { PIRQ_UART0, "UART0" },
74 { PIRQ_UART1, "UART1" },
75 { PIRQ_I2C4, "I2C4" },
76 { PIRQ_I2C5, "I2C5" },
77 { PIRQ_UART2, "UART2" },
78 { PIRQ_UART3, "UART3" },
79 };
80
81 const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
82 {
83 *size = ARRAY_SIZE(irq_association);
84 return irq_association;
85 }
86
87 static void fch_clk_output_48Mhz(void)
88 {
89 u32 ctrl;
90 const struct soc_amd_picasso_config *cfg = config_of_soc();
91
92 ctrl = misc_read32(MISC_CLK_CNTL1);
93 /* If used external clock source for I2S, disable the internal clock output */
94 if (cfg->acp_i2s_use_external_48mhz_osc &&
95 cfg->common_config.acp_config.acp_pin_cfg == I2S_PINS_I2S_TDM)
96 ctrl &= ~BP_X48M0_OUTPUT_EN;
97 else
98 ctrl |= BP_X48M0_OUTPUT_EN;
99 misc_write32(MISC_CLK_CNTL1, ctrl);
100 }
101
102 static void sb_rfmux_config_override(void)
103 {
104 u8 port;
105 const struct soc_amd_picasso_config *cfg;
106
107 cfg = config_of_soc();
108
109 for (port = 0; port < USB_PD_PORT_COUNT; port++) {
110 if (cfg->usb_pd_config_override[port].rfmux_override_en) {
111 write32p(USB_PD_PORT_CONTROL + PD_PORT_MUX_OFFSET(port),
112 cfg->usb_pd_config_override[port].rfmux_config
113 | USB_PD_RFMUX_OVERRIDE);
114 }
115 }
116 }
117
118 static void fch_init_acpi_ports(void)
119 {
120 u32 reg;
121
122 /* We use some of these ports in SMM regardless of whether or not
123 * ACPI tables are generated. Enable these ports indiscriminately.
124 */
125
126 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
127 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
128 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
129 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
130
131 if (CONFIG(HAVE_SMI_HANDLER)) {
132 /* APMC - SMI Command Port */
133 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
134 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
135
136 /* SMI on SlpTyp requires sending SMI before completion
137 response of the I/O write. */
138 reg = pm_read32(PM_PCI_CTRL);
139 reg |= FORCE_SLPSTATE_RETRY;
140 pm_write32(PM_PCI_CTRL, reg);
141
142 /* Disable SlpTyp feature */
143 reg = pm_read8(PM_RST_CTRL1);
144 reg &= ~SLPTYPE_CONTROL_EN;
145 pm_write8(PM_RST_CTRL1, reg);
146
147 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
148 } else {
149 pm_write16(PM_ACPI_SMI_CMD, 0);
150 }
151
152 /* Decode ACPI registers and enable standard features */
153 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
154 PM_ACPI_GLOBAL_EN |
155 PM_ACPI_RTC_EN_EN |
156 PM_ACPI_TIMER_EN_EN);
157 }
158
159 /*
160 * A-Link to AHB bridge, part of the AMBA fabric. These are internal clocks
161 * and unneeded for Raven/Picasso so gate them to save power.
162 */
163 static void al2ahb_clock_gate(void)
164 {
165 uint8_t al2ahb_val;
166 uintptr_t al2ahb_base = ALINK_AHB_ADDRESS;
167
168 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET);
169 al2ahb_val |= AL2AHB_CLK_GATE_EN;
170 write8p(al2ahb_base + AL2AHB_CONTROL_CLK_OFFSET, al2ahb_val);
171 al2ahb_val = read8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET);
172 al2ahb_val |= AL2AHB_HCLK_GATE_EN;
173 write8p(al2ahb_base + AL2AHB_CONTROL_HCLK_OFFSET, al2ahb_val);
174 }
175
176 /* configure the general purpose PCIe clock outputs according to the devicetree settings */
177 static void gpp_clk_setup(void)
178 {
179 struct soc_amd_picasso_config *cfg = config_of_soc();
180 gpp_clk_setup_common(&cfg->gpp_clk_config[0], ARRAY_SIZE(cfg->gpp_clk_config));
181 }
182
183 void fch_init(void *chip_info)
184 {
185 i2c_soc_init();
186 fch_init_acpi_ports();
187
188 acpi_pm_gpe_add_events_print_events();
189 gpio_add_events();
190
191 al2ahb_clock_gate();
192
193 gpp_clk_setup();
194
195 fch_clk_output_48Mhz();
196
197 sb_rfmux_config_override();
198 }
199
200 void fch_final(void *chip_info)
201 {
202 }
203
204 /*
205 * Update the PCI devices with a valid IRQ number
206 * that is set in the mainboard PCI_IRQ structures.
207 */
208 static void set_pci_irqs(void *unused)
209 {
210 /* Write PCI_INTR regs 0xC00/0xC01 */
211 write_pci_int_table();
212
213 /* pirq_data is consumed by `write_pci_cfg_irqs` */
214 populate_pirq_data();
215
216 /* Write IRQs for all devicetree enabled devices */
217 write_pci_cfg_irqs();
218 }
219
220 /*
221 * Hook this function into the PCI state machine
222 * on entry into BS_DEV_ENABLE.
223 */
224 BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);