blob: 796c9dfb779ae4479eb0275e1442f9152b7208c6 [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 Tungdcf4b602025-07-04 13:14:49 +08004#include "mps/mp2x6xx.hpp"
Christopher Meis7e446a42024-10-22 09:36:41 +02005#include "xdpe1x2xx/xdpe1x2xx.hpp"
6
7#include <map>
8
9namespace phosphor::software::VR
10{
11
12std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
13 enum VRType vrType, uint16_t bus,
14 uint16_t address)
15{
Christopher Meis7e446a42024-10-22 09:36:41 +020016 switch (vrType)
17 {
18 case VRType::XDPE1X2XX:
Kevin Tungdcf4b602025-07-04 13:14:49 +080019 return std::make_unique<XDPE1X2XX>(ctx, bus, address);
Christopher Meisf00ce802025-04-08 08:07:31 +020020 case VRType::ISL69269:
Kevin Tungdcf4b602025-07-04 13:14:49 +080021 return std::make_unique<ISL69269>(ctx, bus, address);
22 case VRType::MP2X6XX:
23 return std::make_unique<MP2X6XX>(ctx, bus, address);
Christopher Meis7e446a42024-10-22 09:36:41 +020024 default:
Kevin Tungdcf4b602025-07-04 13:14:49 +080025 return nullptr;
Christopher Meis7e446a42024-10-22 09:36:41 +020026 }
Christopher Meis7e446a42024-10-22 09:36:41 +020027}
28
29bool stringToEnum(std::string& vrStr, VRType& vrType)
30{
31 std::map<std::string, enum VRType> VRTypeToString{
32 {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
Christopher Meisf00ce802025-04-08 08:07:31 +020033 {"ISL69269Firmware", VRType::ISL69269},
Kevin Tungdcf4b602025-07-04 13:14:49 +080034 {"MP2X6XXFirmware", VRType::MP2X6XX}};
Christopher Meis7e446a42024-10-22 09:36:41 +020035
36 if (VRTypeToString.contains(vrStr))
37 {
38 vrType = VRTypeToString[vrStr];
39 return true;
40 }
41 return false;
42}
43
44} // namespace phosphor::software::VR