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