1 #include "i2cvr_software_manager.hpp" 2 3 #include "common/include/dbus_helper.hpp" 4 #include "common/include/software_manager.hpp" 5 #include "i2cvr_device.hpp" 6 #include "vr.hpp" 7 8 #include <phosphor-logging/lg2.hpp> 9 #include <sdbusplus/async.hpp> 10 #include <sdbusplus/bus.hpp> 11 #include <xyz/openbmc_project/ObjectMapper/client.hpp> 12 13 #include <cstdint> 14 15 PHOSPHOR_LOG2_USING; 16 17 namespace VR = phosphor::software::VR; 18 namespace I2CDevice = phosphor::software::i2c_vr::device; 19 namespace SoftwareInf = phosphor::software; 20 namespace ManagerInf = phosphor::software::manager; 21 22 const std::string configDBusName = "I2CVR"; 23 const std::vector<std::string> emConfigTypes = {"XDPE1X2XXFirmware", 24 "ISL69269Firmware"}; 25 26 I2CVRSoftwareManager::I2CVRSoftwareManager(sdbusplus::async::context& ctx) : 27 ManagerInf::SoftwareManager(ctx, configDBusName) 28 {} 29 30 void I2CVRSoftwareManager::start() 31 { 32 std::vector<std::string> configIntfs; 33 configIntfs.reserve(emConfigTypes.size()); 34 for (auto& name : emConfigTypes) 35 { 36 configIntfs.push_back("xyz.openbmc_project.Configuration." + name); 37 } 38 39 ctx.spawn(initDevices(configIntfs)); 40 ctx.run(); 41 } 42 43 sdbusplus::async::task<bool> I2CVRSoftwareManager::initDevice( 44 const std::string& service, const std::string& path, SoftwareConfig& config) 45 { 46 std::string configIface = 47 "xyz.openbmc_project.Configuration." + config.configType; 48 49 std::optional<uint64_t> busNum = co_await dbusGetRequiredProperty<uint64_t>( 50 ctx, service, path, configIface, "Bus"); 51 std::optional<uint64_t> address = 52 co_await dbusGetRequiredProperty<uint64_t>(ctx, service, path, 53 configIface, "Address"); 54 std::optional<std::string> vrChipType = 55 co_await dbusGetRequiredProperty<std::string>(ctx, service, path, 56 configIface, "Type"); 57 58 if (!busNum.has_value() || !address.has_value() || !vrChipType.has_value()) 59 { 60 error("missing config property"); 61 co_return false; 62 } 63 64 VR::VRType vrType; 65 if (!VR::stringToEnum(vrChipType.value(), vrType)) 66 { 67 error("unknown voltage regulator type: {TYPE}", "TYPE", 68 vrChipType.value()); 69 co_return false; 70 } 71 72 lg2::debug( 73 "[config] Voltage regulator device type: {TYPE} on Bus: {BUS} at Address: {ADDR}", 74 "TYPE", vrChipType.value(), "BUS", busNum.value(), "ADDR", 75 address.value()); 76 77 auto i2cDevice = std::make_unique<I2CDevice::I2CVRDevice>( 78 ctx, vrType, static_cast<uint16_t>(busNum.value()), 79 static_cast<uint16_t>(address.value()), config, this); 80 81 std::unique_ptr<SoftwareInf::Software> software = 82 std::make_unique<SoftwareInf::Software>(ctx, *i2cDevice); 83 84 uint32_t sum; 85 if (!(co_await i2cDevice->getVersion(&sum))) 86 { 87 error("unable to obtain Version/CRC from voltage regulator"); 88 co_return false; 89 } 90 91 software->setVersion(std::format("{:X}", sum), 92 SoftwareInf::SoftwareVersion::VersionPurpose::Other); 93 94 software->enableUpdate({RequestedApplyTimes::OnReset}); 95 96 i2cDevice->softwareCurrent = std::move(software); 97 98 devices.insert({config.objectPath, std::move(i2cDevice)}); 99 100 co_return true; 101 } 102 103 int main() 104 { 105 sdbusplus::async::context ctx; 106 107 I2CVRSoftwareManager i2cVRSoftwareManager(ctx); 108 109 i2cVRSoftwareManager.start(); 110 return 0; 111 } 112