blob: 6e903d3c4f79fd6c44fc2984efcf98163f539b73 [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 Venture043d3232018-08-31 10:10:53 -07009#include <phosphor-logging/elog-errors.hpp>
Patrick Venture043d3232018-08-31 10:10:53 -070010#include <xyz/openbmc_project/Control/Device/error.hpp>
Patrick Venture9331ab72018-01-29 09:48:47 -080011
Patrick Williamse8771fd2023-05-10 07:51:06 -050012#include <filesystem>
Patrick Williams64129932024-02-13 21:10:17 -060013#include <format>
Patrick Williamse8771fd2023-05-10 07:51:06 -050014#include <string>
15
Patrick Venture9331ab72018-01-29 09:48:47 -080016using namespace phosphor::logging;
17
18namespace hwmon
19{
20
21uint64_t FanPwm::target(uint64_t value)
22{
Patrick Venture9331ab72018-01-29 09:48:47 -080023 using namespace std::literals;
24
Kun Yi901f1172018-06-14 10:23:03 -070025 std::string empty;
Patrick Venture043d3232018-08-31 10:10:53 -070026 // Write target out to sysfs
Kun Yi901f1172018-06-14 10:23:03 -070027 try
Patrick Venture9331ab72018-01-29 09:48:47 -080028 {
Patrick Venture2511c092018-12-19 14:31:29 -080029 _ioAccess->write(value, _type, _id, empty, hwmonio::retries,
30 hwmonio::delay);
Kun Yi901f1172018-06-14 10:23:03 -070031 }
32 catch (const std::system_error& e)
33 {
Patrick Venture043d3232018-08-31 10:10:53 -070034 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
Kun Yi901f1172018-06-14 10:23:03 -070035 report<WriteFailure>(
Patrick Venture043d3232018-08-31 10:10:53 -070036 xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
37 e.code().value()),
38 xyz::openbmc_project::Control::Device::WriteFailure::
Patrick Venture2511c092018-12-19 14:31:29 -080039 CALLOUT_DEVICE_PATH(_devPath.c_str()));
Patrick Venture9331ab72018-01-29 09:48:47 -080040
Patrick Williamse8771fd2023-05-10 07:51:06 -050041 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
42 empty);
Patrick Venture9331ab72018-01-29 09:48:47 -080043
Patrick Williams64129932024-02-13 21:10:17 -060044 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
Matt Spinler6a391de2020-07-08 13:03:10 -050045 e.code().value())
46 .c_str());
Patrick Venture9331ab72018-01-29 09:48:47 -080047
Kun Yi901f1172018-06-14 10:23:03 -070048 exit(EXIT_FAILURE);
Patrick Venture9331ab72018-01-29 09:48:47 -080049 }
50
51 return FanPwmObject::target(value);
52}
53
54} // namespace hwmon