xref: /openbmc/phosphor-hwmon/sysfs.hpp (revision f9aff805)
126b815faSBrad Bishop #pragma once
26292aeedSMatthew Barth 
36292aeedSMatthew Barth #include <string>
46292aeedSMatthew Barth 
5043d3230SPatrick Venture namespace sysfs
6043d3230SPatrick Venture {
71e6324faSPatrick Venture 
make_sysfs_path(const std::string & path,const std::string & type,const std::string & id,const std::string & entry)8a9b5f05bSBrad Bishop inline std::string make_sysfs_path(const std::string& path,
96292aeedSMatthew Barth                                    const std::string& type,
106292aeedSMatthew Barth                                    const std::string& id,
116292aeedSMatthew Barth                                    const std::string& entry)
126292aeedSMatthew Barth {
136292aeedSMatthew Barth     using namespace std::literals;
146292aeedSMatthew Barth 
15043d3230SPatrick Venture     if (entry.empty())
16043d3230SPatrick Venture     {
179331ab78SPatrick Venture         return path + "/"s + type + id;
189331ab78SPatrick Venture     }
199331ab78SPatrick Venture 
206292aeedSMatthew Barth     return path + "/"s + type + id + "_"s + entry;
216292aeedSMatthew Barth }
226292aeedSMatthew Barth 
23f4bf63adSBrad Bishop /** @brief Return the path to the phandle file matching value in io-channels.
24f4bf63adSBrad Bishop  *
25f4bf63adSBrad Bishop  *  This function will take two passed in paths.
26f4bf63adSBrad Bishop  *  One path is used to find the io-channels file.
27f4bf63adSBrad Bishop  *  The other path is used to find the phandle file.
28f4bf63adSBrad Bishop  *  The 4 byte phandle value is read from the phandle file(s).
29f4bf63adSBrad Bishop  *  The 4 byte phandle value and 4 byte index value is read from io-channels.
30f4bf63adSBrad Bishop  *  When a match is found, the path to the matching phandle file is returned.
31f4bf63adSBrad Bishop  *
32f4bf63adSBrad Bishop  *  @param[in] iochanneldir - Path to file for getting phandle from io-channels
33f4bf63adSBrad Bishop  *  @param[in] phandledir - Path to use for reading from phandle file
34f4bf63adSBrad Bishop  *
35f4bf63adSBrad Bishop  *  @return Path to phandle file with value matching that in io-channels
36f4bf63adSBrad Bishop  */
37043d3230SPatrick Venture std::string findPhandleMatch(const std::string& iochanneldir,
38f4bf63adSBrad Bishop                              const std::string& phandledir);
39613a5b37SBrad Bishop 
4031dbe062SMatt Spinler /** @brief Find hwmon instances from an open-firmware device tree path
41613a5b37SBrad Bishop  *
42613a5b37SBrad Bishop  *  Look for a matching hwmon instance given an
43613a5b37SBrad Bishop  *  open firmware device path.
44613a5b37SBrad Bishop  *
45613a5b37SBrad Bishop  *  @param[in] ofNode- The open firmware device path.
46613a5b37SBrad Bishop  *
47613a5b37SBrad Bishop  *  @returns[in] - The hwmon instance path or an empty
48613a5b37SBrad Bishop  *                 string if no match is found.
49613a5b37SBrad Bishop  */
50*5c014d2bSMatt Spinler std::string findHwmonFromOFPath(const std::string& ofNode);
51613a5b37SBrad Bishop 
52626df17aSMatt Spinler /** @brief Find hwmon instances from a device path
53626df17aSMatt Spinler  *
54626df17aSMatt Spinler  *  Look for a matching hwmon instance given a device path that
55626df17aSMatt Spinler  *  starts with /devices.  This path is the DEVPATH udev attribute
56626df17aSMatt Spinler  *  for the device except it has the '/hwmon/hwmonN' stripped off.
57626df17aSMatt Spinler  *
58626df17aSMatt Spinler  *  @param[in] devPath - The device path.
59626df17aSMatt Spinler  *
60626df17aSMatt Spinler  *  @return - The hwmon instance path or an empty
61626df17aSMatt Spinler  *            string if no match is found.
62626df17aSMatt Spinler  */
63*5c014d2bSMatt Spinler std::string findHwmonFromDevPath(const std::string& devPath);
64626df17aSMatt Spinler 
65431d26a5SBrad Bishop /** @brief Return the path to use for a call out.
66431d26a5SBrad Bishop  *
67431d26a5SBrad Bishop  *  Return an empty string if a callout path cannot be
68431d26a5SBrad Bishop  *  found.
69431d26a5SBrad Bishop  *
70431d26a5SBrad Bishop  *  @param[in] instancePath - /sys/class/hwmon/hwmon<N> path.
71431d26a5SBrad Bishop  *
72431d26a5SBrad Bishop  *  @return Path to use for call out
73431d26a5SBrad Bishop  */
74431d26a5SBrad Bishop std::string findCalloutPath(const std::string& instancePath);
75431d26a5SBrad Bishop 
76dd467396SPatrick Venture } // namespace sysfs
771e6324faSPatrick Venture 
7803476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
79