blob: 1875c66a5368142f0f88e01c6ce95c5020bc76b8 [file] [log] [blame]
Christopher Meis7e446a42024-10-22 09:36:41 +02001#include "vr.hpp"
2
Christopher Meisf00ce802025-04-08 08:07:31 +02003#include "isl69269/isl69269.hpp"
Kevin Tung3f2f3e62025-08-15 15:41:07 +08004#include "mps/mp297x.hpp"
Kevin Tungdcf4b602025-07-04 13:14:49 +08005#include "mps/mp2x6xx.hpp"
Christopher Meis7e446a42024-10-22 09:36:41 +02006#include "xdpe1x2xx/xdpe1x2xx.hpp"
7
8#include <map>
9
10namespace phosphor::software::VR
11{
12
13std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
14 enum VRType vrType, uint16_t bus,
15 uint16_t address)
16{
Christopher Meis7e446a42024-10-22 09:36:41 +020017 switch (vrType)
18 {
19 case VRType::XDPE1X2XX:
Kevin Tungdcf4b602025-07-04 13:14:49 +080020 return std::make_unique<XDPE1X2XX>(ctx, bus, address);
Christopher Meisf00ce802025-04-08 08:07:31 +020021 case VRType::ISL69269:
Kevin Tungdcf4b602025-07-04 13:14:49 +080022 return std::make_unique<ISL69269>(ctx, bus, address);
23 case VRType::MP2X6XX:
24 return std::make_unique<MP2X6XX>(ctx, bus, address);
Kevin Tung3f2f3e62025-08-15 15:41:07 +080025 case VRType::MP297X:
26 return std::make_unique<MP297X>(ctx, bus, address);
cchoux86a2fd02025-08-20 16:22:12 +080027 case VRType::RAA22XGen2:
28 return std::make_unique<ISL69269>(ctx, bus, address,
29 ISL69269::Gen::Gen2);
Christopher Meis7e446a42024-10-22 09:36:41 +020030 default:
Kevin Tungdcf4b602025-07-04 13:14:49 +080031 return nullptr;
Christopher Meis7e446a42024-10-22 09:36:41 +020032 }
Christopher Meis7e446a42024-10-22 09:36:41 +020033}
34
35bool stringToEnum(std::string& vrStr, VRType& vrType)
36{
37 std::map<std::string, enum VRType> VRTypeToString{
38 {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
Christopher Meisf00ce802025-04-08 08:07:31 +020039 {"ISL69269Firmware", VRType::ISL69269},
Kevin Tung3f2f3e62025-08-15 15:41:07 +080040 {"MP2X6XXFirmware", VRType::MP2X6XX},
cchoux86a2fd02025-08-20 16:22:12 +080041 {"MP297XFirmware", VRType::MP297X},
42 {"RAA22XGen2Firmware", VRType::RAA22XGen2}};
Christopher Meis7e446a42024-10-22 09:36:41 +020043 if (VRTypeToString.contains(vrStr))
44 {
45 vrType = VRTypeToString[vrStr];
46 return true;
47 }
48 return false;
49}
50
51} // namespace phosphor::software::VR