blob: 11856485a3472a23162ca719b18bd0eb6ac24fc5 [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";
23const std::vector<std::string> emConfigTypes = {"XDPE1X2XXFirmware",
24 "DummyDeviceFirmware"};
25
26I2CVRSoftwareManager::I2CVRSoftwareManager(sdbusplus::async::context& ctx) :
27 ManagerInf::SoftwareManager(ctx, configDBusName)
28{}
29
30void 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
Christopher Meis7e446a42024-10-22 09:36:41 +020043sdbusplus::async::task<bool> I2CVRSoftwareManager::initDevice(
44 const std::string& service, const std::string& path, SoftwareConfig& config)
Christopher Meis7e446a42024-10-22 09:36:41 +020045{
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::to_string(sum));
92
93 std::set<RequestedApplyTimes> allowedApplyTime = {
94 RequestedApplyTimes::Immediate, RequestedApplyTimes::OnReset};
95
96 software->enableUpdate(allowedApplyTime);
97
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}