xref: /openbmc/phosphor-hwmon/fan_speed.hpp (revision 75e56c67a10e9f4c617f9c72a87deb695322e212)
1 #pragma once
2 
3 #include "hwmonio.hpp"
4 #include "interface.hpp"
5 #include "sysfs.hpp"
6 
7 namespace 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  */
16 class FanSpeed : public FanSpeedObject
17 {
18     public:
19 
20         /**
21          * @brief Constructs FanSpeed Object
22          *
23          * @param[in] instancePath - The hwmon instance path
24          *     (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(const std::string& instancePath,
33                  const std::string& devPath,
34                  const std::string& id,
35                  sdbusplus::bus::bus& bus,
36                  const char* objPath,
37                  bool defer,
38                  uint64_t target) : FanSpeedObject(bus, objPath, defer),
39                     id(id),
40                     ioAccess(instancePath),
41                     devPath(devPath)
42         {
43             FanSpeedObject::target(target);
44         }
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 
53         /**
54          * @brief Writes the pwm_enable sysfs entry if the
55          *        env var with the value to write is present
56          */
57         void enable();
58 
59     private:
60         /** @brief hwmon type */
61         static constexpr auto type = "fan";
62         /** @brief hwmon id */
63         std::string id;
64         /** @brief Hwmon sysfs access. */
65         hwmonio::HwmonIO ioAccess;
66         /** @brief Physical device path. */
67         std::string devPath;
68 
69 };
70 
71 } // namespace hwmon
72