1f6470b5eSDaniel Hsu #include "cpld_interface.hpp"
2f6470b5eSDaniel Hsu
3f6470b5eSDaniel Hsu #include "lattice/interface.hpp"
4f6470b5eSDaniel Hsu
5f6470b5eSDaniel Hsu namespace phosphor::software::cpld
6f6470b5eSDaniel Hsu {
7f6470b5eSDaniel Hsu
instance()8f6470b5eSDaniel Hsu CPLDFactory& CPLDFactory::instance()
9f6470b5eSDaniel Hsu {
10f6470b5eSDaniel Hsu static CPLDFactory factory;
11f6470b5eSDaniel Hsu return factory;
12f6470b5eSDaniel Hsu }
13f6470b5eSDaniel Hsu
registerCPLD(const std::string & vendorName,Creator creator)14*61e12672SDaniel Hsu void CPLDFactory::registerCPLD(const std::string& chipType, Creator creator)
15f6470b5eSDaniel Hsu {
16*61e12672SDaniel Hsu creators[chipType] = std::move(creator);
17f6470b5eSDaniel Hsu }
18f6470b5eSDaniel Hsu
create(const std::string & vendorName,sdbusplus::async::context & ctx,const std::string & chipName,uint16_t bus,uint8_t address) const19f6470b5eSDaniel Hsu std::unique_ptr<CPLDInterface> CPLDFactory::create(
20*61e12672SDaniel Hsu const std::string& chipType, sdbusplus::async::context& ctx,
21f6470b5eSDaniel Hsu const std::string& chipName, uint16_t bus, uint8_t address) const
22f6470b5eSDaniel Hsu {
23*61e12672SDaniel Hsu auto it = creators.find(chipType);
24f6470b5eSDaniel Hsu if (it != creators.end())
25f6470b5eSDaniel Hsu {
26f6470b5eSDaniel Hsu return (it->second)(ctx, chipName, bus, address);
27f6470b5eSDaniel Hsu }
28f6470b5eSDaniel Hsu return nullptr;
29f6470b5eSDaniel Hsu }
30f6470b5eSDaniel Hsu
getConfigs()31f6470b5eSDaniel Hsu std::vector<std::string> CPLDFactory::getConfigs()
32f6470b5eSDaniel Hsu {
33f6470b5eSDaniel Hsu std::vector<std::string> configs;
34f6470b5eSDaniel Hsu configs.reserve(creators.size());
35f6470b5eSDaniel Hsu
36f6470b5eSDaniel Hsu std::transform(creators.begin(), creators.end(),
37f6470b5eSDaniel Hsu std::back_inserter(configs),
38f6470b5eSDaniel Hsu [](const auto& pair) { return pair.first; });
39f6470b5eSDaniel Hsu
40f6470b5eSDaniel Hsu return configs;
41f6470b5eSDaniel Hsu }
42f6470b5eSDaniel Hsu
43f6470b5eSDaniel Hsu } // namespace phosphor::software::cpld
44