Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 1 | #include "fan_speed.hpp" |
| 2 | #include "hwmon.hpp" |
| 3 | #include "sysfs.hpp" |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 4 | #include <experimental/filesystem> |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 5 | #include <phosphor-logging/elog-errors.hpp> |
| 6 | #include <xyz/openbmc_project/Control/Device/error.hpp> |
| 7 | |
| 8 | using namespace phosphor::logging; |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 9 | |
| 10 | namespace hwmon |
| 11 | { |
| 12 | |
| 13 | uint64_t FanSpeed::target(uint64_t value) |
| 14 | { |
| 15 | auto curValue = FanSpeedObject::target(); |
| 16 | |
| 17 | if (curValue != value) |
| 18 | { |
| 19 | //Write target out to sysfs |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 20 | try |
| 21 | { |
| 22 | ioAccess.write( |
| 23 | value, |
| 24 | type, |
| 25 | id, |
Brad Bishop | 754d38c | 2017-09-08 00:46:58 -0400 | [diff] [blame] | 26 | entry::target, |
| 27 | sysfs::hwmonio::retries, |
| 28 | sysfs::hwmonio::delay); |
| 29 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 30 | } |
| 31 | catch (const std::system_error& e) |
| 32 | { |
| 33 | using namespace sdbusplus::xyz::openbmc_project::Control:: |
| 34 | Device::Error; |
| 35 | report<WriteFailure>( |
| 36 | xyz::openbmc_project::Control::Device:: |
| 37 | WriteFailure::CALLOUT_ERRNO(e.code().value()), |
| 38 | xyz::openbmc_project::Control::Device:: |
| 39 | WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 40 | |
| 41 | auto file = sysfs::make_sysfs_path( |
| 42 | ioAccess.path(), |
| 43 | type, |
| 44 | id, |
| 45 | entry::target); |
| 46 | |
| 47 | log<level::INFO>("Logging failing sysfs file", |
| 48 | phosphor::logging::entry("FILE=%s", file.c_str())); |
| 49 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 50 | exit(EXIT_FAILURE); |
| 51 | } |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | return FanSpeedObject::target(value); |
| 55 | } |
| 56 | |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 57 | |
| 58 | void FanSpeed::enable() |
| 59 | { |
| 60 | namespace fs = std::experimental::filesystem; |
| 61 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 62 | auto fullPath = sysfs::make_sysfs_path(ioAccess.path(), |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 63 | type::pwm, |
| 64 | id, |
| 65 | entry::enable); |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 66 | |
| 67 | if (fs::exists(fullPath)) |
| 68 | { |
| 69 | //This class always uses RPM mode |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 70 | try |
| 71 | { |
| 72 | ioAccess.write( |
| 73 | enable::rpmMode, |
| 74 | type::pwm, |
| 75 | id, |
Brad Bishop | 754d38c | 2017-09-08 00:46:58 -0400 | [diff] [blame] | 76 | entry::enable, |
| 77 | sysfs::hwmonio::retries, |
| 78 | sysfs::hwmonio::delay); |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 79 | } |
| 80 | catch (const std::system_error& e) |
| 81 | { |
| 82 | using namespace sdbusplus::xyz::openbmc_project::Control:: |
| 83 | Device::Error; |
| 84 | phosphor::logging::report<WriteFailure>( |
| 85 | xyz::openbmc_project::Control::Device:: |
| 86 | WriteFailure::CALLOUT_ERRNO(e.code().value()), |
| 87 | xyz::openbmc_project::Control::Device:: |
| 88 | WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 89 | |
| 90 | log<level::INFO>("Logging failing sysfs file", |
| 91 | phosphor::logging::entry("FILE=%s", fullPath.c_str())); |
| 92 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 93 | exit(EXIT_FAILURE); |
| 94 | } |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 99 | } // namespace hwmon |