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