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