xref: /openbmc/phosphor-hwmon/fan_pwm.cpp (revision 69a68edd)
1 #include "fan_pwm.hpp"
2 
3 #include "env.hpp"
4 #include "hwmon.hpp"
5 #include "hwmonio.hpp"
6 #include "sensorset.hpp"
7 #include "sysfs.hpp"
8 
9 #include <filesystem>
10 #include <phosphor-logging/elog-errors.hpp>
11 #include <string>
12 #include <xyz/openbmc_project/Control/Device/error.hpp>
13 
14 using namespace phosphor::logging;
15 
16 namespace hwmon
17 {
18 
19 uint64_t FanPwm::target(uint64_t value)
20 {
21     using namespace std::literals;
22 
23     std::string empty;
24     // Write target out to sysfs
25     try
26     {
27         _ioAccess->write(value, _type, _id, empty, hwmonio::retries,
28                          hwmonio::delay);
29     }
30     catch (const std::system_error& e)
31     {
32         using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
33         report<WriteFailure>(
34             xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
35                 e.code().value()),
36             xyz::openbmc_project::Control::Device::WriteFailure::
37                 CALLOUT_DEVICE_PATH(_devPath.c_str()));
38 
39         auto file =
40             sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, empty);
41 
42         log<level::INFO>("Logging failing sysfs file",
43                          phosphor::logging::entry("FILE=%s", file.c_str()));
44 
45         exit(EXIT_FAILURE);
46     }
47 
48     return FanPwmObject::target(value);
49 }
50 
51 } // namespace hwmon
52