blob: 679c04d491878e331bd0a3165f6c96ee584416b9 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbine18d68f2013-10-24 00:05:31 -05002
3#include <stdint.h>
4#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07007#include <acpi/acpi.h>
Aaron Durbin4177db52014-02-05 14:55:26 -06008#include <bootstate.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -08009#include <cbmem.h>
Aaron Durbind7bc23a2013-10-29 16:37:10 -050010#include <console/console.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060011#include <cpu/x86/smm.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050012#include <device/device.h>
13#include <device/pci.h>
14#include <device/pci_ids.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080015#include <pc80/mc146818rtc.h>
Kein Yuan35110232014-02-22 12:26:55 -080016#include <drivers/uart/uart8250reg.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010017#include <string.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050018
Julius Werner18ea2d32014-10-07 16:42:17 -070019#include <soc/iomap.h>
20#include <soc/irq.h>
21#include <soc/lpc.h>
22#include <soc/nvs.h>
23#include <soc/pci_devs.h>
24#include <soc/pmc.h>
25#include <soc/ramstage.h>
26#include <soc/spi.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080027#include "chip.h"
Furquan Shaikh76cedd22020-05-02 10:24:23 -070028#include <acpi/acpigen.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050029
30static inline void
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020031add_mmio_resource(struct device *dev, int i, unsigned long addr,
32 unsigned long size)
Aaron Durbine18d68f2013-10-24 00:05:31 -050033{
34 mmio_resource(dev, i, addr >> 10, size >> 10);
35}
36
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020037static void sc_add_mmio_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -050038{
Duncan Laurie7fbe20b2013-11-04 17:00:22 -080039 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
40 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
41 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
42 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
43 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
44 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
45 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
46 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050047}
48
49/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
50#define LPC_DEFAULT_IO_RANGE_LOWER 0
51#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
52
53static inline int io_range_in_default(int base, int size)
54{
55 /* Does it start above the range? */
56 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
57 return 0;
58
59 /* Is it entirely contained? */
60 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
61 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
62 return 1;
63
64 /* This will return not in range for partial overlaps. */
65 return 0;
66}
67
68/*
69 * Note: this function assumes there is no overlap with the default LPC device's
70 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
71 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020072static void sc_add_io_resource(struct device *dev, int base, int size,
73 int index)
Aaron Durbine18d68f2013-10-24 00:05:31 -050074{
75 struct resource *res;
76
77 if (io_range_in_default(base, size))
78 return;
79
80 res = new_resource(dev, index);
81 res->base = base;
82 res->size = size;
83 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
84}
85
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020086static void sc_add_io_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -050087{
88 struct resource *res;
89
90 /* Add the default claimed IO range for the LPC device. */
91 res = new_resource(dev, 0);
92 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
93 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
94 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
95
96 /* GPIO */
Frans Hendriks802f43d2018-10-29 14:17:16 +010097 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050098
99 /* ACPI */
Frans Hendriks802f43d2018-10-29 14:17:16 +0100100 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Aaron Durbine18d68f2013-10-24 00:05:31 -0500101}
102
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200103static void sc_read_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500104{
105 /* Get the normal PCI resources of this device. */
106 pci_dev_read_resources(dev);
107
108 /* Add non-standard MMIO resources. */
109 sc_add_mmio_resources(dev);
110
111 /* Add IO resources. */
112 sc_add_io_resources(dev);
113}
114
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800115static void sc_rtc_init(void)
116{
Aaron Durbin64b4bdd2017-09-15 14:24:03 -0600117 cmos_init(rtc_failure());
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800118}
119
Kein Yuan35110232014-02-22 12:26:55 -0800120/*
121 * The UART hardware loses power while in suspend. Because of this the kernel
122 * can hang because it doesn't re-initialize serial ports it is using for
123 * consoles at resume time. The following function configures the UART
124 * if the hardware is enabled though it may not be the correct baud rate
125 * or configuration. This is definitely a hack, but it helps the kernel
126 * along.
127 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200128static void com1_configure_resume(struct device *dev)
Kein Yuan35110232014-02-22 12:26:55 -0800129{
130 const uint16_t port = 0x3f8;
131
Martin Roth99a3bba2014-12-07 14:57:26 -0700132 /* Is the UART I/O port enabled? */
Kein Yuan35110232014-02-22 12:26:55 -0800133 if (!(pci_read_config32(dev, UART_CONT) & 1))
134 return;
135
136 /* Disable interrupts */
137 outb(0x0, port + UART8250_IER);
138
139 /* Enable FIFOs */
140 outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR);
141
142 /* assert DTR and RTS so the other end is happy */
143 outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR);
144
145 /* DLAB on */
146 outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR);
147
148 /* Set Baud Rate Divisor. 1 ==> 115200 Baud */
149 outb(1, port + UART8250_DLL);
150 outb(0, port + UART8250_DLM);
151
152 /* Set to 3 for 8N1 */
153 outb(3, port + UART8250_LCR);
154}
155
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200156static void sc_init(struct device *dev)
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600157{
158 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800159 u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08);
Alexander Couzens316170e2015-11-24 09:46:18 +0100160 u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800161 u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1);
162 u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600163 const struct baytrail_irq_route *ir = &global_baytrail_irq_route;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300164 struct soc_intel_baytrail_config *config = config_of(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600165
166 /* Set up the PIRQ PIC routing based on static config. */
167 for (i = 0; i < NUM_PIRQS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800168 write8(pr_base + i, ir->pic[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600169 }
170 /* Set up the per device PIRQ routing base on static config. */
171 for (i = 0; i < NUM_IR_DEVS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800172 write16(ir_base + i, ir->pcidev[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600173 }
Aaron Durbin1af36632013-11-07 10:42:16 -0600174
175 /* Route SCI to IRQ9 */
176 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800177
178 sc_rtc_init();
179
180 if (config->disable_slp_x_stretch_sus_fail) {
181 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
182 write32(gen_pmcon1,
183 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
184 } else {
185 write32(gen_pmcon1,
186 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
187 }
Kein Yuan35110232014-02-22 12:26:55 -0800188
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200189 if (acpi_is_wakeup_s3())
Kein Yuan35110232014-02-22 12:26:55 -0800190 com1_configure_resume(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600191}
192
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500193/*
194 * Common code for the south cluster devices.
195 */
196
Martin Roth99a3bba2014-12-07 14:57:26 -0700197/* Set bit in function disable register to hide this device. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200198static void sc_disable_devfn(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500199{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800200 u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS);
201 u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500202 uint32_t mask = 0;
203 uint32_t mask2 = 0;
204
205 switch (dev->path.pci.devfn) {
206 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
207 mask |= SDIO_DIS;
208 break;
209 case PCI_DEVFN(SD_DEV, SD_FUNC):
210 mask |= SD_DIS;
211 break;
212 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
213 mask |= SATA_DIS;
214 break;
215 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
216 mask |= XHCI_DIS;
217 /* Disable super speed PHY when XHCI is not available. */
218 mask2 |= USH_SS_PHY_DIS;
219 break;
220 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
221 mask |= LPE_DIS;
222 break;
223 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
224 mask |= MMC_DIS;
225 break;
226 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
227 mask |= SIO_DMA1_DIS;
228 break;
229 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
230 mask |= I2C1_DIS;
231 break;
232 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
233 mask |= I2C1_DIS;
234 break;
235 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
236 mask |= I2C3_DIS;
237 break;
238 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
239 mask |= I2C4_DIS;
240 break;
241 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
242 mask |= I2C5_DIS;
243 break;
244 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
245 mask |= I2C6_DIS;
246 break;
247 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
248 mask |= I2C7_DIS;
249 break;
250 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
251 mask |= TXE_DIS;
252 break;
253 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
254 mask |= HDA_DIS;
255 break;
256 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
257 mask |= PCIE_PORT1_DIS;
258 break;
259 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
260 mask |= PCIE_PORT2_DIS;
261 break;
262 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
263 mask |= PCIE_PORT3_DIS;
264 break;
265 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
266 mask |= PCIE_PORT4_DIS;
267 break;
268 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
269 mask |= EHCI_DIS;
270 break;
271 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
272 mask |= SIO_DMA2_DIS;
273 break;
274 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
275 mask |= PWM1_DIS;
276 break;
277 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
278 mask |= PWM2_DIS;
279 break;
280 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
281 mask |= HSUART1_DIS;
282 break;
283 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
284 mask |= HSUART2_DIS;
285 break;
286 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
287 mask |= SPI_DIS;
288 break;
289 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
290 mask2 |= SMBUS_DIS;
291 break;
292 }
293
294 if (mask != 0) {
295 write32(func_dis, read32(func_dis) | mask);
296 /* Ensure posted write hits. */
297 read32(func_dis);
298 }
299
300 if (mask2 != 0) {
301 write32(func_dis2, read32(func_dis2) | mask2);
302 /* Ensure posted write hits. */
303 read32(func_dis2);
304 }
305}
306
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200307static inline void set_d3hot_bits(struct device *dev, int offset)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500308{
309 uint32_t reg8;
310 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
311 reg8 = pci_read_config8(dev, offset + 4);
312 reg8 |= 0x3;
313 pci_write_config8(dev, offset + 4, reg8);
314}
315
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500316/* Parts of the audio subsystem are powered by the HDA device. Therefore, one
317 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
318 * the audio paths work for LPE audio. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200319static void hda_work_around(struct device *dev)
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500320{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800321 u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500322
323 /* Need to set magic register 0x43 to 0xd7 in config space. */
324 pci_write_config8(dev, 0x43, 0xd7);
325
326 /* Need to set bit 0 of GCTL to take the device out of reset. However,
327 * that requires setting up the 64-bit BAR. */
328 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
329 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200330 pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500331 write32(gctl, read32(gctl) | 0x1);
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200332 pci_write_config16(dev, PCI_COMMAND, 0);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500333 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
334}
335
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200336static int place_device_in_d3hot(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500337{
Martin Roth57e89092019-10-23 21:45:23 -0600338 unsigned int offset;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500339
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500340 /* Parts of the HDA block are used for LPE audio as well.
341 * Therefore assume the HDA will never be put into D3Hot. */
342 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
343 hda_work_around(dev);
344 return 0;
345 }
346
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500347 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
348
349 if (offset != 0) {
350 set_d3hot_bits(dev, offset);
351 return 0;
352 }
353
354 /* For some reason some of the devices don't have the capability
355 * pointer set correctly. Work around this by hard coding the offset. */
356 switch (dev->path.pci.devfn) {
357 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
358 offset = 0x80;
359 break;
360 case PCI_DEVFN(SD_DEV, SD_FUNC):
361 offset = 0x80;
362 break;
363 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
364 offset = 0x80;
365 break;
366 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
367 offset = 0x80;
368 break;
369 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
370 offset = 0x80;
371 break;
372 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
373 offset = 0x80;
374 break;
375 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
376 offset = 0x80;
377 break;
378 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
379 offset = 0x80;
380 break;
381 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
382 offset = 0x80;
383 break;
384 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
385 offset = 0x80;
386 break;
387 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
388 offset = 0x80;
389 break;
390 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
391 offset = 0x80;
392 break;
393 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
394 offset = 0x80;
395 break;
396 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
397 offset = 0x80;
398 break;
399 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
400 offset = 0x80;
401 break;
402 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
403 offset = 0x80;
404 break;
405 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
406 offset = 0x80;
407 break;
408 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
409 offset = 0x80;
410 break;
411 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
412 offset = 0x70;
413 break;
414 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
415 offset = 0x70;
416 break;
417 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
418 offset = 0x70;
419 break;
420 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
421 offset = 0x50;
422 break;
423 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
424 offset = 0x50;
425 break;
426 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
Aaron Durbin1eae3ee2013-10-30 17:08:59 -0500427 /* TXE cannot be placed in D3Hot. */
428 return 0;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500429 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
430 offset = 0xa0;
431 break;
432 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
433 offset = 0xa0;
434 break;
435 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
436 offset = 0xa0;
437 break;
438 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
439 offset = 0xa0;
440 break;
441 }
442
443 if (offset != 0) {
444 set_d3hot_bits(dev, offset);
445 return 0;
446 }
447
448 return -1;
449}
450
451/* Common PCI device function disable. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200452void southcluster_enable_dev(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500453{
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200454 uint16_t reg16;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500455
456 if (!dev->enabled) {
457 int slot = PCI_SLOT(dev->path.pci.devfn);
458 int func = PCI_FUNC(dev->path.pci.devfn);
459 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
460 dev_path(dev), slot, func);
461
462 /* Ensure memory, io, and bus master are all disabled */
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200463 reg16 = pci_read_config16(dev, PCI_COMMAND);
464 reg16 &= ~(PCI_COMMAND_MASTER |
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500465 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200466 pci_write_config16(dev, PCI_COMMAND, reg16);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500467
468 /* Place device in D3Hot */
469 if (place_device_in_d3hot(dev) < 0) {
470 printk(BIOS_WARNING,
471 "Could not place %02x.%01x into D3Hot. "
472 "Keeping device visible.\n", slot, func);
473 return;
474 }
475 /* Disable this device if possible */
476 sc_disable_devfn(dev);
477 } else {
478 /* Enable SERR */
Elyes HAOUAS6468d87d2020-04-29 10:22:42 +0200479 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500480 }
481}
482
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700483static void southcluster_inject_dsdt(const struct device *device)
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200484{
485 global_nvs_t *gnvs;
486
487 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
488 if (!gnvs) {
489 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
490 if (gnvs)
491 memset(gnvs, 0, sizeof(*gnvs));
492 }
493
494 if (gnvs) {
495 acpi_create_gnvs(gnvs);
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200496 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300497 apm_control(APM_CNT_GNVS_UPDATE);
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200498
499 /* Add it to DSDT. */
500 acpigen_write_scope("\\");
501 acpigen_write_name_dword("NVSA", (u32) gnvs);
502 acpigen_pop_len();
503 }
504}
505
506
Aaron Durbine18d68f2013-10-24 00:05:31 -0500507static struct device_operations device_ops = {
508 .read_resources = sc_read_resources,
509 .set_resources = pci_dev_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200510 .acpi_inject_dsdt = southcluster_inject_dsdt,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200511 .write_acpi_tables = acpi_write_hpet,
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600512 .init = sc_init,
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500513 .enable = southcluster_enable_dev,
Nico Huber51b75ae2019-03-14 16:02:05 +0100514 .scan_bus = scan_static_bus,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500515 .ops_pci = &soc_pci_ops,
516};
517
518static const struct pci_driver southcluster __pci_driver = {
519 .ops = &device_ops,
520 .vendor = PCI_VENDOR_ID_INTEL,
521 .device = LPC_DEVID,
522};
Aaron Durbin4177db52014-02-05 14:55:26 -0600523
Aaron Durbin64031672018-04-21 14:45:32 -0600524int __weak mainboard_get_spi_config(struct spi_config *cfg)
Aaron Durbin4177db52014-02-05 14:55:26 -0600525{
526 return -1;
527}
528
529static void finalize_chipset(void *unused)
530{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800531 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
532 u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS);
533 u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2);
534 u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR);
535 u8 *spi = (u8 *)SPI_BASE_ADDRESS;
Aaron Durbin4177db52014-02-05 14:55:26 -0600536 struct spi_config cfg;
537
538 /* Set the lock enable on the BIOS control register. */
539 write32(bcr, read32(bcr) | BCR_LE);
540
541 /* Set BIOS lock down bit controlling boot block size and swapping. */
542 write32(gcs, read32(gcs) | BILD);
543
544 /* Lock sleep stretching policy and set SMI lock. */
545 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
546
547 /* Set the CF9 lock. */
548 write32(etr, read32(etr) | CF9LOCK);
549
550 if (mainboard_get_spi_config(&cfg) < 0) {
551 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
552 } else {
553 write16(spi + PREOP, cfg.preop);
554 write16(spi + OPTYPE, cfg.optype);
555 write32(spi + OPMENU0, cfg.opmenu[0]);
556 write32(spi + OPMENU1, cfg.opmenu[1]);
557 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
558 write32(spi + UVSCC, cfg.uvscc);
559 write32(spi + LVSCC, cfg.lvscc | VCL);
560 }
Aaron Durbin4177db52014-02-05 14:55:26 -0600561}
562
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500563BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
564BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);