blob: 15ce94626e4968c6434077455bd40475d3878d24 [file] [log] [blame]
Matt Spinlerb778df02017-10-16 13:15:18 -05001#include <phosphor-logging/elog-errors.hpp>
2#include <xyz/openbmc_project/Control/Device/error.hpp>
3#include "sensorset.hpp"
4#include "env.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06005#include "fan_speed.hpp"
6#include "hwmon.hpp"
7#include "sysfs.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04008
9using namespace phosphor::logging;
Matthew Barth048ac872017-03-09 14:36:08 -060010
11namespace hwmon
12{
13
14uint64_t FanSpeed::target(uint64_t value)
15{
16 auto curValue = FanSpeedObject::target();
17
18 if (curValue != value)
19 {
20 //Write target out to sysfs
Brad Bishop751043e2017-08-29 11:13:46 -040021 try
22 {
23 ioAccess.write(
24 value,
25 type,
26 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040027 entry::target,
28 sysfs::hwmonio::retries,
29 sysfs::hwmonio::delay);
30
Brad Bishop751043e2017-08-29 11:13:46 -040031 }
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()));
Matt Spinler9b65f762017-10-05 10:36:22 -050041
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
Brad Bishop751043e2017-08-29 11:13:46 -040051 exit(EXIT_FAILURE);
52 }
Matthew Barth048ac872017-03-09 14:36:08 -060053 }
54
55 return FanSpeedObject::target(value);
56}
57
Matt Spinler0a8de642017-05-11 10:59:39 -050058
59void FanSpeed::enable()
60{
Patrick Venture7a5285d2018-04-17 19:15:05 -070061 auto enable = env::getEnv("ENABLE", type, id);
Matt Spinlerb778df02017-10-16 13:15:18 -050062 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050063 {
Matt Spinlerb778df02017-10-16 13:15:18 -050064 auto val = std::stoul(enable);
65
Brad Bishop751043e2017-08-29 11:13:46 -040066 try
67 {
68 ioAccess.write(
Matt Spinlerb778df02017-10-16 13:15:18 -050069 val,
Brad Bishop751043e2017-08-29 11:13:46 -040070 type::pwm,
71 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040072 entry::enable,
73 sysfs::hwmonio::retries,
74 sysfs::hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040075 }
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()));
Matt Spinler9b65f762017-10-05 10:36:22 -050085
Matt Spinlerb778df02017-10-16 13:15:18 -050086 auto fullPath = sysfs::make_sysfs_path(
87 ioAccess.path(),
88 type::pwm,
89 id,
90 entry::enable);
91
Matt Spinler9b65f762017-10-05 10:36:22 -050092 log<level::INFO>("Logging failing sysfs file",
93 phosphor::logging::entry("FILE=%s", fullPath.c_str()));
94
Brad Bishop751043e2017-08-29 11:13:46 -040095 exit(EXIT_FAILURE);
96 }
Matt Spinler0a8de642017-05-11 10:59:39 -050097 }
98}
99
100
Matthew Barth048ac872017-03-09 14:36:08 -0600101} // namespace hwmon