blob: f1cf7a3b7fbf6c39024d16e25c4574c10d3c68ec [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02007#include <option.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01008#include <pc80/mc146818rtc.h>
9#include <pc80/isa-dma.h>
10#include <pc80/i8259.h>
11#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020012#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020013#include <device/pci_ops.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010014#include <arch/ioapic.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070015#include <acpi/acpi.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010016#include <elog.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070017#include <acpi/acpigen.h>
Vladimir Serbinenko67bfbfd2014-10-25 15:49:23 +020018#include <cpu/x86/smm.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030019#include "chip.h"
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010020#include "pch.h"
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010021#include <southbridge/intel/common/pciehp.h>
Kyösti Mälkki90993952018-05-01 19:36:25 +030022#include <southbridge/intel/common/acpi_pirq_gen.h>
Arthur Heymansaadd1d02019-05-28 13:39:20 +020023#include <southbridge/intel/common/spi.h>
Tim Wawrzynczakf62c4942021-02-26 10:30:52 -070024#include <southbridge/intel/common/rcba_pirq.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010025
26#define NMI_OFF 0
27
Vladimir Serbinenko46957052013-11-26 01:16:20 +010028typedef struct southbridge_intel_ibexpeak_config config_t;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010029
30/**
Martin Roth26f97f92021-10-01 14:53:22 -060031 * Set miscellaneous static southbridge features.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010032 *
33 * @param dev PCI device with I/O APIC control registers
34 */
35static void pch_enable_ioapic(struct device *dev)
36{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080037 set_ioapic_id(VIO_APIC_VADDR, 0x01);
Kyösti Mälkki04a40372021-06-06 08:04:28 +030038
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010039 /* affirm full set of redirection table entries ("write once") */
Kyösti Mälkki04a40372021-06-06 08:04:28 +030040 ioapic_lock_max_vectors(VIO_APIC_VADDR);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010041}
42
43static void pch_enable_serial_irqs(struct device *dev)
44{
45 /* Set packet length and toggle silent mode bit for one frame. */
46 pci_write_config8(dev, SERIRQ_CNTL,
47 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Julius Wernercd49cce2019-03-05 16:53:33 -080048#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010049 pci_write_config8(dev, SERIRQ_CNTL,
50 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
51#endif
52}
53
54/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
55 * 0x00 - 0000 = Reserved
56 * 0x01 - 0001 = Reserved
57 * 0x02 - 0010 = Reserved
58 * 0x03 - 0011 = IRQ3
59 * 0x04 - 0100 = IRQ4
60 * 0x05 - 0101 = IRQ5
61 * 0x06 - 0110 = IRQ6
62 * 0x07 - 0111 = IRQ7
63 * 0x08 - 1000 = Reserved
64 * 0x09 - 1001 = IRQ9
65 * 0x0A - 1010 = IRQ10
66 * 0x0B - 1011 = IRQ11
67 * 0x0C - 1100 = IRQ12
68 * 0x0D - 1101 = Reserved
69 * 0x0E - 1110 = IRQ14
70 * 0x0F - 1111 = IRQ15
71 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
72 * 0x80 - The PIRQ is not routed.
73 */
74
Elyes HAOUASbe841402018-05-13 13:40:39 +020075static void pch_pirq_init(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010076{
Elyes HAOUASbe841402018-05-13 13:40:39 +020077 struct device *irq_dev;
Angel Pons77f340a2020-10-17 18:39:04 +020078 /*
79 * Interrupt 11 is not used by legacy devices and so can always be used for
80 * PCI interrupts. Full legacy IRQ routing is complicated and hard to
81 * get right. Fortunately all modern OS use MSI and so it's not that big of
82 * an issue anyway. Still we have to provide a reasonable default. Using
83 * interrupt 11 for it everywhere is a working default. ACPI-aware OS can
84 * move it to any interrupt and others will just leave them at default.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010085 */
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020086 const u8 pirq_routing = 11;
87
88 pci_write_config8(dev, PIRQA_ROUT, pirq_routing);
89 pci_write_config8(dev, PIRQB_ROUT, pirq_routing);
90 pci_write_config8(dev, PIRQC_ROUT, pirq_routing);
91 pci_write_config8(dev, PIRQD_ROUT, pirq_routing);
92
93 pci_write_config8(dev, PIRQE_ROUT, pirq_routing);
94 pci_write_config8(dev, PIRQF_ROUT, pirq_routing);
95 pci_write_config8(dev, PIRQG_ROUT, pirq_routing);
96 pci_write_config8(dev, PIRQH_ROUT, pirq_routing);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010097
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020098 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020099 u8 int_pin=0;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100100
101 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
102 continue;
103
104 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
105
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200106 if (int_pin == 0)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100107 continue;
108
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200109 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, pirq_routing);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100110 }
111}
112
Elyes HAOUASbe841402018-05-13 13:40:39 +0200113static void pch_gpi_routing(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100114{
115 /* Get the chip configuration */
116 config_t *config = dev->chip_info;
117 u32 reg32 = 0;
118
119 /* An array would be much nicer here, or some
120 * other method of doing this.
121 */
122 reg32 |= (config->gpi0_routing & 0x03) << 0;
123 reg32 |= (config->gpi1_routing & 0x03) << 2;
124 reg32 |= (config->gpi2_routing & 0x03) << 4;
125 reg32 |= (config->gpi3_routing & 0x03) << 6;
126 reg32 |= (config->gpi4_routing & 0x03) << 8;
127 reg32 |= (config->gpi5_routing & 0x03) << 10;
128 reg32 |= (config->gpi6_routing & 0x03) << 12;
129 reg32 |= (config->gpi7_routing & 0x03) << 14;
130 reg32 |= (config->gpi8_routing & 0x03) << 16;
131 reg32 |= (config->gpi9_routing & 0x03) << 18;
132 reg32 |= (config->gpi10_routing & 0x03) << 20;
133 reg32 |= (config->gpi11_routing & 0x03) << 22;
134 reg32 |= (config->gpi12_routing & 0x03) << 24;
135 reg32 |= (config->gpi13_routing & 0x03) << 26;
136 reg32 |= (config->gpi14_routing & 0x03) << 28;
137 reg32 |= (config->gpi15_routing & 0x03) << 30;
138
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200139 pci_write_config32(dev, GPIO_ROUT, reg32);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100140}
141
Elyes HAOUASbe841402018-05-13 13:40:39 +0200142static void pch_power_options(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100143{
144 u8 reg8;
145 u16 reg16, pmbase;
146 u32 reg32;
147 const char *state;
148 /* Get the chip configuration */
149 config_t *config = dev->chip_info;
150
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100151 /* Which state do we want to goto after g3 (power restored)?
152 * 0 == S0 Full On
153 * 1 == S5 Soft Off
154 *
155 * If the option is not existent (Laptops), use Kconfig setting.
156 */
Angel Pons88dcb312021-04-26 17:10:28 +0200157 const unsigned int pwr_on = get_uint_option("power_on_after_fail",
Angel Pons62719a32021-04-19 13:15:28 +0200158 CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100159
160 reg16 = pci_read_config16(dev, GEN_PMCON_3);
161 reg16 &= 0xfffe;
162 switch (pwr_on) {
163 case MAINBOARD_POWER_OFF:
164 reg16 |= 1;
165 state = "off";
166 break;
167 case MAINBOARD_POWER_ON:
168 reg16 &= ~1;
169 state = "on";
170 break;
171 case MAINBOARD_POWER_KEEP:
172 reg16 &= ~1;
173 state = "state keep";
174 break;
175 default:
176 state = "undefined";
177 }
178
179 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
180 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
181
182 reg16 &= ~(1 << 10);
183 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
184
185 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
186
187 pci_write_config16(dev, GEN_PMCON_3, reg16);
188 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
189
190 /* Set up NMI on errors. */
191 reg8 = inb(0x61);
192 reg8 &= 0x0f; /* Higher Nibble must be 0 */
193 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
194 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
195 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
196 outb(reg8, 0x61);
197
198 reg8 = inb(0x70);
Angel Pons88dcb312021-04-26 17:10:28 +0200199 const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100200 if (nmi_option) {
201 printk(BIOS_INFO, "NMI sources enabled.\n");
202 reg8 &= ~(1 << 7); /* Set NMI. */
203 } else {
204 printk(BIOS_INFO, "NMI sources disabled.\n");
Elyes HAOUAS9c5d4632018-04-26 22:21:21 +0200205 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100206 }
207 outb(reg8, 0x70);
208
209 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
210 reg16 = pci_read_config16(dev, GEN_PMCON_1);
211 reg16 &= ~(3 << 0); // SMI# rate 1 minute
212 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Kyösti Mälkki94464472020-06-13 13:45:42 +0300213 if (CONFIG(DEBUG_PERIODIC_SMI))
214 reg16 |= (3 << 0); // Periodic SMI every 8s
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100215 pci_write_config16(dev, GEN_PMCON_1, reg16);
216
217 // Set the board's GPI routing.
218 pch_gpi_routing(dev);
219
220 pmbase = pci_read_config16(dev, 0x40) & 0xfffe;
221
222 outl(config->gpe0_en, pmbase + GPE0_EN);
223 outw(config->alt_gp_smi_en, pmbase + ALT_GP_SMI_EN);
224
225 /* Set up power management block and determine sleep mode */
226 reg32 = inl(pmbase + 0x04); // PM1_CNT
227 reg32 &= ~(7 << 10); // SLP_TYP
228 reg32 |= (1 << 0); // SCI_EN
229 outl(reg32, pmbase + 0x04);
230
231 /* Clear magic status bits to prevent unexpected wake */
Angel Pons42b4e4e2019-09-18 10:58:53 +0200232 reg32 = RCBA32(PRSTS);
233 reg32 |= (1 << 5) | (1 << 4) | (1 << 0);
234 RCBA32(PRSTS) = reg32;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100235
Angel Pons42b4e4e2019-09-18 10:58:53 +0200236 /* FIXME: Does this even exist? */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100237 reg32 = RCBA32(0x3f02);
238 reg32 &= ~0xf;
239 RCBA32(0x3f02) = reg32;
240}
241
242static void pch_rtc_init(struct device *dev)
243{
244 u8 reg8;
245 int rtc_failed;
246
247 reg8 = pci_read_config8(dev, GEN_PMCON_3);
248 rtc_failed = reg8 & RTC_BATTERY_DEAD;
249 if (rtc_failed) {
250 reg8 &= ~RTC_BATTERY_DEAD;
251 pci_write_config8(dev, GEN_PMCON_3, reg8);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100252 elog_add_event(ELOG_TYPE_RTC_RESET);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100253 }
254 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
255
Gabe Blackb3f08c62014-04-30 17:12:25 -0700256 cmos_init(rtc_failed);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100257}
258
259static void mobile5_pm_init(struct device *dev)
260{
261 int i;
262
263 printk(BIOS_DEBUG, "Mobile 5 PM init\n");
264 pci_write_config8(dev, 0xa9, 0x47);
265
Angel Pons77f340a2020-10-17 18:39:04 +0200266 RCBA32(0x1d44) = 0x00000000;
267 (void)RCBA32(0x1d44);
268 RCBA32(0x1d48) = 0x00030000;
269 (void)RCBA32(0x1d48);
270 RCBA32(0x1e80) = 0x000c0801;
271 (void)RCBA32(0x1e80);
272 RCBA32(0x1e84) = 0x000200f0;
273 (void)RCBA32(0x1e84);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100274
Angel Pons77f340a2020-10-17 18:39:04 +0200275 const u32 rcba2010[] = {
276 /* 2010: */ 0x00188200, 0x14000016, 0xbc4abcb5, 0x00000000,
277 /* 2020: */ 0xf0c9605b, 0x13683040, 0x04c8f16e, 0x09e90170
278 };
279 for (i = 0; i < ARRAY_SIZE(rcba2010); i++) {
280 RCBA32(0x2010 + 4 * i) = rcba2010[i];
281 RCBA32(0x2010 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100282 }
283
Angel Pons77f340a2020-10-17 18:39:04 +0200284 RCBA32(0x2100) = 0x00000000;
285 (void)RCBA32(0x2100);
286 RCBA32(0x2104) = 0x00000757;
287 (void)RCBA32(0x2104);
288 RCBA32(0x2108) = 0x00170001;
289 (void)RCBA32(0x2108);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100290
Angel Pons77f340a2020-10-17 18:39:04 +0200291 RCBA32(0x211c) = 0x00000000;
292 (void)RCBA32(0x211c);
293 RCBA32(0x2120) = 0x00010000;
294 (void)RCBA32(0x2120);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100295
Angel Pons77f340a2020-10-17 18:39:04 +0200296 RCBA32(0x21fc) = 0x00000000;
297 (void)RCBA32(0x21fc);
298 RCBA32(0x2200) = 0x20000044;
299 (void)RCBA32(0x2200);
300 RCBA32(0x2204) = 0x00000001;
301 (void)RCBA32(0x2204);
302 RCBA32(0x2208) = 0x00003457;
303 (void)RCBA32(0x2208);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100304
Angel Pons77f340a2020-10-17 18:39:04 +0200305 const u32 rcba2210[] = {
306 /* 2210 */ 0x00000000, 0x00000001, 0xa0fff210, 0x0000df00,
307 /* 2220 */ 0x00e30880, 0x00000070, 0x00004000, 0x00000000,
308 /* 2230 */ 0x00e30880, 0x00000070, 0x00004000, 0x00000000,
309 /* 2240 */ 0x00002301, 0x36000000, 0x00010107, 0x00160000,
310 /* 2250 */ 0x00001b01, 0x36000000, 0x00010107, 0x00160000,
311 /* 2260 */ 0x00000601, 0x16000000, 0x00010107, 0x00160000,
312 /* 2270 */ 0x00001c01, 0x16000000, 0x00010107, 0x00160000
313 };
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100314
Angel Pons77f340a2020-10-17 18:39:04 +0200315 for (i = 0; i < ARRAY_SIZE(rcba2210); i++) {
316 RCBA32(0x2210 + 4 * i) = rcba2210[i];
317 RCBA32(0x2210 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100318 }
319
Angel Pons77f340a2020-10-17 18:39:04 +0200320 const u32 rcba2300[] = {
321 /* 2300: */ 0x00000000, 0x40000000, 0x4646827b, 0x6e803131,
322 /* 2310: */ 0x32c77887, 0x00077733, 0x00007447, 0x00000040,
323 /* 2320: */ 0xcccc0cfc, 0x0fbb0fff
324 };
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100325
Angel Pons77f340a2020-10-17 18:39:04 +0200326 for (i = 0; i < ARRAY_SIZE(rcba2300); i++) {
327 RCBA32(0x2300 + 4 * i) = rcba2300[i];
328 RCBA32(0x2300 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100329 }
330
Angel Pons77f340a2020-10-17 18:39:04 +0200331 RCBA32(0x37fc) = 0x00000000;
332 (void)RCBA32(0x37fc);
333 RCBA32(0x3dfc) = 0x00000000;
334 (void)RCBA32(0x3dfc);
335 RCBA32(0x3e7c) = 0xffffffff;
336 (void)RCBA32(0x3e7c);
337 RCBA32(0x3efc) = 0x00000000;
338 (void)RCBA32(0x3efc);
339 RCBA32(0x3f00) = 0x0000010b;
340 (void)RCBA32(0x3f00);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100341}
342
343static void enable_hpet(void)
344{
345 u32 reg32;
346
347 /* Move HPET to default address 0xfed00000 and enable it */
348 reg32 = RCBA32(HPTC);
349 reg32 |= (1 << 7); // HPET Address Enable
350 reg32 &= ~(3 << 0);
351 RCBA32(HPTC) = reg32;
Arthur Heymans37e1d932019-10-02 14:33:34 +0200352 RCBA32(HPTC); /* Read back for it to work */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100353
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800354 write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100355}
356
Elyes HAOUASbe841402018-05-13 13:40:39 +0200357static void enable_clock_gating(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100358{
359 u32 reg32;
360 u16 reg16;
361
362 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
363
364 reg16 = pci_read_config16(dev, GEN_PMCON_1);
365 reg16 |= (1 << 2) | (1 << 11);
366 pci_write_config16(dev, GEN_PMCON_1, reg16);
367
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100368 reg32 = RCBA32(CG);
369 reg32 |= (1 << 31);
370 reg32 |= (1 << 29) | (1 << 28);
371 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
372 reg32 |= (1 << 16);
373 reg32 |= (1 << 17);
374 reg32 |= (1 << 18);
375 reg32 |= (1 << 22);
376 reg32 |= (1 << 23);
377 reg32 &= ~(1 << 20);
378 reg32 |= (1 << 19);
379 reg32 |= (1 << 0);
380 reg32 |= (0xf << 1);
381 RCBA32(CG) = reg32;
382
383 RCBA32_OR(0x38c0, 0x7);
384 RCBA32_OR(0x36d4, 0x6680c004);
385 RCBA32_OR(0x3564, 0x3);
386}
387
Vladimir Serbinenko456f4952015-05-28 20:42:32 +0200388static void pch_set_acpi_mode(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100389{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300390 if (!acpi_is_wakeup_s3()) {
391 apm_control(APM_CNT_ACPI_DISABLE);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100392 }
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100393}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100394
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100395static void pch_fixups(struct device *dev)
396{
397 /*
398 * Enable DMI ASPM in the PCH
399 */
400 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
401 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
402 RCBA32_OR(0x21a8, 0x3);
403}
404
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100405static void lpc_init(struct device *dev)
406{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100407 printk(BIOS_DEBUG, "pch: %s\n", __func__);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100408
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100409 /* IO APIC initialization. */
410 pch_enable_ioapic(dev);
411
412 pch_enable_serial_irqs(dev);
413
414 /* Setup the PIRQ. */
415 pch_pirq_init(dev);
416
417 /* Setup power options. */
418 pch_power_options(dev);
419
420 /* Initialize power management */
Arthur Heymansd0310fa2019-10-02 00:21:01 +0200421 mobile5_pm_init(dev);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100422
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100423 /* Initialize the real time clock. */
424 pch_rtc_init(dev);
425
426 /* Initialize ISA DMA. */
427 isa_dma_init();
428
429 /* Initialize the High Precision Event Timers, if present. */
430 enable_hpet();
431
432 /* Initialize Clock Gating */
433 enable_clock_gating(dev);
434
435 setup_i8259();
436
437 /* The OS should do this? */
438 /* Interrupt 9 should be level triggered (SCI) */
439 i8259_configure_irq_trigger(9, 1);
440
Vladimir Serbinenko456f4952015-05-28 20:42:32 +0200441 pch_set_acpi_mode();
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100442
443 pch_fixups(dev);
444}
445
Elyes HAOUASbe841402018-05-13 13:40:39 +0200446static void pch_lpc_read_resources(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100447{
448 struct resource *res;
449 config_t *config = dev->chip_info;
450 u8 io_index = 0;
451
452 /* Get the normal PCI resources of this device. */
453 pci_dev_read_resources(dev);
454
455 /* Add an extra subtractive resource for both memory and I/O. */
456 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
457 res->base = 0;
458 res->size = 0x1000;
459 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
460 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
461
462 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
463 res->base = 0xff800000;
464 res->size = 0x00800000; /* 8 MB for flash */
465 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
466 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
467
468 res = new_resource(dev, 3); /* IOAPIC */
469 res->base = IO_APIC_ADDR;
470 res->size = 0x00001000;
471 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
472
473 /* Set PCH IO decode ranges if required.*/
474 if ((config->gen1_dec & 0xFFFC) > 0x1000) {
475 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
476 res->base = config->gen1_dec & 0xFFFC;
477 res->size = (config->gen1_dec >> 16) & 0xFC;
478 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
479 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
480 }
481
482 if ((config->gen2_dec & 0xFFFC) > 0x1000) {
483 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
484 res->base = config->gen2_dec & 0xFFFC;
485 res->size = (config->gen2_dec >> 16) & 0xFC;
486 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
487 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
488 }
489
490 if ((config->gen3_dec & 0xFFFC) > 0x1000) {
491 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
492 res->base = config->gen3_dec & 0xFFFC;
493 res->size = (config->gen3_dec >> 16) & 0xFC;
494 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
495 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
496 }
497
498 if ((config->gen4_dec & 0xFFFC) > 0x1000) {
499 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
500 res->base = config->gen4_dec & 0xFFFC;
501 res->size = (config->gen4_dec >> 16) & 0xFC;
502 res->flags = IORESOURCE_IO| IORESOURCE_SUBTRACTIVE |
503 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
504 }
505}
506
Elyes HAOUASbe841402018-05-13 13:40:39 +0200507static void pch_lpc_enable(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100508{
509 /* Enable PCH Display Port */
510 RCBA16(DISPBDF) = 0x0010;
511 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
512
513 pch_enable(dev);
514}
515
Kyösti Mälkki90993952018-05-01 19:36:25 +0300516static const char *lpc_acpi_name(const struct device *dev)
517{
518 return "LPCB";
519}
520
Furquan Shaikh7536a392020-04-24 21:59:21 -0700521static void southbridge_fill_ssdt(const struct device *device)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100522{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300523 struct device *dev = pcidev_on_root(0x1f, 0);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100524 config_t *chip = dev->chip_info;
525
526 intel_acpi_pcie_hotplug_generator(chip->pcie_hotplug_map, 8);
Kyösti Mälkki90993952018-05-01 19:36:25 +0300527 intel_acpi_gen_def_acpi_pirq(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100528}
529
Bill XIEd533b162017-08-22 16:26:22 +0800530static void lpc_final(struct device *dev)
531{
Arthur Heymansaadd1d02019-05-28 13:39:20 +0200532 spi_finalize_ops();
533
Bill XIEd533b162017-08-22 16:26:22 +0800534 /* Call SMM finalize() handlers before resume */
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300535 if (CONFIG(INTEL_CHIPSET_LOCKDOWN) ||
536 acpi_is_wakeup_s3()) {
537 apm_control(APM_CNT_FINALIZE);
Bill XIEd533b162017-08-22 16:26:22 +0800538 }
539}
540
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100541static struct device_operations device_ops = {
542 .read_resources = pch_lpc_read_resources,
543 .set_resources = pci_dev_set_resources,
Arthur Heymans3b452e02019-10-03 09:16:10 +0200544 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200545 .acpi_fill_ssdt = southbridge_fill_ssdt,
Kyösti Mälkki90993952018-05-01 19:36:25 +0300546 .acpi_name = lpc_acpi_name,
Angel Pons77f340a2020-10-17 18:39:04 +0200547 .write_acpi_tables = acpi_write_hpet,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100548 .init = lpc_init,
Bill XIEd533b162017-08-22 16:26:22 +0800549 .final = lpc_final,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100550 .enable = pch_lpc_enable,
Nico Huber51b75ae2019-03-14 16:02:05 +0100551 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200552 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100553};
554
Felix Singer838fbc72019-11-21 21:23:32 +0100555static const unsigned short pci_device_ids[] = {
Angel Pons45621832021-02-24 22:02:04 +0100556 PCI_DID_INTEL_IBEXPEAK_LPC_P55,
557 PCI_DID_INTEL_IBEXPEAK_LPC_PM55,
558 PCI_DID_INTEL_IBEXPEAK_LPC_H55,
Felix Singer838fbc72019-11-21 21:23:32 +0100559 PCI_DID_INTEL_IBEXPEAK_LPC_QM57,
Angel Pons45621832021-02-24 22:02:04 +0100560 PCI_DID_INTEL_IBEXPEAK_LPC_H57,
Felix Singer838fbc72019-11-21 21:23:32 +0100561 PCI_DID_INTEL_IBEXPEAK_LPC_HM55,
Angel Pons45621832021-02-24 22:02:04 +0100562 PCI_DID_INTEL_IBEXPEAK_LPC_Q57,
563 PCI_DID_INTEL_IBEXPEAK_LPC_HM57,
564 PCI_DID_INTEL_IBEXPEAK_LPC_QS57,
565 PCI_DID_INTEL_IBEXPEAK_LPC_3400,
566 PCI_DID_INTEL_IBEXPEAK_LPC_3420,
567 PCI_DID_INTEL_IBEXPEAK_LPC_3450,
Felix Singer838fbc72019-11-21 21:23:32 +0100568 0
569};
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100570
571static const struct pci_driver pch_lpc __pci_driver = {
572 .ops = &device_ops,
573 .vendor = PCI_VENDOR_ID_INTEL,
574 .devices = pci_device_ids,
575};