Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 3 | #include "hwmonio.hpp" |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 4 | #include "interface.hpp" |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 5 | #include "sysfs.hpp" |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 6 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 9 | namespace hwmon |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @class FanSpeed |
| 14 | * @brief Target fan speed control implementation |
| 15 | * @details Derived FanSpeedObject type that writes the target value to sysfs |
| 16 | * which in turn sets the fan speed to that target value |
| 17 | */ |
| 18 | class FanSpeed : public FanSpeedObject |
| 19 | { |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 20 | public: |
| 21 | /** |
| 22 | * @brief Constructs FanSpeed Object |
| 23 | * |
| 24 | * @param[in] io - HwmonIO(instance path) (ex /sys/class/hwmon/hwmon1) |
| 25 | * @param[in] devPath - The /sys/devices sysfs path |
| 26 | * @param[in] id - The hwmon id |
| 27 | * @param[in] bus - Dbus bus object |
| 28 | * @param[in] objPath - Dbus object path |
| 29 | * @param[in] defer - Dbus object registration defer |
| 30 | * @param[in] target - initial target speed value |
| 31 | */ |
| 32 | FanSpeed(std::unique_ptr<hwmonio::HwmonIOInterface> io, |
| 33 | const std::string& devPath, const std::string& id, |
Patrick Williams | ad6043f | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 34 | sdbusplus::bus_t& bus, const char* objPath, bool defer, |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 35 | uint64_t target) : |
Patrick Williams | d273b1e | 2022-03-30 21:55:44 -0500 | [diff] [blame] | 36 | FanSpeedObject(bus, objPath, |
| 37 | defer ? FanSpeedObject::action::emit_no_signals |
| 38 | : FanSpeedObject::action::emit_object_added), |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 39 | _id(id), _ioAccess(std::move(io)), _devPath(devPath) |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 40 | { |
| 41 | FanSpeedObject::target(target); |
| 42 | } |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 43 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @brief Set the value of target |
| 46 | * |
| 47 | * @return Value of target |
| 48 | */ |
| 49 | uint64_t target(uint64_t value) override; |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 50 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 51 | /** |
| 52 | * @brief Writes the pwm_enable sysfs entry if the |
| 53 | * env var with the value to write is present |
| 54 | */ |
| 55 | void enable(); |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 56 | |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 57 | private: |
| 58 | /** @brief hwmon type */ |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 59 | static constexpr auto _type = "fan"; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 60 | /** @brief hwmon id */ |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 61 | std::string _id; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 62 | /** @brief Hwmon sysfs access. */ |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 63 | std::unique_ptr<hwmonio::HwmonIOInterface> _ioAccess; |
Patrick Venture | 043d323 | 2018-08-31 10:10:53 -0700 | [diff] [blame] | 64 | /** @brief Physical device path. */ |
Patrick Venture | abf2970 | 2018-12-19 14:37:18 -0800 | [diff] [blame] | 65 | std::string _devPath; |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace hwmon |