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