Angel Pons | 6bc1374 | 2020-04-05 15:46:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 3 | #include <acpi/acpi_pm.h> |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 4 | #include <device/pci_type.h> |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 5 | #include <elog.h> |
Furquan Shaikh | c83e70e | 2018-06-25 14:29:48 -0700 | [diff] [blame] | 6 | #include <intelblocks/pmclib.h> |
Karthikeyan Ramasubramanian | f84c103 | 2019-03-20 13:15:00 -0600 | [diff] [blame] | 7 | #include <intelblocks/xhci.h> |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 8 | #include <soc/pm.h> |
| 9 | #include <soc/pci_devs.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 10 | #include <soc/smbus.h> |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | |
| 13 | static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start) |
| 14 | { |
| 15 | int i; |
| 16 | |
| 17 | gpe0_sts &= gpe0_en; |
| 18 | |
| 19 | for (i = 0; i <= 31; i++) { |
| 20 | if (gpe0_sts & (1 << i)) |
Aaron Durbin | aa90203 | 2020-08-17 09:37:13 -0600 | [diff] [blame] | 21 | elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i + start); |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 22 | } |
| 23 | } |
| 24 | |
Kyösti Mälkki | 6b43055 | 2021-01-22 07:52:43 +0200 | [diff] [blame] | 25 | static void pch_log_wake_source(const struct chipset_power_state *ps) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 26 | { |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 27 | const struct xhci_wake_info xhci_wake_info[] = { |
| 28 | { PCH_DEVFN_XHCI, ELOG_WAKE_SOURCE_PME_XHCI }, |
| 29 | }; |
| 30 | |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 31 | /* Power Button */ |
| 32 | if (ps->pm1_sts & PWRBTN_STS) |
| 33 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
| 34 | |
| 35 | /* RTC */ |
| 36 | if (ps->pm1_sts & RTC_STS) |
| 37 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
| 38 | |
| 39 | /* PCI Express (TODO: determine wake device) */ |
| 40 | if (ps->pm1_sts & PCIEXPWAK_STS) |
| 41 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
| 42 | |
| 43 | /* PME */ |
Lee Leahy | d8fb362 | 2017-03-09 10:10:25 -0800 | [diff] [blame] | 44 | if (ps->gpe0_sts[GPE0_A] & CSE_PME_STS) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 45 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0); |
| 46 | |
Karthikeyan Ramasubramanian | f84c103 | 2019-03-20 13:15:00 -0600 | [diff] [blame] | 47 | /* XHCI */ |
| 48 | if (ps->gpe0_sts[GPE0_A] & XHCI_PME_STS) |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 49 | xhci_update_wake_event(xhci_wake_info, |
| 50 | ARRAY_SIZE(xhci_wake_info)); |
Karthikeyan Ramasubramanian | f84c103 | 2019-03-20 13:15:00 -0600 | [diff] [blame] | 51 | |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 52 | /* SMBUS Wake */ |
| 53 | if (ps->gpe0_sts[GPE0_A] & SMB_WAK_STS) |
| 54 | elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0); |
| 55 | |
Furquan Shaikh | c83e70e | 2018-06-25 14:29:48 -0700 | [diff] [blame] | 56 | /* ACPI Wake Event - Log prev sleep state only if it was not S0. */ |
| 57 | if (ps->prev_sleep_state != ACPI_S0) |
| 58 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, ps->prev_sleep_state); |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 59 | |
| 60 | /* Log GPIO events in set A-D */ |
| 61 | pch_log_gpio_gpe(ps->gpe0_sts[GPE0_A], ps->gpe0_en[GPE0_A], 0); |
| 62 | pch_log_gpio_gpe(ps->gpe0_sts[GPE0_B], ps->gpe0_en[GPE0_B], 32); |
| 63 | pch_log_gpio_gpe(ps->gpe0_sts[GPE0_C], ps->gpe0_en[GPE0_C], 64); |
| 64 | pch_log_gpio_gpe(ps->gpe0_sts[GPE0_D], ps->gpe0_en[GPE0_D], 96); |
| 65 | } |
| 66 | |
Kyösti Mälkki | 6b43055 | 2021-01-22 07:52:43 +0200 | [diff] [blame] | 67 | static void pch_log_power_and_resets(const struct chipset_power_state *ps) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 68 | { |
| 69 | /* RTC Reset */ |
| 70 | if (ps->gen_pmcon1 & RPS) |
| 71 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 72 | |
| 73 | /* System Reset */ |
Aaron Durbin | f39692e | 2017-04-27 14:14:05 -0500 | [diff] [blame] | 74 | if (ps->gen_pmcon1 & WARM_RESET_STS) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 75 | elog_add_event(ELOG_TYPE_SYSTEM_RESET); |
| 76 | |
| 77 | /* TCO Timeout */ |
| 78 | if (ps->prev_sleep_state != ACPI_S3 && |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 79 | ps->tco1_sts & TCO_TIMEOUT) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 80 | elog_add_event(ELOG_TYPE_TCO_RESET); |
| 81 | |
| 82 | /* Power Button Override */ |
| 83 | if (ps->pm1_sts & PRBTNOR_STS) |
| 84 | elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | void pch_log_state(void) |
| 89 | { |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 90 | const struct chipset_power_state *ps; |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 91 | |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 92 | if (acpi_pm_state_for_elog(&ps) < 0) |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 93 | return; |
Brandon Breitenstein | 3b0e761 | 2016-07-18 15:14:12 -0700 | [diff] [blame] | 94 | |
| 95 | /* Power and Reset */ |
| 96 | pch_log_power_and_resets(ps); |
| 97 | |
| 98 | /* Wake Sources */ |
| 99 | if (ps->prev_sleep_state > ACPI_S0) |
| 100 | pch_log_wake_source(ps); |
| 101 | } |
Furquan Shaikh | c83e70e | 2018-06-25 14:29:48 -0700 | [diff] [blame] | 102 | |
| 103 | void elog_gsmi_cb_platform_log_wake_source(void) |
| 104 | { |
| 105 | struct chipset_power_state ps; |
| 106 | |
| 107 | pmc_fill_pm_reg_info(&ps); |
| 108 | pch_log_wake_source(&ps); |
| 109 | } |