blob: 22fe85326aee60d125f0f549162797aee9cf069b [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2013 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07006 * Copyright (C) 2015 Intel Corp.
Frans Hendriksbd5233e2018-12-05 15:24:48 +01007 * Copyright (C) 2018 Eltan B.V.
Lee Leahy77ff0b12015-05-05 15:07:29 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070017 */
18
Lee Leahy77ff0b12015-05-05 15:07:29 -070019#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020020#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <arch/acpi.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070023#include <arch/acpigen.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070025#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070026#include <console/console.h>
27#include <cpu/x86/smm.h>
28#include <device/device.h>
29#include <device/pci.h>
30#include <device/pci_ids.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010031#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010032#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010033#include <pc80/i8259.h>
Lee Leahy32471722015-04-20 15:20:28 -070034#include <romstage_handoff.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070035#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070036#include <soc/iomap.h>
37#include <soc/irq.h>
38#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070039#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070040#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070041#include <soc/ramstage.h>
42#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070043#include <spi-generic.h>
44#include <stdint.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070045#include <reg_script.h>
46
47static const struct reg_script ops[] = {
48 REG_MMIO_RMW32(ILB_BASE_ADDRESS + SCNT,
49 ~SCNT_MODE, 0), /* put LPC SERIRQ in Quiet Mode */
50 REG_SCRIPT_END
51};
52
53static void enable_serirq_quiet_mode(void)
54{
55 reg_script_run(ops);
56}
Lee Leahy77ff0b12015-05-05 15:07:29 -070057
58static inline void
Elyes HAOUASb13fac32018-05-24 22:29:44 +020059add_mmio_resource(struct device *dev, int i, unsigned long addr,
60 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070061{
Elyes HAOUASa342f392018-10-17 10:56:26 +020062 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070063 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070064 mmio_resource(dev, i, addr >> 10, size >> 10);
65}
66
Elyes HAOUASb13fac32018-05-24 22:29:44 +020067static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070068{
Elyes HAOUASa342f392018-10-17 10:56:26 +020069 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070070 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070071 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
72 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
73 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
74 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
75 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
76 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
77 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
78 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
79}
80
81/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
82#define LPC_DEFAULT_IO_RANGE_LOWER 0
83#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
84
Frans Hendriks93484132018-12-10 12:38:16 +010085/*
86 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE
87 * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing
88 * information to operating systems and drivers. The INT_PIN register is
89 * generally read only and reports which interrupt pin A - D it uses. The
90 * INT_LINE register is configurable and reports which IRQ (generally the
91 * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling
92 * on devices that are downstream on a PCI bridge into account.
93 *
94 * This function will loop through all enabled PCI devices and program the
95 * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it
96 * uses. It then configures each interrupt in the pic to be level triggered.
97 */
98static void write_pci_config_irqs(void)
99{
100 struct device *irq_dev;
101 struct device *targ_dev;
102 uint8_t int_line = 0;
103 uint8_t original_int_pin = 0;
104 uint8_t new_int_pin = 0;
105 uint16_t current_bdf = 0;
106 uint16_t parent_bdf = 0;
107 uint8_t pirq = 0;
108 uint8_t device_num = 0;
109 const struct soc_irq_route *ir = &global_soc_irq_route;
110
111 if (ir == NULL) {
112 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments"
113 " because 'global_braswell_irq_route' structure does"
114 " not exist\n");
115 return;
116 }
117
118 /*
119 * Loop through all enabled devices and program their
120 * INT_LINE, INT_PIN registers from values taken from
121 * the Interrupt Route registers in the ILB
122 */
123 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
124 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
125
126 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
127 (!irq_dev->enabled))
128 continue;
129
130 current_bdf = irq_dev->path.pci.devfn |
131 irq_dev->bus->secondary << 8;
132
133 /*
134 * Step 1: Get the INT_PIN and device structure to look for
135 * in the pirq_data table defined in the mainboard directory.
136 */
137 targ_dev = NULL;
138 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
139 if (targ_dev == NULL || new_int_pin < 1)
140 continue;
141
142 /* Get the original INT_PIN for record keeping */
143 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
144
145 parent_bdf = targ_dev->path.pci.devfn
146 | targ_dev->bus->secondary << 8;
147 device_num = PCI_SLOT(parent_bdf);
148
149 if (ir->pcidev[device_num] == 0) {
150 printk(BIOS_WARNING,
151 "Warning: PCI Device %d does not have an IRQ "
152 "entry, skipping it\n", device_num);
153 continue;
154 }
155
156 /* Find the PIRQ that is attached to the INT_PIN */
157 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
158 & 0x7;
159
160 /* Get the INT_LINE this device/function will use */
161 int_line = ir->pic[pirq];
162
163 if (int_line != PIRQ_PIC_IRQDISABLE) {
164 /* Set this IRQ to level triggered */
165 i8259_configure_irq_trigger(int_line,
166 IRQ_LEVEL_TRIGGERED);
167 /* Set the Interrupt Line register */
168 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
169 int_line);
170 } else {
171 /*
172 * Set the Interrupt line register as 'unknown' or
173 * 'unused'
174 */
175 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
176 PIRQ_PIC_UNKNOWN_UNUSED);
177 }
178
179 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n",
180 original_int_pin, pin_to_str(original_int_pin));
181 if (parent_bdf != current_bdf)
182 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n",
183 new_int_pin, pin_to_str(new_int_pin));
184 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n"
185 "\tINT_LINE\t: 0x%X (IRQ %d)\n",
186 'A' + pirq, int_line, int_line);
187 }
188 printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n");
189}
190
Lee Leahy77ff0b12015-05-05 15:07:29 -0700191static inline int io_range_in_default(int base, int size)
192{
193 /* Does it start above the range? */
194 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
195 return 0;
196
197 /* Is it entirely contained? */
198 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
199 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
200 return 1;
201
202 /* This will return not in range for partial overlaps. */
203 return 0;
204}
205
206/*
207 * Note: this function assumes there is no overlap with the default LPC device's
208 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
209 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200210static void sc_add_io_resource(struct device *dev, int base, int size,
211 int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700212{
213 struct resource *res;
214
Elyes HAOUASa342f392018-10-17 10:56:26 +0200215 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700216 __FILE__, __func__, dev_name(dev), base, size, index);
217
Lee Leahy77ff0b12015-05-05 15:07:29 -0700218 if (io_range_in_default(base, size))
219 return;
220
221 res = new_resource(dev, index);
222 res->base = base;
223 res->size = size;
224 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
225}
226
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200227static void sc_add_io_resources(struct device *dev)
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)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700232 __FILE__, __func__, dev_name(dev));
233
Lee Leahy77ff0b12015-05-05 15:07:29 -0700234 /* Add the default claimed IO range for the LPC device. */
235 res = new_resource(dev, 0);
236 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
237 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
238 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
239
240 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100241 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700242
243 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100244 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700245}
246
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200247static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700248{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200249 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700250 __FILE__, __func__, dev_name(dev));
251
Lee Leahy77ff0b12015-05-05 15:07:29 -0700252 /* Get the normal PCI resources of this device. */
253 pci_dev_read_resources(dev);
254
255 /* Add non-standard MMIO resources. */
256 sc_add_mmio_resources(dev);
257
258 /* Add IO resources. */
259 sc_add_io_resources(dev);
260}
261
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200262static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700263{
264 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700265 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
266 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
267 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700268 const struct soc_irq_route *ir = &global_soc_irq_route;
269 struct soc_intel_braswell_config *config = dev->chip_info;
270
Elyes HAOUASa342f392018-10-17 10:56:26 +0200271 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700272 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700273
Frans Hendriks255f35c2018-12-11 15:21:47 +0100274 isa_dma_init();
275
Lee Leahy77ff0b12015-05-05 15:07:29 -0700276 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700277 for (i = 0; i < NUM_PIRQS; i++)
278 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
279 ir->pic[i]);
280
Lee Leahy77ff0b12015-05-05 15:07:29 -0700281 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700282 for (i = 0; i < NUM_IR_DEVS; i++)
283 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
284 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700285
Frans Hendriks93484132018-12-10 12:38:16 +0100286 /* Interrupt 9 should be level triggered (SCI) */
287 i8259_configure_irq_trigger(9, 1);
288
289 for (i = 0; i < NUM_PIRQS; i++) {
290 if (ir->pic[i])
291 i8259_configure_irq_trigger(ir->pic[i], 1);
292 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700293
Lee Leahy77ff0b12015-05-05 15:07:29 -0700294 if (config->disable_slp_x_stretch_sus_fail) {
295 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
296 write32(gen_pmcon1,
297 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
298 } else {
299 write32(gen_pmcon1,
300 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
301 }
302
Frans Hendriks93484132018-12-10 12:38:16 +0100303 /* Write IRQ assignments to PCI config space */
304 write_pci_config_irqs();
305
306 /* Initialize i8259 pic */
307 setup_i8259();
308
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100309 /* Initialize i8254 timers */
310 setup_i8254();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700311}
312
313/*
314 * Common code for the south cluster devices.
315 */
316
Lee Leahy32471722015-04-20 15:20:28 -0700317/* Set bit in function disble register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200318static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700319{
Lee Leahy32471722015-04-20 15:20:28 -0700320 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
321 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700322 uint32_t mask = 0;
323 uint32_t mask2 = 0;
324
Elyes HAOUASa342f392018-10-17 10:56:26 +0200325 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700326 __FILE__, __func__, dev_name(dev));
327
328#define SET_DIS_MASK(name_) \
329 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
330 mask |= name_ ## _DIS
331#define SET_DIS_MASK2(name_) \
332 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
333 mask2 |= name_ ## _DIS
334
Lee Leahy77ff0b12015-05-05 15:07:29 -0700335 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700336 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700337 break;
Lee Leahy32471722015-04-20 15:20:28 -0700338 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700339 break;
Lee Leahy32471722015-04-20 15:20:28 -0700340 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700341 break;
Lee Leahy32471722015-04-20 15:20:28 -0700342 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700343 /* Disable super speed PHY when XHCI is not available. */
344 mask2 |= USH_SS_PHY_DIS;
345 break;
Lee Leahy32471722015-04-20 15:20:28 -0700346 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700347 break;
Lee Leahy32471722015-04-20 15:20:28 -0700348 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700349 break;
Lee Leahy32471722015-04-20 15:20:28 -0700350 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700351 break;
Lee Leahy32471722015-04-20 15:20:28 -0700352 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700353 break;
Lee Leahy32471722015-04-20 15:20:28 -0700354 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700355 break;
Lee Leahy32471722015-04-20 15:20:28 -0700356 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700357 break;
Lee Leahy32471722015-04-20 15:20:28 -0700358 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700359 break;
Lee Leahy32471722015-04-20 15:20:28 -0700360 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700361 break;
Lee Leahy32471722015-04-20 15:20:28 -0700362 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700363 break;
Lee Leahy32471722015-04-20 15:20:28 -0700364 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700365 break;
Lee Leahy32471722015-04-20 15:20:28 -0700366 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700367 break;
Lee Leahy32471722015-04-20 15:20:28 -0700368 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700369 break;
Lee Leahy32471722015-04-20 15:20:28 -0700370 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700371 break;
Lee Leahy32471722015-04-20 15:20:28 -0700372 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700373 break;
Lee Leahy32471722015-04-20 15:20:28 -0700374 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700375 break;
Lee Leahy32471722015-04-20 15:20:28 -0700376 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700377 break;
Lee Leahy32471722015-04-20 15:20:28 -0700378 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700379 break;
Lee Leahy32471722015-04-20 15:20:28 -0700380 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700381 break;
Lee Leahy32471722015-04-20 15:20:28 -0700382 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700383 break;
Lee Leahy32471722015-04-20 15:20:28 -0700384 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700385 break;
Lee Leahy32471722015-04-20 15:20:28 -0700386 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700387 break;
Lee Leahy32471722015-04-20 15:20:28 -0700388 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700389 break;
Lee Leahy32471722015-04-20 15:20:28 -0700390 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700391 break;
392 }
393
394 if (mask != 0) {
395 write32(func_dis, read32(func_dis) | mask);
396 /* Ensure posted write hits. */
397 read32(func_dis);
398 }
399
400 if (mask2 != 0) {
401 write32(func_dis2, read32(func_dis2) | mask2);
402 /* Ensure posted write hits. */
403 read32(func_dis2);
404 }
405}
406
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200407static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700408{
409 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700410
Elyes HAOUASa342f392018-10-17 10:56:26 +0200411 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700412 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700413 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
414 reg8 = pci_read_config8(dev, offset + 4);
415 reg8 |= 0x3;
416 pci_write_config8(dev, offset + 4, reg8);
417}
418
Lee Leahy32471722015-04-20 15:20:28 -0700419/*
420 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700421 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700422 * the audio paths work for LPE audio.
423 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200424static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700425{
Lee Leahy32471722015-04-20 15:20:28 -0700426 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
427
Elyes HAOUASa342f392018-10-17 10:56:26 +0200428 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700429 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700430
431 /* Need to set magic register 0x43 to 0xd7 in config space. */
432 pci_write_config8(dev, 0x43, 0xd7);
433
Lee Leahy32471722015-04-20 15:20:28 -0700434 /*
435 * Need to set bit 0 of GCTL to take the device out of reset. However,
436 * that requires setting up the 64-bit BAR.
437 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700438 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
439 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
440 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
441 write32(gctl, read32(gctl) | 0x1);
442 pci_write_config8(dev, PCI_COMMAND, 0);
443 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
444}
445
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200446static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700447{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700448 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700449
Elyes HAOUASa342f392018-10-17 10:56:26 +0200450 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700451 __FILE__, __func__, dev_name(dev));
452
453 /*
454 * Parts of the HDA block are used for LPE audio as well.
455 * Therefore assume the HDA will never be put into D3Hot.
456 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700457 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
458 hda_work_around(dev);
459 return 0;
460 }
461
462 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
463
464 if (offset != 0) {
465 set_d3hot_bits(dev, offset);
466 return 0;
467 }
468
Lee Leahy32471722015-04-20 15:20:28 -0700469 /*
470 * For some reason some of the devices don't have the capability
471 * pointer set correctly. Work around this by hard coding the offset.
472 */
473#define DEV_CASE(name_) \
474 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
475
Lee Leahy77ff0b12015-05-05 15:07:29 -0700476 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700477 DEV_CASE(SDIO) :
478 DEV_CASE(SD) :
479 DEV_CASE(MMC) :
480 DEV_CASE(LPE) :
481 DEV_CASE(SIO_DMA1) :
482 DEV_CASE(I2C1) :
483 DEV_CASE(I2C2) :
484 DEV_CASE(I2C3) :
485 DEV_CASE(I2C4) :
486 DEV_CASE(I2C5) :
487 DEV_CASE(I2C6) :
488 DEV_CASE(I2C7) :
489 DEV_CASE(SIO_DMA2) :
490 DEV_CASE(PWM1) :
491 DEV_CASE(PWM2) :
492 DEV_CASE(HSUART1) :
493 DEV_CASE(HSUART2) :
494 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700495 offset = 0x80;
496 break;
Lee Leahy32471722015-04-20 15:20:28 -0700497 DEV_CASE(SATA) :
498 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700499 offset = 0x70;
500 break;
Lee Leahy32471722015-04-20 15:20:28 -0700501 DEV_CASE(HDA) :
502 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700503 offset = 0x50;
504 break;
Lee Leahy32471722015-04-20 15:20:28 -0700505 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700506 /* TXE cannot be placed in D3Hot. */
507 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700508 DEV_CASE(PCIE_PORT1) :
509 DEV_CASE(PCIE_PORT2) :
510 DEV_CASE(PCIE_PORT3) :
511 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700512 offset = 0xa0;
513 break;
514 }
515
516 if (offset != 0) {
517 set_d3hot_bits(dev, offset);
518 return 0;
519 }
520
521 return -1;
522}
523
524/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200525void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700526{
527 uint32_t reg32;
528
Elyes HAOUASa342f392018-10-17 10:56:26 +0200529 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700530 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700531 if (!dev->enabled) {
532 int slot = PCI_SLOT(dev->path.pci.devfn);
533 int func = PCI_FUNC(dev->path.pci.devfn);
534 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
535 dev_path(dev), slot, func);
536
537 /* Ensure memory, io, and bus master are all disabled */
538 reg32 = pci_read_config32(dev, PCI_COMMAND);
539 reg32 &= ~(PCI_COMMAND_MASTER |
540 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
541 pci_write_config32(dev, PCI_COMMAND, reg32);
542
543 /* Place device in D3Hot */
544 if (place_device_in_d3hot(dev) < 0) {
545 printk(BIOS_WARNING,
546 "Could not place %02x.%01x into D3Hot. "
547 "Keeping device visible.\n", slot, func);
548 return;
549 }
550 /* Disable this device if possible */
551 sc_disable_devfn(dev);
552 } else {
553 /* Enable SERR */
554 reg32 = pci_read_config32(dev, PCI_COMMAND);
555 reg32 |= PCI_COMMAND_SERR;
556 pci_write_config32(dev, PCI_COMMAND, reg32);
557 }
558}
559
560static struct device_operations device_ops = {
561 .read_resources = sc_read_resources,
562 .set_resources = pci_dev_set_resources,
563 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700564 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
565 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700566 .init = sc_init,
567 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700568 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700569 .ops_pci = &soc_pci_ops,
570};
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
Aaron Durbin64031672018-04-21 14:45:32 -0600578int __weak mainboard_get_spi_config(struct spi_config *cfg)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700579{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200580 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700581 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700582 return -1;
583}
584
585static void finalize_chipset(void *unused)
586{
Lee Leahy32471722015-04-20 15:20:28 -0700587 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
588 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
589 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
590 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
591 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700592 struct spi_config cfg;
593
Elyes HAOUASa342f392018-10-17 10:56:26 +0200594 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700595 __FILE__, __func__, unused);
596
Lee Leahy77ff0b12015-05-05 15:07:29 -0700597 /* Set the lock enable on the BIOS control register. */
598 write32(bcr, read32(bcr) | BCR_LE);
599
600 /* Set BIOS lock down bit controlling boot block size and swapping. */
601 write32(gcs, read32(gcs) | BILD);
602
603 /* Lock sleep stretching policy and set SMI lock. */
604 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
605
606 /* Set the CF9 lock. */
607 write32(etr, read32(etr) | CF9LOCK);
608
609 if (mainboard_get_spi_config(&cfg) < 0) {
610 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
611 } else {
612 write16(spi + PREOP, cfg.preop);
613 write16(spi + OPTYPE, cfg.optype);
614 write32(spi + OPMENU0, cfg.opmenu[0]);
615 write32(spi + OPMENU1, cfg.opmenu[1]);
616 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
617 write32(spi + UVSCC, cfg.uvscc);
618 write32(spi + LVSCC, cfg.lvscc | VCL);
619 }
Lee Leahy32471722015-04-20 15:20:28 -0700620 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700621 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700622
623 printk(BIOS_DEBUG, "Finalizing SMM.\n");
624 outb(APM_CNT_FINALIZE, APM_CNT);
625}
626
Hannah Williams2cfdde72015-04-15 19:48:07 -0700627BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);