1 #include "fan_speed.hpp"
2
3 #include "env.hpp"
4 #include "hwmon.hpp"
5 #include "hwmonio.hpp"
6 #include "sensorset.hpp"
7 #include "sysfs.hpp"
8
9 #include <phosphor-logging/elog-errors.hpp>
10 #include <xyz/openbmc_project/Control/Device/error.hpp>
11
12 #include <format>
13
14 using namespace phosphor::logging;
15
16 namespace hwmon
17 {
18
target(uint64_t value)19 uint64_t FanSpeed::target(uint64_t value)
20 {
21 try
22 {
23 _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
24 hwmonio::delay);
25 }
26 catch (const std::system_error& e)
27 {
28 using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
29 report<WriteFailure>(
30 xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
31 e.code().value()),
32 xyz::openbmc_project::Control::Device::WriteFailure::
33 CALLOUT_DEVICE_PATH(_devPath.c_str()));
34
35 auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
36 entry::target);
37
38 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
39 e.code().value())
40 .c_str());
41
42 exit(EXIT_FAILURE);
43 }
44
45 return FanSpeedObject::target(value);
46 }
47
enable()48 void FanSpeed::enable()
49 {
50 auto enable = env::getEnv("ENABLE", _type, _id);
51 if (!enable.empty())
52 {
53 auto val = std::stoul(enable);
54
55 try
56 {
57 _ioAccess->write(val, type::pwm, _id, entry::enable,
58 hwmonio::retries, hwmonio::delay);
59 }
60 catch (const std::system_error& e)
61 {
62 using namespace sdbusplus::xyz::openbmc_project::Control::Device::
63 Error;
64 phosphor::logging::report<WriteFailure>(
65 xyz::openbmc_project::Control::Device::WriteFailure::
66 CALLOUT_ERRNO(e.code().value()),
67 xyz::openbmc_project::Control::Device::WriteFailure::
68 CALLOUT_DEVICE_PATH(_devPath.c_str()));
69
70 auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
71 _id, entry::enable);
72
73 log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
74 fullPath, e.code().value())
75 .c_str());
76
77 exit(EXIT_FAILURE);
78 }
79 }
80 }
81
82 } // namespace hwmon
83