blob: e990410f385281480d9f9822f4d9673ff7f2e033 [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
Matt Spinler5e034af2020-06-24 15:21:53 -05009#include <fmt/format.h>
10
Patrick Venture043d3232018-08-31 10:10:53 -070011#include <phosphor-logging/elog-errors.hpp>
12#include <xyz/openbmc_project/Control/Device/error.hpp>
13
Brad Bishop751043e2017-08-29 11:13:46 -040014using namespace phosphor::logging;
Matthew Barth048ac872017-03-09 14:36:08 -060015
16namespace hwmon
17{
18
19uint64_t FanSpeed::target(uint64_t value)
20{
21 auto curValue = FanSpeedObject::target();
22
23 if (curValue != value)
24 {
Patrick Venture043d3232018-08-31 10:10:53 -070025 // Write target out to sysfs
Brad Bishop751043e2017-08-29 11:13:46 -040026 try
27 {
Patrick Ventureabf29702018-12-19 14:37:18 -080028 _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
29 hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040030 }
31 catch (const std::system_error& e)
32 {
Patrick Venture043d3232018-08-31 10:10:53 -070033 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
34 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040035 report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070036 xyz::openbmc_project::Control::Device::WriteFailure::
37 CALLOUT_ERRNO(e.code().value()),
38 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080039 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050040
Patrick Ventureabf29702018-12-19 14:37:18 -080041 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
Patrick Venture043d3232018-08-31 10:10:53 -070042 entry::target);
Matt Spinler9b65f762017-10-05 10:36:22 -050043
Matt Spinler5e034af2020-06-24 15:21:53 -050044 log<level::INFO>(
45 fmt::format("Failing sysfs file: {}", file).c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050046
Brad Bishop751043e2017-08-29 11:13:46 -040047 exit(EXIT_FAILURE);
48 }
Matthew Barth048ac872017-03-09 14:36:08 -060049 }
50
51 return FanSpeedObject::target(value);
52}
53
Matt Spinler0a8de642017-05-11 10:59:39 -050054void FanSpeed::enable()
55{
Patrick Ventureabf29702018-12-19 14:37:18 -080056 auto enable = env::getEnv("ENABLE", _type, _id);
Matt Spinlerb778df02017-10-16 13:15:18 -050057 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050058 {
Matt Spinlerb778df02017-10-16 13:15:18 -050059 auto val = std::stoul(enable);
60
Brad Bishop751043e2017-08-29 11:13:46 -040061 try
62 {
Patrick Ventureabf29702018-12-19 14:37:18 -080063 _ioAccess->write(val, type::pwm, _id, entry::enable,
64 hwmonio::retries, hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040065 }
66 catch (const std::system_error& e)
67 {
Patrick Venture043d3232018-08-31 10:10:53 -070068 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
69 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040070 phosphor::logging::report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070071 xyz::openbmc_project::Control::Device::WriteFailure::
72 CALLOUT_ERRNO(e.code().value()),
73 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080074 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050075
Patrick Ventureabf29702018-12-19 14:37:18 -080076 auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
77 _id, entry::enable);
Matt Spinlerb778df02017-10-16 13:15:18 -050078
Patrick Venture043d3232018-08-31 10:10:53 -070079 log<level::INFO>(
Matt Spinler5e034af2020-06-24 15:21:53 -050080 fmt::format("Failing sysfs file: {}", fullPath).c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050081
Brad Bishop751043e2017-08-29 11:13:46 -040082 exit(EXIT_FAILURE);
83 }
Matt Spinler0a8de642017-05-11 10:59:39 -050084 }
85}
86
Matthew Barth048ac872017-03-09 14:36:08 -060087} // namespace hwmon