xref: /openbmc/phosphor-hwmon/fan_pwm.hpp (revision 5906173a)
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 FanPwm
14  * @brief Target fan pwm control implementation
15  * @details Derived FanPwmObject type that writes the target value to sysfs
16  * which in turn sets the fan speed to that target value
17  */
18 class FanPwm : public FanPwmObject
19 {
20   public:
21     /**
22      * @brief Constructs FanPwm Object
23      *
24      * @param[in] io - HwmonIO
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      */
31     FanPwm(std::unique_ptr<hwmonio::HwmonIOInterface> io,
32            const std::string& devPath, const std::string& id,
33            sdbusplus::bus::bus& bus, const char* objPath, bool defer,
34            uint64_t target) :
35         FanPwmObject(bus, objPath, defer),
36         _id(id), _ioAccess(std::move(io)), _devPath(devPath)
37     {
38         FanPwmObject::target(target);
39     }
40 
41     /**
42      * @brief Set the value of target
43      *
44      * @return Value of target
45      */
46     uint64_t target(uint64_t value) override;
47 
48   private:
49     /** @brief hwmon type */
50     static constexpr auto _type = "pwm";
51     /** @brief hwmon id */
52     std::string _id;
53     /** @brief Hwmon sysfs access. */
54     std::unique_ptr<hwmonio::HwmonIOInterface> _ioAccess;
55     /** @brief Physical device path. */
56     std::string _devPath;
57 };
58 
59 } // namespace hwmon
60