blob: 755a601bda2b0117638fddadb3f8f747f80a4c54 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070016 */
17
18#include <arch/io.h>
19#include <arch/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070020#include <cbmem.h>
Lee Leahy32471722015-04-20 15:20:28 -070021#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ops.h>
25#include <elog.h>
26#include <soc/iomap.h>
Lee Leahy32471722015-04-20 15:20:28 -070027#include <soc/pm.h>
28#include <stdint.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070029
30static void log_power_and_resets(const struct chipset_power_state *ps)
31{
32 if (ps->gen_pmcon1 & PWR_FLR) {
33 elog_add_event(ELOG_TYPE_POWER_FAIL);
34 elog_add_event(ELOG_TYPE_PWROK_FAIL);
35 }
36
Lee Leahy32471722015-04-20 15:20:28 -070037 if (ps->gen_pmcon1 & SUS_PWR_FLR)
Lee Leahy77ff0b12015-05-05 15:07:29 -070038 elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
Lee Leahy77ff0b12015-05-05 15:07:29 -070039
Lee Leahy32471722015-04-20 15:20:28 -070040 if (ps->gen_pmcon1 & RPS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070041 elog_add_event(ELOG_TYPE_RTC_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070042
Lee Leahy32471722015-04-20 15:20:28 -070043 if (ps->tco_sts & SECOND_TO_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070044 elog_add_event(ELOG_TYPE_TCO_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070045
Lee Leahy32471722015-04-20 15:20:28 -070046 if (ps->pm1_sts & PRBTNOR_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070047 elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
Lee Leahy77ff0b12015-05-05 15:07:29 -070048
Lee Leahy32471722015-04-20 15:20:28 -070049 if (ps->gen_pmcon1 & SRS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070050 elog_add_event(ELOG_TYPE_RESET_BUTTON);
Lee Leahy77ff0b12015-05-05 15:07:29 -070051
Lee Leahy32471722015-04-20 15:20:28 -070052 if (ps->gen_pmcon1 & GEN_RST_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070053 elog_add_event(ELOG_TYPE_SYSTEM_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070054}
55
56static void log_wake_events(const struct chipset_power_state *ps)
57{
58 const uint32_t pcie_wake_mask = PCI_EXP_STS | PCIE_WAKE3_STS |
59 PCIE_WAKE2_STS | PCIE_WAKE1_STS |
60 PCIE_WAKE0_STS;
61 uint32_t gpe0_sts;
62 uint32_t gpio_mask;
63 int i;
64
65 /* Mask off disabled events. */
66 gpe0_sts = ps->gpe0_sts & ps->gpe0_en;
67
Lee Leahy32471722015-04-20 15:20:28 -070068 if (ps->pm1_sts & WAK_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070069 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
Lee Leahy32471722015-04-20 15:20:28 -070070 acpi_slp_type == 3 ? 3 : 5);
Lee Leahy77ff0b12015-05-05 15:07:29 -070071
Lee Leahy32471722015-04-20 15:20:28 -070072 if (ps->pm1_sts & PWRBTN_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070073 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070074
Lee Leahy32471722015-04-20 15:20:28 -070075 if (ps->pm1_sts & RTC_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070076 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070077
Lee Leahy32471722015-04-20 15:20:28 -070078 if (gpe0_sts & PME_B0_EN)
Lee Leahy77ff0b12015-05-05 15:07:29 -070079 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070080
Lee Leahy32471722015-04-20 15:20:28 -070081 if (gpe0_sts & pcie_wake_mask)
Lee Leahy77ff0b12015-05-05 15:07:29 -070082 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070083
84 gpio_mask = SUS_GPIO_STS0;
85 i = 0;
86 while (gpio_mask) {
Lee Leahy32471722015-04-20 15:20:28 -070087 if (gpio_mask & gpe0_sts)
Lee Leahy77ff0b12015-05-05 15:07:29 -070088 elog_add_event_wake(ELOG_WAKE_SOURCE_GPIO, i);
Lee Leahy77ff0b12015-05-05 15:07:29 -070089 gpio_mask <<= 1;
90 i++;
91 }
92}
93
94void southcluster_log_state(void)
95{
96 struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
97
98 if (ps == NULL) {
Lee Leahy32471722015-04-20 15:20:28 -070099 printk(BIOS_DEBUG,
100 "Not logging power state information. Power state not found in cbmem.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700101 return;
102 }
103
104 log_power_and_resets(ps);
105 log_wake_events(ps);
106}