blob: 7b01cfa8e17461f147ecba79a3343e300931bc8c [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>
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>
Kein Yuan35110232014-02-22 12:26:55 -080022#include <arch/acpi.h>
Elyes HAOUASd2b9ec12018-10-27 09:41:02 +020023#include <arch/cpu.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060024#include <bootstate.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080025#include <cbmem.h>
Aaron Durbind7bc23a2013-10-29 16:37:10 -050026#include <console/console.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060027#include <cpu/x86/smm.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050028#include <device/device.h>
29#include <device/pci.h>
30#include <device/pci_ids.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080031#include <pc80/mc146818rtc.h>
Kein Yuan35110232014-02-22 12:26:55 -080032#include <drivers/uart/uart8250reg.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050033
Julius Werner18ea2d32014-10-07 16:42:17 -070034#include <soc/iomap.h>
35#include <soc/irq.h>
36#include <soc/lpc.h>
37#include <soc/nvs.h>
38#include <soc/pci_devs.h>
39#include <soc/pmc.h>
40#include <soc/ramstage.h>
41#include <soc/spi.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080042#include "chip.h"
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +020043#include <arch/acpigen.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050044
45static inline void
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020046add_mmio_resource(struct device *dev, int i, unsigned long addr,
47 unsigned long size)
Aaron Durbine18d68f2013-10-24 00:05:31 -050048{
49 mmio_resource(dev, i, addr >> 10, size >> 10);
50}
51
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020052static void sc_add_mmio_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -050053{
Duncan Laurie7fbe20b2013-11-04 17:00:22 -080054 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
55 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
56 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
57 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
58 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
59 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
60 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
61 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050062}
63
64/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
65#define LPC_DEFAULT_IO_RANGE_LOWER 0
66#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
67
68static inline int io_range_in_default(int base, int size)
69{
70 /* Does it start above the range? */
71 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
72 return 0;
73
74 /* Is it entirely contained? */
75 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
76 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
77 return 1;
78
79 /* This will return not in range for partial overlaps. */
80 return 0;
81}
82
83/*
84 * Note: this function assumes there is no overlap with the default LPC device's
85 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
86 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020087static void sc_add_io_resource(struct device *dev, int base, int size,
88 int index)
Aaron Durbine18d68f2013-10-24 00:05:31 -050089{
90 struct resource *res;
91
92 if (io_range_in_default(base, size))
93 return;
94
95 res = new_resource(dev, index);
96 res->base = base;
97 res->size = size;
98 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
99}
100
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200101static void sc_add_io_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500102{
103 struct resource *res;
104
105 /* Add the default claimed IO range for the LPC device. */
106 res = new_resource(dev, 0);
107 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
108 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
109 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
110
111 /* GPIO */
Frans Hendriks802f43d2018-10-29 14:17:16 +0100112 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -0500113
114 /* ACPI */
Frans Hendriks802f43d2018-10-29 14:17:16 +0100115 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -0500116}
117
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200118static void sc_read_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500119{
120 /* Get the normal PCI resources of this device. */
121 pci_dev_read_resources(dev);
122
123 /* Add non-standard MMIO resources. */
124 sc_add_mmio_resources(dev);
125
126 /* Add IO resources. */
127 sc_add_io_resources(dev);
128}
129
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800130static void sc_rtc_init(void)
131{
Aaron Durbin64b4bdd2017-09-15 14:24:03 -0600132 cmos_init(rtc_failure());
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800133}
134
Kein Yuan35110232014-02-22 12:26:55 -0800135/*
136 * The UART hardware loses power while in suspend. Because of this the kernel
137 * can hang because it doesn't re-initialize serial ports it is using for
138 * consoles at resume time. The following function configures the UART
139 * if the hardware is enabled though it may not be the correct baud rate
140 * or configuration. This is definitely a hack, but it helps the kernel
141 * along.
142 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200143static void com1_configure_resume(struct device *dev)
Kein Yuan35110232014-02-22 12:26:55 -0800144{
145 const uint16_t port = 0x3f8;
146
Martin Roth99a3bba2014-12-07 14:57:26 -0700147 /* Is the UART I/O port enabled? */
Kein Yuan35110232014-02-22 12:26:55 -0800148 if (!(pci_read_config32(dev, UART_CONT) & 1))
149 return;
150
151 /* Disable interrupts */
152 outb(0x0, port + UART8250_IER);
153
154 /* Enable FIFOs */
155 outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR);
156
157 /* assert DTR and RTS so the other end is happy */
158 outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR);
159
160 /* DLAB on */
161 outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR);
162
163 /* Set Baud Rate Divisor. 1 ==> 115200 Baud */
164 outb(1, port + UART8250_DLL);
165 outb(0, port + UART8250_DLM);
166
167 /* Set to 3 for 8N1 */
168 outb(3, port + UART8250_LCR);
169}
170
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200171static void sc_init(struct device *dev)
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600172{
173 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800174 u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08);
Alexander Couzens316170e2015-11-24 09:46:18 +0100175 u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800176 u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1);
177 u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600178 const struct baytrail_irq_route *ir = &global_baytrail_irq_route;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800179 struct soc_intel_baytrail_config *config = dev->chip_info;
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600180
181 /* Set up the PIRQ PIC routing based on static config. */
182 for (i = 0; i < NUM_PIRQS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800183 write8(pr_base + i, ir->pic[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600184 }
185 /* Set up the per device PIRQ routing base on static config. */
186 for (i = 0; i < NUM_IR_DEVS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800187 write16(ir_base + i, ir->pcidev[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600188 }
Aaron Durbin1af36632013-11-07 10:42:16 -0600189
190 /* Route SCI to IRQ9 */
191 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800192
193 sc_rtc_init();
194
195 if (config->disable_slp_x_stretch_sus_fail) {
196 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
197 write32(gen_pmcon1,
198 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
199 } else {
200 write32(gen_pmcon1,
201 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
202 }
Kein Yuan35110232014-02-22 12:26:55 -0800203
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200204 if (acpi_is_wakeup_s3())
Kein Yuan35110232014-02-22 12:26:55 -0800205 com1_configure_resume(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600206}
207
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500208/*
209 * Common code for the south cluster devices.
210 */
211
Martin Roth99a3bba2014-12-07 14:57:26 -0700212/* Set bit in function disable register to hide this device. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200213static void sc_disable_devfn(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500214{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800215 u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS);
216 u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500217 uint32_t mask = 0;
218 uint32_t mask2 = 0;
219
220 switch (dev->path.pci.devfn) {
221 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
222 mask |= SDIO_DIS;
223 break;
224 case PCI_DEVFN(SD_DEV, SD_FUNC):
225 mask |= SD_DIS;
226 break;
227 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
228 mask |= SATA_DIS;
229 break;
230 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
231 mask |= XHCI_DIS;
232 /* Disable super speed PHY when XHCI is not available. */
233 mask2 |= USH_SS_PHY_DIS;
234 break;
235 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
236 mask |= LPE_DIS;
237 break;
238 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
239 mask |= MMC_DIS;
240 break;
241 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
242 mask |= SIO_DMA1_DIS;
243 break;
244 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
245 mask |= I2C1_DIS;
246 break;
247 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
248 mask |= I2C1_DIS;
249 break;
250 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
251 mask |= I2C3_DIS;
252 break;
253 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
254 mask |= I2C4_DIS;
255 break;
256 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
257 mask |= I2C5_DIS;
258 break;
259 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
260 mask |= I2C6_DIS;
261 break;
262 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
263 mask |= I2C7_DIS;
264 break;
265 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
266 mask |= TXE_DIS;
267 break;
268 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
269 mask |= HDA_DIS;
270 break;
271 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
272 mask |= PCIE_PORT1_DIS;
273 break;
274 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
275 mask |= PCIE_PORT2_DIS;
276 break;
277 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
278 mask |= PCIE_PORT3_DIS;
279 break;
280 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
281 mask |= PCIE_PORT4_DIS;
282 break;
283 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
284 mask |= EHCI_DIS;
285 break;
286 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
287 mask |= SIO_DMA2_DIS;
288 break;
289 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
290 mask |= PWM1_DIS;
291 break;
292 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
293 mask |= PWM2_DIS;
294 break;
295 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
296 mask |= HSUART1_DIS;
297 break;
298 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
299 mask |= HSUART2_DIS;
300 break;
301 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
302 mask |= SPI_DIS;
303 break;
304 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
305 mask2 |= SMBUS_DIS;
306 break;
307 }
308
309 if (mask != 0) {
310 write32(func_dis, read32(func_dis) | mask);
311 /* Ensure posted write hits. */
312 read32(func_dis);
313 }
314
315 if (mask2 != 0) {
316 write32(func_dis2, read32(func_dis2) | mask2);
317 /* Ensure posted write hits. */
318 read32(func_dis2);
319 }
320}
321
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200322static inline void set_d3hot_bits(struct device *dev, int offset)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500323{
324 uint32_t reg8;
325 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
326 reg8 = pci_read_config8(dev, offset + 4);
327 reg8 |= 0x3;
328 pci_write_config8(dev, offset + 4, reg8);
329}
330
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500331/* Parts of the audio subsystem are powered by the HDA device. Therefore, one
332 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
333 * the audio paths work for LPE audio. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200334static void hda_work_around(struct device *dev)
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500335{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800336 u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500337
338 /* Need to set magic register 0x43 to 0xd7 in config space. */
339 pci_write_config8(dev, 0x43, 0xd7);
340
341 /* Need to set bit 0 of GCTL to take the device out of reset. However,
342 * that requires setting up the 64-bit BAR. */
343 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
344 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
345 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
346 write32(gctl, read32(gctl) | 0x1);
347 pci_write_config8(dev, PCI_COMMAND, 0);
348 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
349}
350
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200351static int place_device_in_d3hot(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500352{
353 unsigned offset;
354
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500355 /* Parts of the HDA block are used for LPE audio as well.
356 * Therefore assume the HDA will never be put into D3Hot. */
357 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
358 hda_work_around(dev);
359 return 0;
360 }
361
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500362 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
363
364 if (offset != 0) {
365 set_d3hot_bits(dev, offset);
366 return 0;
367 }
368
369 /* For some reason some of the devices don't have the capability
370 * pointer set correctly. Work around this by hard coding the offset. */
371 switch (dev->path.pci.devfn) {
372 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
373 offset = 0x80;
374 break;
375 case PCI_DEVFN(SD_DEV, SD_FUNC):
376 offset = 0x80;
377 break;
378 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
379 offset = 0x80;
380 break;
381 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
382 offset = 0x80;
383 break;
384 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
385 offset = 0x80;
386 break;
387 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
388 offset = 0x80;
389 break;
390 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
391 offset = 0x80;
392 break;
393 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
394 offset = 0x80;
395 break;
396 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
397 offset = 0x80;
398 break;
399 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
400 offset = 0x80;
401 break;
402 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
403 offset = 0x80;
404 break;
405 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
406 offset = 0x80;
407 break;
408 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
409 offset = 0x80;
410 break;
411 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
412 offset = 0x80;
413 break;
414 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
415 offset = 0x80;
416 break;
417 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
418 offset = 0x80;
419 break;
420 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
421 offset = 0x80;
422 break;
423 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
424 offset = 0x80;
425 break;
426 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
427 offset = 0x70;
428 break;
429 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
430 offset = 0x70;
431 break;
432 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
433 offset = 0x70;
434 break;
435 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
436 offset = 0x50;
437 break;
438 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
439 offset = 0x50;
440 break;
441 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
Aaron Durbin1eae3ee2013-10-30 17:08:59 -0500442 /* TXE cannot be placed in D3Hot. */
443 return 0;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500444 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
445 offset = 0xa0;
446 break;
447 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
448 offset = 0xa0;
449 break;
450 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
451 offset = 0xa0;
452 break;
453 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
454 offset = 0xa0;
455 break;
456 }
457
458 if (offset != 0) {
459 set_d3hot_bits(dev, offset);
460 return 0;
461 }
462
463 return -1;
464}
465
466/* Common PCI device function disable. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200467void southcluster_enable_dev(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500468{
469 uint32_t reg32;
470
471 if (!dev->enabled) {
472 int slot = PCI_SLOT(dev->path.pci.devfn);
473 int func = PCI_FUNC(dev->path.pci.devfn);
474 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
475 dev_path(dev), slot, func);
476
477 /* Ensure memory, io, and bus master are all disabled */
478 reg32 = pci_read_config32(dev, PCI_COMMAND);
479 reg32 &= ~(PCI_COMMAND_MASTER |
480 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
481 pci_write_config32(dev, PCI_COMMAND, reg32);
482
483 /* Place device in D3Hot */
484 if (place_device_in_d3hot(dev) < 0) {
485 printk(BIOS_WARNING,
486 "Could not place %02x.%01x into D3Hot. "
487 "Keeping device visible.\n", slot, func);
488 return;
489 }
490 /* Disable this device if possible */
491 sc_disable_devfn(dev);
492 } else {
493 /* Enable SERR */
494 reg32 = pci_read_config32(dev, PCI_COMMAND);
495 reg32 |= PCI_COMMAND_SERR;
496 pci_write_config32(dev, PCI_COMMAND, reg32);
497 }
498}
499
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200500static void southcluster_inject_dsdt(struct device *device)
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200501{
502 global_nvs_t *gnvs;
503
504 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
505 if (!gnvs) {
506 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
507 if (gnvs)
508 memset(gnvs, 0, sizeof(*gnvs));
509 }
510
511 if (gnvs) {
512 acpi_create_gnvs(gnvs);
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200513 /* And tell SMI about it */
514 smm_setup_structures(gnvs, NULL, NULL);
515
516 /* Add it to DSDT. */
517 acpigen_write_scope("\\");
518 acpigen_write_name_dword("NVSA", (u32) gnvs);
519 acpigen_pop_len();
520 }
521}
522
523
Aaron Durbine18d68f2013-10-24 00:05:31 -0500524static struct device_operations device_ops = {
525 .read_resources = sc_read_resources,
526 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200527 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
528 .write_acpi_tables = acpi_write_hpet,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500529 .enable_resources = NULL,
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600530 .init = sc_init,
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500531 .enable = southcluster_enable_dev,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200532 .scan_bus = scan_lpc_bus,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500533 .ops_pci = &soc_pci_ops,
534};
535
536static const struct pci_driver southcluster __pci_driver = {
537 .ops = &device_ops,
538 .vendor = PCI_VENDOR_ID_INTEL,
539 .device = LPC_DEVID,
540};
Aaron Durbin4177db52014-02-05 14:55:26 -0600541
Aaron Durbin64031672018-04-21 14:45:32 -0600542int __weak mainboard_get_spi_config(struct spi_config *cfg)
Aaron Durbin4177db52014-02-05 14:55:26 -0600543{
544 return -1;
545}
546
547static void finalize_chipset(void *unused)
548{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800549 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
550 u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS);
551 u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2);
552 u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR);
553 u8 *spi = (u8 *)SPI_BASE_ADDRESS;
Aaron Durbin4177db52014-02-05 14:55:26 -0600554 struct spi_config cfg;
555
556 /* Set the lock enable on the BIOS control register. */
557 write32(bcr, read32(bcr) | BCR_LE);
558
559 /* Set BIOS lock down bit controlling boot block size and swapping. */
560 write32(gcs, read32(gcs) | BILD);
561
562 /* Lock sleep stretching policy and set SMI lock. */
563 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
564
565 /* Set the CF9 lock. */
566 write32(etr, read32(etr) | CF9LOCK);
567
568 if (mainboard_get_spi_config(&cfg) < 0) {
569 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
570 } else {
571 write16(spi + PREOP, cfg.preop);
572 write16(spi + OPTYPE, cfg.optype);
573 write32(spi + OPMENU0, cfg.opmenu[0]);
574 write32(spi + OPMENU1, cfg.opmenu[1]);
575 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
576 write32(spi + UVSCC, cfg.uvscc);
577 write32(spi + LVSCC, cfg.lvscc | VCL);
578 }
579
580 printk(BIOS_DEBUG, "Finalizing SMM.\n");
581 outb(APM_CNT_FINALIZE, APM_CNT);
582}
583
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500584BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
585BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);