blob: 7adf09e341f2d58830dc85a36cdfc2ef0e93dece [file] [log] [blame]
Andy YF Wang40247cc2019-09-06 18:30:56 +08001#pragma once
2
3#include "device.hpp"
4#include "pmbus.hpp"
5#include "tools/i2c/i2c_interface.hpp"
6
7#include <sdbusplus/bus.hpp>
8
9#include <algorithm>
10#include <filesystem>
11
12namespace phosphor
13{
14namespace power
15{
16
17/**
18 * @class MihawkCPLD
19 *
20 * This class implements fault analysis for Mihawk's CPLD
21 * power sequencer device.
22 *
23 */
24class MihawkCPLD : public Device
25{
26 public:
27 MihawkCPLD() = delete;
28 ~MihawkCPLD() = default;
29 MihawkCPLD(const MihawkCPLD&) = delete;
30 MihawkCPLD& operator=(const MihawkCPLD&) = delete;
31 MihawkCPLD(MihawkCPLD&&) = default;
32 MihawkCPLD& operator=(MihawkCPLD&&) = default;
33
34 /**
35 * Constructor
36 *
37 * @param[in] instance - the device instance number
38 * @param[in] bus - D-Bus bus object
39 */
Patrick Williams7354ce62022-07-22 19:26:56 -050040 MihawkCPLD(size_t instance, sdbusplus::bus_t& bus);
Andy YF Wang40247cc2019-09-06 18:30:56 +080041
42 /**
43 * Analyzes the device for errors when the device is
44 * known to be in an error state. A log will be created.
45 */
46 void onFailure() override;
47
48 /**
49 * Checks the device for errors and only creates a log
50 * if one is found.
51 */
52 void analyze() override;
53
54 /**
55 * Clears faults in the device
56 */
57 void clearFaults() override
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000058 {}
Andy YF Wang40247cc2019-09-06 18:30:56 +080059
60 private:
61 /**
62 * If checkPoweronFault() or checkPowerreadyFault()
63 * returns "true", use readFromCPLDErrorCode()
64 * to read CPLD-error-code-register
65 * to analyze the fail reason.
66 *
67 * @param[in] statusReg - I2C's statusReg, slaveAddr
68 * offset.
69 * ex.Mihawk's CPLD-register is on slaveAddr ox40 of
70 * i2c-11, but poweron_errcode-register is on slaveAddr
71 * offset 0x21, power_ready-errorcode-register is on
72 * slaveAddr offset 0x22.
73 *
74 * @return int - the error-code value which is read on
75 * CPLD-error-code-register.
76 */
77 int readFromCPLDErrorCode(int statusReg);
78
79 /**
80 * Checks for PoweronFault on Mihawk's
81 * CPLD-power_on-error-interrupt-bit-register
82 * whether is transfered to "1".
83 *
84 * @return bool - true if power_on fail.
85 */
86 bool checkPoweronFault();
87
88 /**
89 * Clear CPLD intrupt record after reading CPLD_register.
90 */
91 void clearCPLDregister();
92
93 /**
94 * Check for PowerreadyFault on Mihawk's
95 * CPLD-power_ready-error-interrupt-bit-register
96 * whether is transfered to "1".
97 *
98 * @return bool - true if power_ready fail.
99 */
100 bool checkPowerreadyFault();
101
102 /**
103 * Use I2CInterface to read & write CPLD_register.
104 */
105 std::unique_ptr<i2c::I2CInterface> i2c;
106
107 /**
108 * The D-Bus bus object
109 */
Patrick Williams7354ce62022-07-22 19:26:56 -0500110 sdbusplus::bus_t& bus;
Andy YF Wang40247cc2019-09-06 18:30:56 +0800111
112 /**
113 * Open CPLD_register via i2c.
114 */
115 void openCPLDDevice();
116
117 /**
118 * The parameter which is checked CPLD's the same error
119 * whether is created again.
120 */
121 bool errorcodeMask;
122
123 enum class ErrorCode : int
124 {
125 /**
126 * All of powerOnErrorcode are the definition of error-code
127 * which are read on CPLD-error-code-register.
128 */
129 /**
130 * The definition of error-code:
131 * Read CPLD-error-code-register fail.
132 */
133 _0 = 0,
134
135 /**
136 * The definition of error-code:
137 * PSU0_PGOOD fail.
138 */
139 _1 = 1,
140
141 /**
142 * The definition of error-code:
143 * PSU1_PGOOD fail.
144 */
145 _2 = 2,
146
147 /**
148 * The definition of error-code:
149 * 240Va_Fault_A fail.
150 */
151 _3 = 3,
152
153 /**
154 * The definition of error-code:
155 * 240Va_Fault_B fail.
156 */
157 _4 = 4,
158
159 /**
160 * The definition of error-code:
161 * 240Va_Fault_C fail.
162 */
163 _5 = 5,
164
165 /**
166 * The definition of error-code:
167 * 240Va_Fault_D fail.
168 */
169 _6 = 6,
170
171 /**
172 * The definition of error-code:
173 * 240Va_Fault_E fail.
174 */
175 _7 = 7,
176
177 /**
178 * The definition of error-code:
179 * 240Va_Fault_F fail.
180 */
181 _8 = 8,
182
183 /**
184 * The definition of error-code:
185 * 240Va_Fault_G fail.
186 */
187 _9 = 9,
188
189 /**
190 * The definition of error-code:
191 * 240Va_Fault_H fail.
192 */
193 _10 = 10,
194
195 /**
196 * The definition of error-code:
197 * 240Va_Fault_J fail.
198 */
199 _11 = 11,
200
201 /**
202 * The definition of error-code:
203 * 240Va_Fault_K fail.
204 */
205 _12 = 12,
206
207 /**
208 * The definition of error-code:
209 * 240Va_Fault_L fail.
210 */
211 _13 = 13,
212
213 /**
214 * The definition of error-code:
215 * P5V_PGOOD fail.
216 */
217 _14 = 14,
218
219 /**
220 * The definition of error-code:
221 * P3V3_PGOOD fail.
222 */
223 _15 = 15,
224
225 /**
226 * The definition of error-code:
227 * P1V8_PGOOD fail.
228 */
229 _16 = 16,
230
231 /**
232 * The definition of error-code:
233 * P1V1_PGOOD fail.
234 */
235 _17 = 17,
236
237 /**
238 * The definition of error-code:
239 * P0V9_PGOOD fail.
240 */
241 _18 = 18,
242
243 /**
244 * The definition of error-code:
245 * P2V5A_PGOOD fail.
246 */
247 _19 = 19,
248
249 /**
250 * The definition of error-code:
251 * P2V5B_PGOOD fail.
252 */
253 _20 = 20,
254
255 /**
256 * The definition of error-code:
257 * Vdn0_PGOOD fail.
258 */
259 _21 = 21,
260
261 /**
262 * The definition of error-code:
263 * Vdn1_PGOOD fail.
264 */
265 _22 = 22,
266
267 /**
268 * The definition of error-code:
269 * P1V5_PGOOD fail.
270 */
271 _23 = 23,
272
273 /**
274 * The definition of error-code:
275 * Vio0_PGOOD fail.
276 */
277 _24 = 24,
278
279 /**
280 * The definition of error-code:
281 * Vio1_PGOOD fail.
282 */
283 _25 = 25,
284
285 /**
286 * The definition of error-code:
287 * Vdd0_PGOOD fail.
288 */
289 _26 = 26,
290
291 /**
292 * The definition of error-code:
293 * Vcs0_PGOOD fail.
294 */
295 _27 = 27,
296
297 /**
298 * The definition of error-code:
299 * Vdd1_PGOOD fail.
300 */
301 _28 = 28,
302
303 /**
304 * The definition of error-code:
305 * Vcs1_PGOOD fail.
306 */
307 _29 = 29,
308
309 /**
310 * The definition of error-code:
311 * Vddr0_PGOOD fail.
312 */
313 _30 = 30,
314
315 /**
316 * The definition of error-code:
317 * Vtt0_PGOOD fail.
318 */
319 _31 = 31,
320
321 /**
322 * The definition of error-code:
323 * Vddr1_PGOOD fail.
324 */
325 _32 = 32,
326
327 /**
328 * The definition of error-code:
329 * Vtt1_PGOOD fail.
330 */
331 _33 = 33,
332
333 /**
334 * The definition of error-code:
335 * GPU0_PGOOD fail.
336 */
337 _34 = 34,
338
339 /**
340 * The definition of error-code:
341 * GPU1_PGOOD fail.
342 */
343 _35 = 35,
344
345 /**
346 * The definition of error-code:
347 * PSU0PSU1_PGOOD fail.
348 */
349 _36 = 170
350 };
351};
352
353} // namespace power
354} // namespace phosphor