blob: e47061425d8d897c9b2934cf46b44dd4b2aaa987 [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"
Matt Spinlerd998b732017-08-21 15:35:54 -05008#include "gpio.hpp"
Matt Spinlerb54357f2017-08-21 14:38:54 -05009#include "pmbus.hpp"
10#include "types.hpp"
11
12namespace witherspoon
13{
14namespace power
15{
16
17/**
18 * @class UCD90160
19 *
20 * This class implements fault analysis for the UCD90160
21 * power sequencer device.
22 *
23 */
24class UCD90160 : public Device
25{
26 public:
27
28 UCD90160() = delete;
29 ~UCD90160() = default;
30 UCD90160(const UCD90160&) = delete;
31 UCD90160& operator=(const UCD90160&) = delete;
32 UCD90160(UCD90160&&) = default;
33 UCD90160& operator=(UCD90160&&) = default;
34
35 /**
36 * Constructor
37 *
38 * @param[in] instance - the device instance number
39 */
40 UCD90160(size_t instance);
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 */
Matt Spinler81be00b2017-09-07 15:28:38 -050057 void clearFaults() override
58 {
59 }
Matt Spinlerb54357f2017-08-21 14:38:54 -050060
61 private:
62
63 /**
Matt Spinlerfcd4a712017-09-19 10:45:07 -050064 * Given the device path for a chip, find its gpiochip
65 * path
66 *
67 * @param[in] path - device path, like
68 * /sys/devices/.../i2c-11/11-0064
69 *
70 * @return fs::path - The gpiochip path, like
71 * /dev/gpiochip1
Matt Spinler110b2842017-08-21 15:23:27 -050072 */
Matt Spinlerfcd4a712017-09-19 10:45:07 -050073 static std::experimental::filesystem::path findGPIODevice(
74 const std::experimental::filesystem::path& path);
Matt Spinler110b2842017-08-21 15:23:27 -050075
76 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -050077 * Checks for VOUT faults on the device.
78 *
79 * This device can monitor voltages of its dependent
80 * devices, and VOUT faults are voltage faults
81 * on these devices.
82 *
83 * @return bool - true if an error log was created
84 */
85 bool checkVOUTFaults();
86
87 /**
88 * Checks for PGOOD faults on the device.
89 *
90 * This device can monitor the PGOOD signals of its dependent
91 * devices, and this check will look for faults of
92 * those PGOODs.
93 *
94 * @param[in] polling - If this is running while polling for errors,
95 * as opposing to analyzing a fail condition.
96 *
97 * @return bool - true if an error log was created
98 */
99 bool checkPGOODFaults(bool polling);
100
101 /**
102 * Creates an error log when the device has an error
103 * but it isn't a PGOOD or voltage failure.
104 */
105 void createPowerFaultLog();
106
107 /**
Matt Spinlere7e432b2017-08-21 15:01:40 -0500108 * Reads the status_word register
109 *
110 * @return uint16_t - the register contents
111 */
112 uint16_t readStatusWord();
113
114 /**
115 * Reads the mfr_status register
116 *
117 * @return uint32_t - the register contents
118 */
119 uint32_t readMFRStatus();
120
121 /**
122 * Says if we've already logged a Vout fault
123 *
124 * The policy is only 1 of the same error will
125 * be logged for the duration of a class instance.
126 *
127 * @param[in] page - the page to check
128 *
129 * @return bool - if we've already logged a fault against
130 * this page
131 */
132 inline bool isVoutFaultLogged(uint32_t page) const
133 {
134 return std::find(voutErrors.begin(),
135 voutErrors.end(),
136 page) != voutErrors.end();
137 }
138
139 /**
140 * Saves that a Vout fault has been logged
141 *
142 * @param[in] page - the page the error was logged against
143 */
144 inline void setVoutFaultLogged(uint32_t page)
145 {
146 voutErrors.push_back(page);
147 }
148
149 /**
Matt Spinlerd998b732017-08-21 15:35:54 -0500150 * Says if we've already logged a PGOOD fault
151 *
152 * The policy is only 1 of the same errors will
153 * be logged for the duration of a class instance.
154 *
155 * @param[in] input - the input to check
156 *
157 * @return bool - if we've already logged a fault against
158 * this input
159 */
160 inline bool isPGOODFaultLogged(uint32_t input) const
161 {
162 return std::find(pgoodErrors.begin(),
163 pgoodErrors.end(),
164 input) != pgoodErrors.end();
165 }
166
167 /**
168 * Saves that a PGOOD fault has been logged
169 *
170 * @param[in] input - the input the error was logged against
171 */
172 inline void setPGOODFaultLogged(uint32_t input)
173 {
174 pgoodErrors.push_back(input);
175 }
176
177 /**
Matt Spinlere7e432b2017-08-21 15:01:40 -0500178 * List of pages that Vout errors have
179 * already been logged against
180 */
181 std::vector<uint32_t> voutErrors;
182
183 /**
Matt Spinlerd998b732017-08-21 15:35:54 -0500184 * List of inputs that PGOOD errors have
185 * already been logged against
186 */
187 std::vector<uint32_t> pgoodErrors;
188
189 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -0500190 * The read/write interface to this hardware
191 */
192 pmbus::PMBus interface;
193
194 /**
Matt Spinlerd998b732017-08-21 15:35:54 -0500195 * A map of GPI pin IDs to the GPIO object
196 * used to access them
197 */
198 std::map<size_t, std::unique_ptr<gpio::GPIO>> gpios;
199
200 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -0500201 * Keeps track of device access errors to avoid repeatedly
202 * logging errors for bad hardware
203 */
204 bool accessError = false;
205
206 /**
Matt Spinler110b2842017-08-21 15:23:27 -0500207 * The path to the GPIO device used to read
208 * the GPI (PGOOD) status
209 */
210 std::experimental::filesystem::path gpioDevice;
211
212 /**
Matt Spinlerb54357f2017-08-21 14:38:54 -0500213 * Map of device instance to the instance specific data
214 */
215 static const ucd90160::DeviceMap deviceMap;
216};
217
218}
219}