blob: 85d357ca28d5a818c2a8dfca970ec87826f10a6a [file] [log] [blame]
Daniel Hsuf6470b52025-02-26 15:03:47 +08001#include "cpld_interface.hpp"
2
3#include "lattice/interface.hpp"
4
5namespace phosphor::software::cpld
6{
7
8CPLDFactory& CPLDFactory::instance()
9{
10 static CPLDFactory factory;
11 return factory;
12}
13
Daniel Hsu61e12672025-06-12 19:20:46 +080014void CPLDFactory::registerCPLD(const std::string& chipType, Creator creator)
Daniel Hsuf6470b52025-02-26 15:03:47 +080015{
Daniel Hsu61e12672025-06-12 19:20:46 +080016 creators[chipType] = std::move(creator);
Daniel Hsuf6470b52025-02-26 15:03:47 +080017}
18
19std::unique_ptr<CPLDInterface> CPLDFactory::create(
Daniel Hsu61e12672025-06-12 19:20:46 +080020 const std::string& chipType, sdbusplus::async::context& ctx,
Daniel Hsuf6470b52025-02-26 15:03:47 +080021 const std::string& chipName, uint16_t bus, uint8_t address) const
22{
Daniel Hsu61e12672025-06-12 19:20:46 +080023 auto it = creators.find(chipType);
Daniel Hsuf6470b52025-02-26 15:03:47 +080024 if (it != creators.end())
25 {
26 return (it->second)(ctx, chipName, bus, address);
27 }
28 return nullptr;
29}
30
31std::vector<std::string> CPLDFactory::getConfigs()
32{
33 std::vector<std::string> configs;
34 configs.reserve(creators.size());
35
36 std::transform(creators.begin(), creators.end(),
37 std::back_inserter(configs),
38 [](const auto& pair) { return pair.first; });
39
40 return configs;
41}
42
43} // namespace phosphor::software::cpld