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