blob: 253515d21cd9994477e6aaf885db02436b38ed75 [file] [log] [blame]
Patrick Venture9331ab72018-01-29 09:48:47 -08001#include "fan_pwm.hpp"
Patrick Venture043d3232018-08-31 10:10:53 -07002
3#include "env.hpp"
Patrick Venture9331ab72018-01-29 09:48:47 -08004#include "hwmon.hpp"
Patrick Venture75e56c62018-04-20 18:10:15 -07005#include "hwmonio.hpp"
Patrick Venture9331ab72018-01-29 09:48:47 -08006#include "sensorset.hpp"
7#include "sysfs.hpp"
8
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>
Patrick Venture043d3232018-08-31 10:10:53 -070012#include <xyz/openbmc_project/Control/Device/error.hpp>
Patrick Venture9331ab72018-01-29 09:48:47 -080013
Patrick Williamse8771fd2023-05-10 07:51:06 -050014#include <filesystem>
15#include <string>
16
Patrick Venture9331ab72018-01-29 09:48:47 -080017using namespace phosphor::logging;
18
19namespace hwmon
20{
21
22uint64_t FanPwm::target(uint64_t value)
23{
Patrick Venture9331ab72018-01-29 09:48:47 -080024 using namespace std::literals;
25
Kun Yi901f1172018-06-14 10:23:03 -070026 std::string empty;
Patrick Venture043d3232018-08-31 10:10:53 -070027 // Write target out to sysfs
Kun Yi901f1172018-06-14 10:23:03 -070028 try
Patrick Venture9331ab72018-01-29 09:48:47 -080029 {
Patrick Venture2511c092018-12-19 14:31:29 -080030 _ioAccess->write(value, _type, _id, empty, hwmonio::retries,
31 hwmonio::delay);
Kun Yi901f1172018-06-14 10:23:03 -070032 }
33 catch (const std::system_error& e)
34 {
Patrick Venture043d3232018-08-31 10:10:53 -070035 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
Kun Yi901f1172018-06-14 10:23:03 -070036 report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070037 xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
38 e.code().value()),
39 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Venture2511c092018-12-19 14:31:29 -080040 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080041
Patrick Williamse8771fd2023-05-10 07:51:06 -050042 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
43 empty);
Patrick Venture9331ab72018-01-29 09:48:47 -080044
Matt Spinler6a391de2020-07-08 13:03:10 -050045 log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}", file,
46 e.code().value())
47 .c_str());
Patrick Venture9331ab72018-01-29 09:48:47 -080048
Kun Yi901f1172018-06-14 10:23:03 -070049 exit(EXIT_FAILURE);
Patrick Venture9331ab72018-01-29 09:48:47 -080050 }
51
52 return FanPwmObject::target(value);
53}
54
55} // namespace hwmon