xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/vr.hpp (revision 782d6eed913236bc78c533551876389f176bf121)
1 #pragma once
2 
3 #include <sdbusplus/async.hpp>
4 
5 #include <cstdint>
6 #include <memory>
7 #include <string>
8 
9 namespace phosphor::software::VR
10 {
11 
12 enum class VRType
13 {
14     XDPE1X2XX,
15     ISL69269,
16     MP2X6XX,
17     MP297X,
18     MP5998,
19     RAA22XGen2,
20 };
21 
22 class VoltageRegulator
23 {
24   public:
VoltageRegulator(sdbusplus::async::context & ctx)25     explicit VoltageRegulator(sdbusplus::async::context& ctx) : ctx(ctx) {}
26     virtual ~VoltageRegulator() = default;
27 
28     VoltageRegulator(VoltageRegulator& vr) = delete;
29     VoltageRegulator& operator=(VoltageRegulator other) = delete;
30     VoltageRegulator(VoltageRegulator&& other) = delete;
31     VoltageRegulator& operator=(VoltageRegulator&& other) = delete;
32 
33     // @brief Parses the firmware image into the configuration structure
34     //        and verifies its correctness.
35     // @return sdbusplus::async::task<bool> true indicates success.
36     virtual sdbusplus::async::task<bool> verifyImage(const uint8_t* image,
37                                                      size_t imageSize) = 0;
38 
39     // @brief Applies update to the voltage regulator
40     // @return sdbusplus::async::task<bool> true indicates success.
41     virtual sdbusplus::async::task<bool> updateFirmware(bool force) = 0;
42 
43     // @brief Requests the CRC value of the voltage regulator over I2C.
44     // @param pointer to write the result to.
45     // @returns < 0 on error
46     virtual sdbusplus::async::task<bool> getCRC(uint32_t* checksum) = 0;
47 
48     // @brief This function returns true if the voltage regulator supports
49     //        force of updates.
50     virtual bool forcedUpdateAllowed() = 0;
51 
52   protected:
53     sdbusplus::async::context& ctx;
54 };
55 
56 std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
57                                          enum VRType vrType, uint16_t bus,
58                                          uint16_t address);
59 
60 bool stringToEnum(std::string& vrStr, VRType& vrType);
61 
62 } // namespace phosphor::software::VR
63