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