xref: /openbmc/phosphor-bmc-code-mgmt/eeprom-device/eeprom_device.hpp (revision a2eb951f7384c2b4fa494f90e78295f615c12a56)
1994a77ffSKevin Tung #pragma once
2994a77ffSKevin Tung 
3994a77ffSKevin Tung #include "common/include/device.hpp"
4994a77ffSKevin Tung #include "common/include/host_power.hpp"
5994a77ffSKevin Tung #include "common/include/software.hpp"
6994a77ffSKevin Tung #include "common/include/software_manager.hpp"
7994a77ffSKevin Tung #include "eeprom_device_version.hpp"
8994a77ffSKevin Tung 
9994a77ffSKevin Tung #include <gpiod.hpp>
10994a77ffSKevin Tung #include <sdbusplus/async/context.hpp>
11994a77ffSKevin Tung #include <sdbusplus/bus/match.hpp>
12994a77ffSKevin Tung 
13994a77ffSKevin Tung #include <string>
14994a77ffSKevin Tung 
15994a77ffSKevin Tung namespace SoftwareInf = phosphor::software;
16994a77ffSKevin Tung namespace ManagerInf = SoftwareInf::manager;
17994a77ffSKevin Tung namespace HostPowerInf = SoftwareInf::host_power;
18994a77ffSKevin Tung 
19994a77ffSKevin Tung class EEPROMDevice : public Device
20994a77ffSKevin Tung {
21994a77ffSKevin Tung   public:
22994a77ffSKevin Tung     EEPROMDevice(sdbusplus::async::context& ctx, uint16_t bus, uint8_t address,
23994a77ffSKevin Tung                  const std::string& chipModel,
24994a77ffSKevin Tung                  const std::vector<std::string>& gpioLines,
25994a77ffSKevin Tung                  const std::vector<bool>& gpioPolarities,
26994a77ffSKevin Tung                  std::unique_ptr<DeviceVersion> deviceVersion,
27994a77ffSKevin Tung                  SoftwareConfig& config, ManagerInf::SoftwareManager* parent);
28994a77ffSKevin Tung 
29994a77ffSKevin Tung     using Device::softwareCurrent;
30994a77ffSKevin Tung 
31994a77ffSKevin Tung     sdbusplus::async::task<bool> updateDevice(const uint8_t* image,
32994a77ffSKevin Tung                                               size_t image_size) final;
33994a77ffSKevin Tung 
34994a77ffSKevin Tung   private:
35994a77ffSKevin Tung     uint16_t bus;
36994a77ffSKevin Tung     uint8_t address;
37994a77ffSKevin Tung     std::string chipModel;
38994a77ffSKevin Tung     std::vector<std::string> gpioLines;
39994a77ffSKevin Tung     std::vector<bool> gpioPolarities;
40994a77ffSKevin Tung     std::unique_ptr<DeviceVersion> deviceVersion;
41994a77ffSKevin Tung     HostPowerInf::HostPower hostPower;
42994a77ffSKevin Tung 
43994a77ffSKevin Tung     /**
44994a77ffSKevin Tung      * @brief Binds the EEPROM device driver to the I2C device.
45994a77ffSKevin Tung      *
46994a77ffSKevin Tung      * @return `true` on success, `false` otherwise.
47994a77ffSKevin Tung      */
48994a77ffSKevin Tung     sdbusplus::async::task<bool> bindEEPROM();
49994a77ffSKevin Tung     /**
50994a77ffSKevin Tung      * @brief Unbinds the EEPROM device driver from the I2C device.
51994a77ffSKevin Tung      *
52994a77ffSKevin Tung      * @return `true` on success, `false` otherwise.
53994a77ffSKevin Tung      */
54994a77ffSKevin Tung     sdbusplus::async::task<bool> unbindEEPROM();
55994a77ffSKevin Tung     /**
56994a77ffSKevin Tung      * @brief Checks if the EEPROM device is currently bound to its driver.
57994a77ffSKevin Tung      *
58994a77ffSKevin Tung      * @return `true` if the EEPROM device is bound, `false` otherwise.
59994a77ffSKevin Tung      */
60994a77ffSKevin Tung     bool isEEPROMBound();
61994a77ffSKevin Tung     /**
62994a77ffSKevin Tung      * @brief Writes data to the EEPROM.
63994a77ffSKevin Tung      *
64994a77ffSKevin Tung      * @param image         - Pointer to the data to write.
65994a77ffSKevin Tung      * @param image_size    - Size of the data to write in bytes.
66994a77ffSKevin Tung      * @return `true` on success, `false` otherwise.
67994a77ffSKevin Tung      */
68*a2eb951fSKevin Tung     sdbusplus::async::task<bool> writeEEPROM(const uint8_t* image,
69994a77ffSKevin Tung                                              size_t image_size) const;
70994a77ffSKevin Tung     /**
71994a77ffSKevin Tung      *  @brief Handle async host state change signal and updates the version.
72994a77ffSKevin Tung      */
73994a77ffSKevin Tung     sdbusplus::async::task<> processHostStateChange();
74994a77ffSKevin Tung };
75