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