#include "i2cvr_software_manager.hpp" #include "common/include/dbus_helper.hpp" #include "common/include/software_manager.hpp" #include "i2cvr_device.hpp" #include "vr.hpp" #include #include #include #include #include PHOSPHOR_LOG2_USING; namespace VR = phosphor::software::VR; namespace I2CDevice = phosphor::software::i2c_vr::device; namespace SoftwareInf = phosphor::software; namespace ManagerInf = phosphor::software::manager; const std::string configDBusName = "I2CVR"; const std::vector emConfigTypes = { "XDPE1X2XXFirmware", "ISL69269Firmware", "MP2X6XXFirmware", "MP297XFirmware", "RAA22XGen2Firmware"}; I2CVRSoftwareManager::I2CVRSoftwareManager(sdbusplus::async::context& ctx) : ManagerInf::SoftwareManager(ctx, configDBusName) {} void I2CVRSoftwareManager::start() { std::vector configIntfs; configIntfs.reserve(emConfigTypes.size()); for (auto& name : emConfigTypes) { configIntfs.push_back("xyz.openbmc_project.Configuration." + name); } ctx.spawn(initDevices(configIntfs)); ctx.run(); } sdbusplus::async::task I2CVRSoftwareManager::initDevice( const std::string& service, const std::string& path, SoftwareConfig& config) { std::string configIface = "xyz.openbmc_project.Configuration." + config.configType; std::optional busNum = co_await dbusGetRequiredProperty( ctx, service, path, configIface, "Bus"); std::optional address = co_await dbusGetRequiredProperty(ctx, service, path, configIface, "Address"); std::optional vrChipType = co_await dbusGetRequiredProperty(ctx, service, path, configIface, "Type"); if (!busNum.has_value() || !address.has_value() || !vrChipType.has_value()) { error("missing config property"); co_return false; } VR::VRType vrType; if (!VR::stringToEnum(vrChipType.value(), vrType)) { error("unknown voltage regulator type: {TYPE}", "TYPE", vrChipType.value()); co_return false; } lg2::debug( "[config] Voltage regulator device type: {TYPE} on Bus: {BUS} at Address: {ADDR}", "TYPE", vrChipType.value(), "BUS", busNum.value(), "ADDR", address.value()); auto i2cDevice = std::make_unique( ctx, vrType, static_cast(busNum.value()), static_cast(address.value()), config, this); std::unique_ptr software = std::make_unique(ctx, *i2cDevice); uint32_t sum; if (!(co_await i2cDevice->getVersion(&sum))) { error("unable to obtain Version/CRC from voltage regulator"); co_return false; } software->setVersion(std::format("{:X}", sum), SoftwareInf::SoftwareVersion::VersionPurpose::Other); software->enableUpdate({RequestedApplyTimes::OnReset}); i2cDevice->softwareCurrent = std::move(software); devices.insert({config.objectPath, std::move(i2cDevice)}); co_return true; } int main() { sdbusplus::async::context ctx; I2CVRSoftwareManager i2cVRSoftwareManager(ctx); i2cVRSoftwareManager.start(); return 0; }