Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 4 | #include <acpi/acpi_pm.h> |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 7 | #include <elog.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 8 | #include <soc/iomap.h> |
Angel Pons | b5320b2 | 2020-07-07 18:27:30 +0200 | [diff] [blame] | 9 | #include <soc/pm.h> |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 10 | #include <stdint.h> |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 11 | |
| 12 | static 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 Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 19 | if (ps->gen_pmcon1 & SUS_PWR_FLR) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 20 | elog_add_event(ELOG_TYPE_SUS_POWER_FAIL); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 21 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 22 | if (ps->gen_pmcon1 & RPS) |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 23 | elog_add_event(ELOG_TYPE_RTC_RESET); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 24 | |
Kyösti Mälkki | 307320c | 2022-11-21 17:27:07 +0200 | [diff] [blame] | 25 | if (ps->tco_sts & TCO1_32_STS_SECOND_TO_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 26 | elog_add_event(ELOG_TYPE_TCO_RESET); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 27 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 28 | if (ps->pm1_sts & PRBTNOR_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 29 | elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 30 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 31 | if (ps->gen_pmcon1 & SRS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 32 | elog_add_event(ELOG_TYPE_RESET_BUTTON); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 33 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 34 | if (ps->gen_pmcon1 & GEN_RST_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 35 | elog_add_event(ELOG_TYPE_SYSTEM_RESET); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static void log_wake_events(const struct chipset_power_state *ps) |
| 39 | { |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 40 | const uint32_t pcie_wake_mask = PCIE_WAKE3_STS | PCIE_WAKE2_STS | |
| 41 | PCIE_WAKE1_STS | PCIE_WAKE0_STS | PCI_EXP_STS; |
| 42 | |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 43 | 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 Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 50 | if (ps->pm1_sts & WAK_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 51 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 52 | acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 53 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 54 | if (ps->pm1_sts & PWRBTN_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 55 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 56 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 57 | if (ps->pm1_sts & RTC_STS) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 58 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 59 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 60 | if (gpe0_sts & PME_B0_EN) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 61 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 62 | |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 63 | if (gpe0_sts & pcie_wake_mask) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 64 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 65 | |
| 66 | gpio_mask = SUS_GPIO_STS0; |
| 67 | i = 0; |
| 68 | while (gpio_mask) { |
Angel Pons | 5e01c4b | 2020-07-07 17:39:15 +0200 | [diff] [blame] | 69 | if (gpio_mask & gpe0_sts) |
Aaron Durbin | aa90203 | 2020-08-17 09:37:13 -0600 | [diff] [blame] | 70 | elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i); |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 71 | gpio_mask <<= 1; |
| 72 | i++; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void southcluster_log_state(void) |
| 77 | { |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 78 | const struct chipset_power_state *ps; |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 79 | |
Fabio Aiuto | fdcf698 | 2022-09-11 12:25:13 +0200 | [diff] [blame] | 80 | if (acpi_fetch_pm_state(&ps, PS_CLAIMER_ELOG) < 0) |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 81 | return; |
Aaron Durbin | 8f31ecf | 2014-01-09 10:41:30 -0600 | [diff] [blame] | 82 | |
| 83 | log_power_and_resets(ps); |
| 84 | log_wake_events(ps); |
| 85 | } |