blob: 3cd22082b0512d93d1e3e1f3635cc355ee6d84c0 [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älkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <arch/acpi.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070022#include <arch/acpigen.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070023#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070024#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070025#include <console/console.h>
26#include <cpu/x86/smm.h>
27#include <device/device.h>
28#include <device/pci.h>
29#include <device/pci_ids.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010030#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010031#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010032#include <pc80/i8259.h>
Lee Leahy32471722015-04-20 15:20:28 -070033#include <romstage_handoff.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070034#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070035#include <soc/iomap.h>
36#include <soc/irq.h>
37#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070038#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070039#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070040#include <soc/ramstage.h>
41#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070042#include <spi-generic.h>
43#include <stdint.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070044#include <reg_script.h>
45
46static const struct reg_script ops[] = {
47 REG_MMIO_RMW32(ILB_BASE_ADDRESS + SCNT,
48 ~SCNT_MODE, 0), /* put LPC SERIRQ in Quiet Mode */
49 REG_SCRIPT_END
50};
51
52static void enable_serirq_quiet_mode(void)
53{
54 reg_script_run(ops);
55}
Lee Leahy77ff0b12015-05-05 15:07:29 -070056
57static inline void
Elyes HAOUASb13fac32018-05-24 22:29:44 +020058add_mmio_resource(struct device *dev, int i, unsigned long addr,
59 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070060{
Elyes HAOUASa342f392018-10-17 10:56:26 +020061 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070062 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070063 mmio_resource(dev, i, addr >> 10, size >> 10);
64}
65
Elyes HAOUASb13fac32018-05-24 22:29:44 +020066static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070067{
Elyes HAOUASa342f392018-10-17 10:56:26 +020068 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070069 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070070 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
71 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
72 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
73 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
74 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
75 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
76 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
77 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
78}
79
80/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
81#define LPC_DEFAULT_IO_RANGE_LOWER 0
82#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
83
Frans Hendriks93484132018-12-10 12:38:16 +010084/*
85 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE
86 * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing
87 * information to operating systems and drivers. The INT_PIN register is
88 * generally read only and reports which interrupt pin A - D it uses. The
89 * INT_LINE register is configurable and reports which IRQ (generally the
90 * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling
91 * on devices that are downstream on a PCI bridge into account.
92 *
93 * This function will loop through all enabled PCI devices and program the
94 * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it
95 * uses. It then configures each interrupt in the pic to be level triggered.
96 */
97static void write_pci_config_irqs(void)
98{
99 struct device *irq_dev;
100 struct device *targ_dev;
101 uint8_t int_line = 0;
102 uint8_t original_int_pin = 0;
103 uint8_t new_int_pin = 0;
104 uint16_t current_bdf = 0;
105 uint16_t parent_bdf = 0;
106 uint8_t pirq = 0;
107 uint8_t device_num = 0;
108 const struct soc_irq_route *ir = &global_soc_irq_route;
109
110 if (ir == NULL) {
111 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments"
112 " because 'global_braswell_irq_route' structure does"
113 " not exist\n");
114 return;
115 }
116
117 /*
118 * Loop through all enabled devices and program their
119 * INT_LINE, INT_PIN registers from values taken from
120 * the Interrupt Route registers in the ILB
121 */
122 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
123 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
124
125 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
126 (!irq_dev->enabled))
127 continue;
128
129 current_bdf = irq_dev->path.pci.devfn |
130 irq_dev->bus->secondary << 8;
131
132 /*
133 * Step 1: Get the INT_PIN and device structure to look for
134 * in the pirq_data table defined in the mainboard directory.
135 */
136 targ_dev = NULL;
137 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
138 if (targ_dev == NULL || new_int_pin < 1)
139 continue;
140
141 /* Get the original INT_PIN for record keeping */
142 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
143
144 parent_bdf = targ_dev->path.pci.devfn
145 | targ_dev->bus->secondary << 8;
146 device_num = PCI_SLOT(parent_bdf);
147
148 if (ir->pcidev[device_num] == 0) {
149 printk(BIOS_WARNING,
150 "Warning: PCI Device %d does not have an IRQ "
151 "entry, skipping it\n", device_num);
152 continue;
153 }
154
155 /* Find the PIRQ that is attached to the INT_PIN */
156 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
157 & 0x7;
158
159 /* Get the INT_LINE this device/function will use */
160 int_line = ir->pic[pirq];
161
162 if (int_line != PIRQ_PIC_IRQDISABLE) {
163 /* Set this IRQ to level triggered */
164 i8259_configure_irq_trigger(int_line,
165 IRQ_LEVEL_TRIGGERED);
166 /* Set the Interrupt Line register */
167 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
168 int_line);
169 } else {
170 /*
171 * Set the Interrupt line register as 'unknown' or
172 * 'unused'
173 */
174 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
175 PIRQ_PIC_UNKNOWN_UNUSED);
176 }
177
178 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n",
179 original_int_pin, pin_to_str(original_int_pin));
180 if (parent_bdf != current_bdf)
181 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n",
182 new_int_pin, pin_to_str(new_int_pin));
183 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n"
184 "\tINT_LINE\t: 0x%X (IRQ %d)\n",
185 'A' + pirq, int_line, int_line);
186 }
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? */
197 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
198 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
199 return 1;
200
201 /* This will return not in range for partial overlaps. */
202 return 0;
203}
204
205/*
206 * Note: this function assumes there is no overlap with the default LPC device's
207 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
208 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200209static void sc_add_io_resource(struct device *dev, int base, int size,
210 int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700211{
212 struct resource *res;
213
Elyes HAOUASa342f392018-10-17 10:56:26 +0200214 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700215 __FILE__, __func__, dev_name(dev), base, size, index);
216
Lee Leahy77ff0b12015-05-05 15:07:29 -0700217 if (io_range_in_default(base, size))
218 return;
219
220 res = new_resource(dev, index);
221 res->base = base;
222 res->size = size;
223 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
224}
225
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200226static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700227{
228 struct resource *res;
229
Elyes HAOUASa342f392018-10-17 10:56:26 +0200230 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700231 __FILE__, __func__, dev_name(dev));
232
Lee Leahy77ff0b12015-05-05 15:07:29 -0700233 /* Add the default claimed IO range for the LPC device. */
234 res = new_resource(dev, 0);
235 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
236 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
237 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
238
239 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100240 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700241
242 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100243 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700244}
245
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200246static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700247{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200248 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700249 __FILE__, __func__, dev_name(dev));
250
Lee Leahy77ff0b12015-05-05 15:07:29 -0700251 /* Get the normal PCI resources of this device. */
252 pci_dev_read_resources(dev);
253
254 /* Add non-standard MMIO resources. */
255 sc_add_mmio_resources(dev);
256
257 /* Add IO resources. */
258 sc_add_io_resources(dev);
259}
260
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200261static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700262{
263 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700264 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
265 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
266 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700267 const struct soc_irq_route *ir = &global_soc_irq_route;
268 struct soc_intel_braswell_config *config = dev->chip_info;
269
Elyes HAOUASa342f392018-10-17 10:56:26 +0200270 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700271 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700272
Frans Hendriks255f35c2018-12-11 15:21:47 +0100273 isa_dma_init();
274
Lee Leahy77ff0b12015-05-05 15:07:29 -0700275 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700276 for (i = 0; i < NUM_PIRQS; i++)
277 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
278 ir->pic[i]);
279
Lee Leahy77ff0b12015-05-05 15:07:29 -0700280 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700281 for (i = 0; i < NUM_IR_DEVS; i++)
282 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
283 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700284
Frans Hendriks93484132018-12-10 12:38:16 +0100285 /* Interrupt 9 should be level triggered (SCI) */
286 i8259_configure_irq_trigger(9, 1);
287
288 for (i = 0; i < NUM_PIRQS; i++) {
289 if (ir->pic[i])
290 i8259_configure_irq_trigger(ir->pic[i], 1);
291 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700292
Lee Leahy77ff0b12015-05-05 15:07:29 -0700293 if (config->disable_slp_x_stretch_sus_fail) {
294 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
295 write32(gen_pmcon1,
296 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
297 } else {
298 write32(gen_pmcon1,
299 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
300 }
301
Frans Hendriks93484132018-12-10 12:38:16 +0100302 /* Write IRQ assignments to PCI config space */
303 write_pci_config_irqs();
304
305 /* Initialize i8259 pic */
306 setup_i8259();
307
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100308 /* Initialize i8254 timers */
309 setup_i8254();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700310}
311
312/*
313 * Common code for the south cluster devices.
314 */
315
Lee Leahy32471722015-04-20 15:20:28 -0700316/* Set bit in function disble register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200317static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700318{
Lee Leahy32471722015-04-20 15:20:28 -0700319 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
320 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700321 uint32_t mask = 0;
322 uint32_t mask2 = 0;
323
Elyes HAOUASa342f392018-10-17 10:56:26 +0200324 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700325 __FILE__, __func__, dev_name(dev));
326
327#define SET_DIS_MASK(name_) \
328 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
329 mask |= name_ ## _DIS
330#define SET_DIS_MASK2(name_) \
331 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
332 mask2 |= name_ ## _DIS
333
Lee Leahy77ff0b12015-05-05 15:07:29 -0700334 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700335 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700336 break;
Lee Leahy32471722015-04-20 15:20:28 -0700337 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700338 break;
Lee Leahy32471722015-04-20 15:20:28 -0700339 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700340 break;
Lee Leahy32471722015-04-20 15:20:28 -0700341 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700342 /* Disable super speed PHY when XHCI is not available. */
343 mask2 |= USH_SS_PHY_DIS;
344 break;
Lee Leahy32471722015-04-20 15:20:28 -0700345 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700346 break;
Lee Leahy32471722015-04-20 15:20:28 -0700347 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700348 break;
Lee Leahy32471722015-04-20 15:20:28 -0700349 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700350 break;
Lee Leahy32471722015-04-20 15:20:28 -0700351 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700352 break;
Lee Leahy32471722015-04-20 15:20:28 -0700353 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700354 break;
Lee Leahy32471722015-04-20 15:20:28 -0700355 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700356 break;
Lee Leahy32471722015-04-20 15:20:28 -0700357 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700358 break;
Lee Leahy32471722015-04-20 15:20:28 -0700359 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700360 break;
Lee Leahy32471722015-04-20 15:20:28 -0700361 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700362 break;
Lee Leahy32471722015-04-20 15:20:28 -0700363 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700364 break;
Lee Leahy32471722015-04-20 15:20:28 -0700365 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700366 break;
Lee Leahy32471722015-04-20 15:20:28 -0700367 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700368 break;
Lee Leahy32471722015-04-20 15:20:28 -0700369 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700370 break;
Lee Leahy32471722015-04-20 15:20:28 -0700371 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700372 break;
Lee Leahy32471722015-04-20 15:20:28 -0700373 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700374 break;
Lee Leahy32471722015-04-20 15:20:28 -0700375 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700376 break;
Lee Leahy32471722015-04-20 15:20:28 -0700377 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700378 break;
Lee Leahy32471722015-04-20 15:20:28 -0700379 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700380 break;
Lee Leahy32471722015-04-20 15:20:28 -0700381 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700382 break;
Lee Leahy32471722015-04-20 15:20:28 -0700383 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700384 break;
Lee Leahy32471722015-04-20 15:20:28 -0700385 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700386 break;
Lee Leahy32471722015-04-20 15:20:28 -0700387 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700388 break;
Lee Leahy32471722015-04-20 15:20:28 -0700389 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700390 break;
391 }
392
393 if (mask != 0) {
394 write32(func_dis, read32(func_dis) | mask);
395 /* Ensure posted write hits. */
396 read32(func_dis);
397 }
398
399 if (mask2 != 0) {
400 write32(func_dis2, read32(func_dis2) | mask2);
401 /* Ensure posted write hits. */
402 read32(func_dis2);
403 }
404}
405
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200406static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700407{
408 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700409
Elyes HAOUASa342f392018-10-17 10:56:26 +0200410 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700411 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700412 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
413 reg8 = pci_read_config8(dev, offset + 4);
414 reg8 |= 0x3;
415 pci_write_config8(dev, offset + 4, reg8);
416}
417
Lee Leahy32471722015-04-20 15:20:28 -0700418/*
419 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700420 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700421 * the audio paths work for LPE audio.
422 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200423static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700424{
Lee Leahy32471722015-04-20 15:20:28 -0700425 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
426
Elyes HAOUASa342f392018-10-17 10:56:26 +0200427 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700428 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700429
430 /* Need to set magic register 0x43 to 0xd7 in config space. */
431 pci_write_config8(dev, 0x43, 0xd7);
432
Lee Leahy32471722015-04-20 15:20:28 -0700433 /*
434 * Need to set bit 0 of GCTL to take the device out of reset. However,
435 * that requires setting up the 64-bit BAR.
436 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700437 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
438 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
439 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
440 write32(gctl, read32(gctl) | 0x1);
441 pci_write_config8(dev, PCI_COMMAND, 0);
442 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
443}
444
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200445static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700446{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700447 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700448
Elyes HAOUASa342f392018-10-17 10:56:26 +0200449 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700450 __FILE__, __func__, dev_name(dev));
451
452 /*
453 * Parts of the HDA block are used for LPE audio as well.
454 * Therefore assume the HDA will never be put into D3Hot.
455 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700456 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
457 hda_work_around(dev);
458 return 0;
459 }
460
461 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
462
463 if (offset != 0) {
464 set_d3hot_bits(dev, offset);
465 return 0;
466 }
467
Lee Leahy32471722015-04-20 15:20:28 -0700468 /*
469 * For some reason some of the devices don't have the capability
470 * pointer set correctly. Work around this by hard coding the offset.
471 */
472#define DEV_CASE(name_) \
473 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
474
Lee Leahy77ff0b12015-05-05 15:07:29 -0700475 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700476 DEV_CASE(SDIO) :
477 DEV_CASE(SD) :
478 DEV_CASE(MMC) :
479 DEV_CASE(LPE) :
480 DEV_CASE(SIO_DMA1) :
481 DEV_CASE(I2C1) :
482 DEV_CASE(I2C2) :
483 DEV_CASE(I2C3) :
484 DEV_CASE(I2C4) :
485 DEV_CASE(I2C5) :
486 DEV_CASE(I2C6) :
487 DEV_CASE(I2C7) :
488 DEV_CASE(SIO_DMA2) :
489 DEV_CASE(PWM1) :
490 DEV_CASE(PWM2) :
491 DEV_CASE(HSUART1) :
492 DEV_CASE(HSUART2) :
493 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700494 offset = 0x80;
495 break;
Lee Leahy32471722015-04-20 15:20:28 -0700496 DEV_CASE(SATA) :
497 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700498 offset = 0x70;
499 break;
Lee Leahy32471722015-04-20 15:20:28 -0700500 DEV_CASE(HDA) :
501 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700502 offset = 0x50;
503 break;
Lee Leahy32471722015-04-20 15:20:28 -0700504 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700505 /* TXE cannot be placed in D3Hot. */
506 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700507 DEV_CASE(PCIE_PORT1) :
508 DEV_CASE(PCIE_PORT2) :
509 DEV_CASE(PCIE_PORT3) :
510 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700511 offset = 0xa0;
512 break;
513 }
514
515 if (offset != 0) {
516 set_d3hot_bits(dev, offset);
517 return 0;
518 }
519
520 return -1;
521}
522
523/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200524void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700525{
526 uint32_t reg32;
527
Elyes HAOUASa342f392018-10-17 10:56:26 +0200528 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700529 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700530 if (!dev->enabled) {
531 int slot = PCI_SLOT(dev->path.pci.devfn);
532 int func = PCI_FUNC(dev->path.pci.devfn);
533 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
534 dev_path(dev), slot, func);
535
536 /* Ensure memory, io, and bus master are all disabled */
537 reg32 = pci_read_config32(dev, PCI_COMMAND);
538 reg32 &= ~(PCI_COMMAND_MASTER |
539 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
540 pci_write_config32(dev, PCI_COMMAND, reg32);
541
542 /* Place device in D3Hot */
543 if (place_device_in_d3hot(dev) < 0) {
544 printk(BIOS_WARNING,
545 "Could not place %02x.%01x into D3Hot. "
546 "Keeping device visible.\n", slot, func);
547 return;
548 }
549 /* Disable this device if possible */
550 sc_disable_devfn(dev);
551 } else {
552 /* Enable SERR */
553 reg32 = pci_read_config32(dev, PCI_COMMAND);
554 reg32 |= PCI_COMMAND_SERR;
555 pci_write_config32(dev, PCI_COMMAND, reg32);
556 }
557}
558
559static struct device_operations device_ops = {
560 .read_resources = sc_read_resources,
561 .set_resources = pci_dev_set_resources,
562 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700563 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
564 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700565 .init = sc_init,
566 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700567 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700568 .ops_pci = &soc_pci_ops,
569};
570
571static const struct pci_driver southcluster __pci_driver = {
572 .ops = &device_ops,
573 .vendor = PCI_VENDOR_ID_INTEL,
574 .device = LPC_DEVID,
575};
576
Aaron Durbin64031672018-04-21 14:45:32 -0600577int __weak mainboard_get_spi_config(struct spi_config *cfg)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700578{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200579 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700580 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700581 return -1;
582}
583
584static void finalize_chipset(void *unused)
585{
Lee Leahy32471722015-04-20 15:20:28 -0700586 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
587 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
588 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
589 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
590 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700591 struct spi_config cfg;
592
Elyes HAOUASa342f392018-10-17 10:56:26 +0200593 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700594 __FILE__, __func__, unused);
595
Lee Leahy77ff0b12015-05-05 15:07:29 -0700596 /* Set the lock enable on the BIOS control register. */
597 write32(bcr, read32(bcr) | BCR_LE);
598
599 /* Set BIOS lock down bit controlling boot block size and swapping. */
600 write32(gcs, read32(gcs) | BILD);
601
602 /* Lock sleep stretching policy and set SMI lock. */
603 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
604
605 /* Set the CF9 lock. */
606 write32(etr, read32(etr) | CF9LOCK);
607
608 if (mainboard_get_spi_config(&cfg) < 0) {
609 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
610 } else {
611 write16(spi + PREOP, cfg.preop);
612 write16(spi + OPTYPE, cfg.optype);
613 write32(spi + OPMENU0, cfg.opmenu[0]);
614 write32(spi + OPMENU1, cfg.opmenu[1]);
615 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
616 write32(spi + UVSCC, cfg.uvscc);
617 write32(spi + LVSCC, cfg.lvscc | VCL);
618 }
Lee Leahy32471722015-04-20 15:20:28 -0700619 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700620 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700621
622 printk(BIOS_DEBUG, "Finalizing SMM.\n");
623 outb(APM_CNT_FINALIZE, APM_CNT);
624}
625
Hannah Williams2cfdde72015-04-15 19:48:07 -0700626BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);