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, |
| 26 | entry::target); |
| 27 | } |
| 28 | catch (const std::system_error& e) |
| 29 | { |
| 30 | using namespace sdbusplus::xyz::openbmc_project::Control:: |
| 31 | Device::Error; |
| 32 | report<WriteFailure>( |
| 33 | xyz::openbmc_project::Control::Device:: |
| 34 | WriteFailure::CALLOUT_ERRNO(e.code().value()), |
| 35 | xyz::openbmc_project::Control::Device:: |
| 36 | WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); |
| 37 | exit(EXIT_FAILURE); |
| 38 | } |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | return FanSpeedObject::target(value); |
| 42 | } |
| 43 | |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 44 | |
| 45 | void FanSpeed::enable() |
| 46 | { |
| 47 | namespace fs = std::experimental::filesystem; |
| 48 | |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 49 | auto fullPath = sysfs::make_sysfs_path(ioAccess.path(), |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 50 | type::pwm, |
| 51 | id, |
| 52 | entry::enable); |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 53 | |
| 54 | if (fs::exists(fullPath)) |
| 55 | { |
| 56 | //This class always uses RPM mode |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 57 | try |
| 58 | { |
| 59 | ioAccess.write( |
| 60 | enable::rpmMode, |
| 61 | type::pwm, |
| 62 | id, |
| 63 | entry::enable); |
| 64 | } |
| 65 | catch (const std::system_error& e) |
| 66 | { |
| 67 | using namespace sdbusplus::xyz::openbmc_project::Control:: |
| 68 | Device::Error; |
| 69 | phosphor::logging::report<WriteFailure>( |
| 70 | xyz::openbmc_project::Control::Device:: |
| 71 | WriteFailure::CALLOUT_ERRNO(e.code().value()), |
| 72 | xyz::openbmc_project::Control::Device:: |
| 73 | WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); |
| 74 | exit(EXIT_FAILURE); |
| 75 | } |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 80 | } // namespace hwmon |