blob: 7e92e9037d7aff9d2ee1490032674d6e217b9f00 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07004#include <cbmem.h>
Lee Leahy32471722015-04-20 15:20:28 -07005#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07006#include <device/device.h>
7#include <device/pci.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07008#include <elog.h>
9#include <soc/iomap.h>
Lee Leahy32471722015-04-20 15:20:28 -070010#include <soc/pm.h>
11#include <stdint.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070012
13static void log_power_and_resets(const struct chipset_power_state *ps)
14{
15 if (ps->gen_pmcon1 & PWR_FLR) {
16 elog_add_event(ELOG_TYPE_POWER_FAIL);
17 elog_add_event(ELOG_TYPE_PWROK_FAIL);
18 }
19
Lee Leahy32471722015-04-20 15:20:28 -070020 if (ps->gen_pmcon1 & SUS_PWR_FLR)
Lee Leahy77ff0b12015-05-05 15:07:29 -070021 elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
Lee Leahy77ff0b12015-05-05 15:07:29 -070022
Lee Leahy32471722015-04-20 15:20:28 -070023 if (ps->gen_pmcon1 & RPS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070024 elog_add_event(ELOG_TYPE_RTC_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070025
Lee Leahy32471722015-04-20 15:20:28 -070026 if (ps->tco_sts & SECOND_TO_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070027 elog_add_event(ELOG_TYPE_TCO_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070028
Lee Leahy32471722015-04-20 15:20:28 -070029 if (ps->pm1_sts & PRBTNOR_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070030 elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
Lee Leahy77ff0b12015-05-05 15:07:29 -070031
Lee Leahy32471722015-04-20 15:20:28 -070032 if (ps->gen_pmcon1 & SRS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070033 elog_add_event(ELOG_TYPE_RESET_BUTTON);
Lee Leahy77ff0b12015-05-05 15:07:29 -070034
Lee Leahy32471722015-04-20 15:20:28 -070035 if (ps->gen_pmcon1 & GEN_RST_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070036 elog_add_event(ELOG_TYPE_SYSTEM_RESET);
Lee Leahy77ff0b12015-05-05 15:07:29 -070037}
38
39static void log_wake_events(const struct chipset_power_state *ps)
40{
Angel Ponsaee7ab22020-03-19 00:31:58 +010041 const uint32_t pcie_wake_mask = PCIE_WAKE3_STS | PCIE_WAKE2_STS |
42 PCIE_WAKE1_STS | PCIE_WAKE0_STS | PCI_EXP_STS;
43
Lee Leahy77ff0b12015-05-05 15:07:29 -070044 uint32_t gpe0_sts;
45 uint32_t gpio_mask;
46 int i;
47
48 /* Mask off disabled events. */
49 gpe0_sts = ps->gpe0_sts & ps->gpe0_en;
50
Lee Leahy32471722015-04-20 15:20:28 -070051 if (ps->pm1_sts & WAK_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070052 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
Aaron Durbin1b6196d2016-07-13 23:20:26 -050053 acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5);
Lee Leahy77ff0b12015-05-05 15:07:29 -070054
Lee Leahy32471722015-04-20 15:20:28 -070055 if (ps->pm1_sts & PWRBTN_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070056 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070057
Lee Leahy32471722015-04-20 15:20:28 -070058 if (ps->pm1_sts & RTC_STS)
Lee Leahy77ff0b12015-05-05 15:07:29 -070059 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070060
Lee Leahy32471722015-04-20 15:20:28 -070061 if (gpe0_sts & PME_B0_EN)
Lee Leahy77ff0b12015-05-05 15:07:29 -070062 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070063
Lee Leahy32471722015-04-20 15:20:28 -070064 if (gpe0_sts & pcie_wake_mask)
Lee Leahy77ff0b12015-05-05 15:07:29 -070065 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
Lee Leahy77ff0b12015-05-05 15:07:29 -070066
67 gpio_mask = SUS_GPIO_STS0;
68 i = 0;
69 while (gpio_mask) {
Lee Leahy32471722015-04-20 15:20:28 -070070 if (gpio_mask & gpe0_sts)
Aaron Durbinaa902032020-08-17 09:37:13 -060071 elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i);
Lee Leahy77ff0b12015-05-05 15:07:29 -070072 gpio_mask <<= 1;
73 i++;
74 }
75}
76
77void southcluster_log_state(void)
78{
79 struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
80
81 if (ps == NULL) {
Lee Leahy32471722015-04-20 15:20:28 -070082 printk(BIOS_DEBUG,
83 "Not logging power state information. Power state not found in cbmem.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -070084 return;
85 }
86
87 log_power_and_resets(ps);
88 log_wake_events(ps);
89}