blob: b2734cef3bc507f73741347e9484c9067b2a3a97 [file] [log] [blame]
Daniel Hsuf6470b52025-02-26 15:03:47 +08001#include "interface.hpp"
2
3#include "lattice.hpp"
4
5#include <phosphor-logging/lg2.hpp>
6
7namespace phosphor::software::cpld
8{
9
Daniel Hsuf6470b52025-02-26 15:03:47 +080010sdbusplus::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
23sdbusplus::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
37namespace
38{
39using namespace phosphor::software::cpld;
40
41// Register all the CPLD type with the CPLD factory
42const bool vendorRegistered = [] {
Daniel Hsu61e12672025-06-12 19:20:46 +080043 for (const auto& [type, info] : supportedDeviceMap)
Daniel Hsuf6470b52025-02-26 15:03:47 +080044 {
Daniel Hsu61e12672025-06-12 19:20:46 +080045 auto typeStr = std::string(type);
Daniel Hsuf6470b52025-02-26 15:03:47 +080046 CPLDFactory::instance().registerCPLD(
Daniel Hsu61e12672025-06-12 19:20:46 +080047 type, [info](sdbusplus::async::context& ctx,
48 const std::string& /*chipName*/, uint16_t bus,
49 uint8_t address) {
Daniel Hsuf6470b52025-02-26 15:03:47 +080050 // Create and return a LatticeCPLD instance
51 // Pass the parameters to the constructor
Daniel Hsu61e12672025-06-12 19:20:46 +080052 return std::make_unique<LatticeCPLD>(ctx, info.chipName, bus,
Daniel Hsuf6470b52025-02-26 15:03:47 +080053 address);
54 });
55 }
56 return true;
57}();
58
59} // namespace