blob: 9b4ad63a64583131ece929a69163e69c75eb67c2 [file] [log] [blame]
Matthew Barth048ac872017-03-09 14:36:08 -06001#pragma once
2
Patrick Venture50552372018-06-07 10:53:56 -07003#include <memory>
4
Patrick Venture75e56c62018-04-20 18:10:15 -07005#include "hwmonio.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06006#include "interface.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04007#include "sysfs.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06008
9namespace 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 */
18class FanSpeed : public FanSpeedObject
19{
20 public:
21
22 /**
23 * @brief Constructs FanSpeed Object
24 *
Patrick Venture50552372018-06-07 10:53:56 -070025 * @param[in] io - HwmonIO(instance path) (ex /sys/class/hwmon/hwmon1)
Brad Bishop751043e2017-08-29 11:13:46 -040026 * @param[in] devPath - The /sys/devices sysfs path
Matthew Barth048ac872017-03-09 14:36:08 -060027 * @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 Spinlerb4e65572017-10-17 10:09:18 -050031 * @param[in] target - initial target speed value
Matthew Barth048ac872017-03-09 14:36:08 -060032 */
Patrick Venture50552372018-06-07 10:53:56 -070033 FanSpeed(std::unique_ptr<hwmonio::HwmonIOInterface> io,
Brad Bishop751043e2017-08-29 11:13:46 -040034 const std::string& devPath,
Matthew Barth048ac872017-03-09 14:36:08 -060035 const std::string& id,
36 sdbusplus::bus::bus& bus,
37 const char* objPath,
Matt Spinlerb4e65572017-10-17 10:09:18 -050038 bool defer,
39 uint64_t target) : FanSpeedObject(bus, objPath, defer),
Brad Bishop751043e2017-08-29 11:13:46 -040040 id(id),
Patrick Venture50552372018-06-07 10:53:56 -070041 ioAccess(std::move(io)),
Brad Bishop751043e2017-08-29 11:13:46 -040042 devPath(devPath)
Matthew Barth048ac872017-03-09 14:36:08 -060043 {
Matt Spinlerb4e65572017-10-17 10:09:18 -050044 FanSpeedObject::target(target);
Matthew Barth048ac872017-03-09 14:36:08 -060045 }
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 Spinler0a8de642017-05-11 10:59:39 -050054 /**
Matt Spinlerb778df02017-10-16 13:15:18 -050055 * @brief Writes the pwm_enable sysfs entry if the
56 * env var with the value to write is present
Matt Spinler0a8de642017-05-11 10:59:39 -050057 */
58 void enable();
59
Matthew Barth048ac872017-03-09 14:36:08 -060060 private:
Matthew Barth048ac872017-03-09 14:36:08 -060061 /** @brief hwmon type */
62 static constexpr auto type = "fan";
63 /** @brief hwmon id */
64 std::string id;
Brad Bishop751043e2017-08-29 11:13:46 -040065 /** @brief Hwmon sysfs access. */
Patrick Venture50552372018-06-07 10:53:56 -070066 std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess;
Brad Bishop751043e2017-08-29 11:13:46 -040067 /** @brief Physical device path. */
68 std::string devPath;
69
Matthew Barth048ac872017-03-09 14:36:08 -060070};
71
72} // namespace hwmon