blob: be0d910ed85fdf2ef6730a9fd9277978495d7fd0 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy77ff0b12015-05-05 15:07:29 -070015#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070018#include <arch/acpi.h>
Frans Hendriksad5e0a82019-03-18 13:31:56 +010019#include <arch/ioapic.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070020#include <bootstate.h>
Lee Leahy32471722015-04-20 15:20:28 -070021#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <console/console.h>
23#include <cpu/x86/smm.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
Frans Hendriks2c630172019-04-02 15:06:29 +020027#include <intelblocks/lpc_lib.h>
Frans Hendriks255f35c2018-12-11 15:21:47 +010028#include <pc80/isa-dma.h>
Frans Hendriksbd5233e2018-12-05 15:24:48 +010029#include <pc80/i8254.h>
Frans Hendriks93484132018-12-10 12:38:16 +010030#include <pc80/i8259.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>
Arthur Heymans68b6eb72019-10-13 23:26:36 +020041#include <southbridge/intel/common/spi.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070042
Frans Hendriks2c630172019-04-02 15:06:29 +020043static void sc_set_serial_irqs_mode(struct device *dev, enum serirq_mode mode)
Hannah Williams3fa80a92017-03-22 16:33:36 -070044{
Angel Ponsaee7ab22020-03-19 00:31:58 +010045 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xf);
Frans Hendriks2c630172019-04-02 15:06:29 +020046
47 switch (mode) {
48 case SERIRQ_CONTINUOUS:
49 break;
Angel Ponsaee7ab22020-03-19 00:31:58 +010050
Frans Hendriks2c630172019-04-02 15:06:29 +020051 case SERIRQ_OFF:
Angel Ponsaee7ab22020-03-19 00:31:58 +010052 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) & ~SIRQEN);
Frans Hendriks2c630172019-04-02 15:06:29 +020053 break;
Angel Ponsaee7ab22020-03-19 00:31:58 +010054
Frans Hendriks2c630172019-04-02 15:06:29 +020055 case SERIRQ_QUIET:
56 default:
57 write8(ilb_base + SCNT, read8(ilb_base + SCNT) & ~SCNT_MODE);
58 break;
59 }
Hannah Williams3fa80a92017-03-22 16:33:36 -070060}
Lee Leahy77ff0b12015-05-05 15:07:29 -070061
Angel Ponsaee7ab22020-03-19 00:31:58 +010062static inline void add_mmio_resource(struct device *dev, int i, unsigned long addr,
63 unsigned long size)
Lee Leahy77ff0b12015-05-05 15:07:29 -070064{
Elyes HAOUASa342f392018-10-17 10:56:26 +020065 printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n",
Lee Leahy32471722015-04-20 15:20:28 -070066 __FILE__, __func__, dev_name(dev), addr, size);
Angel Ponsaee7ab22020-03-19 00:31:58 +010067
Lee Leahy77ff0b12015-05-05 15:07:29 -070068 mmio_resource(dev, i, addr >> 10, size >> 10);
69}
70
Elyes HAOUASb13fac32018-05-24 22:29:44 +020071static void sc_add_mmio_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070072{
Angel Ponsaee7ab22020-03-19 00:31:58 +010073 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
74
Lee Leahy77ff0b12015-05-05 15:07:29 -070075 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
76 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
77 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
78 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
79 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
80 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
81 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
82 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Angel Ponsaee7ab22020-03-19 00:31:58 +010083 add_mmio_resource(dev, 0xfff, 0xffffffff - (CONFIG_COREBOOT_ROMSIZE_KB * KiB) + 1,
84 (CONFIG_COREBOOT_ROMSIZE_KB * KiB)); /* BIOS ROM */
85
Frans Hendriksad5e0a82019-03-18 13:31:56 +010086 add_mmio_resource(dev, 0xfec, IO_APIC_ADDR, 0x00001000); /* IOAPIC */
Lee Leahy77ff0b12015-05-05 15:07:29 -070087}
88
89/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
90#define LPC_DEFAULT_IO_RANGE_LOWER 0
91#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
92
Frans Hendriks2c630172019-04-02 15:06:29 +020093static void sc_enable_serial_irqs(struct device *dev)
94{
95 u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF);
96
97 printk(BIOS_SPEW, "Enable serial irq\n");
98 write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) | SIRQEN);
99 write8(ilb_base + SCNT, read8(ilb_base + SCNT) | SCNT_MODE);
100}
101
Frans Hendriks93484132018-12-10 12:38:16 +0100102/*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100103 * Write PCI config space IRQ assignments. PCI devices have the INT_LINE (0x3c) and INT_PIN
104 * (0x3d) registers which report interrupt routing information to operating systems and drivers.
105 * The INT_PIN register is generally read only and reports which interrupt pin A - D it uses.
106 * The INT_LINE register is configurable and reports which IRQ (generally the PIC IRQs 1 - 15)
107 * it will use. This needs to take interrupt pin swizzling on devices that are downstream on
108 * a PCI bridge into account.
Frans Hendriks93484132018-12-10 12:38:16 +0100109 *
Angel Ponsaee7ab22020-03-19 00:31:58 +0100110 * This function will loop through all enabled PCI devices and program the INT_LINE register
111 * with the correct PIC IRQ number for the INT_PIN that it uses. It then configures each
112 * interrupt in the PIC to be level triggered.
Frans Hendriks93484132018-12-10 12:38:16 +0100113 */
114static void write_pci_config_irqs(void)
115{
116 struct device *irq_dev;
117 struct device *targ_dev;
118 uint8_t int_line = 0;
119 uint8_t original_int_pin = 0;
120 uint8_t new_int_pin = 0;
121 uint16_t current_bdf = 0;
122 uint16_t parent_bdf = 0;
123 uint8_t pirq = 0;
124 uint8_t device_num = 0;
125 const struct soc_irq_route *ir = &global_soc_irq_route;
126
127 if (ir == NULL) {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100128 printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments "
129 "because 'global_braswell_irq_route' structure does not exist\n");
Frans Hendriks93484132018-12-10 12:38:16 +0100130 return;
131 }
132
133 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100134 * Loop through all enabled devices and program their INT_LINE, INT_PIN registers from
135 * values taken from the Interrupt Route registers in the ILB
Frans Hendriks93484132018-12-10 12:38:16 +0100136 */
137 printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n");
138 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
139
140 if ((irq_dev->path.type != DEVICE_PATH_PCI) ||
141 (!irq_dev->enabled))
142 continue;
143
144 current_bdf = irq_dev->path.pci.devfn |
145 irq_dev->bus->secondary << 8;
146
147 /*
148 * Step 1: Get the INT_PIN and device structure to look for
149 * in the pirq_data table defined in the mainboard directory.
150 */
151 targ_dev = NULL;
152 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
153 if (targ_dev == NULL || new_int_pin < 1)
154 continue;
155
156 /* Get the original INT_PIN for record keeping */
157 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
158
159 parent_bdf = targ_dev->path.pci.devfn
160 | targ_dev->bus->secondary << 8;
161 device_num = PCI_SLOT(parent_bdf);
162
163 if (ir->pcidev[device_num] == 0) {
164 printk(BIOS_WARNING,
Angel Ponsaee7ab22020-03-19 00:31:58 +0100165 "Warning: PCI Device %d does not have an IRQ entry, "
166 "skipping it\n", device_num);
Frans Hendriks93484132018-12-10 12:38:16 +0100167 continue;
168 }
169
170 /* Find the PIRQ that is attached to the INT_PIN */
171 pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4))
172 & 0x7;
173
174 /* Get the INT_LINE this device/function will use */
175 int_line = ir->pic[pirq];
176
177 if (int_line != PIRQ_PIC_IRQDISABLE) {
178 /* Set this IRQ to level triggered */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100179 i8259_configure_irq_trigger(int_line, IRQ_LEVEL_TRIGGERED);
180
Frans Hendriks93484132018-12-10 12:38:16 +0100181 /* Set the Interrupt Line register */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100182 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
Frans Hendriks93484132018-12-10 12:38:16 +0100183 } else {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100184 /* Set the Interrupt line register as 'unknown' or 'unused' */
185 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, PIRQ_PIC_UNKNOWN_UNUSED);
Frans Hendriks93484132018-12-10 12:38:16 +0100186 }
187
Angel Ponsaee7ab22020-03-19 00:31:58 +0100188 printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n", original_int_pin,
189 pin_to_str(original_int_pin));
190
Frans Hendriks93484132018-12-10 12:38:16 +0100191 if (parent_bdf != current_bdf)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100192 printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n", new_int_pin,
193 pin_to_str(new_int_pin));
194
195 printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n\tINT_LINE\t: 0x%X (IRQ %d)\n",
196 'A' + pirq, int_line, int_line);
Frans Hendriks93484132018-12-10 12:38:16 +0100197 }
198 printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n");
199}
200
Lee Leahy77ff0b12015-05-05 15:07:29 -0700201static inline int io_range_in_default(int base, int size)
202{
203 /* Does it start above the range? */
204 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
205 return 0;
206
207 /* Is it entirely contained? */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100208 if (base >= LPC_DEFAULT_IO_RANGE_LOWER && (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700209 return 1;
210
Angel Ponsaee7ab22020-03-19 00:31:58 +0100211 /* This will return not in range for partial overlaps */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700212 return 0;
213}
214
215/*
216 * Note: this function assumes there is no overlap with the default LPC device's
217 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
218 */
Angel Ponsaee7ab22020-03-19 00:31:58 +0100219static void sc_add_io_resource(struct device *dev, int base, int size, int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700220{
221 struct resource *res;
222
Elyes HAOUASa342f392018-10-17 10:56:26 +0200223 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700224 __FILE__, __func__, dev_name(dev), base, size, index);
225
Lee Leahy77ff0b12015-05-05 15:07:29 -0700226 if (io_range_in_default(base, size))
227 return;
228
229 res = new_resource(dev, index);
230 res->base = base;
231 res->size = size;
232 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
233}
234
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200235static void sc_add_io_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700236{
237 struct resource *res;
238
Angel Ponsaee7ab22020-03-19 00:31:58 +0100239 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700240
Lee Leahy77ff0b12015-05-05 15:07:29 -0700241 /* Add the default claimed IO range for the LPC device. */
242 res = new_resource(dev, 0);
243 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
244 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
245 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
246
247 /* GPIO */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100248 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700249
250 /* ACPI */
Frans Hendriks4b2c12f2018-11-22 07:52:38 +0100251 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700252}
253
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200254static void sc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700255{
Angel Ponsaee7ab22020-03-19 00:31:58 +0100256 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700257
Lee Leahy77ff0b12015-05-05 15:07:29 -0700258 /* Get the normal PCI resources of this device. */
259 pci_dev_read_resources(dev);
260
261 /* Add non-standard MMIO resources. */
262 sc_add_mmio_resources(dev);
263
264 /* Add IO resources. */
265 sc_add_io_resources(dev);
266}
267
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200268static void sc_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700269{
270 int i;
Frans Hendriksb55cd542019-03-06 14:45:12 +0100271 const unsigned long ilb_base = ILB_BASE_ADDRESS;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100272 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
273 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
274
Lee Leahy32471722015-04-20 15:20:28 -0700275 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
Lee Leahy32471722015-04-20 15:20:28 -0700276 const struct soc_irq_route *ir = &global_soc_irq_route;
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300277 struct soc_intel_braswell_config *config = config_of(dev);
Lee Leahy32471722015-04-20 15:20:28 -0700278
Angel Ponsaee7ab22020-03-19 00:31:58 +0100279 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700280
Frans Hendriksb55cd542019-03-06 14:45:12 +0100281 /* Set the value for PCI command register. */
282 pci_write_config16(dev, PCI_COMMAND,
Angel Ponsaee7ab22020-03-19 00:31:58 +0100283 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL);
Frans Hendriksb55cd542019-03-06 14:45:12 +0100284
285 /* Use IRQ9 for SCI Interrupt */
286 write32((void *)(ilb_base + ACTL), 0);
287
Frans Hendriks255f35c2018-12-11 15:21:47 +0100288 isa_dma_init();
289
Frans Hendriks2c630172019-04-02 15:06:29 +0200290 sc_enable_serial_irqs(dev);
291
Lee Leahy77ff0b12015-05-05 15:07:29 -0700292 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700293 for (i = 0; i < NUM_PIRQS; i++)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100294 write8((void *)(pr_base + i*sizeof(ir->pic[i])), ir->pic[i]);
Lee Leahy32471722015-04-20 15:20:28 -0700295
Lee Leahy77ff0b12015-05-05 15:07:29 -0700296 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700297 for (i = 0; i < NUM_IR_DEVS; i++)
Angel Ponsaee7ab22020-03-19 00:31:58 +0100298 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])), ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700299
Frans Hendriks93484132018-12-10 12:38:16 +0100300 /* Interrupt 9 should be level triggered (SCI) */
301 i8259_configure_irq_trigger(9, 1);
302
303 for (i = 0; i < NUM_PIRQS; i++) {
304 if (ir->pic[i])
305 i8259_configure_irq_trigger(ir->pic[i], 1);
306 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700307
Lee Leahy77ff0b12015-05-05 15:07:29 -0700308 if (config->disable_slp_x_stretch_sus_fail) {
309 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
Angel Ponsaee7ab22020-03-19 00:31:58 +0100310 write32(gen_pmcon1, read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
311
Lee Leahy77ff0b12015-05-05 15:07:29 -0700312 } else {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100313 write32(gen_pmcon1, read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700314 }
315
Frans Hendriks93484132018-12-10 12:38:16 +0100316 /* Write IRQ assignments to PCI config space */
317 write_pci_config_irqs();
318
319 /* Initialize i8259 pic */
320 setup_i8259();
321
Frans Hendriksbd5233e2018-12-05 15:24:48 +0100322 /* Initialize i8254 timers */
323 setup_i8254();
Frans Hendriks2c630172019-04-02 15:06:29 +0200324
325 sc_set_serial_irqs_mode(dev, config->serirq_mode);
326
Lee Leahy77ff0b12015-05-05 15:07:29 -0700327}
328
329/*
330 * Common code for the south cluster devices.
331 */
332
Frans Hendrikse6bf51f2019-05-01 10:48:31 +0200333/* Set bit in function disable register to hide this device. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200334static void sc_disable_devfn(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700335{
Angel Ponsaee7ab22020-03-19 00:31:58 +0100336 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
Lee Leahy32471722015-04-20 15:20:28 -0700337 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100338 uint32_t mask = 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700339 uint32_t mask2 = 0;
340
Angel Ponsaee7ab22020-03-19 00:31:58 +0100341 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700342
343#define SET_DIS_MASK(name_) \
344 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
345 mask |= name_ ## _DIS
Angel Ponsaee7ab22020-03-19 00:31:58 +0100346
Lee Leahy32471722015-04-20 15:20:28 -0700347#define SET_DIS_MASK2(name_) \
348 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
349 mask2 |= name_ ## _DIS
350
Lee Leahy77ff0b12015-05-05 15:07:29 -0700351 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700352 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700353 break;
Lee Leahy32471722015-04-20 15:20:28 -0700354 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700355 break;
Lee Leahy32471722015-04-20 15:20:28 -0700356 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700357 break;
Lee Leahy32471722015-04-20 15:20:28 -0700358 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700359 /* Disable super speed PHY when XHCI is not available. */
360 mask2 |= USH_SS_PHY_DIS;
361 break;
Lee Leahy32471722015-04-20 15:20:28 -0700362 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700363 break;
Lee Leahy32471722015-04-20 15:20:28 -0700364 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700365 break;
Lee Leahy32471722015-04-20 15:20:28 -0700366 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700367 break;
Lee Leahy32471722015-04-20 15:20:28 -0700368 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700369 break;
Lee Leahy32471722015-04-20 15:20:28 -0700370 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700371 break;
Lee Leahy32471722015-04-20 15:20:28 -0700372 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700373 break;
Lee Leahy32471722015-04-20 15:20:28 -0700374 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700375 break;
Lee Leahy32471722015-04-20 15:20:28 -0700376 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700377 break;
Lee Leahy32471722015-04-20 15:20:28 -0700378 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700379 break;
Lee Leahy32471722015-04-20 15:20:28 -0700380 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700381 break;
Lee Leahy32471722015-04-20 15:20:28 -0700382 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700383 break;
Lee Leahy32471722015-04-20 15:20:28 -0700384 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700385 break;
Lee Leahy32471722015-04-20 15:20:28 -0700386 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700387 break;
Lee Leahy32471722015-04-20 15:20:28 -0700388 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700389 break;
Lee Leahy32471722015-04-20 15:20:28 -0700390 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700391 break;
Lee Leahy32471722015-04-20 15:20:28 -0700392 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700393 break;
Lee Leahy32471722015-04-20 15:20:28 -0700394 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700395 break;
Lee Leahy32471722015-04-20 15:20:28 -0700396 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700397 break;
Lee Leahy32471722015-04-20 15:20:28 -0700398 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700399 break;
Lee Leahy32471722015-04-20 15:20:28 -0700400 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700401 break;
Lee Leahy32471722015-04-20 15:20:28 -0700402 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700403 break;
Lee Leahy32471722015-04-20 15:20:28 -0700404 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700405 break;
Lee Leahy32471722015-04-20 15:20:28 -0700406 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700407 break;
408 }
409
410 if (mask != 0) {
411 write32(func_dis, read32(func_dis) | mask);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100412 /* Ensure posted write hits */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700413 read32(func_dis);
414 }
415
416 if (mask2 != 0) {
417 write32(func_dis2, read32(func_dis2) | mask2);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100418 /* Ensure posted write hits */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700419 read32(func_dis2);
420 }
421}
422
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200423static inline void set_d3hot_bits(struct device *dev, int offset)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700424{
425 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700426
Elyes HAOUASa342f392018-10-17 10:56:26 +0200427 printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n",
Lee Leahy32471722015-04-20 15:20:28 -0700428 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700429 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
430 reg8 = pci_read_config8(dev, offset + 4);
431 reg8 |= 0x3;
432 pci_write_config8(dev, offset + 4, reg8);
433}
434
Lee Leahy32471722015-04-20 15:20:28 -0700435/*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100436 * Parts of the audio subsystem are powered by the HDA device. Thus, one cannot put HDA into
437 * D3Hot. Instead, perform this workaround to make some of the audio paths work for LPE audio.
Lee Leahy32471722015-04-20 15:20:28 -0700438 */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200439static void hda_work_around(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700440{
Lee Leahy32471722015-04-20 15:20:28 -0700441 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
442
Angel Ponsaee7ab22020-03-19 00:31:58 +0100443 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700444
445 /* Need to set magic register 0x43 to 0xd7 in config space. */
446 pci_write_config8(dev, 0x43, 0xd7);
447
Lee Leahy32471722015-04-20 15:20:28 -0700448 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100449 * Need to set bit 0 of GCTL to take the device out of reset.
450 * However, that requires setting up the 64-bit BAR.
Lee Leahy32471722015-04-20 15:20:28 -0700451 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700452 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
453 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
454 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
455 write32(gctl, read32(gctl) | 0x1);
456 pci_write_config8(dev, PCI_COMMAND, 0);
457 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
458}
459
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200460static int place_device_in_d3hot(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700461{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700462 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700463
Angel Ponsaee7ab22020-03-19 00:31:58 +0100464 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -0700465
466 /*
467 * Parts of the HDA block are used for LPE audio as well.
468 * Therefore assume the HDA will never be put into D3Hot.
469 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700470 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
471 hda_work_around(dev);
472 return 0;
473 }
474
475 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
476
477 if (offset != 0) {
478 set_d3hot_bits(dev, offset);
479 return 0;
480 }
481
Lee Leahy32471722015-04-20 15:20:28 -0700482 /*
Angel Ponsaee7ab22020-03-19 00:31:58 +0100483 * For some reason some of the devices don't have the capability pointer set correctly.
484 * Work around this by hard coding the offset.
Lee Leahy32471722015-04-20 15:20:28 -0700485 */
486#define DEV_CASE(name_) \
487 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
488
Lee Leahy77ff0b12015-05-05 15:07:29 -0700489 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700490 DEV_CASE(SDIO) :
491 DEV_CASE(SD) :
492 DEV_CASE(MMC) :
493 DEV_CASE(LPE) :
494 DEV_CASE(SIO_DMA1) :
495 DEV_CASE(I2C1) :
496 DEV_CASE(I2C2) :
497 DEV_CASE(I2C3) :
498 DEV_CASE(I2C4) :
499 DEV_CASE(I2C5) :
500 DEV_CASE(I2C6) :
501 DEV_CASE(I2C7) :
502 DEV_CASE(SIO_DMA2) :
503 DEV_CASE(PWM1) :
504 DEV_CASE(PWM2) :
505 DEV_CASE(HSUART1) :
506 DEV_CASE(HSUART2) :
507 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700508 offset = 0x80;
509 break;
Lee Leahy32471722015-04-20 15:20:28 -0700510 DEV_CASE(SATA) :
511 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700512 offset = 0x70;
513 break;
Lee Leahy32471722015-04-20 15:20:28 -0700514 DEV_CASE(HDA) :
515 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700516 offset = 0x50;
517 break;
Lee Leahy32471722015-04-20 15:20:28 -0700518 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700519 /* TXE cannot be placed in D3Hot. */
520 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700521 DEV_CASE(PCIE_PORT1) :
522 DEV_CASE(PCIE_PORT2) :
523 DEV_CASE(PCIE_PORT3) :
524 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700525 offset = 0xa0;
526 break;
527 }
528
529 if (offset != 0) {
530 set_d3hot_bits(dev, offset);
531 return 0;
532 }
533
534 return -1;
535}
536
537/* Common PCI device function disable. */
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200538void southcluster_enable_dev(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700539{
540 uint32_t reg32;
541
Angel Ponsaee7ab22020-03-19 00:31:58 +0100542 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
543
Lee Leahy77ff0b12015-05-05 15:07:29 -0700544 if (!dev->enabled) {
545 int slot = PCI_SLOT(dev->path.pci.devfn);
546 int func = PCI_FUNC(dev->path.pci.devfn);
547 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
548 dev_path(dev), slot, func);
549
550 /* Ensure memory, io, and bus master are all disabled */
551 reg32 = pci_read_config32(dev, PCI_COMMAND);
Angel Ponsaee7ab22020-03-19 00:31:58 +0100552 reg32 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700553 pci_write_config32(dev, PCI_COMMAND, reg32);
554
555 /* Place device in D3Hot */
556 if (place_device_in_d3hot(dev) < 0) {
557 printk(BIOS_WARNING,
558 "Could not place %02x.%01x into D3Hot. "
559 "Keeping device visible.\n", slot, func);
560 return;
561 }
562 /* Disable this device if possible */
563 sc_disable_devfn(dev);
564 } else {
565 /* Enable SERR */
566 reg32 = pci_read_config32(dev, PCI_COMMAND);
567 reg32 |= PCI_COMMAND_SERR;
568 pci_write_config32(dev, PCI_COMMAND, reg32);
569 }
570}
571
572static struct device_operations device_ops = {
Angel Ponsaee7ab22020-03-19 00:31:58 +0100573 .read_resources = sc_read_resources,
574 .set_resources = pci_dev_set_resources,
575 .enable_resources = NULL,
576 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
577 .write_acpi_tables = southcluster_write_acpi_tables,
578 .init = sc_init,
579 .enable = southcluster_enable_dev,
580 .scan_bus = scan_static_bus,
581 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700582};
583
584static const struct pci_driver southcluster __pci_driver = {
585 .ops = &device_ops,
586 .vendor = PCI_VENDOR_ID_INTEL,
587 .device = LPC_DEVID,
588};
589
Lee Leahy77ff0b12015-05-05 15:07:29 -0700590static void finalize_chipset(void *unused)
591{
Lee Leahy32471722015-04-20 15:20:28 -0700592 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
593 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
594 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
595 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
596 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Angel Ponsaee7ab22020-03-19 00:31:58 +0100597
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200598 struct vscc_config cfg;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700599
Angel Ponsaee7ab22020-03-19 00:31:58 +0100600 printk(BIOS_SPEW, "%s/%s (%p)\n", __FILE__, __func__, unused);
Lee Leahy32471722015-04-20 15:20:28 -0700601
Angel Ponsaee7ab22020-03-19 00:31:58 +0100602 /* Set the lock enable on the BIOS control register */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700603 write32(bcr, read32(bcr) | BCR_LE);
604
Angel Ponsaee7ab22020-03-19 00:31:58 +0100605 /* Set BIOS lock down bit controlling boot block size and swapping */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700606 write32(gcs, read32(gcs) | BILD);
607
Angel Ponsaee7ab22020-03-19 00:31:58 +0100608 /* Lock sleep stretching policy and set SMI lock */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700609 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
610
Angel Ponsaee7ab22020-03-19 00:31:58 +0100611 /* Set the CF9 lock */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700612 write32(etr, read32(etr) | CF9LOCK);
613
Arthur Heymans68b6eb72019-10-13 23:26:36 +0200614 spi_finalize_ops();
615 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
616
617 if (mainboard_get_spi_vscc_config(&cfg) < 0) {
618 printk(BIOS_DEBUG, "No SPI VSCC configuration.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700619 } else {
Lee Leahy77ff0b12015-05-05 15:07:29 -0700620 write32(spi + UVSCC, cfg.uvscc);
621 write32(spi + LVSCC, cfg.lvscc | VCL);
622 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700623}
624
Hannah Williams2cfdde72015-04-15 19:48:07 -0700625BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);