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