blob: 50ff608cc09c342c2857744b1fea575948ac16bc [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahy77ff0b12015-05-05 15:07:29 -07003
Lee Leahy77ff0b12015-05-05 15:07:29 -07004#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07007#include <arch/acpi.h>
Frans Hendriksad5e0a82019-03-18 13:31:56 +01008#include <arch/ioapic.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07009#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070010#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070011#include <console/console.h>
12#include <cpu/x86/smm.h>
13#include <device/device.h>
14#include <device/pci.h>
15#include <device/pci_ids.h>
Frans Hendriks2c630172019-04-02 15:06:29 +020016#include <intelblocks/lpc_lib.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010017#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010018#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010019#include <pc80/i8259.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070020#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <soc/iomap.h>
22#include <soc/irq.h>
23#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070025#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070026#include <soc/ramstage.h>
27#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070028#include <spi-generic.h>
29#include <stdint.h>
Arthur Heymans68b6eb72019-10-13 23:26:36 +020030#include <southbridge/intel/common/spi.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070031
Frans Hendriks2c630172019-04-02 15:06:29 +020032static void sc_set_serial_irqs_mode(struct device *dev, enum serirq_mode mode)
Hannah Williams3fa80a92017-03-22 16:33:36 -070033{
Angel Ponsaee7ab22020-03-19 00:31:58 +010034 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xf);
Frans Hendriks2c630172019-04-02 15:06:29 +020035
36 switch (mode) {
37 case SERIRQ_CONTINUOUS:
38 break;
Angel Ponsaee7ab22020-03-19 00:31:58 +010039
Frans Hendriks2c630172019-04-02 15:06:29 +020040 case SERIRQ_OFF:
Angel Ponsaee7ab22020-03-19 00:31:58 +010041 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) & ~SIRQEN);
Frans Hendriks2c630172019-04-02 15:06:29 +020042 break;
Angel Ponsaee7ab22020-03-19 00:31:58 +010043
Frans Hendriks2c630172019-04-02 15:06:29 +020044 case SERIRQ_QUIET:
45 default:
46 write8(ilb_base + SCNT, read8(ilb_base + SCNT) & ~SCNT_MODE);
47 break;
48 }
Hannah Williams3fa80a92017-03-22 16:33:36 -070049}
Lee Leahy77ff0b12015-05-05 15:07:29 -070050
Angel Ponsaee7ab22020-03-19 00:31:58 +010051static inline void add_mmio_resource(struct device *dev, int i, unsigned long addr,
52 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070053{
Elyes HAOUASa342f392018-10-17 10:56:26 +020054 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070055 __FILE__, __func__, dev_name(dev), addr, size);
Angel Ponsaee7ab22020-03-19 00:31:58 +010056
Lee Leahy77ff0b12015-05-05 15:07:29 -070057 mmio_resource(dev, i, addr >> 10, size >> 10);
58}
59
Elyes HAOUASb13fac32018-05-24 22:29:44 +020060static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070061{
Angel Ponsaee7ab22020-03-19 00:31:58 +010062 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
63
Lee Leahy77ff0b12015-05-05 15:07:29 -070064 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
65 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
66 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
67 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
68 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
69 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
70 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
71 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Angel Ponsaee7ab22020-03-19 00:31:58 +010072 add_mmio_resource(dev, 0xfff, 0xffffffff - (CONFIG_COREBOOT_ROMSIZE_KB * KiB) + 1,
73 (CONFIG_COREBOOT_ROMSIZE_KB * KiB)); /* BIOS ROM */
74
Frans Hendriksad5e0a82019-03-18 13:31:56 +010075 add_mmio_resource(dev, 0xfec, IO_APIC_ADDR, 0x00001000); /* IOAPIC */
Lee Leahy77ff0b12015-05-05 15:07:29 -070076}
77
78/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
79#define LPC_DEFAULT_IO_RANGE_LOWER 0
80#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
81
Frans Hendriks2c630172019-04-02 15:06:29 +020082static void sc_enable_serial_irqs(struct device *dev)
83{
84 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF);
85
86 printk(BIOS_SPEW, "Enable serial irq\n");
87 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) | SIRQEN);
88 write8(ilb_base + SCNT, read8(ilb_base + SCNT) | SCNT_MODE);
89}
90
Frans Hendriks93484132018-12-10 12:38:16 +010091/*
Angel Ponsaee7ab22020-03-19 00:31:58 +010092 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE (0x3c) and INT_PIN
93 * (0x3d) registers which report interrupt routing information to operating systems and drivers.
94 * The INT_PIN register is generally read only and reports which interrupt pin A - D it uses.
95 * The INT_LINE register is configurable and reports which IRQ (generally the PIC IRQs 1 - 15)
96 * it will use. This needs to take interrupt pin swizzling on devices that are downstream on
97 * a PCI bridge into account.
Frans Hendriks93484132018-12-10 12:38:16 +010098 *
Angel Ponsaee7ab22020-03-19 00:31:58 +010099 * This function will loop through all enabled PCI devices and program the INT_LINE register
100 * with the correct PIC IRQ number for the INT_PIN that it uses. It then configures each
101 * interrupt in the PIC to be level triggered.
Frans Hendriks93484132018-12-10 12:38:16 +0100102 */
103static void write_pci_config_irqs(void)
104{
105 struct device *irq_dev;
106 struct device *targ_dev;
107 uint8_t int_line = 0;
108 uint8_t original_int_pin = 0;
109 uint8_t new_int_pin = 0;
110 uint16_t current_bdf = 0;
111 uint16_t parent_bdf = 0;
112 uint8_t pirq = 0;
113 uint8_t device_num = 0;
114 const struct soc_irq_route *ir = &global_soc_irq_route;
115
116 if (ir == NULL) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100117 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments "
118 "because 'global_braswell_irq_route' structure does not exist\n");
Frans Hendriks93484132018-12-10 12:38:16 +0100119 return;
120 }
121
122 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100123 * Loop through all enabled devices and program their INT_LINE, INT_PIN registers from
124 * values taken from the Interrupt Route registers in the ILB
Frans Hendriks93484132018-12-10 12:38:16 +0100125 */
126 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
127 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
128
129 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
130 (!irq_dev->enabled))
131 continue;
132
133 current_bdf = irq_dev->path.pci.devfn |
134 irq_dev->bus->secondary << 8;
135
136 /*
137 * Step 1: Get the INT_PIN and device structure to look for
138 * in the pirq_data table defined in the mainboard directory.
139 */
140 targ_dev = NULL;
141 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
142 if (targ_dev == NULL || new_int_pin < 1)
143 continue;
144
145 /* Get the original INT_PIN for record keeping */
146 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
147
148 parent_bdf = targ_dev->path.pci.devfn
149 | targ_dev->bus->secondary << 8;
150 device_num = PCI_SLOT(parent_bdf);
151
152 if (ir->pcidev[device_num] == 0) {
153 printk(BIOS_WARNING,
Angel Ponsaee7ab22020-03-19 00:31:58 +0100154 "Warning: PCI Device %d does not have an IRQ entry, "
155 "skipping it\n", device_num);
Frans Hendriks93484132018-12-10 12:38:16 +0100156 continue;
157 }
158
159 /* Find the PIRQ that is attached to the INT_PIN */
160 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
161 & 0x7;
162
163 /* Get the INT_LINE this device/function will use */
164 int_line = ir->pic[pirq];
165
166 if (int_line != PIRQ_PIC_IRQDISABLE) {
167 /* Set this IRQ to level triggered */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100168 i8259_configure_irq_trigger(int_line, IRQ_LEVEL_TRIGGERED);
169
Frans Hendriks93484132018-12-10 12:38:16 +0100170 /* Set the Interrupt Line register */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100171 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
Frans Hendriks93484132018-12-10 12:38:16 +0100172 } else {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100173 /* Set the Interrupt line register as 'unknown' or 'unused' */
174 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, PIRQ_PIC_UNKNOWN_UNUSED);
Frans Hendriks93484132018-12-10 12:38:16 +0100175 }
176
Angel Ponsaee7ab22020-03-19 00:31:58 +0100177 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n", original_int_pin,
178 pin_to_str(original_int_pin));
179
Frans Hendriks93484132018-12-10 12:38:16 +0100180 if (parent_bdf != current_bdf)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100181 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n", new_int_pin,
182 pin_to_str(new_int_pin));
183
184 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n\tINT_LINE\t: 0x%X (IRQ %d)\n",
185 'A' + pirq, int_line, int_line);
Frans Hendriks93484132018-12-10 12:38:16 +0100186 }
187 printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n");
188}
189
Lee Leahy77ff0b12015-05-05 15:07:29 -0700190static inline int io_range_in_default(int base, int size)
191{
192 /* Does it start above the range? */
193 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
194 return 0;
195
196 /* Is it entirely contained? */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100197 if (base >= LPC_DEFAULT_IO_RANGE_LOWER && (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700198 return 1;
199
Angel Ponsaee7ab22020-03-19 00:31:58 +0100200 /* This will return not in range for partial overlaps */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700201 return 0;
202}
203
204/*
205 * Note: this function assumes there is no overlap with the default LPC device's
206 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
207 */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100208static void sc_add_io_resource(struct device *dev, int base, int size, int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700209{
210 struct resource *res;
211
Elyes HAOUASa342f392018-10-17 10:56:26 +0200212 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700213 __FILE__, __func__, dev_name(dev), base, size, index);
214
Lee Leahy77ff0b12015-05-05 15:07:29 -0700215 if (io_range_in_default(base, size))
216 return;
217
218 res = new_resource(dev, index);
219 res->base = base;
220 res->size = size;
221 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
222}
223
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200224static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700225{
226 struct resource *res;
227
Angel Ponsaee7ab22020-03-19 00:31:58 +0100228 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700229
Lee Leahy77ff0b12015-05-05 15:07:29 -0700230 /* Add the default claimed IO range for the LPC device. */
231 res = new_resource(dev, 0);
232 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
233 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
234 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
235
236 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100237 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700238
239 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100240 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700241}
242
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200243static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700244{
Angel Ponsaee7ab22020-03-19 00:31:58 +0100245 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700246
Lee Leahy77ff0b12015-05-05 15:07:29 -0700247 /* Get the normal PCI resources of this device. */
248 pci_dev_read_resources(dev);
249
250 /* Add non-standard MMIO resources. */
251 sc_add_mmio_resources(dev);
252
253 /* Add IO resources. */
254 sc_add_io_resources(dev);
255}
256
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200257static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700258{
259 int i;
Frans Hendriksb55cd542019-03-06 14:45:12 +0100260 const unsigned long ilb_base = ILB_BASE_ADDRESS;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100261 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
262 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
263
Lee Leahy32471722015-04-20 15:20:28 -0700264 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700265 const struct soc_irq_route *ir = &global_soc_irq_route;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300266 struct soc_intel_braswell_config *config = config_of(dev);
Lee Leahy32471722015-04-20 15:20:28 -0700267
Angel Ponsaee7ab22020-03-19 00:31:58 +0100268 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700269
Frans Hendriksb55cd542019-03-06 14:45:12 +0100270 /* Set the value for PCI command register. */
271 pci_write_config16(dev, PCI_COMMAND,
Angel Ponsaee7ab22020-03-19 00:31:58 +0100272 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL);
Frans Hendriksb55cd542019-03-06 14:45:12 +0100273
274 /* Use IRQ9 for SCI Interrupt */
275 write32((void *)(ilb_base + ACTL), 0);
276
Frans Hendriks255f35c2018-12-11 15:21:47 +0100277 isa_dma_init();
278
Frans Hendriks2c630172019-04-02 15:06:29 +0200279 sc_enable_serial_irqs(dev);
280
Lee Leahy77ff0b12015-05-05 15:07:29 -0700281 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700282 for (i = 0; i < NUM_PIRQS; i++)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100283 write8((void *)(pr_base + i*sizeof(ir->pic[i])), ir->pic[i]);
Lee Leahy32471722015-04-20 15:20:28 -0700284
Lee Leahy77ff0b12015-05-05 15:07:29 -0700285 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700286 for (i = 0; i < NUM_IR_DEVS; i++)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100287 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])), ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700288
Frans Hendriks93484132018-12-10 12:38:16 +0100289 /* Interrupt 9 should be level triggered (SCI) */
290 i8259_configure_irq_trigger(9, 1);
291
292 for (i = 0; i < NUM_PIRQS; i++) {
293 if (ir->pic[i])
294 i8259_configure_irq_trigger(ir->pic[i], 1);
295 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700296
Lee Leahy77ff0b12015-05-05 15:07:29 -0700297 if (config->disable_slp_x_stretch_sus_fail) {
298 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
Angel Ponsaee7ab22020-03-19 00:31:58 +0100299 write32(gen_pmcon1, read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
300
Lee Leahy77ff0b12015-05-05 15:07:29 -0700301 } else {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100302 write32(gen_pmcon1, read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700303 }
304
Frans Hendriks93484132018-12-10 12:38:16 +0100305 /* Write IRQ assignments to PCI config space */
306 write_pci_config_irqs();
307
308 /* Initialize i8259 pic */
309 setup_i8259();
310
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100311 /* Initialize i8254 timers */
312 setup_i8254();
Frans Hendriks2c630172019-04-02 15:06:29 +0200313
314 sc_set_serial_irqs_mode(dev, config->serirq_mode);
315
Lee Leahy77ff0b12015-05-05 15:07:29 -0700316}
317
318/*
319 * Common code for the south cluster devices.
320 */
321
Frans Hendrikse6bf51f2019-05-01 10:48:31 +0200322/* Set bit in function disable register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200323static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700324{
Angel Ponsaee7ab22020-03-19 00:31:58 +0100325 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
Lee Leahy32471722015-04-20 15:20:28 -0700326 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100327 uint32_t mask = 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700328 uint32_t mask2 = 0;
329
Angel Ponsaee7ab22020-03-19 00:31:58 +0100330 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700331
332#define SET_DIS_MASK(name_) \
333 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
334 mask |= name_ ## _DIS
Angel Ponsaee7ab22020-03-19 00:31:58 +0100335
Lee Leahy32471722015-04-20 15:20:28 -0700336#define SET_DIS_MASK2(name_) \
337 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
338 mask2 |= name_ ## _DIS
339
Lee Leahy77ff0b12015-05-05 15:07:29 -0700340 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700341 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700342 break;
Lee Leahy32471722015-04-20 15:20:28 -0700343 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700344 break;
Lee Leahy32471722015-04-20 15:20:28 -0700345 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700346 break;
Lee Leahy32471722015-04-20 15:20:28 -0700347 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700348 /* Disable super speed PHY when XHCI is not available. */
349 mask2 |= USH_SS_PHY_DIS;
350 break;
Lee Leahy32471722015-04-20 15:20:28 -0700351 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700352 break;
Lee Leahy32471722015-04-20 15:20:28 -0700353 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700354 break;
Lee Leahy32471722015-04-20 15:20:28 -0700355 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700356 break;
Lee Leahy32471722015-04-20 15:20:28 -0700357 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700358 break;
Lee Leahy32471722015-04-20 15:20:28 -0700359 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700360 break;
Lee Leahy32471722015-04-20 15:20:28 -0700361 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700362 break;
Lee Leahy32471722015-04-20 15:20:28 -0700363 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700364 break;
Lee Leahy32471722015-04-20 15:20:28 -0700365 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700366 break;
Lee Leahy32471722015-04-20 15:20:28 -0700367 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700368 break;
Lee Leahy32471722015-04-20 15:20:28 -0700369 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700370 break;
Lee Leahy32471722015-04-20 15:20:28 -0700371 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700372 break;
Lee Leahy32471722015-04-20 15:20:28 -0700373 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700374 break;
Lee Leahy32471722015-04-20 15:20:28 -0700375 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700376 break;
Lee Leahy32471722015-04-20 15:20:28 -0700377 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700378 break;
Lee Leahy32471722015-04-20 15:20:28 -0700379 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700380 break;
Lee Leahy32471722015-04-20 15:20:28 -0700381 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700382 break;
Lee Leahy32471722015-04-20 15:20:28 -0700383 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700384 break;
Lee Leahy32471722015-04-20 15:20:28 -0700385 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700386 break;
Lee Leahy32471722015-04-20 15:20:28 -0700387 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700388 break;
Lee Leahy32471722015-04-20 15:20:28 -0700389 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700390 break;
Lee Leahy32471722015-04-20 15:20:28 -0700391 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700392 break;
Lee Leahy32471722015-04-20 15:20:28 -0700393 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700394 break;
Lee Leahy32471722015-04-20 15:20:28 -0700395 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700396 break;
397 }
398
399 if (mask != 0) {
400 write32(func_dis, read32(func_dis) | mask);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100401 /* Ensure posted write hits */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700402 read32(func_dis);
403 }
404
405 if (mask2 != 0) {
406 write32(func_dis2, read32(func_dis2) | mask2);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100407 /* Ensure posted write hits */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700408 read32(func_dis2);
409 }
410}
411
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200412static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700413{
414 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700415
Elyes HAOUASa342f392018-10-17 10:56:26 +0200416 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700417 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700418 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
419 reg8 = pci_read_config8(dev, offset + 4);
420 reg8 |= 0x3;
421 pci_write_config8(dev, offset + 4, reg8);
422}
423
Lee Leahy32471722015-04-20 15:20:28 -0700424/*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100425 * Parts of the audio subsystem are powered by the HDA device. Thus, one cannot put HDA into
426 * D3Hot. Instead, perform this workaround to make some of the audio paths work for LPE audio.
Lee Leahy32471722015-04-20 15:20:28 -0700427 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200428static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700429{
Lee Leahy32471722015-04-20 15:20:28 -0700430 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
431
Angel Ponsaee7ab22020-03-19 00:31:58 +0100432 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700433
434 /* Need to set magic register 0x43 to 0xd7 in config space. */
435 pci_write_config8(dev, 0x43, 0xd7);
436
Lee Leahy32471722015-04-20 15:20:28 -0700437 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100438 * Need to set bit 0 of GCTL to take the device out of reset.
439 * However, that requires setting up the 64-bit BAR.
Lee Leahy32471722015-04-20 15:20:28 -0700440 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700441 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
442 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
443 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
444 write32(gctl, read32(gctl) | 0x1);
445 pci_write_config8(dev, PCI_COMMAND, 0);
446 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
447}
448
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200449static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700450{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700451 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700452
Angel Ponsaee7ab22020-03-19 00:31:58 +0100453 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700454
455 /*
456 * Parts of the HDA block are used for LPE audio as well.
457 * Therefore assume the HDA will never be put into D3Hot.
458 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700459 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
460 hda_work_around(dev);
461 return 0;
462 }
463
464 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
465
466 if (offset != 0) {
467 set_d3hot_bits(dev, offset);
468 return 0;
469 }
470
Lee Leahy32471722015-04-20 15:20:28 -0700471 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100472 * For some reason some of the devices don't have the capability pointer set correctly.
473 * Work around this by hard coding the offset.
Lee Leahy32471722015-04-20 15:20:28 -0700474 */
475#define DEV_CASE(name_) \
476 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
477
Lee Leahy77ff0b12015-05-05 15:07:29 -0700478 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700479 DEV_CASE(SDIO) :
480 DEV_CASE(SD) :
481 DEV_CASE(MMC) :
482 DEV_CASE(LPE) :
483 DEV_CASE(SIO_DMA1) :
484 DEV_CASE(I2C1) :
485 DEV_CASE(I2C2) :
486 DEV_CASE(I2C3) :
487 DEV_CASE(I2C4) :
488 DEV_CASE(I2C5) :
489 DEV_CASE(I2C6) :
490 DEV_CASE(I2C7) :
491 DEV_CASE(SIO_DMA2) :
492 DEV_CASE(PWM1) :
493 DEV_CASE(PWM2) :
494 DEV_CASE(HSUART1) :
495 DEV_CASE(HSUART2) :
496 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700497 offset = 0x80;
498 break;
Lee Leahy32471722015-04-20 15:20:28 -0700499 DEV_CASE(SATA) :
500 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700501 offset = 0x70;
502 break;
Lee Leahy32471722015-04-20 15:20:28 -0700503 DEV_CASE(HDA) :
504 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700505 offset = 0x50;
506 break;
Lee Leahy32471722015-04-20 15:20:28 -0700507 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700508 /* TXE cannot be placed in D3Hot. */
509 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700510 DEV_CASE(PCIE_PORT1) :
511 DEV_CASE(PCIE_PORT2) :
512 DEV_CASE(PCIE_PORT3) :
513 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700514 offset = 0xa0;
515 break;
516 }
517
518 if (offset != 0) {
519 set_d3hot_bits(dev, offset);
520 return 0;
521 }
522
523 return -1;
524}
525
526/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200527void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700528{
529 uint32_t reg32;
530
Angel Ponsaee7ab22020-03-19 00:31:58 +0100531 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
532
Lee Leahy77ff0b12015-05-05 15:07:29 -0700533 if (!dev->enabled) {
534 int slot = PCI_SLOT(dev->path.pci.devfn);
535 int func = PCI_FUNC(dev->path.pci.devfn);
536 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
537 dev_path(dev), slot, func);
538
539 /* Ensure memory, io, and bus master are all disabled */
540 reg32 = pci_read_config32(dev, PCI_COMMAND);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100541 reg32 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700542 pci_write_config32(dev, PCI_COMMAND, reg32);
543
544 /* Place device in D3Hot */
545 if (place_device_in_d3hot(dev) < 0) {
546 printk(BIOS_WARNING,
547 "Could not place %02x.%01x into D3Hot. "
548 "Keeping device visible.\n", slot, func);
549 return;
550 }
551 /* Disable this device if possible */
552 sc_disable_devfn(dev);
553 } else {
554 /* Enable SERR */
555 reg32 = pci_read_config32(dev, PCI_COMMAND);
556 reg32 |= PCI_COMMAND_SERR;
557 pci_write_config32(dev, PCI_COMMAND, reg32);
558 }
559}
560
561static struct device_operations device_ops = {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100562 .read_resources = sc_read_resources,
563 .set_resources = pci_dev_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200564 .acpi_inject_dsdt = southcluster_inject_dsdt,
Angel Ponsaee7ab22020-03-19 00:31:58 +0100565 .write_acpi_tables = southcluster_write_acpi_tables,
566 .init = sc_init,
567 .enable = southcluster_enable_dev,
568 .scan_bus = scan_static_bus,
569 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700570};
571
572static const struct pci_driver southcluster __pci_driver = {
573 .ops = &device_ops,
574 .vendor = PCI_VENDOR_ID_INTEL,
575 .device = LPC_DEVID,
576};
577
Lee Leahy77ff0b12015-05-05 15:07:29 -0700578static void finalize_chipset(void *unused)
579{
Lee Leahy32471722015-04-20 15:20:28 -0700580 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
581 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
582 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
583 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
584 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100585
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200586 struct vscc_config cfg;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700587
Angel Ponsaee7ab22020-03-19 00:31:58 +0100588 printk(BIOS_SPEW, "%s/%s (%p)\n", __FILE__, __func__, unused);
Lee Leahy32471722015-04-20 15:20:28 -0700589
Angel Ponsaee7ab22020-03-19 00:31:58 +0100590 /* Set the lock enable on the BIOS control register */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700591 write32(bcr, read32(bcr) | BCR_LE);
592
Angel Ponsaee7ab22020-03-19 00:31:58 +0100593 /* Set BIOS lock down bit controlling boot block size and swapping */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700594 write32(gcs, read32(gcs) | BILD);
595
Angel Ponsaee7ab22020-03-19 00:31:58 +0100596 /* Lock sleep stretching policy and set SMI lock */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700597 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
598
Angel Ponsaee7ab22020-03-19 00:31:58 +0100599 /* Set the CF9 lock */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700600 write32(etr, read32(etr) | CF9LOCK);
601
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200602 spi_finalize_ops();
603 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
604
605 if (mainboard_get_spi_vscc_config(&cfg) < 0) {
606 printk(BIOS_DEBUG, "No SPI VSCC configuration.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700607 } else {
Lee Leahy77ff0b12015-05-05 15:07:29 -0700608 write32(spi + UVSCC, cfg.uvscc);
609 write32(spi + LVSCC, cfg.lvscc | VCL);
610 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700611}
612
Hannah Williams2cfdde72015-04-15 19:48:07 -0700613BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);