xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/mps/mpx9xx.hpp (revision f730973b554c83b7a8e85232e9c730a89d5f3692)
1 #pragma once
2 
3 #include "common/include/pmbus.hpp"
4 #include "mps.hpp"
5 
6 namespace phosphor::software::VR
7 {
8 
9 enum class MPX9XXCmd : uint8_t;
10 
11 /**
12  * @class MPX9XX
13  * @brief Base class for MPX9XX voltage regulators
14  *
15  * Provides common firmware update steps such as unlocking write protection,
16  * programming registers, storing/restoring NVM data, and CRC checks.
17  * Derived classes only need to provide the Config ID command.
18  */
19 class MPX9XX : public MPSVoltageRegulator
20 {
21   public:
MPX9XX(sdbusplus::async::context & ctx,uint16_t bus,uint16_t address)22     MPX9XX(sdbusplus::async::context& ctx, uint16_t bus, uint16_t address) :
23         MPSVoltageRegulator(ctx, bus, address)
24     {}
25 
26     sdbusplus::async::task<bool> verifyImage(const uint8_t* image,
27                                              size_t imageSize) final;
28     sdbusplus::async::task<bool> updateFirmware(bool force) final;
29     sdbusplus::async::task<bool> getCRC(uint32_t* checksum) final;
30     sdbusplus::async::task<bool> parseDeviceConfiguration() final;
31     bool forcedUpdateAllowed() final;
32 
33   private:
34     sdbusplus::async::task<bool> checkId(MPX9XXCmd idCmd, uint32_t expected);
35     sdbusplus::async::task<bool> unlockWriteProtect();
36     sdbusplus::async::task<bool> disableStoreFaultTriggering();
37     sdbusplus::async::task<bool> setMultiConfigAddress(uint8_t config);
38     sdbusplus::async::task<bool> programConfigData(
39         const std::vector<MPSData>& gdata);
40     sdbusplus::async::task<bool> programAllRegisters();
41     sdbusplus::async::task<bool> storeDataIntoMTP();
42     sdbusplus::async::task<bool> restoreDataFromNVM();
43     sdbusplus::async::task<bool> checkMTPCRC();
44 
45   protected:
46     virtual MPX9XXCmd getConfigIdCmd() const = 0;
47 };
48 
49 class MP292X : public MPX9XX
50 {
51   public:
52     using MPX9XX::MPX9XX;
53 
54   protected:
55     MPX9XXCmd getConfigIdCmd() const final;
56 };
57 
58 class MP994X : public MPX9XX
59 {
60   public:
61     using MPX9XX::MPX9XX;
62 
63   protected:
64     MPX9XXCmd getConfigIdCmd() const final;
65 };
66 
67 } // namespace phosphor::software::VR
68