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