blob: c15625876164bd0d768345980a727b5db8ce47aa [file] [log] [blame]
Matthew Barth048ac872017-03-09 14:36:08 -06001#include "fan_speed.hpp"
2#include "hwmon.hpp"
3#include "sysfs.hpp"
Matt Spinler0a8de642017-05-11 10:59:39 -05004#include <experimental/filesystem>
Brad Bishop751043e2017-08-29 11:13:46 -04005#include <phosphor-logging/elog-errors.hpp>
6#include <xyz/openbmc_project/Control/Device/error.hpp>
7
8using namespace phosphor::logging;
Matthew Barth048ac872017-03-09 14:36:08 -06009
10namespace hwmon
11{
12
13uint64_t FanSpeed::target(uint64_t value)
14{
15 auto curValue = FanSpeedObject::target();
16
17 if (curValue != value)
18 {
19 //Write target out to sysfs
Brad Bishop751043e2017-08-29 11:13:46 -040020 try
21 {
22 ioAccess.write(
23 value,
24 type,
25 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040026 entry::target,
27 sysfs::hwmonio::retries,
28 sysfs::hwmonio::delay);
29
Brad Bishop751043e2017-08-29 11:13:46 -040030 }
31 catch (const std::system_error& e)
32 {
33 using namespace sdbusplus::xyz::openbmc_project::Control::
34 Device::Error;
35 report<WriteFailure>(
36 xyz::openbmc_project::Control::Device::
37 WriteFailure::CALLOUT_ERRNO(e.code().value()),
38 xyz::openbmc_project::Control::Device::
39 WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
40 exit(EXIT_FAILURE);
41 }
Matthew Barth048ac872017-03-09 14:36:08 -060042 }
43
44 return FanSpeedObject::target(value);
45}
46
Matt Spinler0a8de642017-05-11 10:59:39 -050047
48void FanSpeed::enable()
49{
50 namespace fs = std::experimental::filesystem;
51
Brad Bishop751043e2017-08-29 11:13:46 -040052 auto fullPath = sysfs::make_sysfs_path(ioAccess.path(),
Patrick Venture1e6324f2017-06-01 14:07:05 -070053 type::pwm,
54 id,
55 entry::enable);
Matt Spinler0a8de642017-05-11 10:59:39 -050056
57 if (fs::exists(fullPath))
58 {
59 //This class always uses RPM mode
Brad Bishop751043e2017-08-29 11:13:46 -040060 try
61 {
62 ioAccess.write(
63 enable::rpmMode,
64 type::pwm,
65 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040066 entry::enable,
67 sysfs::hwmonio::retries,
68 sysfs::hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040069 }
70 catch (const std::system_error& e)
71 {
72 using namespace sdbusplus::xyz::openbmc_project::Control::
73 Device::Error;
74 phosphor::logging::report<WriteFailure>(
75 xyz::openbmc_project::Control::Device::
76 WriteFailure::CALLOUT_ERRNO(e.code().value()),
77 xyz::openbmc_project::Control::Device::
78 WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
79 exit(EXIT_FAILURE);
80 }
Matt Spinler0a8de642017-05-11 10:59:39 -050081 }
82}
83
84
Matthew Barth048ac872017-03-09 14:36:08 -060085} // namespace hwmon