blob: 09a3abf96f10e890650f3e02f079e7c31d8116dd [file] [log] [blame]
Matt Spinlerb54357f2017-08-21 14:38:54 -05001#pragma once
2
3#include <algorithm>
Matt Spinler110b2842017-08-21 15:23:27 -05004#include <experimental/filesystem>
Matt Spinlerb54357f2017-08-21 14:38:54 -05005#include <map>
6#include <vector>
7#include "device.hpp"
8#include "pmbus.hpp"
9#include "types.hpp"
10
11namespace witherspoon
12{
13namespace power
14{
15
16/**
17 * @class UCD90160
18 *
19 * This class implements fault analysis for the UCD90160
20 * power sequencer device.
21 *
22 */
23class UCD90160 : public Device
24{
25 public:
26
27 UCD90160() = delete;
28 ~UCD90160() = default;
29 UCD90160(const UCD90160&) = delete;
30 UCD90160& operator=(const UCD90160&) = delete;
31 UCD90160(UCD90160&&) = default;
32 UCD90160& operator=(UCD90160&&) = default;
33
34 /**
35 * Constructor
36 *
37 * @param[in] instance - the device instance number
38 */
39 UCD90160(size_t instance);
40
41 /**
42 * Analyzes the device for errors when the device is
43 * known to be in an error state. A log will be created.
44 */
45 void onFailure() override;
46
47 /**
48 * Checks the device for errors and only creates a log
49 * if one is found.
50 */
51 void analyze() override;
52
53 /**
54 * Clears faults in the device
55 */
56 void clearFaults() override;
57
58 private:
59
60 /**
Matt Spinler110b2842017-08-21 15:23:27 -050061 * Finds the GPIO device path for this device
62 */
63 void findGPIODevice();
64
65 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -050066 * Checks for VOUT faults on the device.
67 *
68 * This device can monitor voltages of its dependent
69 * devices, and VOUT faults are voltage faults
70 * on these devices.
71 *
72 * @return bool - true if an error log was created
73 */
74 bool checkVOUTFaults();
75
76 /**
77 * Checks for PGOOD faults on the device.
78 *
79 * This device can monitor the PGOOD signals of its dependent
80 * devices, and this check will look for faults of
81 * those PGOODs.
82 *
83 * @param[in] polling - If this is running while polling for errors,
84 * as opposing to analyzing a fail condition.
85 *
86 * @return bool - true if an error log was created
87 */
88 bool checkPGOODFaults(bool polling);
89
90 /**
91 * Creates an error log when the device has an error
92 * but it isn't a PGOOD or voltage failure.
93 */
94 void createPowerFaultLog();
95
96 /**
Matt Spinlere7e432b2017-08-21 15:01:40 -050097 * Reads the status_word register
98 *
99 * @return uint16_t - the register contents
100 */
101 uint16_t readStatusWord();
102
103 /**
104 * Reads the mfr_status register
105 *
106 * @return uint32_t - the register contents
107 */
108 uint32_t readMFRStatus();
109
110 /**
111 * Says if we've already logged a Vout fault
112 *
113 * The policy is only 1 of the same error will
114 * be logged for the duration of a class instance.
115 *
116 * @param[in] page - the page to check
117 *
118 * @return bool - if we've already logged a fault against
119 * this page
120 */
121 inline bool isVoutFaultLogged(uint32_t page) const
122 {
123 return std::find(voutErrors.begin(),
124 voutErrors.end(),
125 page) != voutErrors.end();
126 }
127
128 /**
129 * Saves that a Vout fault has been logged
130 *
131 * @param[in] page - the page the error was logged against
132 */
133 inline void setVoutFaultLogged(uint32_t page)
134 {
135 voutErrors.push_back(page);
136 }
137
138 /**
139 * List of pages that Vout errors have
140 * already been logged against
141 */
142 std::vector<uint32_t> voutErrors;
143
144 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -0500145 * The read/write interface to this hardware
146 */
147 pmbus::PMBus interface;
148
149 /**
150 * Keeps track of device access errors to avoid repeatedly
151 * logging errors for bad hardware
152 */
153 bool accessError = false;
154
155 /**
Matt Spinler110b2842017-08-21 15:23:27 -0500156 * The path to the GPIO device used to read
157 * the GPI (PGOOD) status
158 */
159 std::experimental::filesystem::path gpioDevice;
160
161 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -0500162 * Map of device instance to the instance specific data
163 */
164 static const ucd90160::DeviceMap deviceMap;
165};
166
167}
168}