xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/xdpe1x2xx/xdpe1x2xx.hpp (revision fd34144b13fe506b8dcabf54e868e109a9605f0e)
17e446a40SChristopher Meis #pragma once
27e446a40SChristopher Meis 
37e446a40SChristopher Meis #include "common/include/i2c/i2c.hpp"
47e446a40SChristopher Meis #include "i2c-vr/vr.hpp"
57e446a40SChristopher Meis 
67e446a40SChristopher Meis #include <sdbusplus/async.hpp>
77e446a40SChristopher Meis 
87e446a40SChristopher Meis #include <cstdint>
97e446a40SChristopher Meis 
107e446a40SChristopher Meis namespace phosphor::software::VR
117e446a40SChristopher Meis {
127e446a40SChristopher Meis 
137e446a40SChristopher Meis class XDPE1X2XX : public VoltageRegulator
147e446a40SChristopher Meis {
157e446a40SChristopher Meis   public:
167e446a40SChristopher Meis     XDPE1X2XX(sdbusplus::async::context& ctx, uint16_t bus, uint16_t address);
177e446a40SChristopher Meis 
187e446a40SChristopher Meis     sdbusplus::async::task<bool> verifyImage(const uint8_t* image,
197e446a40SChristopher Meis                                              size_t imageSize) final;
207e446a40SChristopher Meis 
217e446a40SChristopher Meis     sdbusplus::async::task<bool> updateFirmware(bool force) final;
227e446a40SChristopher Meis     sdbusplus::async::task<bool> reset() final;
237e446a40SChristopher Meis 
247e446a40SChristopher Meis     sdbusplus::async::task<bool> getCRC(uint32_t* checksum) final;
257e446a40SChristopher Meis     bool forcedUpdateAllowed() final;
267e446a40SChristopher Meis 
277e446a40SChristopher Meis   private:
287e446a40SChristopher Meis     static const int MaxSectCnt = 16;
297e446a40SChristopher Meis     static const int MaxSectDataCnt = 200;
307e446a40SChristopher Meis 
31*fd34144bSChristopher Meis     struct deviceInfo
32*fd34144bSChristopher Meis     {
33*fd34144bSChristopher Meis         uint8_t deviceId;
34*fd34144bSChristopher Meis         uint8_t deviceRev;
35*fd34144bSChristopher Meis         uint8_t remainingWrites;
36*fd34144bSChristopher Meis         uint32_t scratchPadAddress;
37*fd34144bSChristopher Meis         uint32_t actualCRC;
38*fd34144bSChristopher Meis         uint32_t configSize;
39*fd34144bSChristopher Meis     };
40*fd34144bSChristopher Meis 
417e446a40SChristopher Meis     struct configSect
427e446a40SChristopher Meis     {
437e446a40SChristopher Meis         uint8_t type;
447e446a40SChristopher Meis         uint16_t dataCnt;
457e446a40SChristopher Meis         uint32_t data[MaxSectDataCnt];
467e446a40SChristopher Meis     };
477e446a40SChristopher Meis 
487e446a40SChristopher Meis     struct xdpe1x2xxConfig
497e446a40SChristopher Meis     {
507e446a40SChristopher Meis         uint8_t addr;
517e446a40SChristopher Meis         uint16_t totalCnt;
527e446a40SChristopher Meis         uint32_t sumExp;
537e446a40SChristopher Meis         uint8_t sectCnt;
547e446a40SChristopher Meis         struct configSect section[MaxSectCnt];
557e446a40SChristopher Meis     };
567e446a40SChristopher Meis 
577e446a40SChristopher Meis     sdbusplus::async::task<bool> getDeviceId(uint8_t* deviceId);
58*fd34144bSChristopher Meis     sdbusplus::async::task<bool> mfrFWcmd(uint8_t cmd, uint16_t processTime,
59*fd34144bSChristopher Meis                                           uint8_t* data, uint8_t* resp);
607e446a40SChristopher Meis     sdbusplus::async::task<bool> getRemainingWrites(uint8_t* remain);
617e446a40SChristopher Meis     sdbusplus::async::task<bool> program(bool force);
62*fd34144bSChristopher Meis     sdbusplus::async::task<bool> getScratchPadAddress();
637e446a40SChristopher Meis 
64*fd34144bSChristopher Meis     bool parseImage(const uint8_t* image, size_t imageSize);
65*fd34144bSChristopher Meis     bool checkImage();
667e446a40SChristopher Meis 
677e446a40SChristopher Meis     static uint32_t calcCRC32(const uint32_t* data, int len);
687e446a40SChristopher Meis     static int getConfigSize(uint8_t deviceId, uint8_t revision);
697e446a40SChristopher Meis     static int lineSplit(char** dst, char* src, char* delim);
707e446a40SChristopher Meis 
717e446a40SChristopher Meis     phosphor::i2c::I2C i2cInterface;
727e446a40SChristopher Meis 
73*fd34144bSChristopher Meis     struct deviceInfo info;
747e446a40SChristopher Meis     struct xdpe1x2xxConfig configuration;
757e446a40SChristopher Meis };
767e446a40SChristopher Meis 
777e446a40SChristopher Meis } // namespace phosphor::software::VR
78