blob: c4befe1d5e1cfb2e7c8be2f58d924d0af8207ac7 [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"
FreddieJheng782d6ee2025-08-19 18:53:15 +08006#include "mps/mp5998.hpp"
Christopher Meis7e446a42024-10-22 09:36:41 +02007#include "xdpe1x2xx/xdpe1x2xx.hpp"
8
9#include <map>
10
11namespace phosphor::software::VR
12{
13
14std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
15 enum VRType vrType, uint16_t bus,
16 uint16_t address)
17{
Christopher Meis7e446a42024-10-22 09:36:41 +020018 switch (vrType)
19 {
20 case VRType::XDPE1X2XX:
Kevin Tungdcf4b602025-07-04 13:14:49 +080021 return std::make_unique<XDPE1X2XX>(ctx, bus, address);
Christopher Meisf00ce802025-04-08 08:07:31 +020022 case VRType::ISL69269:
Kevin Tungdcf4b602025-07-04 13:14:49 +080023 return std::make_unique<ISL69269>(ctx, bus, address);
24 case VRType::MP2X6XX:
25 return std::make_unique<MP2X6XX>(ctx, bus, address);
Kevin Tung3f2f3e62025-08-15 15:41:07 +080026 case VRType::MP297X:
27 return std::make_unique<MP297X>(ctx, bus, address);
FreddieJheng782d6ee2025-08-19 18:53:15 +080028 case VRType::MP5998:
29 return std::make_unique<MP5998>(ctx, bus, address);
cchoux86a2fd02025-08-20 16:22:12 +080030 case VRType::RAA22XGen2:
31 return std::make_unique<ISL69269>(ctx, bus, address,
32 ISL69269::Gen::Gen2);
Christopher Meis7e446a42024-10-22 09:36:41 +020033 default:
Kevin Tungdcf4b602025-07-04 13:14:49 +080034 return nullptr;
Christopher Meis7e446a42024-10-22 09:36:41 +020035 }
Christopher Meis7e446a42024-10-22 09:36:41 +020036}
37
38bool stringToEnum(std::string& vrStr, VRType& vrType)
39{
40 std::map<std::string, enum VRType> VRTypeToString{
41 {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
Christopher Meisf00ce802025-04-08 08:07:31 +020042 {"ISL69269Firmware", VRType::ISL69269},
Kevin Tung3f2f3e62025-08-15 15:41:07 +080043 {"MP2X6XXFirmware", VRType::MP2X6XX},
cchoux86a2fd02025-08-20 16:22:12 +080044 {"MP297XFirmware", VRType::MP297X},
FreddieJheng782d6ee2025-08-19 18:53:15 +080045 {"MP5998Firmware", VRType::MP5998},
cchoux86a2fd02025-08-20 16:22:12 +080046 {"RAA22XGen2Firmware", VRType::RAA22XGen2}};
FreddieJheng782d6ee2025-08-19 18:53:15 +080047
Christopher Meis7e446a42024-10-22 09:36:41 +020048 if (VRTypeToString.contains(vrStr))
49 {
50 vrType = VRTypeToString[vrStr];
51 return true;
52 }
53 return false;
54}
55
56} // namespace phosphor::software::VR