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