blob: fd943e1417a6ae0d818c8feec6473f781eac3760 [file] [log] [blame]
Matthew Barth048ac872017-03-09 14:36:08 -06001#pragma once
2
Patrick Venture75e56c62018-04-20 18:10:15 -07003#include "hwmonio.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06004#include "interface.hpp"
Brad Bishop751043e2017-08-29 11:13:46 -04005#include "sysfs.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -06006
Patrick Venture043d3232018-08-31 10:10:53 -07007#include <memory>
8
Matthew Barth048ac872017-03-09 14:36:08 -06009namespace hwmon
10{
11
12/**
13 * @class FanSpeed
14 * @brief Target fan speed control implementation
15 * @details Derived FanSpeedObject type that writes the target value to sysfs
16 * which in turn sets the fan speed to that target value
17 */
18class FanSpeed : public FanSpeedObject
19{
Patrick Venture043d3232018-08-31 10:10:53 -070020 public:
21 /**
22 * @brief Constructs FanSpeed Object
23 *
24 * @param[in] io - HwmonIO(instance path) (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(std::unique_ptr<hwmonio::HwmonIOInterface> io,
33 const std::string& devPath, const std::string& id,
Patrick Williamsad6043f2022-07-22 19:26:56 -050034 sdbusplus::bus_t& bus, const char* objPath, bool defer,
Patrick Venture043d3232018-08-31 10:10:53 -070035 uint64_t target) :
Patrick Williamsd273b1e2022-03-30 21:55:44 -050036 FanSpeedObject(bus, objPath,
37 defer ? FanSpeedObject::action::emit_no_signals
38 : FanSpeedObject::action::emit_object_added),
Patrick Ventureabf29702018-12-19 14:37:18 -080039 _id(id), _ioAccess(std::move(io)), _devPath(devPath)
Patrick Venture043d3232018-08-31 10:10:53 -070040 {
41 FanSpeedObject::target(target);
42 }
Matthew Barth048ac872017-03-09 14:36:08 -060043
Patrick Venture043d3232018-08-31 10:10:53 -070044 /**
45 * @brief Set the value of target
46 *
47 * @return Value of target
48 */
49 uint64_t target(uint64_t value) override;
Matthew Barth048ac872017-03-09 14:36:08 -060050
Patrick Venture043d3232018-08-31 10:10:53 -070051 /**
52 * @brief Writes the pwm_enable sysfs entry if the
53 * env var with the value to write is present
54 */
55 void enable();
Matthew Barth048ac872017-03-09 14:36:08 -060056
Patrick Venture043d3232018-08-31 10:10:53 -070057 private:
58 /** @brief hwmon type */
Patrick Ventureabf29702018-12-19 14:37:18 -080059 static constexpr auto _type = "fan";
Patrick Venture043d3232018-08-31 10:10:53 -070060 /** @brief hwmon id */
Patrick Ventureabf29702018-12-19 14:37:18 -080061 std::string _id;
Patrick Venture043d3232018-08-31 10:10:53 -070062 /** @brief Hwmon sysfs access. */
Patrick Ventureabf29702018-12-19 14:37:18 -080063 std::unique_ptr<hwmonio::HwmonIOInterface> _ioAccess;
Patrick Venture043d3232018-08-31 10:10:53 -070064 /** @brief Physical device path. */
Patrick Ventureabf29702018-12-19 14:37:18 -080065 std::string _devPath;
Matthew Barth048ac872017-03-09 14:36:08 -060066};
67
68} // namespace hwmon