| Christopher Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 1 | #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 | |
| 10 | namespace phosphor::software::VR |
| 11 | { |
| 12 | |
| 13 | class 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 Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 22 | |
| 23 | sdbusplus::async::task<bool> getCRC(uint32_t* checksum) final; |
| 24 | bool forcedUpdateAllowed() final; |
| 25 | |
| 26 | private: |
| 27 | static const int MaxSectCnt = 16; |
| Leo Yang | fd20478 | 2025-10-30 13:42:02 +0800 | [diff] [blame^] | 28 | /*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 Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 31 | |
| Christopher Meis | fd34144 | 2025-06-16 14:34:51 +0200 | [diff] [blame] | 32 | 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 Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 42 | 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 Meis | fd34144 | 2025-06-16 14:34:51 +0200 | [diff] [blame] | 59 | sdbusplus::async::task<bool> mfrFWcmd(uint8_t cmd, uint16_t processTime, |
| 60 | uint8_t* data, uint8_t* resp); |
| Christopher Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 61 | sdbusplus::async::task<bool> getRemainingWrites(uint8_t* remain); |
| 62 | sdbusplus::async::task<bool> program(bool force); |
| Christopher Meis | fd34144 | 2025-06-16 14:34:51 +0200 | [diff] [blame] | 63 | sdbusplus::async::task<bool> getScratchPadAddress(); |
| Christopher Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 64 | |
| Christopher Meis | fd34144 | 2025-06-16 14:34:51 +0200 | [diff] [blame] | 65 | bool parseImage(const uint8_t* image, size_t imageSize); |
| 66 | bool checkImage(); |
| Christopher Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 67 | |
| 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 Meis | fd34144 | 2025-06-16 14:34:51 +0200 | [diff] [blame] | 74 | struct deviceInfo info; |
| Christopher Meis | 7e446a4 | 2024-10-22 09:36:41 +0200 | [diff] [blame] | 75 | struct xdpe1x2xxConfig configuration; |
| 76 | }; |
| 77 | |
| 78 | } // namespace phosphor::software::VR |