blob: f814c0ab884c4ffa301f9ed4c17d3a2207863844 [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 Venture9331ab72018-01-29 09:48:47 -08009#include <experimental/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 Venture043d3232018-08-31 10:10:53 -070027 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::
37 CALLOUT_DEVICE_PATH(devPath.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080038
Patrick Venture043d3232018-08-31 10:10:53 -070039 auto file = sysfs::make_sysfs_path(ioAccess->path(), type, id, empty);
Patrick Venture9331ab72018-01-29 09:48:47 -080040
Kun Yi901f1172018-06-14 10:23:03 -070041 log<level::INFO>("Logging failing sysfs file",
42 phosphor::logging::entry("FILE=%s", file.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080043
Kun Yi901f1172018-06-14 10:23:03 -070044 exit(EXIT_FAILURE);
Patrick Venture9331ab72018-01-29 09:48:47 -080045 }
46
47 return FanPwmObject::target(value);
48}
49
50} // namespace hwmon