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