blob: 73125309f4345ddc39d61a1a766fb5d854b6c587 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy77ff0b12015-05-05 15:07:29 -070015#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070018#include <arch/acpi.h>
Frans Hendriksad5e0a82019-03-18 13:31:56 +010019#include <arch/ioapic.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070020#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070021#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <console/console.h>
23#include <cpu/x86/smm.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
Frans Hendriks2c630172019-04-02 15:06:29 +020027#include <intelblocks/lpc_lib.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010028#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010029#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010030#include <pc80/i8259.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070031#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070032#include <soc/iomap.h>
33#include <soc/irq.h>
34#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070035#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070036#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070037#include <soc/ramstage.h>
38#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070039#include <spi-generic.h>
40#include <stdint.h>
Arthur Heymans68b6eb72019-10-13 23:26:36 +020041#include <southbridge/intel/common/spi.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070042
Frans Hendriks2c630172019-04-02 15:06:29 +020043static void sc_set_serial_irqs_mode(struct device *dev, enum serirq_mode mode)
Hannah Williams3fa80a92017-03-22 16:33:36 -070044{
Frans Hendriks2c630172019-04-02 15:06:29 +020045 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF);
46
47 switch (mode) {
48 case SERIRQ_CONTINUOUS:
49 break;
50 case SERIRQ_OFF:
51 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) &
52 ~SIRQEN);
53 break;
54 case SERIRQ_QUIET:
55 default:
56 write8(ilb_base + SCNT, read8(ilb_base + SCNT) & ~SCNT_MODE);
57 break;
58 }
Hannah Williams3fa80a92017-03-22 16:33:36 -070059}
Lee Leahy77ff0b12015-05-05 15:07:29 -070060
61static inline void
Elyes HAOUASb13fac32018-05-24 22:29:44 +020062add_mmio_resource(struct device *dev, int i, unsigned long addr,
63 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070064{
Elyes HAOUASa342f392018-10-17 10:56:26 +020065 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070066 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070067 mmio_resource(dev, i, addr >> 10, size >> 10);
68}
69
Elyes HAOUASb13fac32018-05-24 22:29:44 +020070static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070071{
Elyes HAOUASa342f392018-10-17 10:56:26 +020072 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070073 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070074 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
75 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
76 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
77 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
78 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
79 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
80 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
81 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Frans Hendriksad5e0a82019-03-18 13:31:56 +010082 add_mmio_resource(dev, 0xfff,
83 0xffffffff - (CONFIG_COREBOOT_ROMSIZE_KB*KiB) + 1,
84 (CONFIG_COREBOOT_ROMSIZE_KB*KiB)); /* BIOS ROM */
85 add_mmio_resource(dev, 0xfec, IO_APIC_ADDR, 0x00001000); /* IOAPIC */
Lee Leahy77ff0b12015-05-05 15:07:29 -070086}
87
88/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
89#define LPC_DEFAULT_IO_RANGE_LOWER 0
90#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
91
Frans Hendriks2c630172019-04-02 15:06:29 +020092static void sc_enable_serial_irqs(struct device *dev)
93{
94 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF);
95
96 printk(BIOS_SPEW, "Enable serial irq\n");
97 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) | SIRQEN);
98 write8(ilb_base + SCNT, read8(ilb_base + SCNT) | SCNT_MODE);
99}
100
Frans Hendriks93484132018-12-10 12:38:16 +0100101/*
102 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE
103 * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing
104 * information to operating systems and drivers. The INT_PIN register is
105 * generally read only and reports which interrupt pin A - D it uses. The
106 * INT_LINE register is configurable and reports which IRQ (generally the
107 * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling
108 * on devices that are downstream on a PCI bridge into account.
109 *
110 * This function will loop through all enabled PCI devices and program the
111 * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it
112 * uses. It then configures each interrupt in the pic to be level triggered.
113 */
114static void write_pci_config_irqs(void)
115{
116 struct device *irq_dev;
117 struct device *targ_dev;
118 uint8_t int_line = 0;
119 uint8_t original_int_pin = 0;
120 uint8_t new_int_pin = 0;
121 uint16_t current_bdf = 0;
122 uint16_t parent_bdf = 0;
123 uint8_t pirq = 0;
124 uint8_t device_num = 0;
125 const struct soc_irq_route *ir = &global_soc_irq_route;
126
127 if (ir == NULL) {
128 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments"
129 " because 'global_braswell_irq_route' structure does"
130 " not exist\n");
131 return;
132 }
133
134 /*
135 * Loop through all enabled devices and program their
136 * INT_LINE, INT_PIN registers from values taken from
137 * the Interrupt Route registers in the ILB
138 */
139 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
140 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
141
142 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
143 (!irq_dev->enabled))
144 continue;
145
146 current_bdf = irq_dev->path.pci.devfn |
147 irq_dev->bus->secondary << 8;
148
149 /*
150 * Step 1: Get the INT_PIN and device structure to look for
151 * in the pirq_data table defined in the mainboard directory.
152 */
153 targ_dev = NULL;
154 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
155 if (targ_dev == NULL || new_int_pin < 1)
156 continue;
157
158 /* Get the original INT_PIN for record keeping */
159 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
160
161 parent_bdf = targ_dev->path.pci.devfn
162 | targ_dev->bus->secondary << 8;
163 device_num = PCI_SLOT(parent_bdf);
164
165 if (ir->pcidev[device_num] == 0) {
166 printk(BIOS_WARNING,
167 "Warning: PCI Device %d does not have an IRQ "
168 "entry, skipping it\n", device_num);
169 continue;
170 }
171
172 /* Find the PIRQ that is attached to the INT_PIN */
173 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
174 & 0x7;
175
176 /* Get the INT_LINE this device/function will use */
177 int_line = ir->pic[pirq];
178
179 if (int_line != PIRQ_PIC_IRQDISABLE) {
180 /* Set this IRQ to level triggered */
181 i8259_configure_irq_trigger(int_line,
182 IRQ_LEVEL_TRIGGERED);
183 /* Set the Interrupt Line register */
184 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
185 int_line);
186 } else {
187 /*
188 * Set the Interrupt line register as 'unknown' or
189 * 'unused'
190 */
191 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
192 PIRQ_PIC_UNKNOWN_UNUSED);
193 }
194
195 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n",
196 original_int_pin, pin_to_str(original_int_pin));
197 if (parent_bdf != current_bdf)
198 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n",
199 new_int_pin, pin_to_str(new_int_pin));
200 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n"
201 "\tINT_LINE\t: 0x%X (IRQ %d)\n",
202 'A' + pirq, int_line, int_line);
203 }
204 printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n");
205}
206
Lee Leahy77ff0b12015-05-05 15:07:29 -0700207static inline int io_range_in_default(int base, int size)
208{
209 /* Does it start above the range? */
210 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
211 return 0;
212
213 /* Is it entirely contained? */
214 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
215 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
216 return 1;
217
218 /* This will return not in range for partial overlaps. */
219 return 0;
220}
221
222/*
223 * Note: this function assumes there is no overlap with the default LPC device's
224 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
225 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200226static void sc_add_io_resource(struct device *dev, int base, int size,
227 int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700228{
229 struct resource *res;
230
Elyes HAOUASa342f392018-10-17 10:56:26 +0200231 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700232 __FILE__, __func__, dev_name(dev), base, size, index);
233
Lee Leahy77ff0b12015-05-05 15:07:29 -0700234 if (io_range_in_default(base, size))
235 return;
236
237 res = new_resource(dev, index);
238 res->base = base;
239 res->size = size;
240 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
241}
242
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200243static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700244{
245 struct resource *res;
246
Elyes HAOUASa342f392018-10-17 10:56:26 +0200247 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700248 __FILE__, __func__, dev_name(dev));
249
Lee Leahy77ff0b12015-05-05 15:07:29 -0700250 /* Add the default claimed IO range for the LPC device. */
251 res = new_resource(dev, 0);
252 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
253 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
254 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
255
256 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100257 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700258
259 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100260 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700261}
262
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200263static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700264{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200265 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700266 __FILE__, __func__, dev_name(dev));
267
Lee Leahy77ff0b12015-05-05 15:07:29 -0700268 /* Get the normal PCI resources of this device. */
269 pci_dev_read_resources(dev);
270
271 /* Add non-standard MMIO resources. */
272 sc_add_mmio_resources(dev);
273
274 /* Add IO resources. */
275 sc_add_io_resources(dev);
276}
277
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200278static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700279{
280 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700281 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
282 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
Frans Hendriksb55cd542019-03-06 14:45:12 +0100283 const unsigned long ilb_base = ILB_BASE_ADDRESS;
Lee Leahy32471722015-04-20 15:20:28 -0700284 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700285 const struct soc_irq_route *ir = &global_soc_irq_route;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300286 struct soc_intel_braswell_config *config = config_of(dev);
Lee Leahy32471722015-04-20 15:20:28 -0700287
Elyes HAOUASa342f392018-10-17 10:56:26 +0200288 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700289 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700290
Frans Hendriksb55cd542019-03-06 14:45:12 +0100291 /* Set the value for PCI command register. */
292 pci_write_config16(dev, PCI_COMMAND,
293 PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
294 PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL);
295
296 /* Use IRQ9 for SCI Interrupt */
297 write32((void *)(ilb_base + ACTL), 0);
298
Frans Hendriks255f35c2018-12-11 15:21:47 +0100299 isa_dma_init();
300
Frans Hendriks2c630172019-04-02 15:06:29 +0200301 sc_enable_serial_irqs(dev);
302
Lee Leahy77ff0b12015-05-05 15:07:29 -0700303 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700304 for (i = 0; i < NUM_PIRQS; i++)
305 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
306 ir->pic[i]);
307
Lee Leahy77ff0b12015-05-05 15:07:29 -0700308 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700309 for (i = 0; i < NUM_IR_DEVS; i++)
310 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
311 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700312
Frans Hendriks93484132018-12-10 12:38:16 +0100313 /* Interrupt 9 should be level triggered (SCI) */
314 i8259_configure_irq_trigger(9, 1);
315
316 for (i = 0; i < NUM_PIRQS; i++) {
317 if (ir->pic[i])
318 i8259_configure_irq_trigger(ir->pic[i], 1);
319 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700320
Lee Leahy77ff0b12015-05-05 15:07:29 -0700321 if (config->disable_slp_x_stretch_sus_fail) {
322 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
323 write32(gen_pmcon1,
324 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
325 } else {
326 write32(gen_pmcon1,
327 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
328 }
329
Frans Hendriks93484132018-12-10 12:38:16 +0100330 /* Write IRQ assignments to PCI config space */
331 write_pci_config_irqs();
332
333 /* Initialize i8259 pic */
334 setup_i8259();
335
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100336 /* Initialize i8254 timers */
337 setup_i8254();
Frans Hendriks2c630172019-04-02 15:06:29 +0200338
339 sc_set_serial_irqs_mode(dev, config->serirq_mode);
340
Lee Leahy77ff0b12015-05-05 15:07:29 -0700341}
342
343/*
344 * Common code for the south cluster devices.
345 */
346
Frans Hendrikse6bf51f2019-05-01 10:48:31 +0200347/* Set bit in function disable register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200348static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700349{
Lee Leahy32471722015-04-20 15:20:28 -0700350 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
351 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700352 uint32_t mask = 0;
353 uint32_t mask2 = 0;
354
Elyes HAOUASa342f392018-10-17 10:56:26 +0200355 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700356 __FILE__, __func__, dev_name(dev));
357
358#define SET_DIS_MASK(name_) \
359 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
360 mask |= name_ ## _DIS
361#define SET_DIS_MASK2(name_) \
362 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
363 mask2 |= name_ ## _DIS
364
Lee Leahy77ff0b12015-05-05 15:07:29 -0700365 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700366 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700367 break;
Lee Leahy32471722015-04-20 15:20:28 -0700368 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700369 break;
Lee Leahy32471722015-04-20 15:20:28 -0700370 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700371 break;
Lee Leahy32471722015-04-20 15:20:28 -0700372 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700373 /* Disable super speed PHY when XHCI is not available. */
374 mask2 |= USH_SS_PHY_DIS;
375 break;
Lee Leahy32471722015-04-20 15:20:28 -0700376 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700377 break;
Lee Leahy32471722015-04-20 15:20:28 -0700378 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700379 break;
Lee Leahy32471722015-04-20 15:20:28 -0700380 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700381 break;
Lee Leahy32471722015-04-20 15:20:28 -0700382 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700383 break;
Lee Leahy32471722015-04-20 15:20:28 -0700384 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700385 break;
Lee Leahy32471722015-04-20 15:20:28 -0700386 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700387 break;
Lee Leahy32471722015-04-20 15:20:28 -0700388 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700389 break;
Lee Leahy32471722015-04-20 15:20:28 -0700390 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700391 break;
Lee Leahy32471722015-04-20 15:20:28 -0700392 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700393 break;
Lee Leahy32471722015-04-20 15:20:28 -0700394 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700395 break;
Lee Leahy32471722015-04-20 15:20:28 -0700396 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700397 break;
Lee Leahy32471722015-04-20 15:20:28 -0700398 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700399 break;
Lee Leahy32471722015-04-20 15:20:28 -0700400 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700401 break;
Lee Leahy32471722015-04-20 15:20:28 -0700402 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700403 break;
Lee Leahy32471722015-04-20 15:20:28 -0700404 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700405 break;
Lee Leahy32471722015-04-20 15:20:28 -0700406 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700407 break;
Lee Leahy32471722015-04-20 15:20:28 -0700408 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700409 break;
Lee Leahy32471722015-04-20 15:20:28 -0700410 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700411 break;
Lee Leahy32471722015-04-20 15:20:28 -0700412 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700413 break;
Lee Leahy32471722015-04-20 15:20:28 -0700414 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700415 break;
Lee Leahy32471722015-04-20 15:20:28 -0700416 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700417 break;
Lee Leahy32471722015-04-20 15:20:28 -0700418 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700419 break;
Lee Leahy32471722015-04-20 15:20:28 -0700420 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700421 break;
422 }
423
424 if (mask != 0) {
425 write32(func_dis, read32(func_dis) | mask);
426 /* Ensure posted write hits. */
427 read32(func_dis);
428 }
429
430 if (mask2 != 0) {
431 write32(func_dis2, read32(func_dis2) | mask2);
432 /* Ensure posted write hits. */
433 read32(func_dis2);
434 }
435}
436
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200437static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700438{
439 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700440
Elyes HAOUASa342f392018-10-17 10:56:26 +0200441 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700442 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700443 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
444 reg8 = pci_read_config8(dev, offset + 4);
445 reg8 |= 0x3;
446 pci_write_config8(dev, offset + 4, reg8);
447}
448
Lee Leahy32471722015-04-20 15:20:28 -0700449/*
450 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700451 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700452 * the audio paths work for LPE audio.
453 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200454static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700455{
Lee Leahy32471722015-04-20 15:20:28 -0700456 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
457
Elyes HAOUASa342f392018-10-17 10:56:26 +0200458 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700459 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700460
461 /* Need to set magic register 0x43 to 0xd7 in config space. */
462 pci_write_config8(dev, 0x43, 0xd7);
463
Lee Leahy32471722015-04-20 15:20:28 -0700464 /*
465 * Need to set bit 0 of GCTL to take the device out of reset. However,
466 * that requires setting up the 64-bit BAR.
467 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700468 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
469 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
470 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
471 write32(gctl, read32(gctl) | 0x1);
472 pci_write_config8(dev, PCI_COMMAND, 0);
473 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
474}
475
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200476static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700477{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700478 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700479
Elyes HAOUASa342f392018-10-17 10:56:26 +0200480 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700481 __FILE__, __func__, dev_name(dev));
482
483 /*
484 * Parts of the HDA block are used for LPE audio as well.
485 * Therefore assume the HDA will never be put into D3Hot.
486 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700487 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
488 hda_work_around(dev);
489 return 0;
490 }
491
492 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
493
494 if (offset != 0) {
495 set_d3hot_bits(dev, offset);
496 return 0;
497 }
498
Lee Leahy32471722015-04-20 15:20:28 -0700499 /*
500 * For some reason some of the devices don't have the capability
501 * pointer set correctly. Work around this by hard coding the offset.
502 */
503#define DEV_CASE(name_) \
504 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
505
Lee Leahy77ff0b12015-05-05 15:07:29 -0700506 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700507 DEV_CASE(SDIO) :
508 DEV_CASE(SD) :
509 DEV_CASE(MMC) :
510 DEV_CASE(LPE) :
511 DEV_CASE(SIO_DMA1) :
512 DEV_CASE(I2C1) :
513 DEV_CASE(I2C2) :
514 DEV_CASE(I2C3) :
515 DEV_CASE(I2C4) :
516 DEV_CASE(I2C5) :
517 DEV_CASE(I2C6) :
518 DEV_CASE(I2C7) :
519 DEV_CASE(SIO_DMA2) :
520 DEV_CASE(PWM1) :
521 DEV_CASE(PWM2) :
522 DEV_CASE(HSUART1) :
523 DEV_CASE(HSUART2) :
524 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700525 offset = 0x80;
526 break;
Lee Leahy32471722015-04-20 15:20:28 -0700527 DEV_CASE(SATA) :
528 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700529 offset = 0x70;
530 break;
Lee Leahy32471722015-04-20 15:20:28 -0700531 DEV_CASE(HDA) :
532 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700533 offset = 0x50;
534 break;
Lee Leahy32471722015-04-20 15:20:28 -0700535 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700536 /* TXE cannot be placed in D3Hot. */
537 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700538 DEV_CASE(PCIE_PORT1) :
539 DEV_CASE(PCIE_PORT2) :
540 DEV_CASE(PCIE_PORT3) :
541 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700542 offset = 0xa0;
543 break;
544 }
545
546 if (offset != 0) {
547 set_d3hot_bits(dev, offset);
548 return 0;
549 }
550
551 return -1;
552}
553
554/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200555void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700556{
557 uint32_t reg32;
558
Elyes HAOUASa342f392018-10-17 10:56:26 +0200559 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700560 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700561 if (!dev->enabled) {
562 int slot = PCI_SLOT(dev->path.pci.devfn);
563 int func = PCI_FUNC(dev->path.pci.devfn);
564 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
565 dev_path(dev), slot, func);
566
567 /* Ensure memory, io, and bus master are all disabled */
568 reg32 = pci_read_config32(dev, PCI_COMMAND);
569 reg32 &= ~(PCI_COMMAND_MASTER |
570 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
571 pci_write_config32(dev, PCI_COMMAND, reg32);
572
573 /* Place device in D3Hot */
574 if (place_device_in_d3hot(dev) < 0) {
575 printk(BIOS_WARNING,
576 "Could not place %02x.%01x into D3Hot. "
577 "Keeping device visible.\n", slot, func);
578 return;
579 }
580 /* Disable this device if possible */
581 sc_disable_devfn(dev);
582 } else {
583 /* Enable SERR */
584 reg32 = pci_read_config32(dev, PCI_COMMAND);
585 reg32 |= PCI_COMMAND_SERR;
586 pci_write_config32(dev, PCI_COMMAND, reg32);
587 }
588}
589
590static struct device_operations device_ops = {
591 .read_resources = sc_read_resources,
592 .set_resources = pci_dev_set_resources,
593 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700594 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
595 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700596 .init = sc_init,
597 .enable = southcluster_enable_dev,
Nico Huber51b75ae2019-03-14 16:02:05 +0100598 .scan_bus = scan_static_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700599 .ops_pci = &soc_pci_ops,
600};
601
602static const struct pci_driver southcluster __pci_driver = {
603 .ops = &device_ops,
604 .vendor = PCI_VENDOR_ID_INTEL,
605 .device = LPC_DEVID,
606};
607
Lee Leahy77ff0b12015-05-05 15:07:29 -0700608static void finalize_chipset(void *unused)
609{
Lee Leahy32471722015-04-20 15:20:28 -0700610 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
611 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
612 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
613 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
614 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200615 struct vscc_config cfg;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700616
Julius Werner540a9802019-12-09 13:03:29 -0800617 printk(BIOS_SPEW, "%s/%s (%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700618 __FILE__, __func__, unused);
619
Lee Leahy77ff0b12015-05-05 15:07:29 -0700620 /* Set the lock enable on the BIOS control register. */
621 write32(bcr, read32(bcr) | BCR_LE);
622
623 /* Set BIOS lock down bit controlling boot block size and swapping. */
624 write32(gcs, read32(gcs) | BILD);
625
626 /* Lock sleep stretching policy and set SMI lock. */
627 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
628
629 /* Set the CF9 lock. */
630 write32(etr, read32(etr) | CF9LOCK);
631
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200632 spi_finalize_ops();
633 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
634
635 if (mainboard_get_spi_vscc_config(&cfg) < 0) {
636 printk(BIOS_DEBUG, "No SPI VSCC configuration.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700637 } else {
Lee Leahy77ff0b12015-05-05 15:07:29 -0700638 write32(spi + UVSCC, cfg.uvscc);
639 write32(spi + LVSCC, cfg.lvscc | VCL);
640 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700641}
642
Hannah Williams2cfdde72015-04-15 19:48:07 -0700643BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);