blob: f1afd5579ce4af6482d3dc3a5ee094d5e702e29c [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"
Patrick Venture75e56c62018-04-20 18:10:15 -07007#include "hwmonio.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06008#include "sysfs.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04009
10using namespace phosphor::logging;
Matthew Barth048ac872017-03-09 14:36:08 -060011
12namespace hwmon
13{
14
15uint64_t FanSpeed::target(uint64_t value)
16{
17 auto curValue = FanSpeedObject::target();
18
19 if (curValue != value)
20 {
21 //Write target out to sysfs
Brad Bishop751043e2017-08-29 11:13:46 -040022 try
23 {
24 ioAccess.write(
25 value,
26 type,
27 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040028 entry::target,
Patrick Venture75e56c62018-04-20 18:10:15 -070029 hwmonio::retries,
30 hwmonio::delay);
Brad Bishop754d38c2017-09-08 00:46:58 -040031
Brad Bishop751043e2017-08-29 11:13:46 -040032 }
33 catch (const std::system_error& e)
34 {
35 using namespace sdbusplus::xyz::openbmc_project::Control::
36 Device::Error;
37 report<WriteFailure>(
38 xyz::openbmc_project::Control::Device::
39 WriteFailure::CALLOUT_ERRNO(e.code().value()),
40 xyz::openbmc_project::Control::Device::
41 WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050042
43 auto file = sysfs::make_sysfs_path(
44 ioAccess.path(),
45 type,
46 id,
47 entry::target);
48
49 log<level::INFO>("Logging failing sysfs file",
50 phosphor::logging::entry("FILE=%s", file.c_str()));
51
Brad Bishop751043e2017-08-29 11:13:46 -040052 exit(EXIT_FAILURE);
53 }
Matthew Barth048ac872017-03-09 14:36:08 -060054 }
55
56 return FanSpeedObject::target(value);
57}
58
Matt Spinler0a8de642017-05-11 10:59:39 -050059
60void FanSpeed::enable()
61{
Patrick Venture7a5285d2018-04-17 19:15:05 -070062 auto enable = env::getEnv("ENABLE", type, id);
Matt Spinlerb778df02017-10-16 13:15:18 -050063 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050064 {
Matt Spinlerb778df02017-10-16 13:15:18 -050065 auto val = std::stoul(enable);
66
Brad Bishop751043e2017-08-29 11:13:46 -040067 try
68 {
69 ioAccess.write(
Matt Spinlerb778df02017-10-16 13:15:18 -050070 val,
Brad Bishop751043e2017-08-29 11:13:46 -040071 type::pwm,
72 id,
Brad Bishop754d38c2017-09-08 00:46:58 -040073 entry::enable,
Patrick Venture75e56c62018-04-20 18:10:15 -070074 hwmonio::retries,
75 hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040076 }
77 catch (const std::system_error& e)
78 {
79 using namespace sdbusplus::xyz::openbmc_project::Control::
80 Device::Error;
81 phosphor::logging::report<WriteFailure>(
82 xyz::openbmc_project::Control::Device::
83 WriteFailure::CALLOUT_ERRNO(e.code().value()),
84 xyz::openbmc_project::Control::Device::
85 WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050086
Matt Spinlerb778df02017-10-16 13:15:18 -050087 auto fullPath = sysfs::make_sysfs_path(
88 ioAccess.path(),
89 type::pwm,
90 id,
91 entry::enable);
92
Matt Spinler9b65f762017-10-05 10:36:22 -050093 log<level::INFO>("Logging failing sysfs file",
94 phosphor::logging::entry("FILE=%s", fullPath.c_str()));
95
Brad Bishop751043e2017-08-29 11:13:46 -040096 exit(EXIT_FAILURE);
97 }
Matt Spinler0a8de642017-05-11 10:59:39 -050098 }
99}
100
101
Matthew Barth048ac872017-03-09 14:36:08 -0600102} // namespace hwmon