summaryrefslogtreecommitdiffstats
path: root/i2c_occ.cpp
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2017-11-30 16:03:50 +0800
committerLei YU <mine260309@gmail.com>2017-12-12 17:09:02 +0800
commit41470e56e5dce5d9d138fd2a136f0010571bc613 (patch)
treee414217104ad36ec1000dfe8a6fb7e6dd107c438 /i2c_occ.cpp
parent482e31ff8e43e0fefbd697b1985795c4d35eec74 (diff)
downloadopenpower-occ-control-41470e56e5dce5d9d138fd2a136f0010571bc613.tar.gz
openpower-occ-control-41470e56e5dce5d9d138fd2a136f0010571bc613.zip
Powercap: add p8 support
P8 uses i2c-occ and powercap is not created. Add P8 support by creating powercap object with i2c device name. Fixes openbmc/openbmc#2688 Change-Id: Ia63070d63f4392cc4b084ab628cdbdcf4206c883 Signed-off-by: Lei YU <mine260309@gmail.com>
Diffstat (limited to 'i2c_occ.cpp')
-rw-r--r--i2c_occ.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/i2c_occ.cpp b/i2c_occ.cpp
index c364967..00e4187 100644
--- a/i2c_occ.cpp
+++ b/i2c_occ.cpp
@@ -12,6 +12,8 @@ namespace i2c_occ
namespace fs = std::experimental::filesystem;
+// The occ_master sysfs file
+constexpr auto OCC_MASTER_FILE = "occ_master";
// The device name's length, e.g. "p8-occ-hwmon"
constexpr auto DEVICE_NAME_LENGTH = 12;
// The occ name's length, e.g. "occ"
@@ -21,6 +23,13 @@ constexpr auto OCC_NAME_LENGTH = 3;
static_assert(sizeof(I2C_OCC_DEVICE_NAME) -1 == DEVICE_NAME_LENGTH);
static_assert(sizeof(OCC_NAME) -1 == OCC_NAME_LENGTH);
+static bool isMasterOcc(const fs::directory_entry& p)
+{
+ auto f = p / OCC_MASTER_FILE;
+ auto str = getFileContent(f);
+ return (!str.empty()) && (str[0] == '1');
+}
+
std::string getFileContent(const fs::path& f)
{
std::string ret(DEVICE_NAME_LENGTH, 0);
@@ -46,10 +55,22 @@ std::vector<std::string> getOccHwmonDevices(const char* path)
auto str = getFileContent(f);
if (str == I2C_OCC_DEVICE_NAME)
{
- result.emplace_back(p.path().filename());
+ if (isMasterOcc(p))
+ {
+ // Insert master occ at the beginning
+ result.emplace(result.begin(), p.path().filename());
+ }
+ else
+ {
+ result.emplace_back(p.path().filename());
+ }
}
}
- std::sort(result.begin(), result.end());
+ }
+ if (!result.empty())
+ {
+ // Sort the occ devices except for master
+ std::sort(result.begin() + 1, result.end());
}
return result;
}
OpenPOWER on IntegriCloud