blob: fb97303a65a54d187265b26a1a360420c4010f80 [file] [log] [blame]
Matthew Barth048ac872017-03-09 14:36:08 -06001#pragma once
2
Patrick Venture75e56c62018-04-20 18:10:15 -07003#include "hwmonio.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06004#include "interface.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04005#include "sysfs.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06006
7namespace hwmon
8{
9
10/**
11 * @class FanSpeed
12 * @brief Target fan speed control implementation
13 * @details Derived FanSpeedObject type that writes the target value to sysfs
14 * which in turn sets the fan speed to that target value
15 */
16class FanSpeed : public FanSpeedObject
17{
18 public:
19
20 /**
21 * @brief Constructs FanSpeed Object
22 *
Brad Bishop751043e2017-08-29 11:13:46 -040023 * @param[in] instancePath - The hwmon instance path
24 * (ex. /sys/class/hwmon/hwmon1)
25 * @param[in] devPath - The /sys/devices sysfs path
Matthew Barth048ac872017-03-09 14:36:08 -060026 * @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
Matt Spinlerb4e65572017-10-17 10:09:18 -050030 * @param[in] target - initial target speed value
Matthew Barth048ac872017-03-09 14:36:08 -060031 */
Brad Bishop751043e2017-08-29 11:13:46 -040032 FanSpeed(const std::string& instancePath,
33 const std::string& devPath,
Matthew Barth048ac872017-03-09 14:36:08 -060034 const std::string& id,
35 sdbusplus::bus::bus& bus,
36 const char* objPath,
Matt Spinlerb4e65572017-10-17 10:09:18 -050037 bool defer,
38 uint64_t target) : FanSpeedObject(bus, objPath, defer),
Brad Bishop751043e2017-08-29 11:13:46 -040039 id(id),
40 ioAccess(instancePath),
41 devPath(devPath)
Matthew Barth048ac872017-03-09 14:36:08 -060042 {
Matt Spinlerb4e65572017-10-17 10:09:18 -050043 FanSpeedObject::target(target);
Matthew Barth048ac872017-03-09 14:36:08 -060044 }
45
46 /**
47 * @brief Set the value of target
48 *
49 * @return Value of target
50 */
51 uint64_t target(uint64_t value) override;
52
Matt Spinler0a8de642017-05-11 10:59:39 -050053 /**
Matt Spinlerb778df02017-10-16 13:15:18 -050054 * @brief Writes the pwm_enable sysfs entry if the
55 * env var with the value to write is present
Matt Spinler0a8de642017-05-11 10:59:39 -050056 */
57 void enable();
58
Matthew Barth048ac872017-03-09 14:36:08 -060059 private:
Matthew Barth048ac872017-03-09 14:36:08 -060060 /** @brief hwmon type */
61 static constexpr auto type = "fan";
62 /** @brief hwmon id */
63 std::string id;
Brad Bishop751043e2017-08-29 11:13:46 -040064 /** @brief Hwmon sysfs access. */
Patrick Venture75e56c62018-04-20 18:10:15 -070065 hwmonio::HwmonIO ioAccess;
Brad Bishop751043e2017-08-29 11:13:46 -040066 /** @brief Physical device path. */
67 std::string devPath;
68
Matthew Barth048ac872017-03-09 14:36:08 -060069};
70
71} // namespace hwmon