xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/vr.hpp (revision f730973b554c83b7a8e85232e9c730a89d5f3692)
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     MP292X,
18     MP297X,
19     MP5998,
20     MP994X,
21     RAA22XGen2,
22     RAA22XGen3p5,
23     TDA38640A
24 };
25 
26 class VoltageRegulator
27 {
28   public:
VoltageRegulator(sdbusplus::async::context & ctx)29     explicit VoltageRegulator(sdbusplus::async::context& ctx) : ctx(ctx) {}
30     virtual ~VoltageRegulator() = default;
31 
32     VoltageRegulator(VoltageRegulator& vr) = delete;
33     VoltageRegulator& operator=(VoltageRegulator other) = delete;
34     VoltageRegulator(VoltageRegulator&& other) = delete;
35     VoltageRegulator& operator=(VoltageRegulator&& other) = delete;
36 
37     // @brief Parses the firmware image into the configuration structure
38     //        and verifies its correctness.
39     // @return sdbusplus::async::task<bool> true indicates success.
40     virtual sdbusplus::async::task<bool> verifyImage(const uint8_t* image,
41                                                      size_t imageSize) = 0;
42 
43     // @brief Applies update to the voltage regulator
44     // @return sdbusplus::async::task<bool> true indicates success.
45     virtual sdbusplus::async::task<bool> updateFirmware(bool force) = 0;
46 
47     // @brief Requests the CRC value of the voltage regulator over I2C.
48     // @param pointer to write the result to.
49     // @returns < 0 on error
50     virtual sdbusplus::async::task<bool> getCRC(uint32_t* checksum) = 0;
51 
52     // @brief This function returns true if the voltage regulator supports
53     //        force of updates.
54     virtual bool forcedUpdateAllowed() = 0;
55 
56   protected:
57     sdbusplus::async::context& ctx;
58 };
59 
60 std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
61                                          enum VRType vrType, uint16_t bus,
62                                          uint16_t address);
63 
64 bool stringToEnum(std::string& vrStr, VRType& vrType);
65 
66 } // namespace phosphor::software::VR
67