blob: 076807c2bb913a95f7673ddc38bb17fffa05766c [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
Patrick Williams64129932024-02-13 21:10:17 -060012#include <format>
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{
Matt Spinler2d56d932024-11-20 11:17:34 -060021 try
Matthew Barth048ac872017-03-09 14:36:08 -060022 {
Matt Spinler2d56d932024-11-20 11:17:34 -060023 _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
24 hwmonio::delay);
25 }
26 catch (const std::system_error& e)
27 {
28 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
29 report<WriteFailure>(
30 xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
31 e.code().value()),
32 xyz::openbmc_project::Control::Device::WriteFailure::
33 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050034
Matt Spinler2d56d932024-11-20 11:17:34 -060035 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
36 entry::target);
Matt Spinler9b65f762017-10-05 10:36:22 -050037
Matt Spinler2d56d932024-11-20 11:17:34 -060038 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
39 e.code().value())
40 .c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050041
Matt Spinler2d56d932024-11-20 11:17:34 -060042 exit(EXIT_FAILURE);
Matthew Barth048ac872017-03-09 14:36:08 -060043 }
44
45 return FanSpeedObject::target(value);
46}
47
Matt Spinler0a8de642017-05-11 10:59:39 -050048void FanSpeed::enable()
49{
Patrick Ventureabf29702018-12-19 14:37:18 -080050 auto enable = env::getEnv("ENABLE", _type, _id);
Matt Spinlerb778df02017-10-16 13:15:18 -050051 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050052 {
Matt Spinlerb778df02017-10-16 13:15:18 -050053 auto val = std::stoul(enable);
54
Brad Bishop751043e2017-08-29 11:13:46 -040055 try
56 {
Patrick Ventureabf29702018-12-19 14:37:18 -080057 _ioAccess->write(val, type::pwm, _id, entry::enable,
58 hwmonio::retries, hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040059 }
60 catch (const std::system_error& e)
61 {
Patrick Venture043d3232018-08-31 10:10:53 -070062 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
63 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040064 phosphor::logging::report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070065 xyz::openbmc_project::Control::Device::WriteFailure::
66 CALLOUT_ERRNO(e.code().value()),
67 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080068 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050069
Patrick Ventureabf29702018-12-19 14:37:18 -080070 auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
71 _id, entry::enable);
Matt Spinlerb778df02017-10-16 13:15:18 -050072
Patrick Williams64129932024-02-13 21:10:17 -060073 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
Matt Spinler6a391de2020-07-08 13:03:10 -050074 fullPath, e.code().value())
75 .c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050076
Brad Bishop751043e2017-08-29 11:13:46 -040077 exit(EXIT_FAILURE);
78 }
Matt Spinler0a8de642017-05-11 10:59:39 -050079 }
80}
81
Matthew Barth048ac872017-03-09 14:36:08 -060082} // namespace hwmon