xref: /openbmc/phosphor-hwmon/fan_speed.hpp (revision c635e8609f5246224dfba7db57991de0b1c5327f)
1  #pragma once
2  
3  #include "interface.hpp"
4  #include "sysfs.hpp"
5  
6  namespace hwmon
7  {
8  
9  /**
10   * @class FanSpeed
11   * @brief Target fan speed control implementation
12   * @details Derived FanSpeedObject type that writes the target value to sysfs
13   * which in turn sets the fan speed to that target value
14   */
15  class FanSpeed : public FanSpeedObject
16  {
17      public:
18  
19          /**
20           * @brief Constructs FanSpeed Object
21           *
22           * @param[in] instancePath - The hwmon instance path
23           *     (ex. /sys/class/hwmon/hwmon1)
24           * @param[in] devPath - The /sys/devices sysfs path
25           * @param[in] id - The hwmon id
26           * @param[in] bus - Dbus bus object
27           * @param[in] objPath - Dbus object path
28           * @param[in] defer - Dbus object registration defer
29           * @param[in] target - initial target speed value
30           */
31          FanSpeed(const std::string& instancePath,
32                   const std::string& devPath,
33                   const std::string& id,
34                   sdbusplus::bus::bus& bus,
35                   const char* objPath,
36                   bool defer,
37                   uint64_t target) : FanSpeedObject(bus, objPath, defer),
38                      id(id),
39                      ioAccess(instancePath),
40                      devPath(devPath)
41          {
42              FanSpeedObject::target(target);
43          }
44  
45          /**
46           * @brief Set the value of target
47           *
48           * @return Value of target
49           */
50          uint64_t target(uint64_t value) override;
51  
52          /**
53           * @brief Writes the pwm_enable sysfs entry if the
54           *        env var with the value to write is present
55           */
56          void enable();
57  
58      private:
59          /** @brief hwmon type */
60          static constexpr auto type = "fan";
61          /** @brief hwmon id */
62          std::string id;
63          /** @brief Hwmon sysfs access. */
64          sysfs::hwmonio::HwmonIO ioAccess;
65          /** @brief Physical device path. */
66          std::string devPath;
67  
68  };
69  
70  } // namespace hwmon
71