blob: dc918ebf4c86f0a451a6869044f8b74b05512c98 [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>
20#include <arch/acpi.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070021#include <arch/acpigen.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070023#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <console/console.h>
25#include <cpu/x86/smm.h>
26#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010029#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010030#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010031#include <pc80/i8259.h>
Lee Leahy32471722015-04-20 15:20:28 -070032#include <romstage_handoff.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070033#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070034#include <soc/iomap.h>
35#include <soc/irq.h>
36#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070037#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070038#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070039#include <soc/ramstage.h>
40#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070041#include <spi-generic.h>
42#include <stdint.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070043#include <reg_script.h>
44
45static const struct reg_script ops[] = {
46 REG_MMIO_RMW32(ILB_BASE_ADDRESS + SCNT,
47 ~SCNT_MODE, 0), /* put LPC SERIRQ in Quiet Mode */
48 REG_SCRIPT_END
49};
50
51static void enable_serirq_quiet_mode(void)
52{
53 reg_script_run(ops);
54}
Lee Leahy77ff0b12015-05-05 15:07:29 -070055
56static inline void
Elyes HAOUASb13fac32018-05-24 22:29:44 +020057add_mmio_resource(struct device *dev, int i, unsigned long addr,
58 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070059{
Elyes HAOUASa342f392018-10-17 10:56:26 +020060 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070061 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070062 mmio_resource(dev, i, addr >> 10, size >> 10);
63}
64
Elyes HAOUASb13fac32018-05-24 22:29:44 +020065static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070066{
Elyes HAOUASa342f392018-10-17 10:56:26 +020067 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070068 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070069 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
70 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
71 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
72 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
73 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
74 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
75 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
76 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
77}
78
79/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
80#define LPC_DEFAULT_IO_RANGE_LOWER 0
81#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
82
Frans Hendriks93484132018-12-10 12:38:16 +010083/*
84 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE
85 * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing
86 * information to operating systems and drivers. The INT_PIN register is
87 * generally read only and reports which interrupt pin A - D it uses. The
88 * INT_LINE register is configurable and reports which IRQ (generally the
89 * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling
90 * on devices that are downstream on a PCI bridge into account.
91 *
92 * This function will loop through all enabled PCI devices and program the
93 * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it
94 * uses. It then configures each interrupt in the pic to be level triggered.
95 */
96static void write_pci_config_irqs(void)
97{
98 struct device *irq_dev;
99 struct device *targ_dev;
100 uint8_t int_line = 0;
101 uint8_t original_int_pin = 0;
102 uint8_t new_int_pin = 0;
103 uint16_t current_bdf = 0;
104 uint16_t parent_bdf = 0;
105 uint8_t pirq = 0;
106 uint8_t device_num = 0;
107 const struct soc_irq_route *ir = &global_soc_irq_route;
108
109 if (ir == NULL) {
110 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments"
111 " because 'global_braswell_irq_route' structure does"
112 " not exist\n");
113 return;
114 }
115
116 /*
117 * Loop through all enabled devices and program their
118 * INT_LINE, INT_PIN registers from values taken from
119 * the Interrupt Route registers in the ILB
120 */
121 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
122 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
123
124 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
125 (!irq_dev->enabled))
126 continue;
127
128 current_bdf = irq_dev->path.pci.devfn |
129 irq_dev->bus->secondary << 8;
130
131 /*
132 * Step 1: Get the INT_PIN and device structure to look for
133 * in the pirq_data table defined in the mainboard directory.
134 */
135 targ_dev = NULL;
136 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
137 if (targ_dev == NULL || new_int_pin < 1)
138 continue;
139
140 /* Get the original INT_PIN for record keeping */
141 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
142
143 parent_bdf = targ_dev->path.pci.devfn
144 | targ_dev->bus->secondary << 8;
145 device_num = PCI_SLOT(parent_bdf);
146
147 if (ir->pcidev[device_num] == 0) {
148 printk(BIOS_WARNING,
149 "Warning: PCI Device %d does not have an IRQ "
150 "entry, skipping it\n", device_num);
151 continue;
152 }
153
154 /* Find the PIRQ that is attached to the INT_PIN */
155 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
156 & 0x7;
157
158 /* Get the INT_LINE this device/function will use */
159 int_line = ir->pic[pirq];
160
161 if (int_line != PIRQ_PIC_IRQDISABLE) {
162 /* Set this IRQ to level triggered */
163 i8259_configure_irq_trigger(int_line,
164 IRQ_LEVEL_TRIGGERED);
165 /* Set the Interrupt Line register */
166 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
167 int_line);
168 } else {
169 /*
170 * Set the Interrupt line register as 'unknown' or
171 * 'unused'
172 */
173 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE,
174 PIRQ_PIC_UNKNOWN_UNUSED);
175 }
176
177 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n",
178 original_int_pin, pin_to_str(original_int_pin));
179 if (parent_bdf != current_bdf)
180 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n",
181 new_int_pin, pin_to_str(new_int_pin));
182 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n"
183 "\tINT_LINE\t: 0x%X (IRQ %d)\n",
184 'A' + pirq, int_line, int_line);
185 }
186 printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n");
187}
188
Lee Leahy77ff0b12015-05-05 15:07:29 -0700189static inline int io_range_in_default(int base, int size)
190{
191 /* Does it start above the range? */
192 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
193 return 0;
194
195 /* Is it entirely contained? */
196 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
197 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
198 return 1;
199
200 /* This will return not in range for partial overlaps. */
201 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 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200208static void sc_add_io_resource(struct device *dev, int base, int size,
209 int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700210{
211 struct resource *res;
212
Elyes HAOUASa342f392018-10-17 10:56:26 +0200213 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700214 __FILE__, __func__, dev_name(dev), base, size, index);
215
Lee Leahy77ff0b12015-05-05 15:07:29 -0700216 if (io_range_in_default(base, size))
217 return;
218
219 res = new_resource(dev, index);
220 res->base = base;
221 res->size = size;
222 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
223}
224
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200225static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700226{
227 struct resource *res;
228
Elyes HAOUASa342f392018-10-17 10:56:26 +0200229 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700230 __FILE__, __func__, dev_name(dev));
231
Lee Leahy77ff0b12015-05-05 15:07:29 -0700232 /* Add the default claimed IO range for the LPC device. */
233 res = new_resource(dev, 0);
234 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
235 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
236 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
237
238 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100239 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700240
241 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100242 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700243}
244
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200245static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700246{
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 /* Get the normal PCI resources of this device. */
251 pci_dev_read_resources(dev);
252
253 /* Add non-standard MMIO resources. */
254 sc_add_mmio_resources(dev);
255
256 /* Add IO resources. */
257 sc_add_io_resources(dev);
258}
259
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200260static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700261{
262 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700263 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
264 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
265 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700266 const struct soc_irq_route *ir = &global_soc_irq_route;
267 struct soc_intel_braswell_config *config = dev->chip_info;
268
Elyes HAOUASa342f392018-10-17 10:56:26 +0200269 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700270 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700271
Frans Hendriks255f35c2018-12-11 15:21:47 +0100272 isa_dma_init();
273
Lee Leahy77ff0b12015-05-05 15:07:29 -0700274 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700275 for (i = 0; i < NUM_PIRQS; i++)
276 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
277 ir->pic[i]);
278
Lee Leahy77ff0b12015-05-05 15:07:29 -0700279 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700280 for (i = 0; i < NUM_IR_DEVS; i++)
281 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
282 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700283
Frans Hendriks93484132018-12-10 12:38:16 +0100284 /* Interrupt 9 should be level triggered (SCI) */
285 i8259_configure_irq_trigger(9, 1);
286
287 for (i = 0; i < NUM_PIRQS; i++) {
288 if (ir->pic[i])
289 i8259_configure_irq_trigger(ir->pic[i], 1);
290 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700291
Lee Leahy77ff0b12015-05-05 15:07:29 -0700292 if (config->disable_slp_x_stretch_sus_fail) {
293 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
294 write32(gen_pmcon1,
295 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
296 } else {
297 write32(gen_pmcon1,
298 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
299 }
300
Frans Hendriks93484132018-12-10 12:38:16 +0100301 /* Write IRQ assignments to PCI config space */
302 write_pci_config_irqs();
303
304 /* Initialize i8259 pic */
305 setup_i8259();
306
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100307 /* Initialize i8254 timers */
308 setup_i8254();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700309}
310
311/*
312 * Common code for the south cluster devices.
313 */
314
Lee Leahy32471722015-04-20 15:20:28 -0700315/* Set bit in function disble register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200316static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700317{
Lee Leahy32471722015-04-20 15:20:28 -0700318 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
319 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700320 uint32_t mask = 0;
321 uint32_t mask2 = 0;
322
Elyes HAOUASa342f392018-10-17 10:56:26 +0200323 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700324 __FILE__, __func__, dev_name(dev));
325
326#define SET_DIS_MASK(name_) \
327 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
328 mask |= name_ ## _DIS
329#define SET_DIS_MASK2(name_) \
330 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
331 mask2 |= name_ ## _DIS
332
Lee Leahy77ff0b12015-05-05 15:07:29 -0700333 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700334 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700335 break;
Lee Leahy32471722015-04-20 15:20:28 -0700336 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700337 break;
Lee Leahy32471722015-04-20 15:20:28 -0700338 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700339 break;
Lee Leahy32471722015-04-20 15:20:28 -0700340 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700341 /* Disable super speed PHY when XHCI is not available. */
342 mask2 |= USH_SS_PHY_DIS;
343 break;
Lee Leahy32471722015-04-20 15:20:28 -0700344 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700345 break;
Lee Leahy32471722015-04-20 15:20:28 -0700346 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700347 break;
Lee Leahy32471722015-04-20 15:20:28 -0700348 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700349 break;
Lee Leahy32471722015-04-20 15:20:28 -0700350 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700351 break;
Lee Leahy32471722015-04-20 15:20:28 -0700352 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700353 break;
Lee Leahy32471722015-04-20 15:20:28 -0700354 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700355 break;
Lee Leahy32471722015-04-20 15:20:28 -0700356 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700357 break;
Lee Leahy32471722015-04-20 15:20:28 -0700358 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700359 break;
Lee Leahy32471722015-04-20 15:20:28 -0700360 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700361 break;
Lee Leahy32471722015-04-20 15:20:28 -0700362 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700363 break;
Lee Leahy32471722015-04-20 15:20:28 -0700364 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700365 break;
Lee Leahy32471722015-04-20 15:20:28 -0700366 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700367 break;
Lee Leahy32471722015-04-20 15:20:28 -0700368 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700369 break;
Lee Leahy32471722015-04-20 15:20:28 -0700370 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700371 break;
Lee Leahy32471722015-04-20 15:20:28 -0700372 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700373 break;
Lee Leahy32471722015-04-20 15:20:28 -0700374 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700375 break;
Lee Leahy32471722015-04-20 15:20:28 -0700376 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700377 break;
Lee Leahy32471722015-04-20 15:20:28 -0700378 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700379 break;
Lee Leahy32471722015-04-20 15:20:28 -0700380 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700381 break;
Lee Leahy32471722015-04-20 15:20:28 -0700382 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700383 break;
Lee Leahy32471722015-04-20 15:20:28 -0700384 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700385 break;
Lee Leahy32471722015-04-20 15:20:28 -0700386 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700387 break;
Lee Leahy32471722015-04-20 15:20:28 -0700388 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700389 break;
390 }
391
392 if (mask != 0) {
393 write32(func_dis, read32(func_dis) | mask);
394 /* Ensure posted write hits. */
395 read32(func_dis);
396 }
397
398 if (mask2 != 0) {
399 write32(func_dis2, read32(func_dis2) | mask2);
400 /* Ensure posted write hits. */
401 read32(func_dis2);
402 }
403}
404
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200405static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700406{
407 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700408
Elyes HAOUASa342f392018-10-17 10:56:26 +0200409 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700410 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700411 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
412 reg8 = pci_read_config8(dev, offset + 4);
413 reg8 |= 0x3;
414 pci_write_config8(dev, offset + 4, reg8);
415}
416
Lee Leahy32471722015-04-20 15:20:28 -0700417/*
418 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700419 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700420 * the audio paths work for LPE audio.
421 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200422static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700423{
Lee Leahy32471722015-04-20 15:20:28 -0700424 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
425
Elyes HAOUASa342f392018-10-17 10:56:26 +0200426 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700427 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700428
429 /* Need to set magic register 0x43 to 0xd7 in config space. */
430 pci_write_config8(dev, 0x43, 0xd7);
431
Lee Leahy32471722015-04-20 15:20:28 -0700432 /*
433 * Need to set bit 0 of GCTL to take the device out of reset. However,
434 * that requires setting up the 64-bit BAR.
435 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700436 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
437 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
438 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
439 write32(gctl, read32(gctl) | 0x1);
440 pci_write_config8(dev, PCI_COMMAND, 0);
441 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
442}
443
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200444static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700445{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700446 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700447
Elyes HAOUASa342f392018-10-17 10:56:26 +0200448 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700449 __FILE__, __func__, dev_name(dev));
450
451 /*
452 * Parts of the HDA block are used for LPE audio as well.
453 * Therefore assume the HDA will never be put into D3Hot.
454 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700455 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
456 hda_work_around(dev);
457 return 0;
458 }
459
460 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
461
462 if (offset != 0) {
463 set_d3hot_bits(dev, offset);
464 return 0;
465 }
466
Lee Leahy32471722015-04-20 15:20:28 -0700467 /*
468 * For some reason some of the devices don't have the capability
469 * pointer set correctly. Work around this by hard coding the offset.
470 */
471#define DEV_CASE(name_) \
472 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
473
Lee Leahy77ff0b12015-05-05 15:07:29 -0700474 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700475 DEV_CASE(SDIO) :
476 DEV_CASE(SD) :
477 DEV_CASE(MMC) :
478 DEV_CASE(LPE) :
479 DEV_CASE(SIO_DMA1) :
480 DEV_CASE(I2C1) :
481 DEV_CASE(I2C2) :
482 DEV_CASE(I2C3) :
483 DEV_CASE(I2C4) :
484 DEV_CASE(I2C5) :
485 DEV_CASE(I2C6) :
486 DEV_CASE(I2C7) :
487 DEV_CASE(SIO_DMA2) :
488 DEV_CASE(PWM1) :
489 DEV_CASE(PWM2) :
490 DEV_CASE(HSUART1) :
491 DEV_CASE(HSUART2) :
492 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700493 offset = 0x80;
494 break;
Lee Leahy32471722015-04-20 15:20:28 -0700495 DEV_CASE(SATA) :
496 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700497 offset = 0x70;
498 break;
Lee Leahy32471722015-04-20 15:20:28 -0700499 DEV_CASE(HDA) :
500 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700501 offset = 0x50;
502 break;
Lee Leahy32471722015-04-20 15:20:28 -0700503 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700504 /* TXE cannot be placed in D3Hot. */
505 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700506 DEV_CASE(PCIE_PORT1) :
507 DEV_CASE(PCIE_PORT2) :
508 DEV_CASE(PCIE_PORT3) :
509 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700510 offset = 0xa0;
511 break;
512 }
513
514 if (offset != 0) {
515 set_d3hot_bits(dev, offset);
516 return 0;
517 }
518
519 return -1;
520}
521
522/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200523void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700524{
525 uint32_t reg32;
526
Elyes HAOUASa342f392018-10-17 10:56:26 +0200527 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700528 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700529 if (!dev->enabled) {
530 int slot = PCI_SLOT(dev->path.pci.devfn);
531 int func = PCI_FUNC(dev->path.pci.devfn);
532 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
533 dev_path(dev), slot, func);
534
535 /* Ensure memory, io, and bus master are all disabled */
536 reg32 = pci_read_config32(dev, PCI_COMMAND);
537 reg32 &= ~(PCI_COMMAND_MASTER |
538 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
539 pci_write_config32(dev, PCI_COMMAND, reg32);
540
541 /* Place device in D3Hot */
542 if (place_device_in_d3hot(dev) < 0) {
543 printk(BIOS_WARNING,
544 "Could not place %02x.%01x into D3Hot. "
545 "Keeping device visible.\n", slot, func);
546 return;
547 }
548 /* Disable this device if possible */
549 sc_disable_devfn(dev);
550 } else {
551 /* Enable SERR */
552 reg32 = pci_read_config32(dev, PCI_COMMAND);
553 reg32 |= PCI_COMMAND_SERR;
554 pci_write_config32(dev, PCI_COMMAND, reg32);
555 }
556}
557
558static struct device_operations device_ops = {
559 .read_resources = sc_read_resources,
560 .set_resources = pci_dev_set_resources,
561 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700562 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
563 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700564 .init = sc_init,
565 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700566 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700567 .ops_pci = &soc_pci_ops,
568};
569
570static const struct pci_driver southcluster __pci_driver = {
571 .ops = &device_ops,
572 .vendor = PCI_VENDOR_ID_INTEL,
573 .device = LPC_DEVID,
574};
575
Aaron Durbin64031672018-04-21 14:45:32 -0600576int __weak mainboard_get_spi_config(struct spi_config *cfg)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700577{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200578 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700579 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700580 return -1;
581}
582
583static void finalize_chipset(void *unused)
584{
Lee Leahy32471722015-04-20 15:20:28 -0700585 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
586 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
587 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
588 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
589 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700590 struct spi_config cfg;
591
Elyes HAOUASa342f392018-10-17 10:56:26 +0200592 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700593 __FILE__, __func__, unused);
594
Lee Leahy77ff0b12015-05-05 15:07:29 -0700595 /* Set the lock enable on the BIOS control register. */
596 write32(bcr, read32(bcr) | BCR_LE);
597
598 /* Set BIOS lock down bit controlling boot block size and swapping. */
599 write32(gcs, read32(gcs) | BILD);
600
601 /* Lock sleep stretching policy and set SMI lock. */
602 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
603
604 /* Set the CF9 lock. */
605 write32(etr, read32(etr) | CF9LOCK);
606
607 if (mainboard_get_spi_config(&cfg) < 0) {
608 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
609 } else {
610 write16(spi + PREOP, cfg.preop);
611 write16(spi + OPTYPE, cfg.optype);
612 write32(spi + OPMENU0, cfg.opmenu[0]);
613 write32(spi + OPMENU1, cfg.opmenu[1]);
614 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
615 write32(spi + UVSCC, cfg.uvscc);
616 write32(spi + LVSCC, cfg.lvscc | VCL);
617 }
Lee Leahy32471722015-04-20 15:20:28 -0700618 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700619 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700620
621 printk(BIOS_DEBUG, "Finalizing SMM.\n");
622 outb(APM_CNT_FINALIZE, APM_CNT);
623}
624
Hannah Williams2cfdde72015-04-15 19:48:07 -0700625BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);