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