1 #include "interface.hpp"
2
3 #include "lattice.hpp"
4
5 #include <phosphor-logging/lg2.hpp>
6
7 namespace phosphor::software::cpld
8 {
9
updateFirmware(bool,const uint8_t * image,size_t imageSize,std::function<bool (int)> progressCallBack)10 sdbusplus::async::task<bool> LatticeCPLD::updateFirmware(
11 bool /*force*/, const uint8_t* image, size_t imageSize,
12 std::function<bool(int)> progressCallBack)
13 {
14 lg2::info("Updating Lattice CPLD firmware");
15
16 std::replace(chipname.begin(), chipname.end(), '_', '-');
17 auto cpldManager = std::make_unique<CpldLatticeManager>(
18 ctx, bus, address, image, imageSize, chipname, "CFG0", false);
19
20 co_return co_await cpldManager->updateFirmware(progressCallBack);
21 }
22
getVersion(std::string & version)23 sdbusplus::async::task<bool> LatticeCPLD::getVersion(std::string& version)
24 {
25 lg2::info("Getting Lattice CPLD version");
26
27 std::replace(chipname.begin(), chipname.end(), '_', '-');
28 auto cpldManager = std::make_unique<CpldLatticeManager>(
29 ctx, bus, address, nullptr, 0, chipname, "CFG0", false);
30
31 co_return co_await cpldManager->getVersion(version);
32 }
33
34 } // namespace phosphor::software::cpld
35
36 // Factory function to create lattice CPLD device
37 namespace
38 {
39 using namespace phosphor::software::cpld;
40
41 // Register all the CPLD type with the CPLD factory
__anonbfe9fa260202null42 const bool vendorRegistered = [] {
43 for (const auto& [type, info] : supportedDeviceMap)
44 {
45 auto typeStr = std::string(type);
46 CPLDFactory::instance().registerCPLD(
47 type, [info](sdbusplus::async::context& ctx,
48 const std::string& /*chipName*/, uint16_t bus,
49 uint8_t address) {
50 // Create and return a LatticeCPLD instance
51 // Pass the parameters to the constructor
52 return std::make_unique<LatticeCPLD>(ctx, info.chipName, bus,
53 address);
54 });
55 }
56 return true;
57 }();
58
59 } // namespace
60