diff options
| author | Brandon Wyman <v2cib530@us.ibm.com> | 2017-05-24 14:24:00 -0500 |
|---|---|---|
| committer | Brandon Wyman <v2cib530@us.ibm.com> | 2017-06-06 11:21:59 -0500 |
| commit | 4eb9858d2025128ffb45c6f965d49cef58559c6a (patch) | |
| tree | 86901fe3500a19e7e04503036207fae742f2db36 /sysfs.cpp | |
| parent | ab10f164b71eb84e7b378be81523c5e955f8723e (diff) | |
| download | phosphor-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.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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; } |

