blob: 65e5655a836dcef58599db88f8d6d939f777dea4 [file] [log] [blame]
Matthew Barth048ac872017-03-09 14:36:08 -06001#include "fan_speed.hpp"
Patrick Venture043d3232018-08-31 10:10:53 -07002
3#include "env.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06004#include "hwmon.hpp"
Patrick Venture75e56c62018-04-20 18:10:15 -07005#include "hwmonio.hpp"
Patrick Venture043d3232018-08-31 10:10:53 -07006#include "sensorset.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06007#include "sysfs.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04008
Patrick Venture043d3232018-08-31 10:10:53 -07009#include <phosphor-logging/elog-errors.hpp>
10#include <xyz/openbmc_project/Control/Device/error.hpp>
11
Brad Bishop751043e2017-08-29 11:13:46 -040012using namespace phosphor::logging;
Matthew Barth048ac872017-03-09 14:36:08 -060013
14namespace hwmon
15{
16
17uint64_t FanSpeed::target(uint64_t value)
18{
19 auto curValue = FanSpeedObject::target();
20
21 if (curValue != value)
22 {
Patrick Venture043d3232018-08-31 10:10:53 -070023 // Write target out to sysfs
Brad Bishop751043e2017-08-29 11:13:46 -040024 try
25 {
Patrick Ventureabf29702018-12-19 14:37:18 -080026 _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
27 hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040028 }
29 catch (const std::system_error& e)
30 {
Patrick Venture043d3232018-08-31 10:10:53 -070031 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
32 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040033 report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070034 xyz::openbmc_project::Control::Device::WriteFailure::
35 CALLOUT_ERRNO(e.code().value()),
36 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080037 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050038
Patrick Ventureabf29702018-12-19 14:37:18 -080039 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
Patrick Venture043d3232018-08-31 10:10:53 -070040 entry::target);
Matt Spinler9b65f762017-10-05 10:36:22 -050041
42 log<level::INFO>("Logging failing sysfs file",
Patrick Venture043d3232018-08-31 10:10:53 -070043 phosphor::logging::entry("FILE=%s", file.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050044
Brad Bishop751043e2017-08-29 11:13:46 -040045 exit(EXIT_FAILURE);
46 }
Matthew Barth048ac872017-03-09 14:36:08 -060047 }
48
49 return FanSpeedObject::target(value);
50}
51
Matt Spinler0a8de642017-05-11 10:59:39 -050052void FanSpeed::enable()
53{
Patrick Ventureabf29702018-12-19 14:37:18 -080054 auto enable = env::getEnv("ENABLE", _type, _id);
Matt Spinlerb778df02017-10-16 13:15:18 -050055 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050056 {
Matt Spinlerb778df02017-10-16 13:15:18 -050057 auto val = std::stoul(enable);
58
Brad Bishop751043e2017-08-29 11:13:46 -040059 try
60 {
Patrick Ventureabf29702018-12-19 14:37:18 -080061 _ioAccess->write(val, type::pwm, _id, entry::enable,
62 hwmonio::retries, hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040063 }
64 catch (const std::system_error& e)
65 {
Patrick Venture043d3232018-08-31 10:10:53 -070066 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
67 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040068 phosphor::logging::report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070069 xyz::openbmc_project::Control::Device::WriteFailure::
70 CALLOUT_ERRNO(e.code().value()),
71 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080072 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050073
Patrick Ventureabf29702018-12-19 14:37:18 -080074 auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
75 _id, entry::enable);
Matt Spinlerb778df02017-10-16 13:15:18 -050076
Patrick Venture043d3232018-08-31 10:10:53 -070077 log<level::INFO>(
78 "Logging failing sysfs file",
79 phosphor::logging::entry("FILE=%s", fullPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050080
Brad Bishop751043e2017-08-29 11:13:46 -040081 exit(EXIT_FAILURE);
82 }
Matt Spinler0a8de642017-05-11 10:59:39 -050083 }
84}
85
Matthew Barth048ac872017-03-09 14:36:08 -060086} // namespace hwmon