xref: /openbmc/phosphor-hwmon/fan_pwm.hpp (revision ad6043f6)
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      */
FanPwm(std::unique_ptr<hwmonio::HwmonIOInterface> io,const std::string & devPath,const std::string & id,sdbusplus::bus_t & bus,const char * objPath,bool defer,uint64_t target)31     FanPwm(std::unique_ptr<hwmonio::HwmonIOInterface> io,
32            const std::string& devPath, const std::string& id,
33            sdbusplus::bus_t& bus, const char* objPath, bool defer,
34            uint64_t target) :
35         FanPwmObject(bus, objPath,
36                      defer ? FanPwmObject::action::emit_no_signals
37                            : FanPwmObject::action::emit_object_added),
38         _id(id), _ioAccess(std::move(io)), _devPath(devPath)
39     {
40         FanPwmObject::target(target);
41     }
42 
43     /**
44      * @brief Set the value of target
45      *
46      * @return Value of target
47      */
48     uint64_t target(uint64_t value) override;
49 
50   private:
51     /** @brief hwmon type */
52     static constexpr auto _type = "pwm";
53     /** @brief hwmon id */
54     std::string _id;
55     /** @brief Hwmon sysfs access. */
56     std::unique_ptr<hwmonio::HwmonIOInterface> _ioAccess;
57     /** @brief Physical device path. */
58     std::string _devPath;
59 };
60 
61 } // namespace hwmon
62