xref: /openbmc/phosphor-hwmon/hwmon.hpp (revision 9bbe6026)
126b815faSBrad Bishop #pragma once
26292aeedSMatthew Barth 
3043d3230SPatrick Venture #include "interface.hpp"
4043d3230SPatrick Venture 
56292aeedSMatthew Barth #include <string>
609791857SPatrick Venture #include <tuple>
709791857SPatrick Venture 
86292aeedSMatthew Barth namespace hwmon
96292aeedSMatthew Barth {
106292aeedSMatthew Barth namespace entry
116292aeedSMatthew Barth {
120fcb8b3bSBrad Bishop static constexpr auto cinput = "input";
130fcb8b3bSBrad Bishop static constexpr auto clabel = "label";
14bf7b7b1dSMatthew Barth static constexpr auto ctarget = "target";
150a8de645SMatt Spinler static constexpr auto cenable = "enable";
1635819381SMatthew Barth static constexpr auto cfault = "fault";
17*9bbe6026SCarol Wang static constexpr auto caverage = "average";
18*9bbe6026SCarol Wang static constexpr auto caverage_interval = "average_interval";
190fcb8b3bSBrad Bishop 
200fcb8b3bSBrad Bishop static const std::string input = cinput;
210fcb8b3bSBrad Bishop static const std::string label = clabel;
22bf7b7b1dSMatthew Barth static const std::string target = ctarget;
230a8de645SMatt Spinler static const std::string enable = cenable;
2435819381SMatthew Barth static const std::string fault = cfault;
25*9bbe6026SCarol Wang static const std::string average = caverage;
26*9bbe6026SCarol Wang static const std::string average_interval = caverage_interval;
27043d3230SPatrick Venture } // namespace entry
280a8de645SMatt Spinler 
296292aeedSMatthew Barth namespace type
306292aeedSMatthew Barth {
310fcb8b3bSBrad Bishop static constexpr auto cfan = "fan";
320fcb8b3bSBrad Bishop static constexpr auto ctemp = "temp";
330fcb8b3bSBrad Bishop static constexpr auto cvolt = "in";
34e49b6a03SJaghathiswari Rankappagounder Natarajan static constexpr auto ccurr = "curr";
355afe21a5SBrad Bishop static constexpr auto cenergy = "energy";
365afe21a5SBrad Bishop static constexpr auto cpower = "power";
370a8de645SMatt Spinler static constexpr auto cpwm = "pwm";
380a8de645SMatt Spinler 
390fcb8b3bSBrad Bishop static const std::string fan = cfan;
400fcb8b3bSBrad Bishop static const std::string temp = ctemp;
410fcb8b3bSBrad Bishop static const std::string volt = cvolt;
425afe21a5SBrad Bishop static const std::string curr = ccurr;
435afe21a5SBrad Bishop static const std::string energy = cenergy;
445afe21a5SBrad Bishop static const std::string power = cpower;
450a8de645SMatt Spinler static const std::string pwm = cpwm;
46043d3230SPatrick Venture } // namespace type
4709791857SPatrick Venture 
48043d3230SPatrick Venture static constexpr auto typeAttrMap = {
4909791857SPatrick Venture     // 1 - hwmon class
5009791857SPatrick Venture     // 2 - unit
5109791857SPatrick Venture     // 3 - sysfs scaling factor
5209791857SPatrick Venture     // 4 - namespace
53043d3230SPatrick Venture     std::make_tuple(hwmon::type::ctemp, ValueInterface::Unit::DegreesC, -3,
5409791857SPatrick Venture                     "temperature"),
55043d3230SPatrick Venture     std::make_tuple(hwmon::type::cfan, ValueInterface::Unit::RPMS, 0,
5609791857SPatrick Venture                     "fan_tach"),
57043d3230SPatrick Venture     std::make_tuple(hwmon::type::cvolt, ValueInterface::Unit::Volts, -3,
5809791857SPatrick Venture                     "voltage"),
59043d3230SPatrick Venture     std::make_tuple(hwmon::type::ccurr, ValueInterface::Unit::Amperes, -3,
6009791857SPatrick Venture                     "current"),
61043d3230SPatrick Venture     std::make_tuple(hwmon::type::cenergy, ValueInterface::Unit::Joules, -6,
6209791857SPatrick Venture                     "energy"),
63043d3230SPatrick Venture     std::make_tuple(hwmon::type::cpower, ValueInterface::Unit::Watts, -6,
6409791857SPatrick Venture                     "power"),
6509791857SPatrick Venture };
6609791857SPatrick Venture 
getHwmonType(decltype (typeAttrMap)::const_reference attrs)6709791857SPatrick Venture inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
6809791857SPatrick Venture {
6909791857SPatrick Venture     return std::get<0>(attrs);
706292aeedSMatthew Barth }
716292aeedSMatthew Barth 
getUnit(decltype (typeAttrMap)::const_reference attrs)7209791857SPatrick Venture inline auto getUnit(decltype(typeAttrMap)::const_reference attrs)
7309791857SPatrick Venture {
7409791857SPatrick Venture     return std::get<1>(attrs);
7509791857SPatrick Venture }
7609791857SPatrick Venture 
getScale(decltype (typeAttrMap)::const_reference attrs)7709791857SPatrick Venture inline auto getScale(decltype(typeAttrMap)::const_reference attrs)
7809791857SPatrick Venture {
7909791857SPatrick Venture     return std::get<2>(attrs);
8009791857SPatrick Venture }
8109791857SPatrick Venture 
getNamespace(decltype (typeAttrMap)::const_reference attrs)8209791857SPatrick Venture inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
8309791857SPatrick Venture {
8409791857SPatrick Venture     return std::get<3>(attrs);
8509791857SPatrick Venture }
8609791857SPatrick Venture 
8709791857SPatrick Venture using AttributeIterator = decltype(*typeAttrMap.begin());
88043d3230SPatrick Venture using Attributes =
89043d3230SPatrick Venture     std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
9009791857SPatrick Venture 
9109791857SPatrick Venture /** @brief Get Attribute tuple for the type
9209791857SPatrick Venture  *
9309791857SPatrick Venture  *  Given a type, it tries to find the corresponding tuple
9409791857SPatrick Venture  *
9509791857SPatrick Venture  *  @param[in] type the sensor type
9609791857SPatrick Venture  *  @param[in,out] A pointer to the Attribute tuple
9709791857SPatrick Venture  */
9809791857SPatrick Venture bool getAttributes(const std::string& type, Attributes& attributes);
9909791857SPatrick Venture 
10009791857SPatrick Venture } //  namespace hwmon
10109791857SPatrick Venture 
10203476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
103