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