Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 1 | #include "fan_speed.hpp" |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 2 | |
| 3 | #include "env.hpp" |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 4 | #include "hwmon.hpp" |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 5 | #include "hwmonio.hpp" |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 6 | #include "sensorset.hpp" |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 7 | #include "sysfs.hpp" |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 8 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
| 10 | #include <xyz/openbmc_project/Control/Device/error.hpp> |
| 11 | |
Patrick Williams | 6412993 | 2024-02-13 21:10:17 -0600 | [diff] [blame] | 12 | #include <format> |
| 13 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 14 | using namespace phosphor::logging; |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 15 | |
| 16 | namespace hwmon |
| 17 | { |
| 18 | |
| 19 | uint64_t FanSpeed::target(uint64_t value) |
| 20 | { |
Matt Spinler | 2d56d93 | 2024-11-20 11:17:34 -0600 | [diff] [blame] | 21 | try |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 22 | { |
Matt Spinler | 2d56d93 | 2024-11-20 11:17:34 -0600 | [diff] [blame] | 23 | _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries, |
| 24 | hwmonio::delay); |
| 25 | } |
| 26 | catch (const std::system_error& e) |
| 27 | { |
| 28 | using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error; |
| 29 | report<WriteFailure>( |
| 30 | xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO( |
| 31 | e.code().value()), |
| 32 | xyz::openbmc_project::Control::Device::WriteFailure:: |
| 33 | CALLOUT_DEVICE_PATH(_devPath.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 34 | |
Matt Spinler | 2d56d93 | 2024-11-20 11:17:34 -0600 | [diff] [blame] | 35 | auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, |
| 36 | entry::target); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 37 | |
Matt Spinler | 2d56d93 | 2024-11-20 11:17:34 -0600 | [diff] [blame] | 38 | log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file, |
| 39 | e.code().value()) |
| 40 | .c_str()); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 41 | |
Matt Spinler | 2d56d93 | 2024-11-20 11:17:34 -0600 | [diff] [blame] | 42 | exit(EXIT_FAILURE); |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | return FanSpeedObject::target(value); |
| 46 | } |
| 47 | |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 48 | void FanSpeed::enable() |
| 49 | { |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 50 | auto enable = env::getEnv("ENABLE", _type, _id); |
Matt Spinler | b778df0 | 2017-10-16 13:15:18 -0500 | [diff] [blame] | 51 | if (!enable.empty()) |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 52 | { |
Matt Spinler | b778df0 | 2017-10-16 13:15:18 -0500 | [diff] [blame] | 53 | auto val = std::stoul(enable); |
| 54 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 55 | try |
| 56 | { |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 57 | _ioAccess->write(val, type::pwm, _id, entry::enable, |
| 58 | hwmonio::retries, hwmonio::delay); |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 59 | } |
| 60 | catch (const std::system_error& e) |
| 61 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 62 | using namespace sdbusplus::xyz::openbmc_project::Control::Device:: |
| 63 | Error; |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 64 | phosphor::logging::report<WriteFailure>( |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 65 | xyz::openbmc_project::Control::Device::WriteFailure:: |
| 66 | CALLOUT_ERRNO(e.code().value()), |
| 67 | xyz::openbmc_project::Control::Device::WriteFailure:: |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 68 | CALLOUT_DEVICE_PATH(_devPath.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 69 | |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 70 | auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm, |
| 71 | _id, entry::enable); |
Matt Spinler | b778df0 | 2017-10-16 13:15:18 -0500 | [diff] [blame] | 72 | |
Patrick Williams | 6412993 | 2024-02-13 21:10:17 -0600 | [diff] [blame] | 73 | log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", |
Matt Spinler | 6a391de | 2020-07-08 13:03:10 -0500 | [diff] [blame] | 74 | fullPath, e.code().value()) |
| 75 | .c_str()); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 76 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 77 | exit(EXIT_FAILURE); |
| 78 | } |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 82 | } // namespace hwmon |