1 #include <phosphor-logging/elog-errors.hpp> 2 #include <xyz/openbmc_project/Control/Device/error.hpp> 3 #include "sensorset.hpp" 4 #include "env.hpp" 5 #include "fan_speed.hpp" 6 #include "hwmon.hpp" 7 #include "hwmonio.hpp" 8 #include "sysfs.hpp" 9 10 using namespace phosphor::logging; 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 22 try 23 { 24 ioAccess.write( 25 value, 26 type, 27 id, 28 entry::target, 29 hwmonio::retries, 30 hwmonio::delay); 31 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())); 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 52 exit(EXIT_FAILURE); 53 } 54 } 55 56 return FanSpeedObject::target(value); 57 } 58 59 60 void FanSpeed::enable() 61 { 62 auto enable = env::getEnv("ENABLE", type, id); 63 if (!enable.empty()) 64 { 65 auto val = std::stoul(enable); 66 67 try 68 { 69 ioAccess.write( 70 val, 71 type::pwm, 72 id, 73 entry::enable, 74 hwmonio::retries, 75 hwmonio::delay); 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())); 86 87 auto fullPath = sysfs::make_sysfs_path( 88 ioAccess.path(), 89 type::pwm, 90 id, 91 entry::enable); 92 93 log<level::INFO>("Logging failing sysfs file", 94 phosphor::logging::entry("FILE=%s", fullPath.c_str())); 95 96 exit(EXIT_FAILURE); 97 } 98 } 99 } 100 101 102 } // namespace hwmon 103