blob: d9ddcdc840b8b305fc8f9bd2e35d144ae08e5157 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass2b605152014-11-12 22:42:15 -07002/*
3 * From coreboot southbridge/intel/bd82x6x/lpc.c
4 *
5 * Copyright (C) 2008-2009 coresystems GmbH
Simon Glass2b605152014-11-12 22:42:15 -07006 */
7
8#include <common.h>
Simon Glassaad78d22015-03-05 12:25:33 -07009#include <dm.h>
Simon Glass2b605152014-11-12 22:42:15 -070010#include <errno.h>
11#include <fdtdec.h>
Simon Glass72cd0852014-11-14 18:18:35 -070012#include <rtc.h>
Simon Glass2b605152014-11-12 22:42:15 -070013#include <pci.h>
Simon Glassbb096b92016-03-11 22:06:56 -070014#include <asm/intel_regs.h>
Simon Glass72cd0852014-11-14 18:18:35 -070015#include <asm/interrupt.h>
16#include <asm/io.h>
17#include <asm/ioapic.h>
Simon Glass8c30b572016-03-11 22:06:57 -070018#include <asm/lpc_common.h>
Simon Glass2b605152014-11-12 22:42:15 -070019#include <asm/pci.h>
20#include <asm/arch/pch.h>
21
Simon Glass05af0502017-01-16 07:03:37 -070022DECLARE_GLOBAL_DATA_PTR;
23
Simon Glass72cd0852014-11-14 18:18:35 -070024#define NMI_OFF 0
25
26#define ENABLE_ACPI_MODE_IN_COREBOOT 0
27#define TEST_SMM_FLASH_LOCKDOWN 0
28
Simon Glass4265abd2016-01-17 16:11:42 -070029static int pch_enable_apic(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070030{
31 u32 reg32;
32 int i;
33
34 /* Enable ACPI I/O and power management. Set SCI IRQ to IRQ9 */
Simon Glass4265abd2016-01-17 16:11:42 -070035 dm_pci_write_config8(pch, ACPI_CNTL, 0x80);
Simon Glass72cd0852014-11-14 18:18:35 -070036
37 writel(0, IO_APIC_INDEX);
38 writel(1 << 25, IO_APIC_DATA);
39
40 /* affirm full set of redirection table entries ("write once") */
41 writel(1, IO_APIC_INDEX);
42 reg32 = readl(IO_APIC_DATA);
43 writel(1, IO_APIC_INDEX);
44 writel(reg32, IO_APIC_DATA);
45
46 writel(0, IO_APIC_INDEX);
47 reg32 = readl(IO_APIC_DATA);
48 debug("PCH APIC ID = %x\n", (reg32 >> 24) & 0x0f);
49 if (reg32 != (1 << 25)) {
50 printf("APIC Error - cannot write to registers\n");
51 return -EPERM;
52 }
53
54 debug("Dumping IOAPIC registers\n");
55 for (i = 0; i < 3; i++) {
56 writel(i, IO_APIC_INDEX);
57 debug(" reg 0x%04x:", i);
58 reg32 = readl(IO_APIC_DATA);
59 debug(" 0x%08x\n", reg32);
60 }
61
62 /* Select Boot Configuration register. */
63 writel(3, IO_APIC_INDEX);
64
65 /* Use Processor System Bus to deliver interrupts. */
66 writel(1, IO_APIC_DATA);
67
68 return 0;
69}
70
Simon Glass4265abd2016-01-17 16:11:42 -070071static void pch_enable_serial_irqs(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070072{
73 u32 value;
74
75 /* Set packet length and toggle silent mode bit for one frame. */
76 value = (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0);
77#ifdef CONFIG_SERIRQ_CONTINUOUS_MODE
Simon Glass4265abd2016-01-17 16:11:42 -070078 dm_pci_write_config8(pch, SERIRQ_CNTL, value);
Simon Glass72cd0852014-11-14 18:18:35 -070079#else
Simon Glass4265abd2016-01-17 16:11:42 -070080 dm_pci_write_config8(pch, SERIRQ_CNTL, value | (1 << 6));
Simon Glass72cd0852014-11-14 18:18:35 -070081#endif
82}
83
Simon Glass4265abd2016-01-17 16:11:42 -070084static int pch_pirq_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070085{
86 uint8_t route[8], *ptr;
87
Simon Glasse160f7d2017-01-17 16:52:55 -070088 if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch),
Simon Glass4265abd2016-01-17 16:11:42 -070089 "intel,pirq-routing", route, sizeof(route)))
Simon Glass72cd0852014-11-14 18:18:35 -070090 return -EINVAL;
91 ptr = route;
Simon Glass4265abd2016-01-17 16:11:42 -070092 dm_pci_write_config8(pch, PIRQA_ROUT, *ptr++);
93 dm_pci_write_config8(pch, PIRQB_ROUT, *ptr++);
94 dm_pci_write_config8(pch, PIRQC_ROUT, *ptr++);
95 dm_pci_write_config8(pch, PIRQD_ROUT, *ptr++);
Simon Glass72cd0852014-11-14 18:18:35 -070096
Simon Glass4265abd2016-01-17 16:11:42 -070097 dm_pci_write_config8(pch, PIRQE_ROUT, *ptr++);
98 dm_pci_write_config8(pch, PIRQF_ROUT, *ptr++);
99 dm_pci_write_config8(pch, PIRQG_ROUT, *ptr++);
100 dm_pci_write_config8(pch, PIRQH_ROUT, *ptr++);
Simon Glass72cd0852014-11-14 18:18:35 -0700101
102 /*
103 * TODO(sjg@chromium.org): U-Boot does not set up the interrupts
104 * here. It's unclear if it is needed
105 */
106 return 0;
107}
108
Simon Glass4265abd2016-01-17 16:11:42 -0700109static int pch_gpi_routing(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700110{
111 u8 route[16];
112 u32 reg;
113 int gpi;
114
Simon Glasse160f7d2017-01-17 16:52:55 -0700115 if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch),
Simon Glass4265abd2016-01-17 16:11:42 -0700116 "intel,gpi-routing", route, sizeof(route)))
Simon Glass72cd0852014-11-14 18:18:35 -0700117 return -EINVAL;
118
119 for (reg = 0, gpi = 0; gpi < ARRAY_SIZE(route); gpi++)
120 reg |= route[gpi] << (gpi * 2);
121
Simon Glass4265abd2016-01-17 16:11:42 -0700122 dm_pci_write_config32(pch, 0xb8, reg);
Simon Glass72cd0852014-11-14 18:18:35 -0700123
124 return 0;
125}
126
Simon Glass4265abd2016-01-17 16:11:42 -0700127static int pch_power_options(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700128{
Simon Glass4265abd2016-01-17 16:11:42 -0700129 const void *blob = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -0700130 int node = dev_of_offset(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700131 u8 reg8;
132 u16 reg16, pmbase;
133 u32 reg32;
134 const char *state;
135 int pwr_on;
136 int nmi_option;
137 int ret;
138
139 /*
140 * Which state do we want to goto after g3 (power restored)?
141 * 0 == S0 Full On
142 * 1 == S5 Soft Off
143 *
144 * If the option is not existent (Laptops), use Kconfig setting.
145 * TODO(sjg@chromium.org): Make this configurable
146 */
147 pwr_on = MAINBOARD_POWER_ON;
148
Simon Glass4265abd2016-01-17 16:11:42 -0700149 dm_pci_read_config16(pch, GEN_PMCON_3, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700150 reg16 &= 0xfffe;
151 switch (pwr_on) {
152 case MAINBOARD_POWER_OFF:
153 reg16 |= 1;
154 state = "off";
155 break;
156 case MAINBOARD_POWER_ON:
157 reg16 &= ~1;
158 state = "on";
159 break;
160 case MAINBOARD_POWER_KEEP:
161 reg16 &= ~1;
162 state = "state keep";
163 break;
164 default:
165 state = "undefined";
166 }
167
168 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
169 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
170
171 reg16 &= ~(1 << 10);
172 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
173
174 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
175
Simon Glass4265abd2016-01-17 16:11:42 -0700176 dm_pci_write_config16(pch, GEN_PMCON_3, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700177 debug("Set power %s after power failure.\n", state);
178
179 /* Set up NMI on errors. */
180 reg8 = inb(0x61);
181 reg8 &= 0x0f; /* Higher Nibble must be 0 */
182 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
183 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
184 outb(reg8, 0x61);
185
186 reg8 = inb(0x70);
187 /* TODO(sjg@chromium.org): Make this configurable */
188 nmi_option = NMI_OFF;
189 if (nmi_option) {
190 debug("NMI sources enabled.\n");
191 reg8 &= ~(1 << 7); /* Set NMI. */
192 } else {
193 debug("NMI sources disabled.\n");
194 /* Can't mask NMI from PCI-E and NMI_NOW */
195 reg8 |= (1 << 7);
196 }
197 outb(reg8, 0x70);
198
199 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Simon Glass4265abd2016-01-17 16:11:42 -0700200 dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700201 reg16 &= ~(3 << 0); /* SMI# rate 1 minute */
202 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
203#if DEBUG_PERIODIC_SMIS
204 /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using periodic SMIs */
205 reg16 |= (3 << 0); /* Periodic SMI every 8s */
206#endif
Simon Glass4265abd2016-01-17 16:11:42 -0700207 dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700208
209 /* Set the board's GPI routing. */
Simon Glass4265abd2016-01-17 16:11:42 -0700210 ret = pch_gpi_routing(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700211 if (ret)
212 return ret;
213
Simon Glass4265abd2016-01-17 16:11:42 -0700214 dm_pci_read_config16(pch, 0x40, &pmbase);
215 pmbase &= 0xfffe;
Simon Glass72cd0852014-11-14 18:18:35 -0700216
Simon Glass4e0318c2016-09-25 21:33:34 -0600217 writel(fdtdec_get_int(blob, node, "intel,gpe0-enable", 0),
218 (ulong)pmbase + GPE0_EN);
219 writew(fdtdec_get_int(blob, node, "intel,alt-gp-smi-enable", 0),
220 (ulong)pmbase + ALT_GP_SMI_EN);
Simon Glass72cd0852014-11-14 18:18:35 -0700221
222 /* Set up power management block and determine sleep mode */
223 reg32 = inl(pmbase + 0x04); /* PM1_CNT */
224 reg32 &= ~(7 << 10); /* SLP_TYP */
225 reg32 |= (1 << 0); /* SCI_EN */
226 outl(reg32, pmbase + 0x04);
227
228 /* Clear magic status bits to prevent unexpected wake */
229 setbits_le32(RCB_REG(0x3310), (1 << 4) | (1 << 5) | (1 << 0));
230 clrbits_le32(RCB_REG(0x3f02), 0xf);
231
232 return 0;
233}
234
Simon Glass4265abd2016-01-17 16:11:42 -0700235static void pch_rtc_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700236{
237 int rtc_failed;
238 u8 reg8;
239
Simon Glass4265abd2016-01-17 16:11:42 -0700240 dm_pci_read_config8(pch, GEN_PMCON_3, &reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700241 rtc_failed = reg8 & RTC_BATTERY_DEAD;
242 if (rtc_failed) {
243 reg8 &= ~RTC_BATTERY_DEAD;
Simon Glass4265abd2016-01-17 16:11:42 -0700244 dm_pci_write_config8(pch, GEN_PMCON_3, reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700245 }
246 debug("rtc_failed = 0x%x\n", rtc_failed);
247
Simon Glass72cd0852014-11-14 18:18:35 -0700248 /* TODO: Handle power failure */
249 if (rtc_failed)
250 printf("RTC power failed\n");
Simon Glass72cd0852014-11-14 18:18:35 -0700251}
252
253/* CougarPoint PCH Power Management init */
Simon Glass4265abd2016-01-17 16:11:42 -0700254static void cpt_pm_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700255{
256 debug("CougarPoint PM init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700257 dm_pci_write_config8(pch, 0xa9, 0x47);
Simon Glass72cd0852014-11-14 18:18:35 -0700258 setbits_le32(RCB_REG(0x2238), (1 << 6) | (1 << 0));
259
260 setbits_le32(RCB_REG(0x228c), 1 << 0);
261 setbits_le32(RCB_REG(0x1100), (1 << 13) | (1 << 14));
262 setbits_le32(RCB_REG(0x0900), 1 << 14);
263 writel(0xc0388400, RCB_REG(0x2304));
264 setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
265 setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
266 clrsetbits_le32(RCB_REG(0x3314), ~0x1f, 0xf);
267 writel(0x050f0000, RCB_REG(0x3318));
268 writel(0x04000000, RCB_REG(0x3324));
269 setbits_le32(RCB_REG(0x3340), 0xfffff);
270 setbits_le32(RCB_REG(0x3344), 1 << 1);
271
272 writel(0x0001c000, RCB_REG(0x3360));
273 writel(0x00061100, RCB_REG(0x3368));
274 writel(0x7f8fdfff, RCB_REG(0x3378));
275 writel(0x000003fc, RCB_REG(0x337c));
276 writel(0x00001000, RCB_REG(0x3388));
277 writel(0x0001c000, RCB_REG(0x3390));
278 writel(0x00000800, RCB_REG(0x33a0));
279 writel(0x00001000, RCB_REG(0x33b0));
280 writel(0x00093900, RCB_REG(0x33c0));
281 writel(0x24653002, RCB_REG(0x33cc));
282 writel(0x062108fe, RCB_REG(0x33d0));
283 clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
284 writel(0x01010000, RCB_REG(0x3a28));
285 writel(0x01010404, RCB_REG(0x3a2c));
286 writel(0x01041041, RCB_REG(0x3a80));
287 clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
288 setbits_le32(RCB_REG(0x3a84), 1 << 24); /* SATA 2/3 disabled */
289 setbits_le32(RCB_REG(0x3a88), 1 << 0); /* SATA 4/5 disabled */
290 writel(0x00000001, RCB_REG(0x3a6c));
291 clrsetbits_le32(RCB_REG(0x2344), ~0x00ffff00, 0xff00000c);
292 clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
293 writel(0, RCB_REG(0x33c8));
294 setbits_le32(RCB_REG(0x21b0), 0xf);
295}
296
297/* PantherPoint PCH Power Management init */
Simon Glass4265abd2016-01-17 16:11:42 -0700298static void ppt_pm_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700299{
300 debug("PantherPoint PM init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700301 dm_pci_write_config8(pch, 0xa9, 0x47);
Simon Glass72cd0852014-11-14 18:18:35 -0700302 setbits_le32(RCB_REG(0x2238), 1 << 0);
303 setbits_le32(RCB_REG(0x228c), 1 << 0);
304 setbits_le16(RCB_REG(0x1100), (1 << 13) | (1 << 14));
305 setbits_le16(RCB_REG(0x0900), 1 << 14);
306 writel(0xc03b8400, RCB_REG(0x2304));
307 setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
308 setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
309 clrsetbits_le32(RCB_REG(0x3314), 0x1f, 0xf);
310 writel(0x054f0000, RCB_REG(0x3318));
311 writel(0x04000000, RCB_REG(0x3324));
312 setbits_le32(RCB_REG(0x3340), 0xfffff);
313 setbits_le32(RCB_REG(0x3344), (1 << 1) | (1 << 0));
314 writel(0x0001c000, RCB_REG(0x3360));
315 writel(0x00061100, RCB_REG(0x3368));
316 writel(0x7f8fdfff, RCB_REG(0x3378));
317 writel(0x000003fd, RCB_REG(0x337c));
318 writel(0x00001000, RCB_REG(0x3388));
319 writel(0x0001c000, RCB_REG(0x3390));
320 writel(0x00000800, RCB_REG(0x33a0));
321 writel(0x00001000, RCB_REG(0x33b0));
322 writel(0x00093900, RCB_REG(0x33c0));
323 writel(0x24653002, RCB_REG(0x33cc));
324 writel(0x067388fe, RCB_REG(0x33d0));
325 clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
326 writel(0x01010000, RCB_REG(0x3a28));
327 writel(0x01010404, RCB_REG(0x3a2c));
328 writel(0x01040000, RCB_REG(0x3a80));
329 clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
330 /* SATA 2/3 disabled */
331 setbits_le32(RCB_REG(0x3a84), 1 << 24);
332 /* SATA 4/5 disabled */
333 setbits_le32(RCB_REG(0x3a88), 1 << 0);
334 writel(0x00000001, RCB_REG(0x3a6c));
335 clrsetbits_le32(RCB_REG(0x2344), 0xff0000ff, 0xff00000c);
336 clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
337 setbits_le32(RCB_REG(0x33a4), (1 << 0));
338 writel(0, RCB_REG(0x33c8));
339 setbits_le32(RCB_REG(0x21b0), 0xf);
340}
341
342static void enable_hpet(void)
343{
344 /* Move HPET to default address 0xfed00000 and enable it */
345 clrsetbits_le32(RCB_REG(HPTC), 3 << 0, 1 << 7);
346}
347
Simon Glass4265abd2016-01-17 16:11:42 -0700348static void enable_clock_gating(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700349{
350 u32 reg32;
351 u16 reg16;
352
353 setbits_le32(RCB_REG(0x2234), 0xf);
354
Simon Glass4265abd2016-01-17 16:11:42 -0700355 dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700356 reg16 |= (1 << 2) | (1 << 11);
Simon Glass4265abd2016-01-17 16:11:42 -0700357 dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700358
Simon Glass2545fa52016-09-25 21:33:35 -0600359 pch_iobp_update(pch, 0xeb007f07, ~0U, 1 << 31);
360 pch_iobp_update(pch, 0xeb004000, ~0U, 1 << 7);
361 pch_iobp_update(pch, 0xec007f07, ~0U, 1 << 31);
362 pch_iobp_update(pch, 0xec004000, ~0U, 1 << 7);
Simon Glass72cd0852014-11-14 18:18:35 -0700363
364 reg32 = readl(RCB_REG(CG));
365 reg32 |= (1 << 31);
366 reg32 |= (1 << 29) | (1 << 28);
367 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
368 reg32 |= (1 << 16);
369 reg32 |= (1 << 17);
370 reg32 |= (1 << 18);
371 reg32 |= (1 << 22);
372 reg32 |= (1 << 23);
373 reg32 &= ~(1 << 20);
374 reg32 |= (1 << 19);
375 reg32 |= (1 << 0);
376 reg32 |= (0xf << 1);
377 writel(reg32, RCB_REG(CG));
378
379 setbits_le32(RCB_REG(0x38c0), 0x7);
380 setbits_le32(RCB_REG(0x36d4), 0x6680c004);
381 setbits_le32(RCB_REG(0x3564), 0x3);
382}
383
Simon Glass4265abd2016-01-17 16:11:42 -0700384static void pch_disable_smm_only_flashing(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700385{
386 u8 reg8;
387
388 debug("Enabling BIOS updates outside of SMM... ");
Simon Glass4265abd2016-01-17 16:11:42 -0700389 dm_pci_read_config8(pch, 0xdc, &reg8); /* BIOS_CNTL */
Simon Glass72cd0852014-11-14 18:18:35 -0700390 reg8 &= ~(1 << 5);
Simon Glass4265abd2016-01-17 16:11:42 -0700391 dm_pci_write_config8(pch, 0xdc, reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700392}
393
Simon Glass4265abd2016-01-17 16:11:42 -0700394static void pch_fixups(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700395{
396 u8 gen_pmcon_2;
397
398 /* Indicate DRAM init done for MRC S3 to know it can resume */
Simon Glass4265abd2016-01-17 16:11:42 -0700399 dm_pci_read_config8(pch, GEN_PMCON_2, &gen_pmcon_2);
Simon Glass72cd0852014-11-14 18:18:35 -0700400 gen_pmcon_2 |= (1 << 7);
Simon Glass4265abd2016-01-17 16:11:42 -0700401 dm_pci_write_config8(pch, GEN_PMCON_2, gen_pmcon_2);
Simon Glass72cd0852014-11-14 18:18:35 -0700402
403 /* Enable DMI ASPM in the PCH */
404 clrbits_le32(RCB_REG(0x2304), 1 << 10);
405 setbits_le32(RCB_REG(0x21a4), (1 << 11) | (1 << 10));
406 setbits_le32(RCB_REG(0x21a8), 0x3);
407}
408
Simon Glassfe40bd42016-01-17 16:11:12 -0700409static void set_spi_speed(void)
410{
411 u32 fdod;
412
413 /* Observe SPI Descriptor Component Section 0 */
414 writel(0x1000, RCB_REG(SPI_DESC_COMP0));
415
416 /* Extract the1 Write/Erase SPI Frequency from descriptor */
417 fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
418 fdod >>= 24;
419 fdod &= 7;
420
421 /* Set Software Sequence frequency to match */
422 clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
423}
424
Simon Glass4265abd2016-01-17 16:11:42 -0700425static int lpc_init_extra(struct udevice *dev)
Simon Glass72cd0852014-11-14 18:18:35 -0700426{
Simon Glass4265abd2016-01-17 16:11:42 -0700427 struct udevice *pch = dev->parent;
Simon Glass72cd0852014-11-14 18:18:35 -0700428
429 debug("pch: lpc_init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700430 dm_pci_write_bar32(pch, 0, 0);
431 dm_pci_write_bar32(pch, 1, 0xff800000);
432 dm_pci_write_bar32(pch, 2, 0xfec00000);
433 dm_pci_write_bar32(pch, 3, 0x800);
434 dm_pci_write_bar32(pch, 4, 0x900);
Simon Glass72cd0852014-11-14 18:18:35 -0700435
Simon Glass72cd0852014-11-14 18:18:35 -0700436 /* Set the value for PCI command register. */
Simon Glass4265abd2016-01-17 16:11:42 -0700437 dm_pci_write_config16(pch, PCI_COMMAND, 0x000f);
Simon Glass72cd0852014-11-14 18:18:35 -0700438
439 /* IO APIC initialization. */
Simon Glass4265abd2016-01-17 16:11:42 -0700440 pch_enable_apic(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700441
Simon Glass4265abd2016-01-17 16:11:42 -0700442 pch_enable_serial_irqs(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700443
444 /* Setup the PIRQ. */
Simon Glass4265abd2016-01-17 16:11:42 -0700445 pch_pirq_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700446
447 /* Setup power options. */
Simon Glass4265abd2016-01-17 16:11:42 -0700448 pch_power_options(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700449
450 /* Initialize power management */
Simon Glass9434c7a2016-01-17 16:11:52 -0700451 switch (pch_silicon_type(pch)) {
Simon Glass72cd0852014-11-14 18:18:35 -0700452 case PCH_TYPE_CPT: /* CougarPoint */
Simon Glass4265abd2016-01-17 16:11:42 -0700453 cpt_pm_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700454 break;
455 case PCH_TYPE_PPT: /* PantherPoint */
Simon Glass4265abd2016-01-17 16:11:42 -0700456 ppt_pm_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700457 break;
458 default:
Simon Glass4265abd2016-01-17 16:11:42 -0700459 printf("Unknown Chipset: %s\n", pch->name);
Simon Glass72cd0852014-11-14 18:18:35 -0700460 return -ENOSYS;
461 }
462
463 /* Initialize the real time clock. */
Simon Glass4265abd2016-01-17 16:11:42 -0700464 pch_rtc_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700465
466 /* Initialize the High Precision Event Timers, if present. */
467 enable_hpet();
468
469 /* Initialize Clock Gating */
Simon Glass4265abd2016-01-17 16:11:42 -0700470 enable_clock_gating(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700471
Simon Glass4265abd2016-01-17 16:11:42 -0700472 pch_disable_smm_only_flashing(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700473
Simon Glass4265abd2016-01-17 16:11:42 -0700474 pch_fixups(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700475
476 return 0;
477}
478
Simon Glassfcd30cd2016-01-17 16:11:21 -0700479static int bd82x6x_lpc_early_init(struct udevice *dev)
480{
Simon Glass8c30b572016-03-11 22:06:57 -0700481 set_spi_speed();
482
Simon Glassfcd30cd2016-01-17 16:11:21 -0700483 /* Setting up Southbridge. In the northbridge code. */
484 debug("Setting up static southbridge registers\n");
Simon Glassbb096b92016-03-11 22:06:56 -0700485 dm_pci_write_config32(dev->parent, PCH_RCBA_BASE,
486 RCB_BASE_ADDRESS | 1);
Simon Glassfcd30cd2016-01-17 16:11:21 -0700487 dm_pci_write_config32(dev->parent, PMBASE, DEFAULT_PMBASE | 1);
488
489 /* Enable ACPI BAR */
490 dm_pci_write_config8(dev->parent, ACPI_CNTL, 0x80);
491
492 debug("Disabling watchdog reboot\n");
493 setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */
494 outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
495
Simon Glass9fd11c72016-01-17 16:11:22 -0700496 dm_pci_write_config32(dev->parent, GPIO_BASE, DEFAULT_GPIOBASE | 1);
497 dm_pci_write_config32(dev->parent, GPIO_CNTL, 0x10);
498
Simon Glassfcd30cd2016-01-17 16:11:21 -0700499 return 0;
500}
501
Simon Glass4acc83d2016-01-17 16:11:10 -0700502static int bd82x6x_lpc_probe(struct udevice *dev)
503{
Simon Glass788cd902016-01-17 16:11:11 -0700504 int ret;
505
Simon Glass4e190722016-01-17 16:11:40 -0700506 if (!(gd->flags & GD_FLG_RELOC)) {
Simon Glass8c30b572016-03-11 22:06:57 -0700507 ret = lpc_common_early_init(dev);
Simon Glass4e190722016-01-17 16:11:40 -0700508 if (ret) {
509 debug("%s: lpc_early_init() failed\n", __func__);
510 return ret;
511 }
Simon Glass788cd902016-01-17 16:11:11 -0700512
Simon Glass4e190722016-01-17 16:11:40 -0700513 return bd82x6x_lpc_early_init(dev);
Simon Glass788cd902016-01-17 16:11:11 -0700514 }
515
Simon Glass4265abd2016-01-17 16:11:42 -0700516 return lpc_init_extra(dev);
Simon Glass4acc83d2016-01-17 16:11:10 -0700517}
518
Simon Glass90b16d12015-03-26 09:29:29 -0600519static const struct udevice_id bd82x6x_lpc_ids[] = {
520 { .compatible = "intel,bd82x6x-lpc" },
521 { }
522};
523
524U_BOOT_DRIVER(bd82x6x_lpc_drv) = {
525 .name = "lpc",
526 .id = UCLASS_LPC,
527 .of_match = bd82x6x_lpc_ids,
Simon Glass4acc83d2016-01-17 16:11:10 -0700528 .probe = bd82x6x_lpc_probe,
Simon Glass90b16d12015-03-26 09:29:29 -0600529};