blob: 26ffaa08d73e46098d85755bed51a4305a8b406e [file] [log] [blame]
Simon Glass2b605152014-11-12 22:42:15 -07001/*
2 * From coreboot southbridge/intel/bd82x6x/lpc.c
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * SPDX-License-Identifier: GPL-2.0
7 */
8
9#include <common.h>
Simon Glassaad78d22015-03-05 12:25:33 -070010#include <dm.h>
Simon Glass2b605152014-11-12 22:42:15 -070011#include <errno.h>
12#include <fdtdec.h>
Simon Glass72cd0852014-11-14 18:18:35 -070013#include <rtc.h>
Simon Glass2b605152014-11-12 22:42:15 -070014#include <pci.h>
Simon Glass72cd0852014-11-14 18:18:35 -070015#include <asm/acpi.h>
Simon Glassbb096b92016-03-11 22:06:56 -070016#include <asm/intel_regs.h>
Simon Glass72cd0852014-11-14 18:18:35 -070017#include <asm/interrupt.h>
18#include <asm/io.h>
19#include <asm/ioapic.h>
Simon Glass2b605152014-11-12 22:42:15 -070020#include <asm/pci.h>
21#include <asm/arch/pch.h>
22
Simon Glass72cd0852014-11-14 18:18:35 -070023#define NMI_OFF 0
24
25#define ENABLE_ACPI_MODE_IN_COREBOOT 0
26#define TEST_SMM_FLASH_LOCKDOWN 0
27
Simon Glass4265abd2016-01-17 16:11:42 -070028static int pch_enable_apic(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070029{
30 u32 reg32;
31 int i;
32
33 /* Enable ACPI I/O and power management. Set SCI IRQ to IRQ9 */
Simon Glass4265abd2016-01-17 16:11:42 -070034 dm_pci_write_config8(pch, ACPI_CNTL, 0x80);
Simon Glass72cd0852014-11-14 18:18:35 -070035
36 writel(0, IO_APIC_INDEX);
37 writel(1 << 25, IO_APIC_DATA);
38
39 /* affirm full set of redirection table entries ("write once") */
40 writel(1, IO_APIC_INDEX);
41 reg32 = readl(IO_APIC_DATA);
42 writel(1, IO_APIC_INDEX);
43 writel(reg32, IO_APIC_DATA);
44
45 writel(0, IO_APIC_INDEX);
46 reg32 = readl(IO_APIC_DATA);
47 debug("PCH APIC ID = %x\n", (reg32 >> 24) & 0x0f);
48 if (reg32 != (1 << 25)) {
49 printf("APIC Error - cannot write to registers\n");
50 return -EPERM;
51 }
52
53 debug("Dumping IOAPIC registers\n");
54 for (i = 0; i < 3; i++) {
55 writel(i, IO_APIC_INDEX);
56 debug(" reg 0x%04x:", i);
57 reg32 = readl(IO_APIC_DATA);
58 debug(" 0x%08x\n", reg32);
59 }
60
61 /* Select Boot Configuration register. */
62 writel(3, IO_APIC_INDEX);
63
64 /* Use Processor System Bus to deliver interrupts. */
65 writel(1, IO_APIC_DATA);
66
67 return 0;
68}
69
Simon Glass4265abd2016-01-17 16:11:42 -070070static void pch_enable_serial_irqs(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070071{
72 u32 value;
73
74 /* Set packet length and toggle silent mode bit for one frame. */
75 value = (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0);
76#ifdef CONFIG_SERIRQ_CONTINUOUS_MODE
Simon Glass4265abd2016-01-17 16:11:42 -070077 dm_pci_write_config8(pch, SERIRQ_CNTL, value);
Simon Glass72cd0852014-11-14 18:18:35 -070078#else
Simon Glass4265abd2016-01-17 16:11:42 -070079 dm_pci_write_config8(pch, SERIRQ_CNTL, value | (1 << 6));
Simon Glass72cd0852014-11-14 18:18:35 -070080#endif
81}
82
Simon Glass4265abd2016-01-17 16:11:42 -070083static int pch_pirq_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -070084{
85 uint8_t route[8], *ptr;
86
Simon Glass4265abd2016-01-17 16:11:42 -070087 if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
88 "intel,pirq-routing", route, sizeof(route)))
Simon Glass72cd0852014-11-14 18:18:35 -070089 return -EINVAL;
90 ptr = route;
Simon Glass4265abd2016-01-17 16:11:42 -070091 dm_pci_write_config8(pch, PIRQA_ROUT, *ptr++);
92 dm_pci_write_config8(pch, PIRQB_ROUT, *ptr++);
93 dm_pci_write_config8(pch, PIRQC_ROUT, *ptr++);
94 dm_pci_write_config8(pch, PIRQD_ROUT, *ptr++);
Simon Glass72cd0852014-11-14 18:18:35 -070095
Simon Glass4265abd2016-01-17 16:11:42 -070096 dm_pci_write_config8(pch, PIRQE_ROUT, *ptr++);
97 dm_pci_write_config8(pch, PIRQF_ROUT, *ptr++);
98 dm_pci_write_config8(pch, PIRQG_ROUT, *ptr++);
99 dm_pci_write_config8(pch, PIRQH_ROUT, *ptr++);
Simon Glass72cd0852014-11-14 18:18:35 -0700100
101 /*
102 * TODO(sjg@chromium.org): U-Boot does not set up the interrupts
103 * here. It's unclear if it is needed
104 */
105 return 0;
106}
107
Simon Glass4265abd2016-01-17 16:11:42 -0700108static int pch_gpi_routing(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700109{
110 u8 route[16];
111 u32 reg;
112 int gpi;
113
Simon Glass4265abd2016-01-17 16:11:42 -0700114 if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
115 "intel,gpi-routing", route, sizeof(route)))
Simon Glass72cd0852014-11-14 18:18:35 -0700116 return -EINVAL;
117
118 for (reg = 0, gpi = 0; gpi < ARRAY_SIZE(route); gpi++)
119 reg |= route[gpi] << (gpi * 2);
120
Simon Glass4265abd2016-01-17 16:11:42 -0700121 dm_pci_write_config32(pch, 0xb8, reg);
Simon Glass72cd0852014-11-14 18:18:35 -0700122
123 return 0;
124}
125
Simon Glass4265abd2016-01-17 16:11:42 -0700126static int pch_power_options(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700127{
Simon Glass4265abd2016-01-17 16:11:42 -0700128 const void *blob = gd->fdt_blob;
129 int node = pch->of_offset;
Simon Glass72cd0852014-11-14 18:18:35 -0700130 u8 reg8;
131 u16 reg16, pmbase;
132 u32 reg32;
133 const char *state;
134 int pwr_on;
135 int nmi_option;
136 int ret;
137
138 /*
139 * Which state do we want to goto after g3 (power restored)?
140 * 0 == S0 Full On
141 * 1 == S5 Soft Off
142 *
143 * If the option is not existent (Laptops), use Kconfig setting.
144 * TODO(sjg@chromium.org): Make this configurable
145 */
146 pwr_on = MAINBOARD_POWER_ON;
147
Simon Glass4265abd2016-01-17 16:11:42 -0700148 dm_pci_read_config16(pch, GEN_PMCON_3, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700149 reg16 &= 0xfffe;
150 switch (pwr_on) {
151 case MAINBOARD_POWER_OFF:
152 reg16 |= 1;
153 state = "off";
154 break;
155 case MAINBOARD_POWER_ON:
156 reg16 &= ~1;
157 state = "on";
158 break;
159 case MAINBOARD_POWER_KEEP:
160 reg16 &= ~1;
161 state = "state keep";
162 break;
163 default:
164 state = "undefined";
165 }
166
167 reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
168 reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
169
170 reg16 &= ~(1 << 10);
171 reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
172
173 reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
174
Simon Glass4265abd2016-01-17 16:11:42 -0700175 dm_pci_write_config16(pch, GEN_PMCON_3, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700176 debug("Set power %s after power failure.\n", state);
177
178 /* Set up NMI on errors. */
179 reg8 = inb(0x61);
180 reg8 &= 0x0f; /* Higher Nibble must be 0 */
181 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
182 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
183 outb(reg8, 0x61);
184
185 reg8 = inb(0x70);
186 /* TODO(sjg@chromium.org): Make this configurable */
187 nmi_option = NMI_OFF;
188 if (nmi_option) {
189 debug("NMI sources enabled.\n");
190 reg8 &= ~(1 << 7); /* Set NMI. */
191 } else {
192 debug("NMI sources disabled.\n");
193 /* Can't mask NMI from PCI-E and NMI_NOW */
194 reg8 |= (1 << 7);
195 }
196 outb(reg8, 0x70);
197
198 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Simon Glass4265abd2016-01-17 16:11:42 -0700199 dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700200 reg16 &= ~(3 << 0); /* SMI# rate 1 minute */
201 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
202#if DEBUG_PERIODIC_SMIS
203 /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using periodic SMIs */
204 reg16 |= (3 << 0); /* Periodic SMI every 8s */
205#endif
Simon Glass4265abd2016-01-17 16:11:42 -0700206 dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700207
208 /* Set the board's GPI routing. */
Simon Glass4265abd2016-01-17 16:11:42 -0700209 ret = pch_gpi_routing(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700210 if (ret)
211 return ret;
212
Simon Glass4265abd2016-01-17 16:11:42 -0700213 dm_pci_read_config16(pch, 0x40, &pmbase);
214 pmbase &= 0xfffe;
Simon Glass72cd0852014-11-14 18:18:35 -0700215
216 writel(pmbase + GPE0_EN, fdtdec_get_int(blob, node,
217 "intel,gpe0-enable", 0));
218 writew(pmbase + ALT_GP_SMI_EN, fdtdec_get_int(blob, node,
219 "intel,alt-gp-smi-enable", 0));
220
221 /* Set up power management block and determine sleep mode */
222 reg32 = inl(pmbase + 0x04); /* PM1_CNT */
223 reg32 &= ~(7 << 10); /* SLP_TYP */
224 reg32 |= (1 << 0); /* SCI_EN */
225 outl(reg32, pmbase + 0x04);
226
227 /* Clear magic status bits to prevent unexpected wake */
228 setbits_le32(RCB_REG(0x3310), (1 << 4) | (1 << 5) | (1 << 0));
229 clrbits_le32(RCB_REG(0x3f02), 0xf);
230
231 return 0;
232}
233
Simon Glass4265abd2016-01-17 16:11:42 -0700234static void pch_rtc_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700235{
236 int rtc_failed;
237 u8 reg8;
238
Simon Glass4265abd2016-01-17 16:11:42 -0700239 dm_pci_read_config8(pch, GEN_PMCON_3, &reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700240 rtc_failed = reg8 & RTC_BATTERY_DEAD;
241 if (rtc_failed) {
242 reg8 &= ~RTC_BATTERY_DEAD;
Simon Glass4265abd2016-01-17 16:11:42 -0700243 dm_pci_write_config8(pch, GEN_PMCON_3, reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700244 }
245 debug("rtc_failed = 0x%x\n", rtc_failed);
246
Simon Glass72cd0852014-11-14 18:18:35 -0700247 /* TODO: Handle power failure */
248 if (rtc_failed)
249 printf("RTC power failed\n");
Simon Glass72cd0852014-11-14 18:18:35 -0700250}
251
252/* CougarPoint PCH Power Management init */
Simon Glass4265abd2016-01-17 16:11:42 -0700253static void cpt_pm_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700254{
255 debug("CougarPoint PM init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700256 dm_pci_write_config8(pch, 0xa9, 0x47);
Simon Glass72cd0852014-11-14 18:18:35 -0700257 setbits_le32(RCB_REG(0x2238), (1 << 6) | (1 << 0));
258
259 setbits_le32(RCB_REG(0x228c), 1 << 0);
260 setbits_le32(RCB_REG(0x1100), (1 << 13) | (1 << 14));
261 setbits_le32(RCB_REG(0x0900), 1 << 14);
262 writel(0xc0388400, RCB_REG(0x2304));
263 setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
264 setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
265 clrsetbits_le32(RCB_REG(0x3314), ~0x1f, 0xf);
266 writel(0x050f0000, RCB_REG(0x3318));
267 writel(0x04000000, RCB_REG(0x3324));
268 setbits_le32(RCB_REG(0x3340), 0xfffff);
269 setbits_le32(RCB_REG(0x3344), 1 << 1);
270
271 writel(0x0001c000, RCB_REG(0x3360));
272 writel(0x00061100, RCB_REG(0x3368));
273 writel(0x7f8fdfff, RCB_REG(0x3378));
274 writel(0x000003fc, RCB_REG(0x337c));
275 writel(0x00001000, RCB_REG(0x3388));
276 writel(0x0001c000, RCB_REG(0x3390));
277 writel(0x00000800, RCB_REG(0x33a0));
278 writel(0x00001000, RCB_REG(0x33b0));
279 writel(0x00093900, RCB_REG(0x33c0));
280 writel(0x24653002, RCB_REG(0x33cc));
281 writel(0x062108fe, RCB_REG(0x33d0));
282 clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
283 writel(0x01010000, RCB_REG(0x3a28));
284 writel(0x01010404, RCB_REG(0x3a2c));
285 writel(0x01041041, RCB_REG(0x3a80));
286 clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
287 setbits_le32(RCB_REG(0x3a84), 1 << 24); /* SATA 2/3 disabled */
288 setbits_le32(RCB_REG(0x3a88), 1 << 0); /* SATA 4/5 disabled */
289 writel(0x00000001, RCB_REG(0x3a6c));
290 clrsetbits_le32(RCB_REG(0x2344), ~0x00ffff00, 0xff00000c);
291 clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
292 writel(0, RCB_REG(0x33c8));
293 setbits_le32(RCB_REG(0x21b0), 0xf);
294}
295
296/* PantherPoint PCH Power Management init */
Simon Glass4265abd2016-01-17 16:11:42 -0700297static void ppt_pm_init(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700298{
299 debug("PantherPoint PM init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700300 dm_pci_write_config8(pch, 0xa9, 0x47);
Simon Glass72cd0852014-11-14 18:18:35 -0700301 setbits_le32(RCB_REG(0x2238), 1 << 0);
302 setbits_le32(RCB_REG(0x228c), 1 << 0);
303 setbits_le16(RCB_REG(0x1100), (1 << 13) | (1 << 14));
304 setbits_le16(RCB_REG(0x0900), 1 << 14);
305 writel(0xc03b8400, RCB_REG(0x2304));
306 setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18));
307 setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1));
308 clrsetbits_le32(RCB_REG(0x3314), 0x1f, 0xf);
309 writel(0x054f0000, RCB_REG(0x3318));
310 writel(0x04000000, RCB_REG(0x3324));
311 setbits_le32(RCB_REG(0x3340), 0xfffff);
312 setbits_le32(RCB_REG(0x3344), (1 << 1) | (1 << 0));
313 writel(0x0001c000, RCB_REG(0x3360));
314 writel(0x00061100, RCB_REG(0x3368));
315 writel(0x7f8fdfff, RCB_REG(0x3378));
316 writel(0x000003fd, RCB_REG(0x337c));
317 writel(0x00001000, RCB_REG(0x3388));
318 writel(0x0001c000, RCB_REG(0x3390));
319 writel(0x00000800, RCB_REG(0x33a0));
320 writel(0x00001000, RCB_REG(0x33b0));
321 writel(0x00093900, RCB_REG(0x33c0));
322 writel(0x24653002, RCB_REG(0x33cc));
323 writel(0x067388fe, RCB_REG(0x33d0));
324 clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060);
325 writel(0x01010000, RCB_REG(0x3a28));
326 writel(0x01010404, RCB_REG(0x3a2c));
327 writel(0x01040000, RCB_REG(0x3a80));
328 clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001);
329 /* SATA 2/3 disabled */
330 setbits_le32(RCB_REG(0x3a84), 1 << 24);
331 /* SATA 4/5 disabled */
332 setbits_le32(RCB_REG(0x3a88), 1 << 0);
333 writel(0x00000001, RCB_REG(0x3a6c));
334 clrsetbits_le32(RCB_REG(0x2344), 0xff0000ff, 0xff00000c);
335 clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20);
336 setbits_le32(RCB_REG(0x33a4), (1 << 0));
337 writel(0, RCB_REG(0x33c8));
338 setbits_le32(RCB_REG(0x21b0), 0xf);
339}
340
341static void enable_hpet(void)
342{
343 /* Move HPET to default address 0xfed00000 and enable it */
344 clrsetbits_le32(RCB_REG(HPTC), 3 << 0, 1 << 7);
345}
346
Simon Glass4265abd2016-01-17 16:11:42 -0700347static void enable_clock_gating(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700348{
349 u32 reg32;
350 u16 reg16;
351
352 setbits_le32(RCB_REG(0x2234), 0xf);
353
Simon Glass4265abd2016-01-17 16:11:42 -0700354 dm_pci_read_config16(pch, GEN_PMCON_1, &reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700355 reg16 |= (1 << 2) | (1 << 11);
Simon Glass4265abd2016-01-17 16:11:42 -0700356 dm_pci_write_config16(pch, GEN_PMCON_1, reg16);
Simon Glass72cd0852014-11-14 18:18:35 -0700357
Simon Glass9434c7a2016-01-17 16:11:52 -0700358 pch_iobp_update(pch, 0xEB007F07, ~0UL, (1 << 31));
359 pch_iobp_update(pch, 0xEB004000, ~0UL, (1 << 7));
360 pch_iobp_update(pch, 0xEC007F07, ~0UL, (1 << 31));
361 pch_iobp_update(pch, 0xEC004000, ~0UL, (1 << 7));
Simon Glass72cd0852014-11-14 18:18:35 -0700362
363 reg32 = readl(RCB_REG(CG));
364 reg32 |= (1 << 31);
365 reg32 |= (1 << 29) | (1 << 28);
366 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
367 reg32 |= (1 << 16);
368 reg32 |= (1 << 17);
369 reg32 |= (1 << 18);
370 reg32 |= (1 << 22);
371 reg32 |= (1 << 23);
372 reg32 &= ~(1 << 20);
373 reg32 |= (1 << 19);
374 reg32 |= (1 << 0);
375 reg32 |= (0xf << 1);
376 writel(reg32, RCB_REG(CG));
377
378 setbits_le32(RCB_REG(0x38c0), 0x7);
379 setbits_le32(RCB_REG(0x36d4), 0x6680c004);
380 setbits_le32(RCB_REG(0x3564), 0x3);
381}
382
Simon Glass4265abd2016-01-17 16:11:42 -0700383static void pch_disable_smm_only_flashing(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700384{
385 u8 reg8;
386
387 debug("Enabling BIOS updates outside of SMM... ");
Simon Glass4265abd2016-01-17 16:11:42 -0700388 dm_pci_read_config8(pch, 0xdc, &reg8); /* BIOS_CNTL */
Simon Glass72cd0852014-11-14 18:18:35 -0700389 reg8 &= ~(1 << 5);
Simon Glass4265abd2016-01-17 16:11:42 -0700390 dm_pci_write_config8(pch, 0xdc, reg8);
Simon Glass72cd0852014-11-14 18:18:35 -0700391}
392
Simon Glass4265abd2016-01-17 16:11:42 -0700393static void pch_fixups(struct udevice *pch)
Simon Glass72cd0852014-11-14 18:18:35 -0700394{
395 u8 gen_pmcon_2;
396
397 /* Indicate DRAM init done for MRC S3 to know it can resume */
Simon Glass4265abd2016-01-17 16:11:42 -0700398 dm_pci_read_config8(pch, GEN_PMCON_2, &gen_pmcon_2);
Simon Glass72cd0852014-11-14 18:18:35 -0700399 gen_pmcon_2 |= (1 << 7);
Simon Glass4265abd2016-01-17 16:11:42 -0700400 dm_pci_write_config8(pch, GEN_PMCON_2, gen_pmcon_2);
Simon Glass72cd0852014-11-14 18:18:35 -0700401
402 /* Enable DMI ASPM in the PCH */
403 clrbits_le32(RCB_REG(0x2304), 1 << 10);
404 setbits_le32(RCB_REG(0x21a4), (1 << 11) | (1 << 10));
405 setbits_le32(RCB_REG(0x21a8), 0x3);
406}
407
Simon Glassfe40bd42016-01-17 16:11:12 -0700408/*
409 * Enable Prefetching and Caching.
410 */
411static void enable_spi_prefetch(struct udevice *pch)
412{
413 u8 reg8;
414
415 dm_pci_read_config8(pch, 0xdc, &reg8);
416 reg8 &= ~(3 << 2);
417 reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
418 dm_pci_write_config8(pch, 0xdc, reg8);
419}
420
421static void enable_port80_on_lpc(struct udevice *pch)
422{
423 /* Enable port 80 POST on LPC */
Simon Glassbb096b92016-03-11 22:06:56 -0700424 dm_pci_write_config32(pch, PCH_RCBA_BASE, RCB_BASE_ADDRESS | 1);
Simon Glassfe40bd42016-01-17 16:11:12 -0700425 clrbits_le32(RCB_REG(GCS), 4);
426}
427
428static void set_spi_speed(void)
429{
430 u32 fdod;
431
432 /* Observe SPI Descriptor Component Section 0 */
433 writel(0x1000, RCB_REG(SPI_DESC_COMP0));
434
435 /* Extract the1 Write/Erase SPI Frequency from descriptor */
436 fdod = readl(RCB_REG(SPI_FREQ_WR_ERA));
437 fdod >>= 24;
438 fdod &= 7;
439
440 /* Set Software Sequence frequency to match */
441 clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod);
442}
443
Simon Glass788cd902016-01-17 16:11:11 -0700444/**
445 * lpc_early_init() - set up LPC serial ports and other early things
446 *
447 * @dev: LPC device
448 * @return 0 if OK, -ve on error
449 */
450static int lpc_early_init(struct udevice *dev)
Simon Glass2b605152014-11-12 22:42:15 -0700451{
452 struct reg_info {
453 u32 base;
454 u32 size;
455 } values[4], *ptr;
456 int count;
457 int i;
458
Simon Glass788cd902016-01-17 16:11:11 -0700459 count = fdtdec_get_int_array_count(gd->fdt_blob, dev->of_offset,
460 "intel,gen-dec", (u32 *)values,
461 sizeof(values) / sizeof(u32));
Simon Glass2b605152014-11-12 22:42:15 -0700462 if (count < 0)
463 return -EINVAL;
464
465 /* Set COM1/COM2 decode range */
Simon Glass788cd902016-01-17 16:11:11 -0700466 dm_pci_write_config16(dev->parent, LPC_IO_DEC, 0x0010);
Simon Glass2b605152014-11-12 22:42:15 -0700467
468 /* Enable PS/2 Keyboard/Mouse, EC areas and COM1 */
Simon Glass788cd902016-01-17 16:11:11 -0700469 dm_pci_write_config16(dev->parent, LPC_EN, KBC_LPC_EN | MC_LPC_EN |
470 GAMEL_LPC_EN | COMA_LPC_EN);
Simon Glass2b605152014-11-12 22:42:15 -0700471
472 /* Write all registers but use 0 if we run out of data */
473 count = count * sizeof(u32) / sizeof(values[0]);
474 for (i = 0, ptr = values; i < ARRAY_SIZE(values); i++, ptr++) {
475 u32 reg = 0;
476
477 if (i < count)
478 reg = ptr->base | PCI_COMMAND_IO | (ptr->size << 16);
Simon Glass788cd902016-01-17 16:11:11 -0700479 dm_pci_write_config32(dev->parent, LPC_GENX_DEC(i), reg);
Simon Glass2b605152014-11-12 22:42:15 -0700480 }
481
Simon Glassfe40bd42016-01-17 16:11:12 -0700482 enable_spi_prefetch(dev->parent);
483
484 /* This is already done in start.S, but let's do it in C */
485 enable_port80_on_lpc(dev->parent);
486
487 set_spi_speed();
488
Simon Glass2b605152014-11-12 22:42:15 -0700489 return 0;
490}
Simon Glass72cd0852014-11-14 18:18:35 -0700491
Simon Glass4265abd2016-01-17 16:11:42 -0700492static int lpc_init_extra(struct udevice *dev)
Simon Glass72cd0852014-11-14 18:18:35 -0700493{
Simon Glass4265abd2016-01-17 16:11:42 -0700494 struct udevice *pch = dev->parent;
Simon Glass72cd0852014-11-14 18:18:35 -0700495 const void *blob = gd->fdt_blob;
496 int node;
497
498 debug("pch: lpc_init\n");
Simon Glass4265abd2016-01-17 16:11:42 -0700499 dm_pci_write_bar32(pch, 0, 0);
500 dm_pci_write_bar32(pch, 1, 0xff800000);
501 dm_pci_write_bar32(pch, 2, 0xfec00000);
502 dm_pci_write_bar32(pch, 3, 0x800);
503 dm_pci_write_bar32(pch, 4, 0x900);
Simon Glass72cd0852014-11-14 18:18:35 -0700504
Simon Glass90b16d12015-03-26 09:29:29 -0600505 node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_PCH);
Simon Glass72cd0852014-11-14 18:18:35 -0700506 if (node < 0)
507 return -ENOENT;
508
509 /* Set the value for PCI command register. */
Simon Glass4265abd2016-01-17 16:11:42 -0700510 dm_pci_write_config16(pch, PCI_COMMAND, 0x000f);
Simon Glass72cd0852014-11-14 18:18:35 -0700511
512 /* IO APIC initialization. */
Simon Glass4265abd2016-01-17 16:11:42 -0700513 pch_enable_apic(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700514
Simon Glass4265abd2016-01-17 16:11:42 -0700515 pch_enable_serial_irqs(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700516
517 /* Setup the PIRQ. */
Simon Glass4265abd2016-01-17 16:11:42 -0700518 pch_pirq_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700519
520 /* Setup power options. */
Simon Glass4265abd2016-01-17 16:11:42 -0700521 pch_power_options(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700522
523 /* Initialize power management */
Simon Glass9434c7a2016-01-17 16:11:52 -0700524 switch (pch_silicon_type(pch)) {
Simon Glass72cd0852014-11-14 18:18:35 -0700525 case PCH_TYPE_CPT: /* CougarPoint */
Simon Glass4265abd2016-01-17 16:11:42 -0700526 cpt_pm_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700527 break;
528 case PCH_TYPE_PPT: /* PantherPoint */
Simon Glass4265abd2016-01-17 16:11:42 -0700529 ppt_pm_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700530 break;
531 default:
Simon Glass4265abd2016-01-17 16:11:42 -0700532 printf("Unknown Chipset: %s\n", pch->name);
Simon Glass72cd0852014-11-14 18:18:35 -0700533 return -ENOSYS;
534 }
535
536 /* Initialize the real time clock. */
Simon Glass4265abd2016-01-17 16:11:42 -0700537 pch_rtc_init(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700538
539 /* Initialize the High Precision Event Timers, if present. */
540 enable_hpet();
541
542 /* Initialize Clock Gating */
Simon Glass4265abd2016-01-17 16:11:42 -0700543 enable_clock_gating(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700544
Simon Glass4265abd2016-01-17 16:11:42 -0700545 pch_disable_smm_only_flashing(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700546
Simon Glass4265abd2016-01-17 16:11:42 -0700547 pch_fixups(pch);
Simon Glass72cd0852014-11-14 18:18:35 -0700548
549 return 0;
550}
551
Simon Glassfcd30cd2016-01-17 16:11:21 -0700552static int bd82x6x_lpc_early_init(struct udevice *dev)
553{
554 /* Setting up Southbridge. In the northbridge code. */
555 debug("Setting up static southbridge registers\n");
Simon Glassbb096b92016-03-11 22:06:56 -0700556 dm_pci_write_config32(dev->parent, PCH_RCBA_BASE,
557 RCB_BASE_ADDRESS | 1);
Simon Glassfcd30cd2016-01-17 16:11:21 -0700558 dm_pci_write_config32(dev->parent, PMBASE, DEFAULT_PMBASE | 1);
559
560 /* Enable ACPI BAR */
561 dm_pci_write_config8(dev->parent, ACPI_CNTL, 0x80);
562
563 debug("Disabling watchdog reboot\n");
564 setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */
565 outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */
566
Simon Glass9fd11c72016-01-17 16:11:22 -0700567 dm_pci_write_config32(dev->parent, GPIO_BASE, DEFAULT_GPIOBASE | 1);
568 dm_pci_write_config32(dev->parent, GPIO_CNTL, 0x10);
569
Simon Glassfcd30cd2016-01-17 16:11:21 -0700570 return 0;
571}
572
Simon Glass4acc83d2016-01-17 16:11:10 -0700573static int bd82x6x_lpc_probe(struct udevice *dev)
574{
Simon Glass788cd902016-01-17 16:11:11 -0700575 int ret;
576
Simon Glass4e190722016-01-17 16:11:40 -0700577 if (!(gd->flags & GD_FLG_RELOC)) {
578 ret = lpc_early_init(dev);
579 if (ret) {
580 debug("%s: lpc_early_init() failed\n", __func__);
581 return ret;
582 }
Simon Glass788cd902016-01-17 16:11:11 -0700583
Simon Glass4e190722016-01-17 16:11:40 -0700584 return bd82x6x_lpc_early_init(dev);
Simon Glass788cd902016-01-17 16:11:11 -0700585 }
586
Simon Glass4265abd2016-01-17 16:11:42 -0700587 return lpc_init_extra(dev);
Simon Glass4acc83d2016-01-17 16:11:10 -0700588}
589
Simon Glass90b16d12015-03-26 09:29:29 -0600590static const struct udevice_id bd82x6x_lpc_ids[] = {
591 { .compatible = "intel,bd82x6x-lpc" },
592 { }
593};
594
595U_BOOT_DRIVER(bd82x6x_lpc_drv) = {
596 .name = "lpc",
597 .id = UCLASS_LPC,
598 .of_match = bd82x6x_lpc_ids,
Simon Glass4acc83d2016-01-17 16:11:10 -0700599 .probe = bd82x6x_lpc_probe,
Simon Glass90b16d12015-03-26 09:29:29 -0600600};