Add handling of /sys/kernel/debug/pmbus path
The STATUS_WORD, STATUS_INPUT, and other status command data will reside
under the /sys/kernel/debug/pmbus path. Update PMBus class to handle
that path type.
Change-Id: I07c91b8c35cf1b6478068417eadd7820620fae42
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/pmbus.cpp b/pmbus.cpp
index bd9e697..b525bd9 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -48,6 +48,24 @@
return name;
}
+fs::path PMBus::getPath(Type type)
+{
+ switch (type)
+ {
+ default:
+ /* fall through */
+ case Type::Base:
+ return basePath;
+ break;
+ case Type::Hwmon:
+ return basePath / "hwmon" / hwmonDir;
+ break;
+ case Type::Debug:
+ return debugPath / hwmonDir;
+ break;
+ }
+}
+
bool PMBus::readBitInPage(const std::string& name,
size_t page,
Type type)
@@ -60,12 +78,7 @@
{
unsigned long int value = 0;
std::ifstream file;
- fs::path path{basePath};
-
- if (type == Type::Hwmon)
- {
- path /= hwmonRelPath;
- }
+ fs::path path = getPath(type);
path /= name;
@@ -113,12 +126,7 @@
void PMBus::write(const std::string& name, int value, Type type)
{
std::ofstream file;
- fs::path path{basePath};
-
- if (type == Type::Hwmon)
- {
- path /= hwmonRelPath;
- }
+ fs::path path = getPath(type);
path /= name;
@@ -146,7 +154,7 @@
}
}
-void PMBus::findHwmonRelativePath()
+void PMBus::findHwmonDir()
{
fs::path path{basePath};
path /= "hwmon";
@@ -158,15 +166,14 @@
std::string::npos) &&
(fs::is_directory(f.path())))
{
- hwmonRelPath = "hwmon";
- hwmonRelPath /= f.path().filename();
+ hwmonDir = f.path().filename();
break;
}
}
//Don't really want to crash here, just log it
//and let accesses fail later
- if (hwmonRelPath.empty())
+ if (hwmonDir.empty())
{
log<level::ERR>("Unable to find hwmon directory "
"in device base path",
diff --git a/pmbus.hpp b/pmbus.hpp
index d384279..4946829 100644
--- a/pmbus.hpp
+++ b/pmbus.hpp
@@ -9,14 +9,18 @@
namespace pmbus
{
+namespace fs = std::experimental::filesystem;
+
/**
* If the access should be done in the base
- * device directory or the hwmon directory.
+ * device directory, the hwmon directory, or
+ * the debug director.
*/
enum class Type
{
Base,
- Hwmon
+ Hwmon,
+ Debug
};
/**
@@ -48,7 +52,7 @@
PMBus(const std::string& path) :
basePath(path)
{
- findHwmonRelativePath();
+ findHwmonDir();
}
/**
@@ -57,7 +61,7 @@
*
* @param[in] name - path concatenated to
* basePath to read
- * @param[in] type - either Base or Hwmon
+ * @param[in] type - one of Base, Hwmon, or Debug
*
* @return bool - false if result was 0, else true
*/
@@ -71,7 +75,7 @@
* @param[in] name - path concatenated to
* basePath to read
* @param[in] page - page number
- * @param[in] type - either Base or Hwmon
+ * @param[in] type - one of Base, Hwmon, or Debug
*
* @return bool - false if result was 0, else true
*/
@@ -86,7 +90,7 @@
* @param[in] name - path concatenated to
* basePath to write
* @param[in] value - the value to write
- * @param[in] type - either Base or Hwmon
+ * @param[in] type - one of Base, Hwmon, or Debug
*/
void write(const std::string& name, int value, Type type);
@@ -118,19 +122,33 @@
* Finds the path relative to basePath to the hwmon directory
* for the device and stores it in hwmonRelPath.
*/
- void findHwmonRelativePath();
+ void findHwmonDir();
+
+ /**
+ * Returns the path to use for the passed in type.
+ *
+ * @param[in] type - one of Base, Hwmon, or Debug
+ *
+ * @return fs::path - the full path to Base, Hwmon, or Debug path
+ */
+ fs::path getPath(Type type);
private:
/**
* The sysfs device path
*/
- std::experimental::filesystem::path basePath;
+ fs::path basePath;
/**
- * The relative (to basePath) path to the hwmon directory
+ * The directory name under the basePath hwmon directory
*/
- std::experimental::filesystem::path hwmonRelPath;
+ fs::path hwmonDir;
+
+ /**
+ * The pmbus debug path with status files
+ */
+ const fs::path debugPath = "/sys/kernel/debug/pmbus/";
};