xref: /openbmc/phosphor-hwmon/fan_speed.hpp (revision 043d3230)
1 #pragma once
2 
3 #include "hwmonio.hpp"
4 #include "interface.hpp"
5 #include "sysfs.hpp"
6 
7 #include <memory>
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      * @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,
34              sdbusplus::bus::bus& bus, const char* objPath, bool defer,
35              uint64_t target) :
36         FanSpeedObject(bus, objPath, defer),
37         id(id), ioAccess(std::move(io)), devPath(devPath)
38     {
39         FanSpeedObject::target(target);
40     }
41 
42     /**
43      * @brief Set the value of target
44      *
45      * @return Value of target
46      */
47     uint64_t target(uint64_t value) override;
48 
49     /**
50      * @brief Writes the pwm_enable sysfs entry if the
51      *        env var with the value to write is present
52      */
53     void enable();
54 
55   private:
56     /** @brief hwmon type */
57     static constexpr auto type = "fan";
58     /** @brief hwmon id */
59     std::string id;
60     /** @brief Hwmon sysfs access. */
61     std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess;
62     /** @brief Physical device path. */
63     std::string devPath;
64 };
65 
66 } // namespace hwmon
67