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