summaryrefslogtreecommitdiffstats
path: root/sysfs.cpp
diff options
context:
space:
mode:
authorBrandon Wyman <v2cib530@us.ibm.com>2017-05-24 14:24:00 -0500
committerBrandon Wyman <v2cib530@us.ibm.com>2017-06-06 11:21:59 -0500
commit4eb9858d2025128ffb45c6f965d49cef58559c6a (patch)
tree86901fe3500a19e7e04503036207fae742f2db36 /sysfs.cpp
parentab10f164b71eb84e7b378be81523c5e955f8723e (diff)
downloadphosphor-hwmon-4eb9858d2025128ffb45c6f965d49cef58559c6a.tar.gz
phosphor-hwmon-4eb9858d2025128ffb45c6f965d49cef58559c6a.zip
Update algorithm to find iio hwmon instance
If the hwmon instance cannot be found via the path symlink, try to find the instance via the phandle value in io-channels. Change-Id: I20966ec465baca41c1122afe714c1260926eade9 Signed-off-by: Brandon Wyman <v2cib530@us.ibm.com>
Diffstat (limited to 'sysfs.cpp')
-rw-r--r--sysfs.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/sysfs.cpp b/sysfs.cpp
index e6b17fd..ad99bf7 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -22,6 +22,7 @@
#include <xyz/openbmc_project/Sensor/Device/error.hpp>
#include "sysfs.hpp"
#include "util.hpp"
+#include <fstream>
using namespace phosphor::logging;
@@ -33,6 +34,8 @@ std::string findHwmon(const std::string& ofNode)
fs::path fullOfPath{ofRoot};
fullOfPath /= ofNode;
+ fs::path fullOfPathPhandle{fullOfPath};
+ fullOfPathPhandle /= "phandle";
for (const auto& hwmonInst : fs::directory_iterator(hwmonRoot))
{
@@ -41,6 +44,36 @@ std::string findHwmon(const std::string& ofNode)
if (fs::canonical(path) != fullOfPath)
{
+ // Try to find HWMON instance via phandle values.
+ // Used for IIO device drivers.
+ path /= "io-channels";
+ if (fs::exists(path) && fs::exists(fullOfPathPhandle))
+ {
+ std::ifstream ioChannelsFile(path);
+ std::ifstream pHandleFile(fullOfPathPhandle);
+
+ uint32_t ioChannelsValue;
+ uint32_t pHandleValue;
+
+ try
+ {
+ ioChannelsFile.read(reinterpret_cast<char*>(&ioChannelsValue),
+ sizeof(ioChannelsValue));
+ pHandleFile.read(reinterpret_cast<char*>(&pHandleValue),
+ sizeof(pHandleValue));
+
+ if (ioChannelsValue == pHandleValue)
+ {
+ return hwmonInst.path();
+ }
+ }
+ catch (const std::exception& e)
+ {
+ log<level::INFO>(e.what());
+ }
+
+
+ }
continue;
}
OpenPOWER on IntegriCloud