Switch to setting Device active
With the latest Linux driver, the hwmon device is always bound, so
instead use the occ_active attribute to tell the driver when the
OCC has gone active.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Change-Id: Ia89b517d90a1947f87bb5937bf0d4c1b50191201
diff --git a/occ_device.cpp b/occ_device.cpp
index 5cadf14..a660fa2 100644
--- a/occ_device.cpp
+++ b/occ_device.cpp
@@ -15,8 +15,21 @@
using namespace phosphor::logging;
-fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
-fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";
+void Device::setActive(bool active)
+{
+ std::string data = active ? "1" : "0";
+ auto activeFile = devPath / "occ_active";
+ try
+ {
+ write(activeFile, data);
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>(fmt::format("Failed to set {} active: {}",
+ devPath.c_str(), e.what())
+ .c_str());
+ }
+}
std::string Device::getPathBack(const fs::path& path)
{
@@ -38,20 +51,30 @@
}
}
+bool Device::active() const
+{
+ return readBinary("occ_active");
+}
+
bool Device::master() const
{
- int master;
- auto masterFile = devPath / "occ_master";
- std::ifstream file(masterFile, std::ios::in);
+ return readBinary("occ_master");
+}
+
+bool Device::readBinary(const std::string& fileName) const
+{
+ int v;
+ auto filePath = devPath / fileName;
+ std::ifstream file(filePath, std::ios::in);
if (!file)
{
return false;
}
- file >> master;
+ file >> v;
file.close();
- return (master != 0);
+ return v == 1;
}
void Device::errorCallback(bool error)