blob: ecdbfca7094f8c541272f0c3e685e84268101337 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin8f31ecf2014-01-09 10:41:30 -06002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki27872372021-01-21 16:05:26 +02004#include <acpi/acpi_pm.h>
Aaron Durbin8f31ecf2014-01-09 10:41:30 -06005#include <device/device.h>
6#include <device/pci.h>
Aaron Durbin8f31ecf2014-01-09 10:41:30 -06007#include <elog.h>
Julius Werner18ea2d32014-10-07 16:42:17 -07008#include <soc/iomap.h>
Angel Ponsb5320b22020-07-07 18:27:30 +02009#include <soc/pm.h>
Angel Pons5e01c4b2020-07-07 17:39:15 +020010#include <stdint.h>
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060011
12static void log_power_and_resets(const struct chipset_power_state *ps)
13{
14 if (ps->gen_pmcon1 & PWR_FLR) {
15 elog_add_event(ELOG_TYPE_POWER_FAIL);
16 elog_add_event(ELOG_TYPE_PWROK_FAIL);
17 }
18
Angel Pons5e01c4b2020-07-07 17:39:15 +020019 if (ps->gen_pmcon1 & SUS_PWR_FLR)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060020 elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060021
Angel Pons5e01c4b2020-07-07 17:39:15 +020022 if (ps->gen_pmcon1 & RPS)
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080023 elog_add_event(ELOG_TYPE_RTC_RESET);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080024
Kyösti Mälkki307320c2022-11-21 17:27:07 +020025 if (ps->tco_sts & TCO1_32_STS_SECOND_TO_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060026 elog_add_event(ELOG_TYPE_TCO_RESET);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060027
Angel Pons5e01c4b2020-07-07 17:39:15 +020028 if (ps->pm1_sts & PRBTNOR_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060029 elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060030
Angel Pons5e01c4b2020-07-07 17:39:15 +020031 if (ps->gen_pmcon1 & SRS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060032 elog_add_event(ELOG_TYPE_RESET_BUTTON);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060033
Angel Pons5e01c4b2020-07-07 17:39:15 +020034 if (ps->gen_pmcon1 & GEN_RST_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060035 elog_add_event(ELOG_TYPE_SYSTEM_RESET);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060036}
37
38static void log_wake_events(const struct chipset_power_state *ps)
39{
Angel Pons5e01c4b2020-07-07 17:39:15 +020040 const uint32_t pcie_wake_mask = PCIE_WAKE3_STS | PCIE_WAKE2_STS |
41 PCIE_WAKE1_STS | PCIE_WAKE0_STS | PCI_EXP_STS;
42
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060043 uint32_t gpe0_sts;
44 uint32_t gpio_mask;
45 int i;
46
47 /* Mask off disabled events. */
48 gpe0_sts = ps->gpe0_sts & ps->gpe0_en;
49
Angel Pons5e01c4b2020-07-07 17:39:15 +020050 if (ps->pm1_sts & WAK_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060051 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
Angel Pons5e01c4b2020-07-07 17:39:15 +020052 acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060053
Angel Pons5e01c4b2020-07-07 17:39:15 +020054 if (ps->pm1_sts & PWRBTN_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060055 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060056
Angel Pons5e01c4b2020-07-07 17:39:15 +020057 if (ps->pm1_sts & RTC_STS)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060058 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060059
Angel Pons5e01c4b2020-07-07 17:39:15 +020060 if (gpe0_sts & PME_B0_EN)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060061 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060062
Angel Pons5e01c4b2020-07-07 17:39:15 +020063 if (gpe0_sts & pcie_wake_mask)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060064 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060065
66 gpio_mask = SUS_GPIO_STS0;
67 i = 0;
68 while (gpio_mask) {
Angel Pons5e01c4b2020-07-07 17:39:15 +020069 if (gpio_mask & gpe0_sts)
Aaron Durbinaa902032020-08-17 09:37:13 -060070 elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i);
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060071 gpio_mask <<= 1;
72 i++;
73 }
74}
75
76void southcluster_log_state(void)
77{
Kyösti Mälkki27872372021-01-21 16:05:26 +020078 const struct chipset_power_state *ps;
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060079
Fabio Aiutofdcf6982022-09-11 12:25:13 +020080 if (acpi_fetch_pm_state(&ps, PS_CLAIMER_ELOG) < 0)
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060081 return;
Aaron Durbin8f31ecf2014-01-09 10:41:30 -060082
83 log_power_and_resets(ps);
84 log_wake_events(ps);
85}