blob: 2406862bcbc7532ac268195143292323672cb74f [file] [log] [blame]
Kevin Tung994a77f2024-12-23 17:48:56 +08001#include "pt5161l.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4
5#include <algorithm>
6#include <fstream>
7#include <iomanip>
8#include <sstream>
9
10PHOSPHOR_LOG2_USING;
11
12std::string PT5161LDeviceVersion::getVersion()
13{
14 std::string version;
15 std::ostringstream busOss;
16 std::ostringstream addrOss;
17
18 busOss << std::setw(2) << std::setfill('0') << static_cast<int>(bus);
19 addrOss << std::setw(4) << std::setfill('0') << std::hex << std::nouppercase
20 << static_cast<int>(address);
21
22 // The PT5161L driver exposes the firmware version through the fw_ver node
23 std::string path = "/sys/kernel/debug/pt5161l/" + busOss.str() + "-" +
24 addrOss.str() + "/fw_ver";
25
26 std::ifstream file(path);
27 if (!file)
28 {
29 error("Failed to get version: unable to open file: {PATH}", "PATH",
30 path);
31 return version;
32 }
33
34 if (!std::getline(file, version) || version.empty())
35 {
36 error("Failed to read version from file: {PATH}", "PATH", path);
37 }
38
39 return version;
40}
41
42std::optional<HostPowerInf::HostState>
43 PT5161LDeviceVersion::getHostStateToQueryVersion()
44{
45 return HostPowerInf::HostState::Running;
46}