blob: c3b14a94ca0970bab594d510e603f06eaf76d095 [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);
Christopher Meis7e446a42024-10-22 09:36:41 +020027 default:
Kevin Tungdcf4b602025-07-04 13:14:49 +080028 return nullptr;
Christopher Meis7e446a42024-10-22 09:36:41 +020029 }
Christopher Meis7e446a42024-10-22 09:36:41 +020030}
31
32bool stringToEnum(std::string& vrStr, VRType& vrType)
33{
34 std::map<std::string, enum VRType> VRTypeToString{
35 {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
Christopher Meisf00ce802025-04-08 08:07:31 +020036 {"ISL69269Firmware", VRType::ISL69269},
Kevin Tung3f2f3e62025-08-15 15:41:07 +080037 {"MP2X6XXFirmware", VRType::MP2X6XX},
38 {"MP297XFirmware", VRType::MP297X}};
Christopher Meis7e446a42024-10-22 09:36:41 +020039 if (VRTypeToString.contains(vrStr))
40 {
41 vrType = VRTypeToString[vrStr];
42 return true;
43 }
44 return false;
45}
46
47} // namespace phosphor::software::VR