xref: /openbmc/phosphor-hwmon/fan_pwm.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 FanPwm
12  * @brief Target fan pwm control implementation
13  * @details Derived FanPwmObject type that writes the target value to sysfs
14  * which in turn sets the fan speed to that target value
15  */
16 class FanPwm : public FanPwmObject
17 {
18     public:
19 
20         /**
21          * @brief Constructs FanPwm 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          */
31     FanPwm(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) : FanPwmObject(bus, objPath, defer),
38                 id(id),
39                 ioAccess(instancePath),
40                 devPath(devPath)
41         {
42             FanPwmObject::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     private:
53         /** @brief hwmon type */
54         static constexpr auto type = "pwm";
55         /** @brief hwmon id */
56         std::string id;
57         /** @brief Hwmon sysfs access. */
58         hwmonio::HwmonIO ioAccess;
59         /** @brief Physical device path. */
60         std::string devPath;
61 };
62 
63 } // namespace hwmon
64 
65