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