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