19331ab78SPatrick Venture #include "fan_pwm.hpp"
2043d3230SPatrick Venture
3043d3230SPatrick Venture #include "env.hpp"
49331ab78SPatrick Venture #include "hwmon.hpp"
575e56c67SPatrick Venture #include "hwmonio.hpp"
69331ab78SPatrick Venture #include "sensorset.hpp"
79331ab78SPatrick Venture #include "sysfs.hpp"
89331ab78SPatrick Venture
9043d3230SPatrick Venture #include <phosphor-logging/elog-errors.hpp>
10043d3230SPatrick Venture #include <xyz/openbmc_project/Control/Device/error.hpp>
119331ab78SPatrick Venture
12e8771fd4SPatrick Williams #include <filesystem>
1364129937SPatrick Williams #include <format>
14e8771fd4SPatrick Williams #include <string>
15e8771fd4SPatrick Williams
169331ab78SPatrick Venture using namespace phosphor::logging;
179331ab78SPatrick Venture
189331ab78SPatrick Venture namespace hwmon
199331ab78SPatrick Venture {
209331ab78SPatrick Venture
target(uint64_t value)219331ab78SPatrick Venture uint64_t FanPwm::target(uint64_t value)
229331ab78SPatrick Venture {
239331ab78SPatrick Venture using namespace std::literals;
249331ab78SPatrick Venture
259331ab78SPatrick Venture std::string empty;
269331ab78SPatrick Venture // Write target out to sysfs
27901f1177SKun Yi try
28901f1177SKun Yi {
292511c09bSPatrick Venture _ioAccess->write(value, _type, _id, empty, hwmonio::retries,
3075e56c67SPatrick Venture hwmonio::delay);
319331ab78SPatrick Venture }
329331ab78SPatrick Venture catch (const std::system_error& e)
339331ab78SPatrick Venture {
34043d3230SPatrick Venture using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
359331ab78SPatrick Venture report<WriteFailure>(
36043d3230SPatrick Venture xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
37043d3230SPatrick Venture e.code().value()),
38043d3230SPatrick Venture xyz::openbmc_project::Control::Device::WriteFailure::
392511c09bSPatrick Venture CALLOUT_DEVICE_PATH(_devPath.c_str()));
409331ab78SPatrick Venture
41*02e598abSPatrick Williams auto file =
42*02e598abSPatrick Williams sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, empty);
439331ab78SPatrick Venture
4464129937SPatrick Williams log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
456a391de4SMatt Spinler e.code().value())
466a391de4SMatt Spinler .c_str());
479331ab78SPatrick Venture
489331ab78SPatrick Venture exit(EXIT_FAILURE);
499331ab78SPatrick Venture }
509331ab78SPatrick Venture
519331ab78SPatrick Venture return FanPwmObject::target(value);
529331ab78SPatrick Venture }
539331ab78SPatrick Venture
549331ab78SPatrick Venture } // namespace hwmon
55