xref: /openbmc/phosphor-bmc-code-mgmt/i2c-vr/vr.cpp (revision f00ce80edf0bd9e417c095d580151c3eaf83107d)
17e446a40SChristopher Meis #include "vr.hpp"
27e446a40SChristopher Meis 
3*f00ce80eSChristopher Meis #include "isl69269/isl69269.hpp"
47e446a40SChristopher Meis #include "xdpe1x2xx/xdpe1x2xx.hpp"
57e446a40SChristopher Meis 
67e446a40SChristopher Meis #include <map>
77e446a40SChristopher Meis 
87e446a40SChristopher Meis namespace phosphor::software::VR
97e446a40SChristopher Meis {
create(sdbusplus::async::context & ctx,enum VRType vrType,uint16_t bus,uint16_t address)107e446a40SChristopher Meis 
117e446a40SChristopher Meis std::unique_ptr<VoltageRegulator> create(sdbusplus::async::context& ctx,
127e446a40SChristopher Meis                                          enum VRType vrType, uint16_t bus,
137e446a40SChristopher Meis                                          uint16_t address)
147e446a40SChristopher Meis {
157e446a40SChristopher Meis     std::unique_ptr<VoltageRegulator> ret;
167e446a40SChristopher Meis     switch (vrType)
177e446a40SChristopher Meis     {
187e446a40SChristopher Meis         case VRType::XDPE1X2XX:
197e446a40SChristopher Meis             ret = std::make_unique<XDPE1X2XX>(ctx, bus, address);
207e446a40SChristopher Meis             break;
21*f00ce80eSChristopher Meis         case VRType::ISL69269:
22*f00ce80eSChristopher Meis             ret = std::make_unique<ISL69269>(ctx, bus, address);
23*f00ce80eSChristopher Meis             break;
247e446a40SChristopher Meis         default:
257e446a40SChristopher Meis             return NULL;
267e446a40SChristopher Meis     }
277e446a40SChristopher Meis     return ret;
287e446a40SChristopher Meis }
297e446a40SChristopher Meis 
307e446a40SChristopher Meis bool stringToEnum(std::string& vrStr, VRType& vrType)
317e446a40SChristopher Meis {
327e446a40SChristopher Meis     std::map<std::string, enum VRType> VRTypeToString{
337e446a40SChristopher Meis         {"XDPE1X2XXFirmware", VRType::XDPE1X2XX},
34*f00ce80eSChristopher Meis         {"ISL69269Firmware", VRType::ISL69269},
357e446a40SChristopher Meis     };
367e446a40SChristopher Meis 
377e446a40SChristopher Meis     if (VRTypeToString.contains(vrStr))
387e446a40SChristopher Meis     {
397e446a40SChristopher Meis         vrType = VRTypeToString[vrStr];
407e446a40SChristopher Meis         return true;
417e446a40SChristopher Meis     }
427e446a40SChristopher Meis     return false;
437e446a40SChristopher Meis }
447e446a40SChristopher Meis 
457e446a40SChristopher Meis } // namespace phosphor::software::VR
46