blob: b2afcbe2aa2fabac6c8b2156be6a973979483905 [file] [log] [blame]
Christopher Meis7e446a42024-10-22 09:36:41 +02001#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
15PHOSPHOR_LOG2_USING;
16
17namespace VR = phosphor::software::VR;
18namespace I2CDevice = phosphor::software::i2c_vr::device;
19namespace SoftwareInf = phosphor::software;
20namespace ManagerInf = phosphor::software::manager;
21
22const std::string configDBusName = "I2CVR";
Kevin Tungdcf4b602025-07-04 13:14:49 +080023const std::vector<std::string> emConfigTypes = {
Leo Yangb5938702025-09-30 15:51:54 +080024 "XDPE1X2XXFirmware", "ISL69269Firmware", "MP2X6XXFirmware",
25 "MP297XFirmware", "MP5998Firmware", "RAA22XGen2Firmware",
26 "RAA22XGen3p5Firmware"};
Christopher Meis7e446a42024-10-22 09:36:41 +020027
28I2CVRSoftwareManager::I2CVRSoftwareManager(sdbusplus::async::context& ctx) :
29 ManagerInf::SoftwareManager(ctx, configDBusName)
30{}
31
32void I2CVRSoftwareManager::start()
33{
34 std::vector<std::string> configIntfs;
35 configIntfs.reserve(emConfigTypes.size());
36 for (auto& name : emConfigTypes)
37 {
38 configIntfs.push_back("xyz.openbmc_project.Configuration." + name);
39 }
40
41 ctx.spawn(initDevices(configIntfs));
42 ctx.run();
43}
44
Christopher Meis7e446a42024-10-22 09:36:41 +020045sdbusplus::async::task<bool> I2CVRSoftwareManager::initDevice(
46 const std::string& service, const std::string& path, SoftwareConfig& config)
Christopher Meis7e446a42024-10-22 09:36:41 +020047{
48 std::string configIface =
49 "xyz.openbmc_project.Configuration." + config.configType;
50
51 std::optional<uint64_t> busNum = co_await dbusGetRequiredProperty<uint64_t>(
52 ctx, service, path, configIface, "Bus");
53 std::optional<uint64_t> address =
54 co_await dbusGetRequiredProperty<uint64_t>(ctx, service, path,
55 configIface, "Address");
56 std::optional<std::string> vrChipType =
57 co_await dbusGetRequiredProperty<std::string>(ctx, service, path,
58 configIface, "Type");
59
60 if (!busNum.has_value() || !address.has_value() || !vrChipType.has_value())
61 {
62 error("missing config property");
63 co_return false;
64 }
65
66 VR::VRType vrType;
67 if (!VR::stringToEnum(vrChipType.value(), vrType))
68 {
69 error("unknown voltage regulator type: {TYPE}", "TYPE",
70 vrChipType.value());
71 co_return false;
72 }
73
74 lg2::debug(
75 "[config] Voltage regulator device type: {TYPE} on Bus: {BUS} at Address: {ADDR}",
76 "TYPE", vrChipType.value(), "BUS", busNum.value(), "ADDR",
77 address.value());
78
79 auto i2cDevice = std::make_unique<I2CDevice::I2CVRDevice>(
80 ctx, vrType, static_cast<uint16_t>(busNum.value()),
81 static_cast<uint16_t>(address.value()), config, this);
82
83 std::unique_ptr<SoftwareInf::Software> software =
84 std::make_unique<SoftwareInf::Software>(ctx, *i2cDevice);
85
86 uint32_t sum;
87 if (!(co_await i2cDevice->getVersion(&sum)))
88 {
89 error("unable to obtain Version/CRC from voltage regulator");
90 co_return false;
91 }
92
Daniel Hsu2e168db2025-09-08 14:06:48 +080093 software->setVersion(std::format("{:X}", sum),
94 SoftwareInf::SoftwareVersion::VersionPurpose::Other);
Christopher Meis7e446a42024-10-22 09:36:41 +020095
Kevin Tungee551172025-08-22 16:49:40 +080096 software->enableUpdate({RequestedApplyTimes::OnReset});
Christopher Meis7e446a42024-10-22 09:36:41 +020097
98 i2cDevice->softwareCurrent = std::move(software);
99
100 devices.insert({config.objectPath, std::move(i2cDevice)});
101
102 co_return true;
103}
104
105int main()
106{
107 sdbusplus::async::context ctx;
108
109 I2CVRSoftwareManager i2cVRSoftwareManager(ctx);
110
111 i2cVRSoftwareManager.start();
112 return 0;
113}