Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 1 | #include "interface.hpp" |
| 2 | |
| 3 | #include "lattice.hpp" |
| 4 | |
| 5 | #include <phosphor-logging/lg2.hpp> |
| 6 | |
| 7 | namespace phosphor::software::cpld |
| 8 | { |
| 9 | |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 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 | |
| 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 |
| 42 | const bool vendorRegistered = [] { |
Daniel Hsu | 61e1267 | 2025-06-12 19:20:46 +0800 | [diff] [blame^] | 43 | for (const auto& [type, info] : supportedDeviceMap) |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 44 | { |
Daniel Hsu | 61e1267 | 2025-06-12 19:20:46 +0800 | [diff] [blame^] | 45 | auto typeStr = std::string(type); |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 46 | CPLDFactory::instance().registerCPLD( |
Daniel Hsu | 61e1267 | 2025-06-12 19:20:46 +0800 | [diff] [blame^] | 47 | type, [info](sdbusplus::async::context& ctx, |
| 48 | const std::string& /*chipName*/, uint16_t bus, |
| 49 | uint8_t address) { |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 50 | // Create and return a LatticeCPLD instance |
| 51 | // Pass the parameters to the constructor |
Daniel Hsu | 61e1267 | 2025-06-12 19:20:46 +0800 | [diff] [blame^] | 52 | return std::make_unique<LatticeCPLD>(ctx, info.chipName, bus, |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 53 | address); |
| 54 | }); |
| 55 | } |
| 56 | return true; |
| 57 | }(); |
| 58 | |
| 59 | } // namespace |