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