Debian Codegraph @

src/southbridge/intel/lynxpoint/elog.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/io.h>
4 #include <acpi/acpi.h>
5 #include <device/device.h>
6 #include <device/pci.h>
7 #include <device/pci_ops.h>
8 #include <stdint.h>
9 #include <elog.h>
10 #include "pch.h"
11
12 static void pch_log_standard_gpe(u32 gpe0_sts_reg, u32 gpe0_en_reg)
13 {
14 u32 gpe0_en = inl(get_pmbase() + gpe0_en_reg);
15 u32 gpe0_sts = inl(get_pmbase() + gpe0_sts_reg) & gpe0_en;
16
17 /* PME (TODO: determine wake device) */
18 if (gpe0_sts & PME_STS)
19 elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0);
20
21 /* Internal PME (TODO: determine wake device) */
22 if (gpe0_sts & PME_B0_STS)
23 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
24
25 /* SMBUS Wake */
26 if (gpe0_sts & SMB_WAK_STS)
27 elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0);
28 }
29
30 static void pch_log_gpio_gpe(u32 gpe0_sts_reg, u32 gpe0_en_reg, int start)
31 {
32 /* GPE Bank 1 is GPIO 0-31 */
33 u32 gpe0_en = inl(get_pmbase() + gpe0_en_reg);
34 u32 gpe0_sts = inl(get_pmbase() + gpe0_sts_reg) & gpe0_en;
35 int i;
36
37 for (i = 0; i <= 31; i++) {
38 if (gpe0_sts & (1 << i))
39 elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i + start);
40 }
41 }
42
43 static void pch_log_gpe(void)
44 {
45 int i;
46 u16 pmbase = get_pmbase();
47 u32 gpe0_sts, gpe0_en;
48 int gpe0_high_gpios[] = {
49 [0] = 27,
50 [24] = 17,
51 [25] = 19,
52 [26] = 21,
53 [27] = 22,
54 [28] = 43,
55 [29] = 56,
56 [30] = 57,
57 [31] = 60
58 };
59
60 pch_log_standard_gpe(GPE0_EN, GPE0_STS);
61
62 /* GPIO 0-15 */
63 gpe0_en = inw(pmbase + GPE0_EN + sizeof(uint16_t));
64 gpe0_sts = inw(pmbase + GPE0_STS + sizeof(uint16_t)) & gpe0_en;
65 for (i = 0; i <= 15; i++) {
66 if (gpe0_sts & (1 << i))
67 elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i);
68 }
69
70 /*
71 * Now check and log upper status bits
72 */
73
74 gpe0_en = inl(pmbase + GPE0_EN + sizeof(uint32_t));
75 gpe0_sts = inl(pmbase + GPE0_STS + sizeof(uint32_t)) & gpe0_en;
76
77 for (i = 0; i <= 31; i++) {
78 if (!gpe0_high_gpios[i])
79 continue;
80 if (gpe0_sts & (1 << i))
81 elog_add_event_wake(ELOG_WAKE_SOURCE_GPE,
82 gpe0_high_gpios[i]);
83 }
84 }
85
86 static void pch_lp_log_gpe(void)
87 {
88 /* Standard GPE are in GPE set 4 */
89 pch_log_standard_gpe(LP_GPE0_STS_4, LP_GPE0_EN_4);
90
91 /* Log GPIO events in set 1-3 */
92 pch_log_gpio_gpe(LP_GPE0_STS_1, LP_GPE0_EN_1, 0);
93 pch_log_gpio_gpe(LP_GPE0_STS_2, LP_GPE0_EN_2, 32);
94 pch_log_gpio_gpe(LP_GPE0_STS_3, LP_GPE0_EN_3, 64);
95 }
96
97 void pch_log_state(void)
98 {
99 u16 pm1_sts, gen_pmcon_3, tco2_sts;
100 u8 gen_pmcon_2;
101 struct device *lpc = pcidev_on_root(0x1f, 0);
102 if (!lpc)
103 return;
104
105 pm1_sts = inw(get_pmbase() + PM1_STS);
106 tco2_sts = inw(get_pmbase() + TCO2_STS);
107 gen_pmcon_2 = pci_read_config8(lpc, GEN_PMCON_2);
108 gen_pmcon_3 = pci_read_config16(lpc, GEN_PMCON_3);
109
110 /* PWR_FLR Power Failure */
111 if (gen_pmcon_2 & PWROK_FLR)
112 elog_add_event(ELOG_TYPE_POWER_FAIL);
113
114 /* SUS Well Power Failure */
115 if (gen_pmcon_3 & SUS_PWR_FLR)
116 elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
117
118 /* SYS_PWROK Failure */
119 if (gen_pmcon_2 & SYSPWR_FLR)
120 elog_add_event(ELOG_TYPE_SYS_PWROK_FAIL);
121
122 /* PWROK Failure */
123 if (gen_pmcon_2 & PWROK_FLR)
124 elog_add_event(ELOG_TYPE_PWROK_FAIL);
125
126 /* Second TCO Timeout */
127 if (tco2_sts & TCO2_STS_SECOND_TO)
128 elog_add_event(ELOG_TYPE_TCO_RESET);
129
130 /* Power Button Override */
131 if (pm1_sts & PRBTNOR_STS)
132 elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
133
134 /* System Reset Status (reset button pushed) */
135 if (gen_pmcon_2 & SYSTEM_RESET_STS)
136 elog_add_event(ELOG_TYPE_RESET_BUTTON);
137
138 /* General Reset Status */
139 if (gen_pmcon_3 & GEN_RST_STS)
140 elog_add_event(ELOG_TYPE_SYSTEM_RESET);
141
142 /* ACPI Wake */
143 if (pm1_sts & WAK_STS)
144 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
145 acpi_is_wakeup_s3() ? 3 : 5);
146
147 /*
148 * Wake sources
149 */
150
151 /* Power Button */
152 if (pm1_sts & PWRBTN_STS)
153 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
154
155 /* RTC */
156 if (pm1_sts & RTC_STS)
157 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
158
159 /* PCI Express (TODO: determine wake device) */
160 if (pm1_sts & PCIEXPWAK_STS)
161 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
162
163 /* GPE */
164 if (pch_is_lp())
165 pch_lp_log_gpe();
166 else
167 pch_log_gpe();
168 }