xref: /openbmc/phosphor-hwmon/fan_speed.cpp (revision c635e860)
1 #include <phosphor-logging/elog-errors.hpp>
2 #include <xyz/openbmc_project/Control/Device/error.hpp>
3 #include "sensorset.hpp"
4 #include "env.hpp"
5 #include "fan_speed.hpp"
6 #include "hwmon.hpp"
7 #include "sysfs.hpp"
8 
9 using namespace phosphor::logging;
10 
11 namespace hwmon
12 {
13 
14 uint64_t FanSpeed::target(uint64_t value)
15 {
16     auto curValue = FanSpeedObject::target();
17 
18     if (curValue != value)
19     {
20         //Write target out to sysfs
21         try
22         {
23             ioAccess.write(
24                     value,
25                     type,
26                     id,
27                     entry::target,
28                     sysfs::hwmonio::retries,
29                     sysfs::hwmonio::delay);
30 
31         }
32         catch (const std::system_error& e)
33         {
34             using namespace sdbusplus::xyz::openbmc_project::Control::
35                 Device::Error;
36             report<WriteFailure>(
37                     xyz::openbmc_project::Control::Device::
38                         WriteFailure::CALLOUT_ERRNO(e.code().value()),
39                     xyz::openbmc_project::Control::Device::
40                         WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
41 
42             auto file = sysfs::make_sysfs_path(
43                     ioAccess.path(),
44                     type,
45                     id,
46                     entry::target);
47 
48             log<level::INFO>("Logging failing sysfs file",
49                     phosphor::logging::entry("FILE=%s", file.c_str()));
50 
51             exit(EXIT_FAILURE);
52         }
53     }
54 
55     return FanSpeedObject::target(value);
56 }
57 
58 
59 void FanSpeed::enable()
60 {
61     auto enable = env::getEnv("ENABLE", type, id);
62     if (!enable.empty())
63     {
64         auto val = std::stoul(enable);
65 
66         try
67         {
68             ioAccess.write(
69                     val,
70                     type::pwm,
71                     id,
72                     entry::enable,
73                     sysfs::hwmonio::retries,
74                     sysfs::hwmonio::delay);
75         }
76         catch (const std::system_error& e)
77         {
78             using namespace sdbusplus::xyz::openbmc_project::Control::
79                 Device::Error;
80             phosphor::logging::report<WriteFailure>(
81                     xyz::openbmc_project::Control::Device::
82                         WriteFailure::CALLOUT_ERRNO(e.code().value()),
83                     xyz::openbmc_project::Control::Device::
84                         WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
85 
86             auto fullPath = sysfs::make_sysfs_path(
87                     ioAccess.path(),
88                     type::pwm,
89                     id,
90                     entry::enable);
91 
92             log<level::INFO>("Logging failing sysfs file",
93                     phosphor::logging::entry("FILE=%s", fullPath.c_str()));
94 
95             exit(EXIT_FAILURE);
96         }
97     }
98 }
99 
100 
101 } // namespace hwmon
102