blob: 14a40700c59fe26e5e22ec3ecad68d0416bfbb26 [file] [log] [blame]
Christopher Meis7e446a42024-10-22 09:36:41 +02001#pragma once
2
3#include "common/include/i2c/i2c.hpp"
4#include "i2c-vr/vr.hpp"
5
6#include <sdbusplus/async.hpp>
7
8#include <cstdint>
9
10namespace phosphor::software::VR
11{
12
13class XDPE1X2XX : public VoltageRegulator
14{
15 public:
16 XDPE1X2XX(sdbusplus::async::context& ctx, uint16_t bus, uint16_t address);
17
18 sdbusplus::async::task<bool> verifyImage(const uint8_t* image,
19 size_t imageSize) final;
20
21 sdbusplus::async::task<bool> updateFirmware(bool force) final;
Christopher Meis7e446a42024-10-22 09:36:41 +020022
23 sdbusplus::async::task<bool> getCRC(uint32_t* checksum) final;
24 bool forcedUpdateAllowed() final;
25
26 private:
27 static const int MaxSectCnt = 16;
Leo Yangfd204782025-10-30 13:42:02 +080028 /*According to the XDPE192C3E datasheet, the Config User Section size has
29 reached 864 bytes, so MaxSectDataCnt requires at least 216.*/
30 static const int MaxSectDataCnt = 300;
Christopher Meis7e446a42024-10-22 09:36:41 +020031
Christopher Meisfd341442025-06-16 14:34:51 +020032 struct deviceInfo
33 {
34 uint8_t deviceId;
35 uint8_t deviceRev;
36 uint8_t remainingWrites;
37 uint32_t scratchPadAddress;
38 uint32_t actualCRC;
39 uint32_t configSize;
40 };
41
Christopher Meis7e446a42024-10-22 09:36:41 +020042 struct configSect
43 {
44 uint8_t type;
45 uint16_t dataCnt;
46 uint32_t data[MaxSectDataCnt];
47 };
48
49 struct xdpe1x2xxConfig
50 {
51 uint8_t addr;
52 uint16_t totalCnt;
53 uint32_t sumExp;
54 uint8_t sectCnt;
55 struct configSect section[MaxSectCnt];
56 };
57
58 sdbusplus::async::task<bool> getDeviceId(uint8_t* deviceId);
Christopher Meisfd341442025-06-16 14:34:51 +020059 sdbusplus::async::task<bool> mfrFWcmd(uint8_t cmd, uint16_t processTime,
60 uint8_t* data, uint8_t* resp);
Christopher Meis7e446a42024-10-22 09:36:41 +020061 sdbusplus::async::task<bool> getRemainingWrites(uint8_t* remain);
62 sdbusplus::async::task<bool> program(bool force);
Christopher Meisfd341442025-06-16 14:34:51 +020063 sdbusplus::async::task<bool> getScratchPadAddress();
Christopher Meis7e446a42024-10-22 09:36:41 +020064
Christopher Meisfd341442025-06-16 14:34:51 +020065 bool parseImage(const uint8_t* image, size_t imageSize);
66 bool checkImage();
Christopher Meis7e446a42024-10-22 09:36:41 +020067
68 static uint32_t calcCRC32(const uint32_t* data, int len);
69 static int getConfigSize(uint8_t deviceId, uint8_t revision);
70 static int lineSplit(char** dst, char* src, char* delim);
71
72 phosphor::i2c::I2C i2cInterface;
73
Christopher Meisfd341442025-06-16 14:34:51 +020074 struct deviceInfo info;
Christopher Meis7e446a42024-10-22 09:36:41 +020075 struct xdpe1x2xxConfig configuration;
76};
77
78} // namespace phosphor::software::VR