xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/vr.cpp (revision 3638c243ec185766e2db2498e9593a0c1649fde7)
1 #include "vr.hpp"
2 
3 #include "isl69269/isl69269.hpp"
4 #include "mps/mp297x.hpp"
5 #include "mps/mp2x6xx.hpp"
6 #include "mps/mp5998.hpp"
7 #include "mps/mp994x.hpp"
8 #include "tda38640a/tda38640a.hpp"
9 #include "xdpe1x2xx/xdpe1x2xx.hpp"
10 
11 #include <map>
12 
13 namespace phosphor::software::VR
14 {
15 
create(sdbusplus::async::context & ctx,enum VRType vrType,uint16_t bus,uint16_t address)16 std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
17                                          enum VRType vrType, uint16_t bus,
18                                          uint16_t address)
19 {
20     switch (vrType)
21     {
22         case VRType::XDPE1X2XX:
23             return std::make_unique<XDPE1X2XX>(ctx, bus, address);
24         case VRType::ISL69269:
25             return std::make_unique<ISL69269>(ctx, bus, address);
26         case VRType::MP2X6XX:
27             return std::make_unique<MP2X6XX>(ctx, bus, address);
28         case VRType::MP297X:
29             return std::make_unique<MP297X>(ctx, bus, address);
30         case VRType::MP5998:
31             return std::make_unique<MP5998>(ctx, bus, address);
32         case VRType::MP994X:
33             return std::make_unique<MP994X>(ctx, bus, address);
34         case VRType::RAA22XGen2:
35             return std::make_unique<ISL69269>(ctx, bus, address,
36                                               ISL69269::Gen::Gen2);
37         case VRType::RAA22XGen3p5:
38             return std::make_unique<ISL69269>(ctx, bus, address,
39                                               ISL69269::Gen::Gen3p5);
40         case VRType::TDA38640A:
41             return std::make_unique<TDA38640A>(ctx, bus, address);
42         default:
43             return nullptr;
44     }
45 }
46 
stringToEnum(std::string & vrStr,VRType & vrType)47 bool stringToEnum(std::string& vrStr, VRType& vrType)
48 {
49     std::map<std::string, enum VRType> VRTypeToString{
50         {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
51         {"ISL69269Firmware", VRType::ISL69269},
52         {"MP2X6XXFirmware", VRType::MP2X6XX},
53         {"MP297XFirmware", VRType::MP297X},
54         {"MP5998Firmware", VRType::MP5998},
55         {"MP994XFirmware", VRType::MP994X},
56         {"RAA22XGen2Firmware", VRType::RAA22XGen2},
57         {"RAA22XGen3p5Firmware", VRType::RAA22XGen3p5},
58         {"TDA38640AFirmware", VRType::TDA38640A}};
59 
60     if (VRTypeToString.contains(vrStr))
61     {
62         vrType = VRTypeToString[vrStr];
63         return true;
64     }
65     return false;
66 }
67 
68 } // namespace phosphor::software::VR
69