blob: 067e8822e924f264367b939bef6f636370ec0063 [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{
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
Patrick Williams64129932024-02-13 21:10:17 -060044 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
Matt Spinler6a391de2020-07-08 13:03:10 -050045 file, e.code().value())
46 .c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050047
Brad Bishop751043e2017-08-29 11:13:46 -040048 exit(EXIT_FAILURE);
49 }
Matthew Barth048ac872017-03-09 14:36:08 -060050 }
51
52 return FanSpeedObject::target(value);
53}
54
Matt Spinler0a8de642017-05-11 10:59:39 -050055void FanSpeed::enable()
56{
Patrick Ventureabf29702018-12-19 14:37:18 -080057 auto enable = env::getEnv("ENABLE", _type, _id);
Matt Spinlerb778df02017-10-16 13:15:18 -050058 if (!enable.empty())
Matt Spinler0a8de642017-05-11 10:59:39 -050059 {
Matt Spinlerb778df02017-10-16 13:15:18 -050060 auto val = std::stoul(enable);
61
Brad Bishop751043e2017-08-29 11:13:46 -040062 try
63 {
Patrick Ventureabf29702018-12-19 14:37:18 -080064 _ioAccess->write(val, type::pwm, _id, entry::enable,
65 hwmonio::retries, hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -040066 }
67 catch (const std::system_error& e)
68 {
Patrick Venture043d3232018-08-31 10:10:53 -070069 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
70 Error;
Brad Bishop751043e2017-08-29 11:13:46 -040071 phosphor::logging::report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070072 xyz::openbmc_project::Control::Device::WriteFailure::
73 CALLOUT_ERRNO(e.code().value()),
74 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Ventureabf29702018-12-19 14:37:18 -080075 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -050076
Patrick Ventureabf29702018-12-19 14:37:18 -080077 auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
78 _id, entry::enable);
Matt Spinlerb778df02017-10-16 13:15:18 -050079
Patrick Williams64129932024-02-13 21:10:17 -060080 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
Matt Spinler6a391de2020-07-08 13:03:10 -050081 fullPath, e.code().value())
82 .c_str());
Matt Spinler9b65f762017-10-05 10:36:22 -050083
Brad Bishop751043e2017-08-29 11:13:46 -040084 exit(EXIT_FAILURE);
85 }
Matt Spinler0a8de642017-05-11 10:59:39 -050086 }
87}
88
Matthew Barth048ac872017-03-09 14:36:08 -060089} // namespace hwmon