blob: 6e6eee554fd9a721ac5dfe6dbb43654a7cdcaf95 [file] [log] [blame]
Kevin Tung994a77f2024-12-23 17:48:56 +08001#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
15namespace SoftwareInf = phosphor::software;
16namespace ManagerInf = SoftwareInf::manager;
17namespace HostPowerInf = SoftwareInf::host_power;
18
19class 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 */
68 sdbusplus::async::task<int> writeEEPROM(const uint8_t* image,
69 size_t image_size) const;
70 /**
71 * @brief Handle async host state change signal and updates the version.
72 */
73 sdbusplus::async::task<> processHostStateChange();
74};