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