Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 1 | #include "fan_pwm.hpp" |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 2 | |
| 3 | #include "env.hpp" |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 4 | #include "hwmon.hpp" |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 5 | #include "hwmonio.hpp" |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 6 | #include "sensorset.hpp" |
| 7 | #include "sysfs.hpp" |
| 8 | |
Matt Spinler | 5e034af | 2020-06-24 15:21:53 -0500 | [diff] [blame] | 9 | #include <fmt/format.h> |
| 10 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 11 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Control/Device/error.hpp> |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 13 | |
Patrick Williams | e8771fd | 2023-05-10 07:51:06 -0500 | [diff] [blame^] | 14 | #include <filesystem> |
| 15 | #include <string> |
| 16 | |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 17 | using namespace phosphor::logging; |
| 18 | |
| 19 | namespace hwmon |
| 20 | { |
| 21 | |
| 22 | uint64_t FanPwm::target(uint64_t value) |
| 23 | { |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 24 | using namespace std::literals; |
| 25 | |
Kun Yi | 901f117 | 2018-06-14 10:23:03 -0700 | [diff] [blame] | 26 | std::string empty; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 27 | // Write target out to sysfs |
Kun Yi | 901f117 | 2018-06-14 10:23:03 -0700 | [diff] [blame] | 28 | try |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 29 | { |
Patrick Venture | 2511c09 | 2018-12-19 14:31:29 -0800 | [diff] [blame] | 30 | _ioAccess->write(value, _type, _id, empty, hwmonio::retries, |
| 31 | hwmonio::delay); |
Kun Yi | 901f117 | 2018-06-14 10:23:03 -0700 | [diff] [blame] | 32 | } |
| 33 | catch (const std::system_error& e) |
| 34 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 35 | using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error; |
Kun Yi | 901f117 | 2018-06-14 10:23:03 -0700 | [diff] [blame] | 36 | report<WriteFailure>( |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 37 | xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO( |
| 38 | e.code().value()), |
| 39 | xyz::openbmc_project::Control::Device::WriteFailure:: |
Patrick Venture | 2511c09 | 2018-12-19 14:31:29 -0800 | [diff] [blame] | 40 | CALLOUT_DEVICE_PATH(_devPath.c_str())); |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 41 | |
Patrick Williams | e8771fd | 2023-05-10 07:51:06 -0500 | [diff] [blame^] | 42 | auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, |
| 43 | empty); |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 44 | |
Matt Spinler | 6a391de | 2020-07-08 13:03:10 -0500 | [diff] [blame] | 45 | log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}", file, |
| 46 | e.code().value()) |
| 47 | .c_str()); |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 48 | |
Kun Yi | 901f117 | 2018-06-14 10:23:03 -0700 | [diff] [blame] | 49 | exit(EXIT_FAILURE); |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return FanPwmObject::target(value); |
| 53 | } |
| 54 | |
| 55 | } // namespace hwmon |