xref: /openbmc/phosphor-hwmon/fan_pwm.cpp (revision 043d3230)
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 <experimental/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 = sysfs::make_sysfs_path(ioAccess->path(), type, id, empty);
40 
41         log<level::INFO>("Logging failing sysfs file",
42                          phosphor::logging::entry("FILE=%s", file.c_str()));
43 
44         exit(EXIT_FAILURE);
45     }
46 
47     return FanPwmObject::target(value);
48 }
49 
50 } // namespace hwmon
51