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