| Kevin Tung | 994a77f | 2024-12-23 17:48:56 +0800 | [diff] [blame] | 1 | #pragma once | 
 | 2 |  | 
 | 3 | #include "common/include/device.hpp" | 
 | 4 | #include "common/include/host_power.hpp" | 
 | 5 | #include "common/include/software.hpp" | 
 | 6 | #include "common/include/software_manager.hpp" | 
 | 7 | #include "eeprom_device_version.hpp" | 
 | 8 |  | 
 | 9 | #include <gpiod.hpp> | 
 | 10 | #include <sdbusplus/async/context.hpp> | 
 | 11 | #include <sdbusplus/bus/match.hpp> | 
 | 12 |  | 
 | 13 | #include <string> | 
 | 14 |  | 
 | 15 | namespace SoftwareInf = phosphor::software; | 
 | 16 | namespace ManagerInf = SoftwareInf::manager; | 
 | 17 | namespace HostPowerInf = SoftwareInf::host_power; | 
 | 18 |  | 
 | 19 | class EEPROMDevice : public Device | 
 | 20 | { | 
 | 21 |   public: | 
 | 22 |     EEPROMDevice(sdbusplus::async::context& ctx, uint16_t bus, uint8_t address, | 
 | 23 |                  const std::string& chipModel, | 
 | 24 |                  const std::vector<std::string>& gpioLines, | 
 | 25 |                  const std::vector<bool>& gpioPolarities, | 
 | 26 |                  std::unique_ptr<DeviceVersion> deviceVersion, | 
 | 27 |                  SoftwareConfig& config, ManagerInf::SoftwareManager* parent); | 
 | 28 |  | 
 | 29 |     using Device::softwareCurrent; | 
 | 30 |  | 
 | 31 |     sdbusplus::async::task<bool> updateDevice(const uint8_t* image, | 
 | 32 |                                               size_t image_size) final; | 
 | 33 |  | 
 | 34 |   private: | 
 | 35 |     uint16_t bus; | 
 | 36 |     uint8_t address; | 
 | 37 |     std::string chipModel; | 
 | 38 |     std::vector<std::string> gpioLines; | 
 | 39 |     std::vector<bool> gpioPolarities; | 
 | 40 |     std::unique_ptr<DeviceVersion> deviceVersion; | 
 | 41 |     HostPowerInf::HostPower hostPower; | 
 | 42 |  | 
 | 43 |     /** | 
 | 44 |      * @brief Binds the EEPROM device driver to the I2C device. | 
 | 45 |      * | 
 | 46 |      * @return `true` on success, `false` otherwise. | 
 | 47 |      */ | 
 | 48 |     sdbusplus::async::task<bool> bindEEPROM(); | 
 | 49 |     /** | 
 | 50 |      * @brief Unbinds the EEPROM device driver from the I2C device. | 
 | 51 |      * | 
 | 52 |      * @return `true` on success, `false` otherwise. | 
 | 53 |      */ | 
 | 54 |     sdbusplus::async::task<bool> unbindEEPROM(); | 
 | 55 |     /** | 
 | 56 |      * @brief Checks if the EEPROM device is currently bound to its driver. | 
 | 57 |      * | 
 | 58 |      * @return `true` if the EEPROM device is bound, `false` otherwise. | 
 | 59 |      */ | 
 | 60 |     bool isEEPROMBound(); | 
 | 61 |     /** | 
 | 62 |      * @brief Writes data to the EEPROM. | 
 | 63 |      * | 
 | 64 |      * @param image         - Pointer to the data to write. | 
 | 65 |      * @param image_size    - Size of the data to write in bytes. | 
 | 66 |      * @return `true` on success, `false` otherwise. | 
 | 67 |      */ | 
| Kevin Tung | a2eb951 | 2025-05-05 18:28:56 +0800 | [diff] [blame] | 68 |     sdbusplus::async::task<bool> writeEEPROM(const uint8_t* image, | 
 | 69 |                                              size_t image_size) const; | 
| Kevin Tung | 994a77f | 2024-12-23 17:48:56 +0800 | [diff] [blame] | 70 |     /** | 
 | 71 |      *  @brief Handle async host state change signal and updates the version. | 
 | 72 |      */ | 
 | 73 |     sdbusplus::async::task<> processHostStateChange(); | 
 | 74 | }; |