| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "fanautoprovider.h" |
| 5 | |
| 6 | #include "../fanmodeprovider.h" |
| 7 | #include "common/fileutils.h" |
| 8 | #include "common/stringutils.h" |
| 9 | #include "core/info/amd/gpuinfoodfanctrl.h" |
| 10 | #include "core/info/igpuinfo.h" |
| 11 | #include "core/sysfsdatasource.h" |
| 12 | #include "fanauto.h" |
| 13 | #include <filesystem> |
| 14 | #include <memory> |
| 15 | |
| 16 | std::vector<std::unique_ptr<IControl>> |
| 17 | AMD::FanAutoProvider::provideGPUControls(IGPUInfo const &gpuInfo, |
| 18 | ISWInfo const &) const |
| 19 | { |
| 20 | if (!(gpuInfo.vendor() == Vendor::AMD && |
| 21 | !gpuInfo.hasCapability(GPUInfoOdFanCtrl::ID))) |
| 22 | return {}; |
| 23 | |
| 24 | auto path = Utils::File::findHWMonXDirectory(gpuInfo.path().sys / "hwmon"); |
| 25 | if (!path) |
| 26 | return {}; |
| 27 | |
| 28 | auto pwmEnable = path.value() / "pwm1_enable"; |
| 29 | if (!Utils::File::isSysFSEntryValid(pwmEnable)) |
| 30 | return {}; |
| 31 | |
| 32 | std::vector<std::unique_ptr<IControl>> controls; |
| 33 | controls.emplace_back(std::make_unique<AMD::FanAuto>( |
| 34 | std::make_unique<SysFSDataSource<unsigned int>>( |
| 35 | pwmEnable, [](std::string const &data, unsigned int &output) { |
| 36 | Utils::String::toNumber<unsigned int>(output, data); |
| 37 | }))); |
| 38 | |
| 39 | return controls; |
| 40 | } |
| 41 | |
| 42 | bool const AMD::FanAutoProvider::registered_ = |
| 43 | AMD::FanModeProvider::registerProvider( |
| 44 | std::make_unique<AMD::FanAutoProvider>()); |