• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi_pm.h>
4 #include <bootstate.h>
5 #include <stdint.h>
6 #include <elog.h>
7 #include <soc/lpc.h>
8 #include <soc/pm.h>
9 
pch_log_gpio_gpe(u32 gpe0_sts,u32 gpe0_en,int start)10 static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
11 {
12 	int i;
13 
14 	gpe0_sts &= gpe0_en;
15 
16 	for (i = 0; i <= 31; i++) {
17 		if (gpe0_sts & (1 << i))
18 			elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i + start);
19 	}
20 }
21 
pch_log_wake_source(const struct chipset_power_state * ps)22 static void pch_log_wake_source(const struct chipset_power_state *ps)
23 {
24 	/* Power Button */
25 	if (ps->pm1_sts & PWRBTN_STS)
26 		elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
27 
28 	/* RTC */
29 	if (ps->pm1_sts & RTC_STS)
30 		elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
31 
32 	/* PCI Express (TODO: determine wake device) */
33 	if (ps->pm1_sts & PCIEXPWAK_STS)
34 		elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
35 
36 	/* PME (TODO: determine wake device) */
37 	if (ps->gpe0_sts[GPE_STD] & PME_STS)
38 		elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0);
39 
40 	/* Internal PME (TODO: determine wake device) */
41 	if (ps->gpe0_sts[GPE_STD] & PME_B0_STS)
42 		elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
43 
44 	/* SMBUS Wake */
45 	if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS)
46 		elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0);
47 
48 	/* GPIO27 */
49 	if (ps->gpe0_sts[GPE_STD] & GP27_STS)
50 		elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, 27);
51 
52 	/* Log GPIO events in set 1-3 */
53 	pch_log_gpio_gpe(ps->gpe0_sts[GPE_31_0], ps->gpe0_en[GPE_31_0], 0);
54 	pch_log_gpio_gpe(ps->gpe0_sts[GPE_63_32], ps->gpe0_en[GPE_63_32], 32);
55 	pch_log_gpio_gpe(ps->gpe0_sts[GPE_94_64], ps->gpe0_en[GPE_94_64], 64);
56 }
57 
pch_log_power_and_resets(const struct chipset_power_state * ps)58 static void pch_log_power_and_resets(const struct chipset_power_state *ps)
59 {
60 	/* Thermal Trip Status */
61 	if (ps->gen_pmcon2 & THERMTRIP_STS)
62 		elog_add_event(ELOG_TYPE_THERM_TRIP);
63 
64 	/* PWR_FLR Power Failure */
65 	if (ps->gen_pmcon2 & PWROK_FLR)
66 		elog_add_event(ELOG_TYPE_POWER_FAIL);
67 
68 	/* SUS Well Power Failure */
69 	if (ps->gen_pmcon3 & SUS_PWR_FLR)
70 		elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
71 
72 	/* SYS_PWROK Failure */
73 	if (ps->gen_pmcon2 & SYSPWR_FLR)
74 		elog_add_event(ELOG_TYPE_SYS_PWROK_FAIL);
75 
76 	/* PWROK Failure */
77 	if (ps->gen_pmcon2 & PWROK_FLR)
78 		elog_add_event(ELOG_TYPE_PWROK_FAIL);
79 
80 	/* TCO Timeout */
81 	if (ps->prev_sleep_state != ACPI_S3 &&
82 	    ps->tco2_sts & TCO2_STS_SECOND_TO)
83 		elog_add_event(ELOG_TYPE_TCO_RESET);
84 
85 	/* Power Button Override */
86 	if (ps->pm1_sts & PRBTNOR_STS)
87 		elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
88 
89 	/* RTC reset */
90 	if (ps->gen_pmcon3 & RTC_BATTERY_DEAD)
91 		elog_add_event(ELOG_TYPE_RTC_RESET);
92 
93 	/* System Reset Status (reset button pushed) */
94 	if (ps->gen_pmcon2 & SYSTEM_RESET_STS)
95 		elog_add_event(ELOG_TYPE_RESET_BUTTON);
96 
97 	/* General Reset Status */
98 	if (ps->gen_pmcon3 & GEN_RST_STS)
99 		elog_add_event(ELOG_TYPE_SYSTEM_RESET);
100 
101 	/* ACPI Wake Event */
102 	if (ps->prev_sleep_state != ACPI_S0)
103 		elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, ps->prev_sleep_state);
104 }
105 
pch_log_state(void * unused)106 static void pch_log_state(void *unused)
107 {
108 	const struct chipset_power_state *ps;
109 
110 	if (acpi_fetch_pm_state(&ps, PS_CLAIMER_ELOG) < 0)
111 		return;
112 
113 	/* Power and Reset */
114 	pch_log_power_and_resets(ps);
115 
116 	/* Wake Sources */
117 	pch_log_wake_source(ps);
118 }
119 
120 BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, pch_log_state, NULL);
121