blob: ec4d473a58b54ecd2aa93fbe6524bd546517b060 [file] [log] [blame]
Duncan Laurie55cdf552013-03-08 16:01:44 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22/*
23 * Helper functions for dealing with power management registers
24 * and the differences between LynxPoint-H and LynxPoint-LP.
25 */
26
27#include <arch/io.h>
28#ifdef __SMM__
29#include <arch/romcc_io.h>
30#include <device/pci_def.h>
31#else /* !__SMM__ */
32#include <device/device.h>
33#include <device/pci.h>
34#endif
35
36#include <console/console.h>
37#include "pch.h"
38
39#if CONFIG_INTEL_LYNXPOINT_LP
40#include "lp_gpio.h"
41#endif
42
43/* These defines are here to handle the LP variant code dynamically. If these
44 * values are defined in lp_gpio.h but when a non-LP board is being built, the
45 * build will fail. */
46#define GPIO_ALT_GPI_SMI_STS 0x50
47#define GPIO_ALT_GPI_SMI_EN 0x54
48
49/* Print status bits with descriptive names */
50static void print_status_bits(u32 status, const char *bit_names[])
51{
52 int i;
53
54 if (!status)
55 return;
56
57 for (i=31; i>=0; i--) {
58 if (status & (1 << i)) {
59 if (bit_names[i])
60 printk(BIOS_DEBUG, "%s ", bit_names[i]);
61 else
62 printk(BIOS_DEBUG, "BIT%d ", i);
63 }
64 }
65}
66
67/* Print status bits as GPIO numbers */
68static void print_gpio_status(u32 status, int start)
69{
70 int i;
71
72 if (!status)
73 return;
74
75 for (i=31; i>=0; i--) {
76 if (status & (1 << i))
77 printk(BIOS_DEBUG, "GPIO%d ", start + i);
78 }
79}
80
81
82/*
83 * PM1_CNT
84 */
85
86/* Enable events in PM1 control register */
87void enable_pm1_control(u32 mask)
88{
89 u32 pm1_cnt = inl(get_pmbase() + PM1_CNT);
90 pm1_cnt |= mask;
91 outl(pm1_cnt, get_pmbase() + PM1_CNT);
92}
93
94/* Disable events in PM1 control register */
95void disable_pm1_control(u32 mask)
96{
97 u32 pm1_cnt = inl(get_pmbase() + PM1_CNT);
98 pm1_cnt &= ~mask;
99 outl(pm1_cnt, get_pmbase() + PM1_CNT);
100}
101
102
103/*
104 * PM1
105 */
106
107/* Clear and return PM1 status register */
108static u16 reset_pm1_status(void)
109{
110 u16 pm1_sts = inw(get_pmbase() + PM1_STS);
111 outw(pm1_sts, get_pmbase() + PM1_STS);
112 return pm1_sts;
113}
114
115/* Print PM1 status bits */
116static u16 print_pm1_status(u16 pm1_sts)
117{
118 const char *pm1_sts_bits[] = {
119 [0] = "TMROF",
120 [4] = "BM",
121 [5] = "GBL",
122 [8] = "PWRBTN",
123 [10] = "RTC",
124 [11] = "PRBTNOR",
125 [14] = "PCIEXPWAK",
126 [15] = "WAK",
127 };
128
129 if (!pm1_sts)
130 return 0;
131
132 printk(BIOS_SPEW, "PM1_STS: ");
133 print_status_bits(pm1_sts, pm1_sts_bits);
134 printk(BIOS_SPEW, "\n");
135
136 return pm1_sts;
137}
138
139/* Print, clear, and return PM1 status */
140u16 clear_pm1_status(void)
141{
142 return print_pm1_status(reset_pm1_status());
143}
144
145/* Enable PM1 event */
146void enable_pm1(u32 mask)
147{
148 u32 pm1_en = inl(get_pmbase() + PM1_EN);
149 pm1_en |= mask;
150 outl(pm1_en, get_pmbase() + PM1_EN);
151}
152
153
154/*
155 * SMI
156 */
157
158/* Clear and return SMI status register */
159static u32 reset_smi_status(void)
160{
161 u32 smi_sts = inl(get_pmbase() + SMI_STS);
162 outl(smi_sts, get_pmbase() + SMI_STS);
163 return smi_sts;
164}
165
166/* Print SMI status bits */
167static u32 print_smi_status(u32 smi_sts)
168{
169 const char *smi_sts_bits[] = {
170 [2] = "BIOS",
171 [3] = "LEGACY_USB",
172 [4] = "SLP_SMI",
173 [5] = "APM",
174 [6] = "SWSMI_TMR",
175 [8] = "PM1",
176 [9] = "GPE0",
177 [10] = "GPI",
178 [11] = "MCSMI",
179 [12] = "DEVMON",
180 [13] = "TCO",
181 [14] = "PERIODIC",
182 [15] = "SERIRQ_SMI",
183 [16] = "SMBUS_SMI",
184 [17] = "LEGACY_USB2",
185 [18] = "INTEL_USB2",
186 [20] = "PCI_EXP_SMI",
187 [21] = "MONITOR",
188 [26] = "SPI",
189 [27] = "GPIO_UNLOCK"
190 };
191
192 if (!smi_sts)
193 return 0;
194
195 printk(BIOS_DEBUG, "SMI_STS: ");
196 print_status_bits(smi_sts, smi_sts_bits);
197 printk(BIOS_DEBUG, "\n");
198
199 return smi_sts;
200}
201
202/* Print, clear, and return SMI status */
203u32 clear_smi_status(void)
204{
205 return print_smi_status(reset_smi_status());
206}
207
208/* Enable SMI event */
209void enable_smi(u32 mask)
210{
211 u32 smi_en = inl(get_pmbase() + SMI_EN);
212 smi_en |= mask;
213 outl(smi_en, get_pmbase() + SMI_EN);
214}
215
216/* Disable SMI event */
217void disable_smi(u32 mask)
218{
219 u32 smi_en = inl(get_pmbase() + SMI_EN);
220 smi_en &= ~mask;
221 outl(smi_en, get_pmbase() + SMI_EN);
222}
223
224
225/*
226 * ALT_GP_SMI
227 */
228
229/* Clear GPIO SMI status and return events that are enabled and active */
230static u32 reset_alt_smi_status(void)
231{
232 u32 alt_sts, alt_en;
233
234 if (pch_is_lp()) {
235 /* LynxPoint-LP moves this to GPIO region as dword */
236 alt_sts = inl(get_gpiobase() + GPIO_ALT_GPI_SMI_STS);
237 outl(alt_sts, get_gpiobase() + GPIO_ALT_GPI_SMI_STS);
238
239 alt_en = inl(get_gpiobase() + GPIO_ALT_GPI_SMI_EN);
240 } else {
241 u16 pmbase = get_pmbase();
242
243 /* LynxPoint-H adds a second enable/status word */
244 alt_sts = inw(pmbase + ALT_GP_SMI_STS2);
245 outw(alt_sts & 0xffff, pmbase + ALT_GP_SMI_STS2);
246
247 alt_sts <<= 16;
248 alt_sts |= inw(pmbase + ALT_GP_SMI_STS);
249 outw(alt_sts & 0xffff, pmbase + ALT_GP_SMI_STS);
250
251 alt_en = inw(pmbase + ALT_GP_SMI_EN2);
252 alt_en <<= 16;
253 alt_en |= inw(pmbase + ALT_GP_SMI_EN);
254 }
255
256 /* Only report enabled events */
257 return alt_sts & alt_en;
258}
259
260/* Print GPIO SMI status bits */
261static u32 print_alt_smi_status(u32 alt_sts)
262{
263 if (!alt_sts)
264 return 0;
265
266 printk(BIOS_DEBUG, "ALT_STS: ");
267
268 if (pch_is_lp()) {
269 /* First 16 events are GPIO 32-47 */
270 print_gpio_status(alt_sts & 0xffff, 32);
271 } else {
272 const char *alt_sts_bits_high[] = {
273 [0] = "GPIO17",
274 [1] = "GPIO19",
275 [2] = "GPIO21",
276 [3] = "GPIO22",
277 [4] = "GPIO43",
278 [5] = "GPIO56",
279 [6] = "GPIO57",
280 [7] = "GPIO60",
281 };
282
283 /* First 16 events are GPIO 0-15 */
284 print_gpio_status(alt_sts & 0xffff, 0);
285 print_status_bits(alt_sts >> 16, alt_sts_bits_high);
286 }
287
288 printk(BIOS_DEBUG, "\n");
289
290 return alt_sts;
291}
292
293/* Print, clear, and return GPIO SMI status */
294u32 clear_alt_smi_status(void)
295{
296 return print_alt_smi_status(reset_alt_smi_status());
297}
298
299/* Enable GPIO SMI events */
300void enable_alt_smi(u32 mask)
301{
302 if (pch_is_lp()) {
303 u32 alt_en;
304
305 alt_en = inl(get_gpiobase() + GPIO_ALT_GPI_SMI_EN);
306 alt_en |= mask;
307 outl(alt_en, get_gpiobase() + GPIO_ALT_GPI_SMI_EN);
308 } else {
309 u16 pmbase = get_pmbase();
310 u16 alt_en;
311
312 /* Lower enable register */
313 alt_en = inw(pmbase + ALT_GP_SMI_EN);
314 alt_en |= mask & 0xffff;
315 outw(alt_en, pmbase + ALT_GP_SMI_EN);
316
317 /* Upper enable register */
318 alt_en = inw(pmbase + ALT_GP_SMI_EN2);
319 alt_en |= (mask >> 16) & 0xffff;
320 outw(alt_en, pmbase + ALT_GP_SMI_EN2);
321 }
322}
323
324
325/*
326 * TCO
327 */
328
329/* Clear TCO status and return events that are enabled and active */
330static u32 reset_tco_status(void)
331{
332 u32 tcobase = get_pmbase() + 0x60;
333 u32 tco_sts = inl(tcobase + 0x04);
334 u32 tco_en = inl(get_pmbase() + 0x68);
335
336 /* Don't clear BOOT_STS before SECOND_TO_STS */
337 outl(tco_sts & ~(1 << 18), tcobase + 0x04);
338
339 /* Clear BOOT_STS */
340 if (tco_sts & (1 << 18))
341 outl(tco_sts & (1 << 18), tcobase + 0x04);
342
343 return tco_sts & tco_en;
344}
345
346/* Print TCO status bits */
347static u32 print_tco_status(u32 tco_sts)
348{
349 const char *tco_sts_bits[] = {
350 [0] = "NMI2SMI",
351 [1] = "SW_TCO",
352 [2] = "TCO_INT",
353 [3] = "TIMEOUT",
354 [7] = "NEWCENTURY",
355 [8] = "BIOSWR",
356 [9] = "DMISCI",
357 [10] = "DMISMI",
358 [12] = "DMISERR",
359 [13] = "SLVSEL",
360 [16] = "INTRD_DET",
361 [17] = "SECOND_TO",
362 [18] = "BOOT",
363 [20] = "SMLINK_SLV"
364 };
365
366 if (!tco_sts)
367 return 0;
368
369 printk(BIOS_DEBUG, "TCO_STS: ");
370 print_status_bits(tco_sts, tco_sts_bits);
371 printk(BIOS_DEBUG, "\n");
372
373 return tco_sts;
374}
375
376/* Print, clear, and return TCO status */
377u32 clear_tco_status(void)
378{
379 return print_tco_status(reset_tco_status());
380}
381
382/* Enable TCO SCI */
383void enable_tco_sci(void)
384{
385 u16 gpe0_sts = pch_is_lp() ? LP_GPE0_STS_4 : GPE0_STS;
386
387 /* Clear pending events */
388 outl(get_pmbase() + gpe0_sts, TCOSCI_STS);
389
390 /* Enable TCO SCI events */
391 enable_gpe(TCOSCI_EN);
392}
393
394
395/*
396 * GPE0
397 */
398
399/* Clear a GPE0 status and return events that are enabled and active */
400static u32 reset_gpe_status(u16 sts_reg, u16 en_reg)
401{
402 u32 gpe0_sts = inl(get_pmbase() + sts_reg);
403 u32 gpe0_en = inl(get_pmbase() + en_reg);
404
405 outl(gpe0_sts, get_pmbase() + sts_reg);
406
407 /* Only report enabled events */
408 return gpe0_sts & gpe0_en;
409}
410
411/* Print GPE0 status bits */
412static u32 print_gpe_status(u32 gpe0_sts, const char *bit_names[])
413{
414 if (!gpe0_sts)
415 return 0;
416
417 printk(BIOS_DEBUG, "GPE0_STS: ");
418 print_status_bits(gpe0_sts, bit_names);
419 printk(BIOS_DEBUG, "\n");
420
421 return gpe0_sts;
422}
423
424/* Print GPE0 GPIO status bits */
425static u32 print_gpe_gpio(u32 gpe0_sts, int start)
426{
427 if (!gpe0_sts)
428 return 0;
429
430 printk(BIOS_DEBUG, "GPE0_STS: ");
431 print_gpio_status(gpe0_sts, start);
432 printk(BIOS_DEBUG, "\n");
433
434 return gpe0_sts;
435}
436
437/* Print, clear, and return LynxPoint-H GPE0 status */
438static u32 clear_lpt_gpe_status(void)
439{
440 const char *gpe0_sts_bits_low[] = {
441 [1] = "HOTPLUG",
442 [2] = "SWGPE",
443 [6] = "TCO_SCI",
444 [7] = "SMB_WAK",
445 [8] = "RI",
446 [9] = "PCI_EXP",
447 [10] = "BATLOW",
448 [11] = "PME",
449 [13] = "PME_B0",
450 [16] = "GPIO0",
451 [17] = "GPIO1",
452 [18] = "GPIO2",
453 [19] = "GPIO3",
454 [20] = "GPIO4",
455 [21] = "GPIO5",
456 [22] = "GPIO6",
457 [23] = "GPIO7",
458 [24] = "GPIO8",
459 [25] = "GPIO9",
460 [26] = "GPIO10",
461 [27] = "GPIO11",
462 [28] = "GPIO12",
463 [29] = "GPIO13",
464 [30] = "GPIO14",
465 [31] = "GPIO15",
466 };
467 const char *gpe0_sts_bits_high[] = {
468 [3] = "GPIO27",
469 [6] = "WADT",
470 [24] = "GPIO17",
471 [25] = "GPIO19",
472 [26] = "GPIO21",
473 [27] = "GPIO22",
474 [28] = "GPIO43",
475 [29] = "GPIO56",
476 [30] = "GPIO57",
477 [31] = "GPIO60",
478 };
479
480 /* High bits */
481 print_gpe_status(reset_gpe_status(GPE0_STS_2, GPE0_EN_2),
482 gpe0_sts_bits_high);
483
484 /* Standard GPE and GPIO 0-31 */
485 return print_gpe_status(reset_gpe_status(GPE0_STS, GPE0_EN),
486 gpe0_sts_bits_low);
487}
488
489/* Print, clear, and return LynxPoint-LP GPE0 status */
490static u32 clear_lpt_lp_gpe_status(void)
491{
492 const char *gpe0_sts_4_bits[] = {
493 [1] = "HOTPLUG",
494 [2] = "SWGPE",
495 [6] = "TCO_SCI",
496 [7] = "SMB_WAK",
497 [9] = "PCI_EXP",
498 [10] = "BATLOW",
499 [11] = "PME",
500 [12] = "ME",
501 [13] = "PME_B0",
502 [16] = "GPIO27",
503 [18] = "WADT"
504 };
505
506 /* GPIO 0-31 */
507 print_gpe_gpio(reset_gpe_status(LP_GPE0_STS_1, LP_GPE0_EN_1), 0);
508
509 /* GPIO 32-63 */
510 print_gpe_gpio(reset_gpe_status(LP_GPE0_STS_2, LP_GPE0_EN_2), 32);
511
512 /* GPIO 64-94 */
513 print_gpe_gpio(reset_gpe_status(LP_GPE0_STS_3, LP_GPE0_EN_3), 64);
514
515 /* Standard GPE */
516 return print_gpe_status(reset_gpe_status(LP_GPE0_STS_4, LP_GPE0_EN_4),
517 gpe0_sts_4_bits);
518}
519
520/* Clear all GPE status and return "standard" GPE event status */
521u32 clear_gpe_status(void)
522{
523 if (pch_is_lp())
524 return clear_lpt_lp_gpe_status();
525 else
526 return clear_lpt_gpe_status();
527}
528
529/* Enable all requested GPE */
530void enable_all_gpe(u32 set1, u32 set2, u32 set3, u32 set4)
531{
532 u16 pmbase = get_pmbase();
533
534 if (pch_is_lp()) {
535 outl(set1, pmbase + LP_GPE0_EN_1);
536 outl(set2, pmbase + LP_GPE0_EN_2);
537 outl(set3, pmbase + LP_GPE0_EN_3);
538 outl(set4, pmbase + LP_GPE0_EN_4);
539 } else {
540 outl(set1, pmbase + GPE0_EN);
541 outl(set2, pmbase + GPE0_EN_2);
542 }
543}
544
545/* Disable all GPE */
546void disable_all_gpe(void)
547{
548 enable_all_gpe(0, 0, 0, 0);
549}
550
551/* Enable a standard GPE */
552void enable_gpe(u32 mask)
553{
554 u32 gpe0_reg = pch_is_lp() ? LP_GPE0_EN_4 : GPE0_EN;
555 u32 gpe0_en = inl(get_pmbase() + gpe0_reg);
556 gpe0_en |= mask;
557 outl(gpe0_en, get_pmbase() + gpe0_reg);
558}
559
560/* Disable a standard GPE */
561void disable_gpe(u32 mask)
562{
563 u32 gpe0_reg = pch_is_lp() ? LP_GPE0_EN_4 : GPE0_EN;
564 u32 gpe0_en = inl(get_pmbase() + gpe0_reg);
565 gpe0_en &= ~mask;
566 outl(gpe0_en, get_pmbase() + gpe0_reg);
567}