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