blob: 1735020b54483ae1ba643282fa9ef1a2fdbbd462 [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 Serbinenko888d5592013-11-13 17:53:38 +010028/**
Martin Roth26f97f92021-10-01 14:53:22 -060029 * Set miscellaneous static southbridge features.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010030 *
31 * @param dev PCI device with I/O APIC control registers
32 */
33static void pch_enable_ioapic(struct device *dev)
34{
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010035 /* affirm full set of redirection table entries ("write once") */
Kyösti Mälkki04a40372021-06-06 08:04:28 +030036 ioapic_lock_max_vectors(VIO_APIC_VADDR);
Kyösti Mälkkiea6d12a2021-06-08 11:25:29 +030037
Kyösti Mälkki682613f2021-06-08 11:31:19 +030038 setup_ioapic(VIO_APIC_VADDR, 0x01);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010039}
40
41static void pch_enable_serial_irqs(struct device *dev)
42{
43 /* Set packet length and toggle silent mode bit for one frame. */
44 pci_write_config8(dev, SERIRQ_CNTL,
45 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Julius Wernercd49cce2019-03-05 16:53:33 -080046#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010047 pci_write_config8(dev, SERIRQ_CNTL,
48 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
49#endif
50}
51
52/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
53 * 0x00 - 0000 = Reserved
54 * 0x01 - 0001 = Reserved
55 * 0x02 - 0010 = Reserved
56 * 0x03 - 0011 = IRQ3
57 * 0x04 - 0100 = IRQ4
58 * 0x05 - 0101 = IRQ5
59 * 0x06 - 0110 = IRQ6
60 * 0x07 - 0111 = IRQ7
61 * 0x08 - 1000 = Reserved
62 * 0x09 - 1001 = IRQ9
63 * 0x0A - 1010 = IRQ10
64 * 0x0B - 1011 = IRQ11
65 * 0x0C - 1100 = IRQ12
66 * 0x0D - 1101 = Reserved
67 * 0x0E - 1110 = IRQ14
68 * 0x0F - 1111 = IRQ15
69 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
70 * 0x80 - The PIRQ is not routed.
71 */
72
Elyes HAOUASbe841402018-05-13 13:40:39 +020073static void pch_pirq_init(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010074{
Elyes HAOUASbe841402018-05-13 13:40:39 +020075 struct device *irq_dev;
Angel Pons77f340a2020-10-17 18:39:04 +020076 /*
77 * Interrupt 11 is not used by legacy devices and so can always be used for
78 * PCI interrupts. Full legacy IRQ routing is complicated and hard to
79 * get right. Fortunately all modern OS use MSI and so it's not that big of
80 * an issue anyway. Still we have to provide a reasonable default. Using
81 * interrupt 11 for it everywhere is a working default. ACPI-aware OS can
82 * move it to any interrupt and others will just leave them at default.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010083 */
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020084 const u8 pirq_routing = 11;
85
86 pci_write_config8(dev, PIRQA_ROUT, pirq_routing);
87 pci_write_config8(dev, PIRQB_ROUT, pirq_routing);
88 pci_write_config8(dev, PIRQC_ROUT, pirq_routing);
89 pci_write_config8(dev, PIRQD_ROUT, pirq_routing);
90
91 pci_write_config8(dev, PIRQE_ROUT, pirq_routing);
92 pci_write_config8(dev, PIRQF_ROUT, pirq_routing);
93 pci_write_config8(dev, PIRQG_ROUT, pirq_routing);
94 pci_write_config8(dev, PIRQH_ROUT, pirq_routing);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010095
Elyes HAOUASba28e8d2016-08-31 19:22:16 +020096 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +020097 u8 int_pin=0;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010098
99 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
100 continue;
101
102 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
103
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200104 if (int_pin == 0)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100105 continue;
106
Vladimir Serbinenko33b535f2014-10-19 10:13:14 +0200107 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, pirq_routing);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100108 }
109}
110
Elyes HAOUASbe841402018-05-13 13:40:39 +0200111static void pch_gpi_routing(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100112{
113 /* Get the chip configuration */
Elyes Haouasd3687cd2022-02-15 21:49:49 +0100114 const struct southbridge_intel_ibexpeak_config *config = dev->chip_info;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100115 u32 reg32 = 0;
116
117 /* An array would be much nicer here, or some
118 * other method of doing this.
119 */
120 reg32 |= (config->gpi0_routing & 0x03) << 0;
121 reg32 |= (config->gpi1_routing & 0x03) << 2;
122 reg32 |= (config->gpi2_routing & 0x03) << 4;
123 reg32 |= (config->gpi3_routing & 0x03) << 6;
124 reg32 |= (config->gpi4_routing & 0x03) << 8;
125 reg32 |= (config->gpi5_routing & 0x03) << 10;
126 reg32 |= (config->gpi6_routing & 0x03) << 12;
127 reg32 |= (config->gpi7_routing & 0x03) << 14;
128 reg32 |= (config->gpi8_routing & 0x03) << 16;
129 reg32 |= (config->gpi9_routing & 0x03) << 18;
130 reg32 |= (config->gpi10_routing & 0x03) << 20;
131 reg32 |= (config->gpi11_routing & 0x03) << 22;
132 reg32 |= (config->gpi12_routing & 0x03) << 24;
133 reg32 |= (config->gpi13_routing & 0x03) << 26;
134 reg32 |= (config->gpi14_routing & 0x03) << 28;
135 reg32 |= (config->gpi15_routing & 0x03) << 30;
136
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200137 pci_write_config32(dev, GPIO_ROUT, reg32);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100138}
139
Elyes HAOUASbe841402018-05-13 13:40:39 +0200140static void pch_power_options(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100141{
142 u8 reg8;
143 u16 reg16, pmbase;
144 u32 reg32;
145 const char *state;
146 /* Get the chip configuration */
Elyes Haouasd3687cd2022-02-15 21:49:49 +0100147 const struct southbridge_intel_ibexpeak_config *config = dev->chip_info;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100148
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100149 /* Which state do we want to goto after g3 (power restored)?
150 * 0 == S0 Full On
151 * 1 == S5 Soft Off
152 *
153 * If the option is not existent (Laptops), use Kconfig setting.
154 */
Angel Pons88dcb312021-04-26 17:10:28 +0200155 const unsigned int pwr_on = get_uint_option("power_on_after_fail",
Angel Pons62719a32021-04-19 13:15:28 +0200156 CONFIG_MAINBOARD_POWER_FAILURE_STATE);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100157
158 reg16 = pci_read_config16(dev, GEN_PMCON_3);
159 reg16 &= 0xfffe;
160 switch (pwr_on) {
161 case MAINBOARD_POWER_OFF:
162 reg16 |= 1;
163 state = "off";
164 break;
165 case MAINBOARD_POWER_ON:
166 reg16 &= ~1;
167 state = "on";
168 break;
169 case MAINBOARD_POWER_KEEP:
170 reg16 &= ~1;
171 state = "state keep";
172 break;
173 default:
174 state = "undefined";
175 }
176
177 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
178 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
179
180 reg16 &= ~(1 << 10);
181 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
182
183 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
184
185 pci_write_config16(dev, GEN_PMCON_3, reg16);
186 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
187
188 /* Set up NMI on errors. */
189 reg8 = inb(0x61);
190 reg8 &= 0x0f; /* Higher Nibble must be 0 */
191 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
192 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
193 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
194 outb(reg8, 0x61);
195
196 reg8 = inb(0x70);
Angel Pons88dcb312021-04-26 17:10:28 +0200197 const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100198 if (nmi_option) {
199 printk(BIOS_INFO, "NMI sources enabled.\n");
200 reg8 &= ~(1 << 7); /* Set NMI. */
201 } else {
202 printk(BIOS_INFO, "NMI sources disabled.\n");
Elyes HAOUAS9c5d4632018-04-26 22:21:21 +0200203 reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100204 }
205 outb(reg8, 0x70);
206
207 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
208 reg16 = pci_read_config16(dev, GEN_PMCON_1);
209 reg16 &= ~(3 << 0); // SMI# rate 1 minute
210 reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
Kyösti Mälkki94464472020-06-13 13:45:42 +0300211 if (CONFIG(DEBUG_PERIODIC_SMI))
212 reg16 |= (3 << 0); // Periodic SMI every 8s
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100213 pci_write_config16(dev, GEN_PMCON_1, reg16);
214
215 // Set the board's GPI routing.
216 pch_gpi_routing(dev);
217
218 pmbase = pci_read_config16(dev, 0x40) & 0xfffe;
219
220 outl(config->gpe0_en, pmbase + GPE0_EN);
221 outw(config->alt_gp_smi_en, pmbase + ALT_GP_SMI_EN);
222
223 /* Set up power management block and determine sleep mode */
224 reg32 = inl(pmbase + 0x04); // PM1_CNT
225 reg32 &= ~(7 << 10); // SLP_TYP
226 reg32 |= (1 << 0); // SCI_EN
227 outl(reg32, pmbase + 0x04);
228
229 /* Clear magic status bits to prevent unexpected wake */
Angel Pons42b4e4e2019-09-18 10:58:53 +0200230 reg32 = RCBA32(PRSTS);
231 reg32 |= (1 << 5) | (1 << 4) | (1 << 0);
232 RCBA32(PRSTS) = reg32;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100233
Angel Pons42b4e4e2019-09-18 10:58:53 +0200234 /* FIXME: Does this even exist? */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100235 reg32 = RCBA32(0x3f02);
236 reg32 &= ~0xf;
237 RCBA32(0x3f02) = reg32;
238}
239
240static void pch_rtc_init(struct device *dev)
241{
242 u8 reg8;
243 int rtc_failed;
244
245 reg8 = pci_read_config8(dev, GEN_PMCON_3);
246 rtc_failed = reg8 & RTC_BATTERY_DEAD;
247 if (rtc_failed) {
248 reg8 &= ~RTC_BATTERY_DEAD;
249 pci_write_config8(dev, GEN_PMCON_3, reg8);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100250 elog_add_event(ELOG_TYPE_RTC_RESET);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100251 }
252 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
253
Gabe Blackb3f08c62014-04-30 17:12:25 -0700254 cmos_init(rtc_failed);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100255}
256
257static void mobile5_pm_init(struct device *dev)
258{
259 int i;
260
261 printk(BIOS_DEBUG, "Mobile 5 PM init\n");
262 pci_write_config8(dev, 0xa9, 0x47);
263
Angel Pons77f340a2020-10-17 18:39:04 +0200264 RCBA32(0x1d44) = 0x00000000;
265 (void)RCBA32(0x1d44);
266 RCBA32(0x1d48) = 0x00030000;
267 (void)RCBA32(0x1d48);
268 RCBA32(0x1e80) = 0x000c0801;
269 (void)RCBA32(0x1e80);
270 RCBA32(0x1e84) = 0x000200f0;
271 (void)RCBA32(0x1e84);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100272
Angel Pons77f340a2020-10-17 18:39:04 +0200273 const u32 rcba2010[] = {
274 /* 2010: */ 0x00188200, 0x14000016, 0xbc4abcb5, 0x00000000,
275 /* 2020: */ 0xf0c9605b, 0x13683040, 0x04c8f16e, 0x09e90170
276 };
277 for (i = 0; i < ARRAY_SIZE(rcba2010); i++) {
278 RCBA32(0x2010 + 4 * i) = rcba2010[i];
279 RCBA32(0x2010 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100280 }
281
Angel Pons77f340a2020-10-17 18:39:04 +0200282 RCBA32(0x2100) = 0x00000000;
283 (void)RCBA32(0x2100);
284 RCBA32(0x2104) = 0x00000757;
285 (void)RCBA32(0x2104);
286 RCBA32(0x2108) = 0x00170001;
287 (void)RCBA32(0x2108);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100288
Angel Pons77f340a2020-10-17 18:39:04 +0200289 RCBA32(0x211c) = 0x00000000;
290 (void)RCBA32(0x211c);
291 RCBA32(0x2120) = 0x00010000;
292 (void)RCBA32(0x2120);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100293
Angel Pons77f340a2020-10-17 18:39:04 +0200294 RCBA32(0x21fc) = 0x00000000;
295 (void)RCBA32(0x21fc);
296 RCBA32(0x2200) = 0x20000044;
297 (void)RCBA32(0x2200);
298 RCBA32(0x2204) = 0x00000001;
299 (void)RCBA32(0x2204);
300 RCBA32(0x2208) = 0x00003457;
301 (void)RCBA32(0x2208);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100302
Angel Pons77f340a2020-10-17 18:39:04 +0200303 const u32 rcba2210[] = {
304 /* 2210 */ 0x00000000, 0x00000001, 0xa0fff210, 0x0000df00,
305 /* 2220 */ 0x00e30880, 0x00000070, 0x00004000, 0x00000000,
306 /* 2230 */ 0x00e30880, 0x00000070, 0x00004000, 0x00000000,
307 /* 2240 */ 0x00002301, 0x36000000, 0x00010107, 0x00160000,
308 /* 2250 */ 0x00001b01, 0x36000000, 0x00010107, 0x00160000,
309 /* 2260 */ 0x00000601, 0x16000000, 0x00010107, 0x00160000,
310 /* 2270 */ 0x00001c01, 0x16000000, 0x00010107, 0x00160000
311 };
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100312
Angel Pons77f340a2020-10-17 18:39:04 +0200313 for (i = 0; i < ARRAY_SIZE(rcba2210); i++) {
314 RCBA32(0x2210 + 4 * i) = rcba2210[i];
315 RCBA32(0x2210 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100316 }
317
Angel Pons77f340a2020-10-17 18:39:04 +0200318 const u32 rcba2300[] = {
319 /* 2300: */ 0x00000000, 0x40000000, 0x4646827b, 0x6e803131,
320 /* 2310: */ 0x32c77887, 0x00077733, 0x00007447, 0x00000040,
321 /* 2320: */ 0xcccc0cfc, 0x0fbb0fff
322 };
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100323
Angel Pons77f340a2020-10-17 18:39:04 +0200324 for (i = 0; i < ARRAY_SIZE(rcba2300); i++) {
325 RCBA32(0x2300 + 4 * i) = rcba2300[i];
326 RCBA32(0x2300 + 4 * i);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100327 }
328
Angel Pons77f340a2020-10-17 18:39:04 +0200329 RCBA32(0x37fc) = 0x00000000;
330 (void)RCBA32(0x37fc);
331 RCBA32(0x3dfc) = 0x00000000;
332 (void)RCBA32(0x3dfc);
333 RCBA32(0x3e7c) = 0xffffffff;
334 (void)RCBA32(0x3e7c);
335 RCBA32(0x3efc) = 0x00000000;
336 (void)RCBA32(0x3efc);
337 RCBA32(0x3f00) = 0x0000010b;
338 (void)RCBA32(0x3f00);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100339}
340
341static void enable_hpet(void)
342{
343 u32 reg32;
344
345 /* Move HPET to default address 0xfed00000 and enable it */
346 reg32 = RCBA32(HPTC);
347 reg32 |= (1 << 7); // HPET Address Enable
348 reg32 &= ~(3 << 0);
349 RCBA32(HPTC) = reg32;
Arthur Heymans37e1d932019-10-02 14:33:34 +0200350 RCBA32(HPTC); /* Read back for it to work */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100351
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800352 write32((u32 *)0xfed00010, read32((u32 *)0xfed00010) | 1);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100353}
354
Elyes HAOUASbe841402018-05-13 13:40:39 +0200355static void enable_clock_gating(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100356{
357 u32 reg32;
358 u16 reg16;
359
360 RCBA32_AND_OR(0x2234, ~0UL, 0xf);
361
362 reg16 = pci_read_config16(dev, GEN_PMCON_1);
363 reg16 |= (1 << 2) | (1 << 11);
364 pci_write_config16(dev, GEN_PMCON_1, reg16);
365
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100366 reg32 = RCBA32(CG);
367 reg32 |= (1 << 31);
368 reg32 |= (1 << 29) | (1 << 28);
369 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
370 reg32 |= (1 << 16);
371 reg32 |= (1 << 17);
372 reg32 |= (1 << 18);
373 reg32 |= (1 << 22);
374 reg32 |= (1 << 23);
375 reg32 &= ~(1 << 20);
376 reg32 |= (1 << 19);
377 reg32 |= (1 << 0);
378 reg32 |= (0xf << 1);
379 RCBA32(CG) = reg32;
380
381 RCBA32_OR(0x38c0, 0x7);
382 RCBA32_OR(0x36d4, 0x6680c004);
383 RCBA32_OR(0x3564, 0x3);
384}
385
Vladimir Serbinenko456f4952015-05-28 20:42:32 +0200386static void pch_set_acpi_mode(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100387{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300388 if (!acpi_is_wakeup_s3()) {
389 apm_control(APM_CNT_ACPI_DISABLE);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100390 }
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100391}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100392
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100393static void pch_fixups(struct device *dev)
394{
395 /*
396 * Enable DMI ASPM in the PCH
397 */
398 RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
399 RCBA32_OR(0x21a4, (1 << 11)|(1 << 10));
400 RCBA32_OR(0x21a8, 0x3);
401}
402
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100403static void lpc_init(struct device *dev)
404{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100405 printk(BIOS_DEBUG, "pch: %s\n", __func__);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100406
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100407 /* IO APIC initialization. */
408 pch_enable_ioapic(dev);
409
410 pch_enable_serial_irqs(dev);
411
412 /* Setup the PIRQ. */
413 pch_pirq_init(dev);
414
415 /* Setup power options. */
416 pch_power_options(dev);
417
418 /* Initialize power management */
Arthur Heymansd0310fa2019-10-02 00:21:01 +0200419 mobile5_pm_init(dev);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100420
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100421 /* Initialize the real time clock. */
422 pch_rtc_init(dev);
423
424 /* Initialize ISA DMA. */
425 isa_dma_init();
426
427 /* Initialize the High Precision Event Timers, if present. */
428 enable_hpet();
429
430 /* Initialize Clock Gating */
431 enable_clock_gating(dev);
432
433 setup_i8259();
434
435 /* The OS should do this? */
436 /* Interrupt 9 should be level triggered (SCI) */
437 i8259_configure_irq_trigger(9, 1);
438
Vladimir Serbinenko456f4952015-05-28 20:42:32 +0200439 pch_set_acpi_mode();
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100440
441 pch_fixups(dev);
442}
443
Elyes HAOUASbe841402018-05-13 13:40:39 +0200444static void pch_lpc_read_resources(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100445{
446 struct resource *res;
Elyes Haouasd3687cd2022-02-15 21:49:49 +0100447 const struct southbridge_intel_ibexpeak_config *config = dev->chip_info;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100448 u8 io_index = 0;
449
450 /* Get the normal PCI resources of this device. */
451 pci_dev_read_resources(dev);
452
453 /* Add an extra subtractive resource for both memory and I/O. */
454 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
455 res->base = 0;
456 res->size = 0x1000;
457 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
458 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
459
460 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
461 res->base = 0xff800000;
462 res->size = 0x00800000; /* 8 MB for flash */
463 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
464 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
465
466 res = new_resource(dev, 3); /* IOAPIC */
467 res->base = IO_APIC_ADDR;
468 res->size = 0x00001000;
469 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
470
471 /* Set PCH IO decode ranges if required.*/
472 if ((config->gen1_dec & 0xFFFC) > 0x1000) {
473 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
474 res->base = config->gen1_dec & 0xFFFC;
475 res->size = (config->gen1_dec >> 16) & 0xFC;
476 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
477 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
478 }
479
480 if ((config->gen2_dec & 0xFFFC) > 0x1000) {
481 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
482 res->base = config->gen2_dec & 0xFFFC;
483 res->size = (config->gen2_dec >> 16) & 0xFC;
484 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
485 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
486 }
487
488 if ((config->gen3_dec & 0xFFFC) > 0x1000) {
489 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
490 res->base = config->gen3_dec & 0xFFFC;
491 res->size = (config->gen3_dec >> 16) & 0xFC;
492 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
493 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
494 }
495
496 if ((config->gen4_dec & 0xFFFC) > 0x1000) {
497 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
498 res->base = config->gen4_dec & 0xFFFC;
499 res->size = (config->gen4_dec >> 16) & 0xFC;
500 res->flags = IORESOURCE_IO| IORESOURCE_SUBTRACTIVE |
501 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
502 }
503}
504
Elyes HAOUASbe841402018-05-13 13:40:39 +0200505static void pch_lpc_enable(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100506{
507 /* Enable PCH Display Port */
508 RCBA16(DISPBDF) = 0x0010;
509 RCBA32_OR(FD2, PCH_ENABLE_DBDF);
510
511 pch_enable(dev);
512}
513
Kyösti Mälkki90993952018-05-01 19:36:25 +0300514static const char *lpc_acpi_name(const struct device *dev)
515{
516 return "LPCB";
517}
518
Furquan Shaikh7536a392020-04-24 21:59:21 -0700519static void southbridge_fill_ssdt(const struct device *device)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100520{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300521 struct device *dev = pcidev_on_root(0x1f, 0);
Elyes Haouasd3687cd2022-02-15 21:49:49 +0100522 struct southbridge_intel_ibexpeak_config *chip = dev->chip_info;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100523
524 intel_acpi_pcie_hotplug_generator(chip->pcie_hotplug_map, 8);
Kyösti Mälkki90993952018-05-01 19:36:25 +0300525 intel_acpi_gen_def_acpi_pirq(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100526}
527
Bill XIEd533b162017-08-22 16:26:22 +0800528static void lpc_final(struct device *dev)
529{
Arthur Heymansaadd1d02019-05-28 13:39:20 +0200530 spi_finalize_ops();
531
Bill XIEd533b162017-08-22 16:26:22 +0800532 /* Call SMM finalize() handlers before resume */
Kyösti Mälkkiad882c32020-06-02 05:05:30 +0300533 if (CONFIG(INTEL_CHIPSET_LOCKDOWN) ||
534 acpi_is_wakeup_s3()) {
535 apm_control(APM_CNT_FINALIZE);
Bill XIEd533b162017-08-22 16:26:22 +0800536 }
537}
538
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100539static struct device_operations device_ops = {
540 .read_resources = pch_lpc_read_resources,
541 .set_resources = pci_dev_set_resources,
Arthur Heymans3b452e02019-10-03 09:16:10 +0200542 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200543 .acpi_fill_ssdt = southbridge_fill_ssdt,
Kyösti Mälkki90993952018-05-01 19:36:25 +0300544 .acpi_name = lpc_acpi_name,
Angel Pons77f340a2020-10-17 18:39:04 +0200545 .write_acpi_tables = acpi_write_hpet,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100546 .init = lpc_init,
Bill XIEd533b162017-08-22 16:26:22 +0800547 .final = lpc_final,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100548 .enable = pch_lpc_enable,
Nico Huber51b75ae2019-03-14 16:02:05 +0100549 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200550 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100551};
552
Felix Singer838fbc72019-11-21 21:23:32 +0100553static const unsigned short pci_device_ids[] = {
Angel Pons45621832021-02-24 22:02:04 +0100554 PCI_DID_INTEL_IBEXPEAK_LPC_P55,
555 PCI_DID_INTEL_IBEXPEAK_LPC_PM55,
556 PCI_DID_INTEL_IBEXPEAK_LPC_H55,
Felix Singer838fbc72019-11-21 21:23:32 +0100557 PCI_DID_INTEL_IBEXPEAK_LPC_QM57,
Angel Pons45621832021-02-24 22:02:04 +0100558 PCI_DID_INTEL_IBEXPEAK_LPC_H57,
Felix Singer838fbc72019-11-21 21:23:32 +0100559 PCI_DID_INTEL_IBEXPEAK_LPC_HM55,
Angel Pons45621832021-02-24 22:02:04 +0100560 PCI_DID_INTEL_IBEXPEAK_LPC_Q57,
561 PCI_DID_INTEL_IBEXPEAK_LPC_HM57,
562 PCI_DID_INTEL_IBEXPEAK_LPC_QS57,
563 PCI_DID_INTEL_IBEXPEAK_LPC_3400,
564 PCI_DID_INTEL_IBEXPEAK_LPC_3420,
565 PCI_DID_INTEL_IBEXPEAK_LPC_3450,
Felix Singer838fbc72019-11-21 21:23:32 +0100566 0
567};
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100568
569static const struct pci_driver pch_lpc __pci_driver = {
570 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100571 .vendor = PCI_VID_INTEL,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100572 .devices = pci_device_ids,
573};