Felix Held | 230dbd6 | 2021-01-28 23:40:52 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | 72b7891 | 2021-04-13 00:08:33 +0200 | [diff] [blame] | 3 | #include <amdblocks/acpi.h> |
Felix Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 4 | #include <amdblocks/acpimmio.h> |
Raul E Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 5 | #include <amdblocks/amd_pci_util.h> |
Felix Held | dea4e0f | 2021-09-22 20:05:53 +0200 | [diff] [blame] | 6 | #include <amdblocks/gpio.h> |
Felix Held | e094b1f | 2021-02-09 22:55:04 +0100 | [diff] [blame] | 7 | #include <amdblocks/smi.h> |
Felix Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 8 | #include <assert.h> |
Raul E Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 9 | #include <bootstate.h> |
Felix Held | e094b1f | 2021-02-09 22:55:04 +0100 | [diff] [blame] | 10 | #include <cpu/x86/smm.h> |
Zheng Bao | 7b13e4e | 2021-03-16 16:13:56 +0800 | [diff] [blame] | 11 | #include <amdblocks/i2c.h> |
Raul E Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 12 | #include <soc/amd_pci_int_defs.h> |
Felix Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 13 | #include <soc/iomap.h> |
Zheng Bao | 7b13e4e | 2021-03-16 16:13:56 +0800 | [diff] [blame] | 14 | #include <soc/i2c.h> |
Felix Held | e094b1f | 2021-02-09 22:55:04 +0100 | [diff] [blame] | 15 | #include <soc/smi.h> |
Felix Held | 230dbd6 | 2021-01-28 23:40:52 +0100 | [diff] [blame] | 16 | #include <soc/southbridge.h> |
Felix Held | 224b578 | 2021-05-18 01:25:51 +0200 | [diff] [blame] | 17 | #include "chip.h" |
Felix Held | 230dbd6 | 2021-01-28 23:40:52 +0100 | [diff] [blame] | 18 | |
Raul E Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 19 | /* |
| 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 | */ |
| 26 | const 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 | |
| 70 | const 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 Held | fd2982e | 2021-07-22 17:41:38 +0200 | [diff] [blame] | 76 | static 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 Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 84 | static void fch_init_acpi_ports(void) |
| 85 | { |
Felix Held | e094b1f | 2021-02-09 22:55:04 +0100 | [diff] [blame] | 86 | u32 reg; |
| 87 | |
Felix Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 88 | /* 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 Held | e094b1f | 2021-02-09 22:55:04 +0100 | [diff] [blame] | 98 | /* 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 Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 114 | } 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 Dawson | 3e1943e | 2021-05-06 16:08:09 -0600 | [diff] [blame] | 125 | static void fch_init_resets(void) |
| 126 | { |
| 127 | pm_write16(PWR_RESET_CFG, pm_read16(PWR_RESET_CFG) | TOGGLE_ALL_PWR_GOOD); |
| 128 | } |
| 129 | |
Martin Roth | 26f97f9 | 2021-10-01 14:53:22 -0600 | [diff] [blame] | 130 | /* configure the general purpose PCIe clock outputs according to the devicetree settings */ |
Felix Held | 224b578 | 2021-05-18 01:25:51 +0200 | [diff] [blame] | 131 | static 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 Schroeder | 5412a81 | 2021-10-12 10:58:49 -0500 | [diff] [blame] | 172 | static 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 Held | 230dbd6 | 2021-01-28 23:40:52 +0100 | [diff] [blame] | 194 | void fch_init(void *chip_info) |
| 195 | { |
Marshall Dawson | 3e1943e | 2021-05-06 16:08:09 -0600 | [diff] [blame] | 196 | fch_init_resets(); |
Zheng Bao | 7b13e4e | 2021-03-16 16:13:56 +0800 | [diff] [blame] | 197 | i2c_soc_init(); |
Felix Held | 7e703d7 | 2021-02-03 21:38:14 +0100 | [diff] [blame] | 198 | fch_init_acpi_ports(); |
Felix Held | 72b7891 | 2021-04-13 00:08:33 +0200 | [diff] [blame] | 199 | |
| 200 | acpi_pm_gpe_add_events_print_events(); |
| 201 | gpio_add_events(); |
| 202 | acpi_clear_pm_gpe_status(); |
Felix Held | 224b578 | 2021-05-18 01:25:51 +0200 | [diff] [blame] | 203 | |
| 204 | gpp_clk_setup(); |
Felix Held | fd2982e | 2021-07-22 17:41:38 +0200 | [diff] [blame] | 205 | fch_clk_output_48Mhz(); |
Julian Schroeder | 5412a81 | 2021-10-12 10:58:49 -0500 | [diff] [blame] | 206 | cgpll_clock_gate_init(); |
Felix Held | 230dbd6 | 2021-01-28 23:40:52 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void fch_final(void *chip_info) |
| 210 | { |
| 211 | } |
Raul E Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 212 | |
| 213 | static void set_pci_irqs(void *unused) |
| 214 | { |
| 215 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 216 | write_pci_int_table(); |
Raul E Rangel | fd7ed87 | 2021-05-04 15:42:09 -0600 | [diff] [blame] | 217 | |
| 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 Rangel | a6529e7 | 2021-02-09 14:38:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Hook this function into the PCI state machine |
| 227 | * on entry into BS_DEV_ENABLE. |
| 228 | */ |
| 229 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |