blob: ca87d63aa0f5c7ca035139ceae3aa0a4c0a758eb [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.
Lee Leahy77ff0b12015-05-05 15:07:29 -07007 *
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.
Lee Leahy77ff0b12015-05-05 15:07:29 -070016 */
17
Lee Leahy77ff0b12015-05-05 15:07:29 -070018#include <arch/io.h>
19#include <arch/acpi.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070020#include <arch/acpigen.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <bootstate.h>
22#include <cbmem.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>
29#include <pc80/mc146818rtc.h>
Lee Leahy32471722015-04-20 15:20:28 -070030#include <romstage_handoff.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070031#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070032#include <soc/iomap.h>
33#include <soc/irq.h>
34#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070035#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070036#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070037#include <soc/ramstage.h>
38#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070039#include <spi-generic.h>
40#include <stdint.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070041#include <reg_script.h>
42
43static const struct reg_script ops[] = {
44 REG_MMIO_RMW32(ILB_BASE_ADDRESS + SCNT,
45 ~SCNT_MODE, 0), /* put LPC SERIRQ in Quiet Mode */
46 REG_SCRIPT_END
47};
48
49static void enable_serirq_quiet_mode(void)
50{
51 reg_script_run(ops);
52}
Lee Leahy77ff0b12015-05-05 15:07:29 -070053
54static inline void
Elyes HAOUASb13fac32018-05-24 22:29:44 +020055add_mmio_resource(struct device *dev, int i, unsigned long addr,
56 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070057{
Elyes HAOUASa342f392018-10-17 10:56:26 +020058 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070059 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070060 mmio_resource(dev, i, addr >> 10, size >> 10);
61}
62
Elyes HAOUASb13fac32018-05-24 22:29:44 +020063static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070064{
Elyes HAOUASa342f392018-10-17 10:56:26 +020065 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070066 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070067 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
68 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
69 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
70 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
71 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
72 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
73 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
74 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
75}
76
77/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
78#define LPC_DEFAULT_IO_RANGE_LOWER 0
79#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
80
81static inline int io_range_in_default(int base, int size)
82{
83 /* Does it start above the range? */
84 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
85 return 0;
86
87 /* Is it entirely contained? */
88 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
89 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
90 return 1;
91
92 /* This will return not in range for partial overlaps. */
93 return 0;
94}
95
96/*
97 * Note: this function assumes there is no overlap with the default LPC device's
98 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
99 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200100static void sc_add_io_resource(struct device *dev, int base, int size,
101 int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700102{
103 struct resource *res;
104
Elyes HAOUASa342f392018-10-17 10:56:26 +0200105 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700106 __FILE__, __func__, dev_name(dev), base, size, index);
107
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108 if (io_range_in_default(base, size))
109 return;
110
111 res = new_resource(dev, index);
112 res->base = base;
113 res->size = size;
114 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
115}
116
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200117static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700118{
119 struct resource *res;
120
Elyes HAOUASa342f392018-10-17 10:56:26 +0200121 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700122 __FILE__, __func__, dev_name(dev));
123
Lee Leahy77ff0b12015-05-05 15:07:29 -0700124 /* Add the default claimed IO range for the LPC device. */
125 res = new_resource(dev, 0);
126 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
127 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
128 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
129
130 /* GPIO */
131 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE);
132
133 /* ACPI */
134 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE);
135}
136
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200137static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700138{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200139 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700140 __FILE__, __func__, dev_name(dev));
141
Lee Leahy77ff0b12015-05-05 15:07:29 -0700142 /* Get the normal PCI resources of this device. */
143 pci_dev_read_resources(dev);
144
145 /* Add non-standard MMIO resources. */
146 sc_add_mmio_resources(dev);
147
148 /* Add IO resources. */
149 sc_add_io_resources(dev);
150}
151
152static void sc_rtc_init(void)
153{
Aaron Durbinb19e33f2017-09-15 14:32:13 -0600154 printk(BIOS_SPEW, "%s/%s\n", __FILE__, __func__);
155 cmos_init(rtc_failure());
Lee Leahy77ff0b12015-05-05 15:07:29 -0700156}
157
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200158static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700159{
160 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700161 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
162 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
163 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
164 void *actl = (void *)(ILB_BASE_ADDRESS + ACTL);
165 const struct soc_irq_route *ir = &global_soc_irq_route;
166 struct soc_intel_braswell_config *config = dev->chip_info;
167
Elyes HAOUASa342f392018-10-17 10:56:26 +0200168 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700169 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700170
171 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700172 for (i = 0; i < NUM_PIRQS; i++)
173 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
174 ir->pic[i]);
175
Lee Leahy77ff0b12015-05-05 15:07:29 -0700176 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700177 for (i = 0; i < NUM_IR_DEVS; i++)
178 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
179 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700180
181 /* Route SCI to IRQ9 */
182 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
183
184 sc_rtc_init();
185
186 if (config->disable_slp_x_stretch_sus_fail) {
187 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
188 write32(gen_pmcon1,
189 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
190 } else {
191 write32(gen_pmcon1,
192 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
193 }
194
Lee Leahy77ff0b12015-05-05 15:07:29 -0700195}
196
197/*
198 * Common code for the south cluster devices.
199 */
200
Lee Leahy32471722015-04-20 15:20:28 -0700201/* Set bit in function disble register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200202static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700203{
Lee Leahy32471722015-04-20 15:20:28 -0700204 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
205 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700206 uint32_t mask = 0;
207 uint32_t mask2 = 0;
208
Elyes HAOUASa342f392018-10-17 10:56:26 +0200209 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700210 __FILE__, __func__, dev_name(dev));
211
212#define SET_DIS_MASK(name_) \
213 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
214 mask |= name_ ## _DIS
215#define SET_DIS_MASK2(name_) \
216 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
217 mask2 |= name_ ## _DIS
218
Lee Leahy77ff0b12015-05-05 15:07:29 -0700219 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700220 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700221 break;
Lee Leahy32471722015-04-20 15:20:28 -0700222 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700223 break;
Lee Leahy32471722015-04-20 15:20:28 -0700224 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700225 break;
Lee Leahy32471722015-04-20 15:20:28 -0700226 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700227 /* Disable super speed PHY when XHCI is not available. */
228 mask2 |= USH_SS_PHY_DIS;
229 break;
Lee Leahy32471722015-04-20 15:20:28 -0700230 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700231 break;
Lee Leahy32471722015-04-20 15:20:28 -0700232 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700233 break;
Lee Leahy32471722015-04-20 15:20:28 -0700234 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700235 break;
Lee Leahy32471722015-04-20 15:20:28 -0700236 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700237 break;
Lee Leahy32471722015-04-20 15:20:28 -0700238 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700239 break;
Lee Leahy32471722015-04-20 15:20:28 -0700240 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700241 break;
Lee Leahy32471722015-04-20 15:20:28 -0700242 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700243 break;
Lee Leahy32471722015-04-20 15:20:28 -0700244 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700245 break;
Lee Leahy32471722015-04-20 15:20:28 -0700246 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700247 break;
Lee Leahy32471722015-04-20 15:20:28 -0700248 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700249 break;
Lee Leahy32471722015-04-20 15:20:28 -0700250 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700251 break;
Lee Leahy32471722015-04-20 15:20:28 -0700252 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700253 break;
Lee Leahy32471722015-04-20 15:20:28 -0700254 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700255 break;
Lee Leahy32471722015-04-20 15:20:28 -0700256 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700257 break;
Lee Leahy32471722015-04-20 15:20:28 -0700258 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700259 break;
Lee Leahy32471722015-04-20 15:20:28 -0700260 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700261 break;
Lee Leahy32471722015-04-20 15:20:28 -0700262 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700263 break;
Lee Leahy32471722015-04-20 15:20:28 -0700264 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700265 break;
Lee Leahy32471722015-04-20 15:20:28 -0700266 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700267 break;
Lee Leahy32471722015-04-20 15:20:28 -0700268 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700269 break;
Lee Leahy32471722015-04-20 15:20:28 -0700270 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700271 break;
Lee Leahy32471722015-04-20 15:20:28 -0700272 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700273 break;
Lee Leahy32471722015-04-20 15:20:28 -0700274 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700275 break;
276 }
277
278 if (mask != 0) {
279 write32(func_dis, read32(func_dis) | mask);
280 /* Ensure posted write hits. */
281 read32(func_dis);
282 }
283
284 if (mask2 != 0) {
285 write32(func_dis2, read32(func_dis2) | mask2);
286 /* Ensure posted write hits. */
287 read32(func_dis2);
288 }
289}
290
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200291static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700292{
293 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700294
Elyes HAOUASa342f392018-10-17 10:56:26 +0200295 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700296 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700297 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
298 reg8 = pci_read_config8(dev, offset + 4);
299 reg8 |= 0x3;
300 pci_write_config8(dev, offset + 4, reg8);
301}
302
Lee Leahy32471722015-04-20 15:20:28 -0700303/*
304 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700305 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700306 * the audio paths work for LPE audio.
307 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200308static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700309{
Lee Leahy32471722015-04-20 15:20:28 -0700310 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
311
Elyes HAOUASa342f392018-10-17 10:56:26 +0200312 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700313 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700314
315 /* Need to set magic register 0x43 to 0xd7 in config space. */
316 pci_write_config8(dev, 0x43, 0xd7);
317
Lee Leahy32471722015-04-20 15:20:28 -0700318 /*
319 * Need to set bit 0 of GCTL to take the device out of reset. However,
320 * that requires setting up the 64-bit BAR.
321 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700322 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
323 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
324 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
325 write32(gctl, read32(gctl) | 0x1);
326 pci_write_config8(dev, PCI_COMMAND, 0);
327 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
328}
329
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200330static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700331{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700332 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700333
Elyes HAOUASa342f392018-10-17 10:56:26 +0200334 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700335 __FILE__, __func__, dev_name(dev));
336
337 /*
338 * Parts of the HDA block are used for LPE audio as well.
339 * Therefore assume the HDA will never be put into D3Hot.
340 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700341 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
342 hda_work_around(dev);
343 return 0;
344 }
345
346 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
347
348 if (offset != 0) {
349 set_d3hot_bits(dev, offset);
350 return 0;
351 }
352
Lee Leahy32471722015-04-20 15:20:28 -0700353 /*
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 */
357#define DEV_CASE(name_) \
358 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
359
Lee Leahy77ff0b12015-05-05 15:07:29 -0700360 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700361 DEV_CASE(SDIO) :
362 DEV_CASE(SD) :
363 DEV_CASE(MMC) :
364 DEV_CASE(LPE) :
365 DEV_CASE(SIO_DMA1) :
366 DEV_CASE(I2C1) :
367 DEV_CASE(I2C2) :
368 DEV_CASE(I2C3) :
369 DEV_CASE(I2C4) :
370 DEV_CASE(I2C5) :
371 DEV_CASE(I2C6) :
372 DEV_CASE(I2C7) :
373 DEV_CASE(SIO_DMA2) :
374 DEV_CASE(PWM1) :
375 DEV_CASE(PWM2) :
376 DEV_CASE(HSUART1) :
377 DEV_CASE(HSUART2) :
378 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700379 offset = 0x80;
380 break;
Lee Leahy32471722015-04-20 15:20:28 -0700381 DEV_CASE(SATA) :
382 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700383 offset = 0x70;
384 break;
Lee Leahy32471722015-04-20 15:20:28 -0700385 DEV_CASE(HDA) :
386 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700387 offset = 0x50;
388 break;
Lee Leahy32471722015-04-20 15:20:28 -0700389 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700390 /* TXE cannot be placed in D3Hot. */
391 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700392 DEV_CASE(PCIE_PORT1) :
393 DEV_CASE(PCIE_PORT2) :
394 DEV_CASE(PCIE_PORT3) :
395 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700396 offset = 0xa0;
397 break;
398 }
399
400 if (offset != 0) {
401 set_d3hot_bits(dev, offset);
402 return 0;
403 }
404
405 return -1;
406}
407
408/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200409void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700410{
411 uint32_t reg32;
412
Elyes HAOUASa342f392018-10-17 10:56:26 +0200413 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700414 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700415 if (!dev->enabled) {
416 int slot = PCI_SLOT(dev->path.pci.devfn);
417 int func = PCI_FUNC(dev->path.pci.devfn);
418 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
419 dev_path(dev), slot, func);
420
421 /* Ensure memory, io, and bus master are all disabled */
422 reg32 = pci_read_config32(dev, PCI_COMMAND);
423 reg32 &= ~(PCI_COMMAND_MASTER |
424 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
425 pci_write_config32(dev, PCI_COMMAND, reg32);
426
427 /* Place device in D3Hot */
428 if (place_device_in_d3hot(dev) < 0) {
429 printk(BIOS_WARNING,
430 "Could not place %02x.%01x into D3Hot. "
431 "Keeping device visible.\n", slot, func);
432 return;
433 }
434 /* Disable this device if possible */
435 sc_disable_devfn(dev);
436 } else {
437 /* Enable SERR */
438 reg32 = pci_read_config32(dev, PCI_COMMAND);
439 reg32 |= PCI_COMMAND_SERR;
440 pci_write_config32(dev, PCI_COMMAND, reg32);
441 }
442}
443
444static struct device_operations device_ops = {
445 .read_resources = sc_read_resources,
446 .set_resources = pci_dev_set_resources,
447 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700448 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
449 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700450 .init = sc_init,
451 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700452 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700453 .ops_pci = &soc_pci_ops,
454};
455
456static const struct pci_driver southcluster __pci_driver = {
457 .ops = &device_ops,
458 .vendor = PCI_VENDOR_ID_INTEL,
459 .device = LPC_DEVID,
460};
461
Aaron Durbin64031672018-04-21 14:45:32 -0600462int __weak mainboard_get_spi_config(struct spi_config *cfg)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700463{
Elyes HAOUASa342f392018-10-17 10:56:26 +0200464 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700465 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700466 return -1;
467}
468
469static void finalize_chipset(void *unused)
470{
Lee Leahy32471722015-04-20 15:20:28 -0700471 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
472 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
473 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
474 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
475 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700476 struct spi_config cfg;
477
Elyes HAOUASa342f392018-10-17 10:56:26 +0200478 printk(BIOS_SPEW, "%s/%s (0x%p)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700479 __FILE__, __func__, unused);
480
Lee Leahy77ff0b12015-05-05 15:07:29 -0700481 /* Set the lock enable on the BIOS control register. */
482 write32(bcr, read32(bcr) | BCR_LE);
483
484 /* Set BIOS lock down bit controlling boot block size and swapping. */
485 write32(gcs, read32(gcs) | BILD);
486
487 /* Lock sleep stretching policy and set SMI lock. */
488 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
489
490 /* Set the CF9 lock. */
491 write32(etr, read32(etr) | CF9LOCK);
492
493 if (mainboard_get_spi_config(&cfg) < 0) {
494 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
495 } else {
496 write16(spi + PREOP, cfg.preop);
497 write16(spi + OPTYPE, cfg.optype);
498 write32(spi + OPMENU0, cfg.opmenu[0]);
499 write32(spi + OPMENU1, cfg.opmenu[1]);
500 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
501 write32(spi + UVSCC, cfg.uvscc);
502 write32(spi + LVSCC, cfg.lvscc | VCL);
503 }
Lee Leahy32471722015-04-20 15:20:28 -0700504 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700505 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700506
507 printk(BIOS_DEBUG, "Finalizing SMM.\n");
508 outb(APM_CNT_FINALIZE, APM_CNT);
509}
510
Hannah Williams2cfdde72015-04-15 19:48:07 -0700511BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);