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