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