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