blob: f0910c6f7d1672a43f8d2ea6880f6dc69f6a4d0f [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
Patrick Venture9e997b42019-03-08 13:42:10 -08009#include <filesystem>
Patrick Venture043d3232018-08-31 10:10:53 -070010#include <phosphor-logging/elog-errors.hpp>
Patrick Venture9331ab72018-01-29 09:48:47 -080011#include <string>
Patrick Venture043d3232018-08-31 10:10:53 -070012#include <xyz/openbmc_project/Control/Device/error.hpp>
Patrick Venture9331ab72018-01-29 09:48:47 -080013
14using namespace phosphor::logging;
15
16namespace hwmon
17{
18
19uint64_t FanPwm::target(uint64_t value)
20{
Patrick Venture9331ab72018-01-29 09:48:47 -080021 using namespace std::literals;
22
Kun Yi901f1172018-06-14 10:23:03 -070023 std::string empty;
Patrick Venture043d3232018-08-31 10:10:53 -070024 // Write target out to sysfs
Kun Yi901f1172018-06-14 10:23:03 -070025 try
Patrick Venture9331ab72018-01-29 09:48:47 -080026 {
Patrick Venture2511c092018-12-19 14:31:29 -080027 _ioAccess->write(value, _type, _id, empty, hwmonio::retries,
28 hwmonio::delay);
Kun Yi901f1172018-06-14 10:23:03 -070029 }
30 catch (const std::system_error& e)
31 {
Patrick Venture043d3232018-08-31 10:10:53 -070032 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
Kun Yi901f1172018-06-14 10:23:03 -070033 report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070034 xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
35 e.code().value()),
36 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Venture2511c092018-12-19 14:31:29 -080037 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080038
Patrick Venture2511c092018-12-19 14:31:29 -080039 auto file =
40 sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, empty);
Patrick Venture9331ab72018-01-29 09:48:47 -080041
Kun Yi901f1172018-06-14 10:23:03 -070042 log<level::INFO>("Logging failing sysfs file",
43 phosphor::logging::entry("FILE=%s", file.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080044
Kun Yi901f1172018-06-14 10:23:03 -070045 exit(EXIT_FAILURE);
Patrick Venture9331ab72018-01-29 09:48:47 -080046 }
47
48 return FanPwmObject::target(value);
49}
50
51} // namespace hwmon