Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corporation. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <bootstate.h> |
| 18 | #include <cbmem.h> |
| 19 | #include <console/console.h> |
| 20 | #include <stdint.h> |
| 21 | #include <elog.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 22 | #include <soc/pm.h> |
Barnali Sarkar | 0dddcd7 | 2016-08-02 17:49:56 +0530 | [diff] [blame] | 23 | #include <soc/smbus.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 24 | |
| 25 | static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start) |
| 26 | { |
| 27 | int i; |
| 28 | |
| 29 | gpe0_sts &= gpe0_en; |
| 30 | |
| 31 | for (i = 0; i <= 31; i++) { |
| 32 | if (gpe0_sts & (1 << i)) |
| 33 | elog_add_event_wake(ELOG_WAKE_SOURCE_GPIO, i + start); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | static void pch_log_wake_source(struct chipset_power_state *ps) |
| 38 | { |
| 39 | /* Power Button */ |
| 40 | if (ps->pm1_sts & PWRBTN_STS) |
| 41 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
| 42 | |
| 43 | /* RTC */ |
| 44 | if (ps->pm1_sts & RTC_STS) |
| 45 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
| 46 | |
| 47 | /* PCI Express (TODO: determine wake device) */ |
| 48 | if (ps->pm1_sts & PCIEXPWAK_STS) |
| 49 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
| 50 | |
| 51 | /* PME (TODO: determine wake device) */ |
| 52 | if (ps->gpe0_sts[GPE_STD] & PME_STS) |
| 53 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0); |
| 54 | |
| 55 | /* Internal PME (TODO: determine wake device) */ |
| 56 | if (ps->gpe0_sts[GPE_STD] & PME_B0_STS) |
| 57 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0); |
| 58 | |
| 59 | /* SMBUS Wake */ |
| 60 | if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS) |
| 61 | elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0); |
| 62 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 63 | /* Log GPIO events in set 1-3 */ |
| 64 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_31_0], ps->gpe0_en[GPE_31_0], 0); |
| 65 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_63_32], ps->gpe0_en[GPE_63_32], 32); |
Aaron Durbin | 7f78849 | 2015-07-24 17:10:31 -0500 | [diff] [blame] | 66 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_95_64], ps->gpe0_en[GPE_95_64], 64); |
| 67 | /* Treat the STD as an extension of GPIO to obtain visibility. */ |
| 68 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_STD], ps->gpe0_en[GPE_STD], 96); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void pch_log_power_and_resets(struct chipset_power_state *ps) |
| 72 | { |
Duncan Laurie | 63f8c0a | 2015-12-10 01:00:54 -0800 | [diff] [blame] | 73 | /* Thermal Trip */ |
| 74 | if (ps->gblrst_cause[0] & GBLRST_CAUSE0_THERMTRIP) |
| 75 | elog_add_event(ELOG_TYPE_THERM_TRIP); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 76 | |
| 77 | /* PWR_FLR Power Failure */ |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 78 | if (ps->gen_pmcon_b & PWR_FLR) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 79 | elog_add_event(ELOG_TYPE_POWER_FAIL); |
| 80 | |
| 81 | /* SUS Well Power Failure */ |
Duncan Laurie | ac2cbd0 | 2017-03-07 19:22:24 -0800 | [diff] [blame] | 82 | if (ps->gen_pmcon_b & SUS_PWR_FLR) { |
| 83 | /* Do not log SUS_PWR_FLR if waking from deep Sx */ |
| 84 | if (!(ps->prev_sleep_state == ACPI_S3 && deep_s3_enabled()) && |
| 85 | !(ps->prev_sleep_state == ACPI_S5 && deep_s5_enabled())) |
| 86 | elog_add_event(ELOG_TYPE_SUS_POWER_FAIL); |
| 87 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 88 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 89 | /* TCO Timeout */ |
Aaron Durbin | e0a4914 | 2016-07-13 23:20:51 -0500 | [diff] [blame] | 90 | if (ps->prev_sleep_state != ACPI_S3 && |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 91 | ps->tco2_sts & TCO2_STS_SECOND_TO) |
| 92 | elog_add_event(ELOG_TYPE_TCO_RESET); |
| 93 | |
| 94 | /* Power Button Override */ |
| 95 | if (ps->pm1_sts & PRBTNOR_STS) |
| 96 | elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE); |
| 97 | |
| 98 | /* RTC reset */ |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 99 | if (ps->gen_pmcon_b & RTC_BATTERY_DEAD) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 100 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 101 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 102 | /* Host Reset Status */ |
| 103 | if (ps->gen_pmcon_b & HOST_RST_STS) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 104 | elog_add_event(ELOG_TYPE_SYSTEM_RESET); |
| 105 | |
| 106 | /* ACPI Wake Event */ |
Aaron Durbin | e0a4914 | 2016-07-13 23:20:51 -0500 | [diff] [blame] | 107 | if (ps->prev_sleep_state != ACPI_S0) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 108 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, ps->prev_sleep_state); |
| 109 | } |
| 110 | |
| 111 | static void pch_log_state(void *unused) |
| 112 | { |
| 113 | struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 114 | |
| 115 | if (ps == NULL) { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 116 | printk(BIOS_ERR, |
| 117 | "Not logging power state information. Power state not found in cbmem.\n"); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
| 121 | /* Power and Reset */ |
| 122 | pch_log_power_and_resets(ps); |
| 123 | |
| 124 | /* Wake Sources */ |
Duncan Laurie | d68e047 | 2016-03-01 17:01:35 -0800 | [diff] [blame] | 125 | if (ps->prev_sleep_state > 0) |
| 126 | pch_log_wake_source(ps); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Duncan Laurie | ac2cbd0 | 2017-03-07 19:22:24 -0800 | [diff] [blame] | 129 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, pch_log_state, NULL); |