xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/vr.cpp (revision 9ce83ded4fb60a348277158b66258fa27d505462)
1 #include "vr.hpp"
2 
3 #include "isl69269/isl69269.hpp"
4 #include "xdpe1x2xx/xdpe1x2xx.hpp"
5 
6 #include <map>
7 
8 namespace phosphor::software::VR
9 {
10 
11 std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
12                                          enum VRType vrType, uint16_t bus,
13                                          uint16_t address)
14 {
15     std::unique_ptr<VoltageRegulator> ret;
16     switch (vrType)
17     {
18         case VRType::XDPE1X2XX:
19             ret = std::make_unique<XDPE1X2XX>(ctx, bus, address);
20             break;
21         case VRType::ISL69269:
22             ret = std::make_unique<ISL69269>(ctx, bus, address);
23             break;
24         default:
25             return NULL;
26     }
27     return ret;
28 }
29 
30 bool stringToEnum(std::string& vrStr, VRType& vrType)
31 {
32     std::map<std::string, enum VRType> VRTypeToString{
33         {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
34         {"ISL69269Firmware", VRType::ISL69269},
35     };
36 
37     if (VRTypeToString.contains(vrStr))
38     {
39         vrType = VRTypeToString[vrStr];
40         return true;
41     }
42     return false;
43 }
44 
45 } // namespace phosphor::software::VR
46