blob: d5e3400e6f7b8a206d8ab1afa7392b116d38c727 [file] [log] [blame]
Aaron Durbine18d68f2013-10-24 00:05:31 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2013 Google Inc.
Frans Hendriks802f43d2018-10-29 14:17:16 +01006 * Copyright (C) 2018 Eltan B.V.
Aaron Durbine18d68f2013-10-24 00:05:31 -05007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Aaron Durbine18d68f2013-10-24 00:05:31 -050016 */
17
18#include <stdint.h>
19#include <arch/io.h>
Kein Yuan35110232014-02-22 12:26:55 -080020#include <arch/acpi.h>
Elyes HAOUASd2b9ec12018-10-27 09:41:02 +020021#include <arch/cpu.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060022#include <bootstate.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080023#include <cbmem.h>
Aaron Durbind7bc23a2013-10-29 16:37:10 -050024#include <console/console.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060025#include <cpu/x86/smm.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050026#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080029#include <pc80/mc146818rtc.h>
Kein Yuan35110232014-02-22 12:26:55 -080030#include <drivers/uart/uart8250reg.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050031
Julius Werner18ea2d32014-10-07 16:42:17 -070032#include <soc/iomap.h>
33#include <soc/irq.h>
34#include <soc/lpc.h>
35#include <soc/nvs.h>
36#include <soc/pci_devs.h>
37#include <soc/pmc.h>
38#include <soc/ramstage.h>
39#include <soc/spi.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080040#include "chip.h"
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +020041#include <arch/acpigen.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050042
43static inline void
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020044add_mmio_resource(struct device *dev, int i, unsigned long addr,
45 unsigned long size)
Aaron Durbine18d68f2013-10-24 00:05:31 -050046{
47 mmio_resource(dev, i, addr >> 10, size >> 10);
48}
49
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020050static void sc_add_mmio_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -050051{
Duncan Laurie7fbe20b2013-11-04 17:00:22 -080052 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
53 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
54 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
55 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
56 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
57 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
58 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
59 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050060}
61
62/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
63#define LPC_DEFAULT_IO_RANGE_LOWER 0
64#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
65
66static inline int io_range_in_default(int base, int size)
67{
68 /* Does it start above the range? */
69 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
70 return 0;
71
72 /* Is it entirely contained? */
73 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
74 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
75 return 1;
76
77 /* This will return not in range for partial overlaps. */
78 return 0;
79}
80
81/*
82 * Note: this function assumes there is no overlap with the default LPC device's
83 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
84 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020085static void sc_add_io_resource(struct device *dev, int base, int size,
86 int index)
Aaron Durbine18d68f2013-10-24 00:05:31 -050087{
88 struct resource *res;
89
90 if (io_range_in_default(base, size))
91 return;
92
93 res = new_resource(dev, index);
94 res->base = base;
95 res->size = size;
96 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
97}
98
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020099static void sc_add_io_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500100{
101 struct resource *res;
102
103 /* Add the default claimed IO range for the LPC device. */
104 res = new_resource(dev, 0);
105 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
106 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
107 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
108
109 /* GPIO */
Frans Hendriks802f43d2018-10-29 14:17:16 +0100110 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -0500111
112 /* ACPI */
Frans Hendriks802f43d2018-10-29 14:17:16 +0100113 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -0500114}
115
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200116static void sc_read_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500117{
118 /* Get the normal PCI resources of this device. */
119 pci_dev_read_resources(dev);
120
121 /* Add non-standard MMIO resources. */
122 sc_add_mmio_resources(dev);
123
124 /* Add IO resources. */
125 sc_add_io_resources(dev);
126}
127
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800128static void sc_rtc_init(void)
129{
Aaron Durbin64b4bdd2017-09-15 14:24:03 -0600130 cmos_init(rtc_failure());
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800131}
132
Kein Yuan35110232014-02-22 12:26:55 -0800133/*
134 * The UART hardware loses power while in suspend. Because of this the kernel
135 * can hang because it doesn't re-initialize serial ports it is using for
136 * consoles at resume time. The following function configures the UART
137 * if the hardware is enabled though it may not be the correct baud rate
138 * or configuration. This is definitely a hack, but it helps the kernel
139 * along.
140 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200141static void com1_configure_resume(struct device *dev)
Kein Yuan35110232014-02-22 12:26:55 -0800142{
143 const uint16_t port = 0x3f8;
144
Martin Roth99a3bba2014-12-07 14:57:26 -0700145 /* Is the UART I/O port enabled? */
Kein Yuan35110232014-02-22 12:26:55 -0800146 if (!(pci_read_config32(dev, UART_CONT) & 1))
147 return;
148
149 /* Disable interrupts */
150 outb(0x0, port + UART8250_IER);
151
152 /* Enable FIFOs */
153 outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR);
154
155 /* assert DTR and RTS so the other end is happy */
156 outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR);
157
158 /* DLAB on */
159 outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR);
160
161 /* Set Baud Rate Divisor. 1 ==> 115200 Baud */
162 outb(1, port + UART8250_DLL);
163 outb(0, port + UART8250_DLM);
164
165 /* Set to 3 for 8N1 */
166 outb(3, port + UART8250_LCR);
167}
168
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200169static void sc_init(struct device *dev)
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600170{
171 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800172 u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08);
Alexander Couzens316170e2015-11-24 09:46:18 +0100173 u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800174 u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1);
175 u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600176 const struct baytrail_irq_route *ir = &global_baytrail_irq_route;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800177 struct soc_intel_baytrail_config *config = dev->chip_info;
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600178
179 /* Set up the PIRQ PIC routing based on static config. */
180 for (i = 0; i < NUM_PIRQS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800181 write8(pr_base + i, ir->pic[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600182 }
183 /* Set up the per device PIRQ routing base on static config. */
184 for (i = 0; i < NUM_IR_DEVS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800185 write16(ir_base + i, ir->pcidev[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600186 }
Aaron Durbin1af36632013-11-07 10:42:16 -0600187
188 /* Route SCI to IRQ9 */
189 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800190
191 sc_rtc_init();
192
193 if (config->disable_slp_x_stretch_sus_fail) {
194 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
195 write32(gen_pmcon1,
196 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
197 } else {
198 write32(gen_pmcon1,
199 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
200 }
Kein Yuan35110232014-02-22 12:26:55 -0800201
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200202 if (acpi_is_wakeup_s3())
Kein Yuan35110232014-02-22 12:26:55 -0800203 com1_configure_resume(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600204}
205
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500206/*
207 * Common code for the south cluster devices.
208 */
209
Martin Roth99a3bba2014-12-07 14:57:26 -0700210/* Set bit in function disable register to hide this device. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200211static void sc_disable_devfn(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500212{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800213 u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS);
214 u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500215 uint32_t mask = 0;
216 uint32_t mask2 = 0;
217
218 switch (dev->path.pci.devfn) {
219 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
220 mask |= SDIO_DIS;
221 break;
222 case PCI_DEVFN(SD_DEV, SD_FUNC):
223 mask |= SD_DIS;
224 break;
225 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
226 mask |= SATA_DIS;
227 break;
228 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
229 mask |= XHCI_DIS;
230 /* Disable super speed PHY when XHCI is not available. */
231 mask2 |= USH_SS_PHY_DIS;
232 break;
233 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
234 mask |= LPE_DIS;
235 break;
236 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
237 mask |= MMC_DIS;
238 break;
239 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
240 mask |= SIO_DMA1_DIS;
241 break;
242 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
243 mask |= I2C1_DIS;
244 break;
245 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
246 mask |= I2C1_DIS;
247 break;
248 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
249 mask |= I2C3_DIS;
250 break;
251 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
252 mask |= I2C4_DIS;
253 break;
254 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
255 mask |= I2C5_DIS;
256 break;
257 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
258 mask |= I2C6_DIS;
259 break;
260 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
261 mask |= I2C7_DIS;
262 break;
263 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
264 mask |= TXE_DIS;
265 break;
266 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
267 mask |= HDA_DIS;
268 break;
269 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
270 mask |= PCIE_PORT1_DIS;
271 break;
272 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
273 mask |= PCIE_PORT2_DIS;
274 break;
275 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
276 mask |= PCIE_PORT3_DIS;
277 break;
278 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
279 mask |= PCIE_PORT4_DIS;
280 break;
281 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
282 mask |= EHCI_DIS;
283 break;
284 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
285 mask |= SIO_DMA2_DIS;
286 break;
287 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
288 mask |= PWM1_DIS;
289 break;
290 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
291 mask |= PWM2_DIS;
292 break;
293 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
294 mask |= HSUART1_DIS;
295 break;
296 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
297 mask |= HSUART2_DIS;
298 break;
299 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
300 mask |= SPI_DIS;
301 break;
302 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
303 mask2 |= SMBUS_DIS;
304 break;
305 }
306
307 if (mask != 0) {
308 write32(func_dis, read32(func_dis) | mask);
309 /* Ensure posted write hits. */
310 read32(func_dis);
311 }
312
313 if (mask2 != 0) {
314 write32(func_dis2, read32(func_dis2) | mask2);
315 /* Ensure posted write hits. */
316 read32(func_dis2);
317 }
318}
319
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200320static inline void set_d3hot_bits(struct device *dev, int offset)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500321{
322 uint32_t reg8;
323 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
324 reg8 = pci_read_config8(dev, offset + 4);
325 reg8 |= 0x3;
326 pci_write_config8(dev, offset + 4, reg8);
327}
328
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500329/* Parts of the audio subsystem are powered by the HDA device. Therefore, one
330 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
331 * the audio paths work for LPE audio. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200332static void hda_work_around(struct device *dev)
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500333{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800334 u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500335
336 /* Need to set magic register 0x43 to 0xd7 in config space. */
337 pci_write_config8(dev, 0x43, 0xd7);
338
339 /* Need to set bit 0 of GCTL to take the device out of reset. However,
340 * that requires setting up the 64-bit BAR. */
341 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
342 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
343 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
344 write32(gctl, read32(gctl) | 0x1);
345 pci_write_config8(dev, PCI_COMMAND, 0);
346 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
347}
348
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200349static int place_device_in_d3hot(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500350{
351 unsigned offset;
352
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500353 /* Parts of the HDA block are used for LPE audio as well.
354 * Therefore assume the HDA will never be put into D3Hot. */
355 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
356 hda_work_around(dev);
357 return 0;
358 }
359
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500360 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
361
362 if (offset != 0) {
363 set_d3hot_bits(dev, offset);
364 return 0;
365 }
366
367 /* For some reason some of the devices don't have the capability
368 * pointer set correctly. Work around this by hard coding the offset. */
369 switch (dev->path.pci.devfn) {
370 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
371 offset = 0x80;
372 break;
373 case PCI_DEVFN(SD_DEV, SD_FUNC):
374 offset = 0x80;
375 break;
376 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
377 offset = 0x80;
378 break;
379 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
380 offset = 0x80;
381 break;
382 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
383 offset = 0x80;
384 break;
385 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
386 offset = 0x80;
387 break;
388 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
389 offset = 0x80;
390 break;
391 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
392 offset = 0x80;
393 break;
394 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
395 offset = 0x80;
396 break;
397 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
398 offset = 0x80;
399 break;
400 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
401 offset = 0x80;
402 break;
403 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
404 offset = 0x80;
405 break;
406 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
407 offset = 0x80;
408 break;
409 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
410 offset = 0x80;
411 break;
412 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
413 offset = 0x80;
414 break;
415 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
416 offset = 0x80;
417 break;
418 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
419 offset = 0x80;
420 break;
421 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
422 offset = 0x80;
423 break;
424 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
425 offset = 0x70;
426 break;
427 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
428 offset = 0x70;
429 break;
430 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
431 offset = 0x70;
432 break;
433 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
434 offset = 0x50;
435 break;
436 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
437 offset = 0x50;
438 break;
439 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
Aaron Durbin1eae3ee2013-10-30 17:08:59 -0500440 /* TXE cannot be placed in D3Hot. */
441 return 0;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500442 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
443 offset = 0xa0;
444 break;
445 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
446 offset = 0xa0;
447 break;
448 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
449 offset = 0xa0;
450 break;
451 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
452 offset = 0xa0;
453 break;
454 }
455
456 if (offset != 0) {
457 set_d3hot_bits(dev, offset);
458 return 0;
459 }
460
461 return -1;
462}
463
464/* Common PCI device function disable. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200465void southcluster_enable_dev(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500466{
467 uint32_t reg32;
468
469 if (!dev->enabled) {
470 int slot = PCI_SLOT(dev->path.pci.devfn);
471 int func = PCI_FUNC(dev->path.pci.devfn);
472 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
473 dev_path(dev), slot, func);
474
475 /* Ensure memory, io, and bus master are all disabled */
476 reg32 = pci_read_config32(dev, PCI_COMMAND);
477 reg32 &= ~(PCI_COMMAND_MASTER |
478 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
479 pci_write_config32(dev, PCI_COMMAND, reg32);
480
481 /* Place device in D3Hot */
482 if (place_device_in_d3hot(dev) < 0) {
483 printk(BIOS_WARNING,
484 "Could not place %02x.%01x into D3Hot. "
485 "Keeping device visible.\n", slot, func);
486 return;
487 }
488 /* Disable this device if possible */
489 sc_disable_devfn(dev);
490 } else {
491 /* Enable SERR */
492 reg32 = pci_read_config32(dev, PCI_COMMAND);
493 reg32 |= PCI_COMMAND_SERR;
494 pci_write_config32(dev, PCI_COMMAND, reg32);
495 }
496}
497
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200498static void southcluster_inject_dsdt(struct device *device)
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200499{
500 global_nvs_t *gnvs;
501
502 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
503 if (!gnvs) {
504 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
505 if (gnvs)
506 memset(gnvs, 0, sizeof(*gnvs));
507 }
508
509 if (gnvs) {
510 acpi_create_gnvs(gnvs);
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200511 /* And tell SMI about it */
512 smm_setup_structures(gnvs, NULL, NULL);
513
514 /* Add it to DSDT. */
515 acpigen_write_scope("\\");
516 acpigen_write_name_dword("NVSA", (u32) gnvs);
517 acpigen_pop_len();
518 }
519}
520
521
Aaron Durbine18d68f2013-10-24 00:05:31 -0500522static struct device_operations device_ops = {
523 .read_resources = sc_read_resources,
524 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200525 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
526 .write_acpi_tables = acpi_write_hpet,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500527 .enable_resources = NULL,
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600528 .init = sc_init,
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500529 .enable = southcluster_enable_dev,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200530 .scan_bus = scan_lpc_bus,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500531 .ops_pci = &soc_pci_ops,
532};
533
534static const struct pci_driver southcluster __pci_driver = {
535 .ops = &device_ops,
536 .vendor = PCI_VENDOR_ID_INTEL,
537 .device = LPC_DEVID,
538};
Aaron Durbin4177db52014-02-05 14:55:26 -0600539
Aaron Durbin64031672018-04-21 14:45:32 -0600540int __weak mainboard_get_spi_config(struct spi_config *cfg)
Aaron Durbin4177db52014-02-05 14:55:26 -0600541{
542 return -1;
543}
544
545static void finalize_chipset(void *unused)
546{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800547 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
548 u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS);
549 u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2);
550 u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR);
551 u8 *spi = (u8 *)SPI_BASE_ADDRESS;
Aaron Durbin4177db52014-02-05 14:55:26 -0600552 struct spi_config cfg;
553
554 /* Set the lock enable on the BIOS control register. */
555 write32(bcr, read32(bcr) | BCR_LE);
556
557 /* Set BIOS lock down bit controlling boot block size and swapping. */
558 write32(gcs, read32(gcs) | BILD);
559
560 /* Lock sleep stretching policy and set SMI lock. */
561 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
562
563 /* Set the CF9 lock. */
564 write32(etr, read32(etr) | CF9LOCK);
565
566 if (mainboard_get_spi_config(&cfg) < 0) {
567 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
568 } else {
569 write16(spi + PREOP, cfg.preop);
570 write16(spi + OPTYPE, cfg.optype);
571 write32(spi + OPMENU0, cfg.opmenu[0]);
572 write32(spi + OPMENU1, cfg.opmenu[1]);
573 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
574 write32(spi + UVSCC, cfg.uvscc);
575 write32(spi + LVSCC, cfg.lvscc | VCL);
576 }
577
578 printk(BIOS_DEBUG, "Finalizing SMM.\n");
579 outb(APM_CNT_FINALIZE, APM_CNT);
580}
581
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500582BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
583BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);