Add acpi_get_sleep_type() to i82371eb and P2B _PTS/_WAK methods
[coreboot.git] / src / southbridge / intel / i82371eb / wakeup.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
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, MA  02110-1301 USA
19  */
20
21 #include <stdint.h>
22 #include <arch/io.h>
23 #include <console/console.h>
24 #include "i82371eb.h"
25
26 int acpi_get_sleep_type(void);
27
28 /*
29  * Intel 82371EB (PIIX4E) datasheet, section 7.2.3, page 142
30  *
31  * 0: soft off/suspend to disk                                  S5
32  * 1: suspend to ram                                            S3
33  * 2: powered on suspend, context lost                          S2
34  *    Note: 'context lost' means the CPU restarts at the reset
35  *          vector
36  * 3: powered on suspend, CPU context lost                      S1
37  *    Note: Looks like 'CPU context lost' does _not_ mean the
38  *          CPU restarts at the reset vector. Most likely only
39  *          caches are lost, so both 0x3 and 0x4 map to acpi S1
40  * 4: powered on suspend, context maintained                    S1
41  * 5: working (clock control)                                   S0
42  * 6: reserved
43  * 7: reserved
44  */
45 static const u8 acpi_sus_to_slp_typ[8] = {
46         5, 3, 2, 1, 1, 0, 0, 0
47 };
48
49 int acpi_get_sleep_type(void)
50 {
51         u16 reg, result;
52
53         reg = inw(DEFAULT_PMBASE + PMCNTRL);
54         result = acpi_sus_to_slp_typ[(reg >> 10) & 7];
55
56         printk(BIOS_DEBUG, "Wakeup from ACPI sleep type S%d (PMCNTRL=%04x)\n", result, reg);
57
58         return result;
59 }