Add device debug path to PMBus class

Some devices may also have files in
/sys/kernel/debug/<device driver name>.<instance>,
so adding a DeviceDebug path type to support that.

The device driver name and chip instance number are then
required to be passed in to the constructor.

Change-Id: I301d730a29ac7c2c39198e4eb7125aff70d727dc
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/pmbus.cpp b/pmbus.cpp
index 95e3bbb..a289401 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -61,7 +61,11 @@
             return basePath / "hwmon" / hwmonDir;
             break;
         case Type::Debug:
-            return debugPath / hwmonDir;
+            return debugPath / "pmbus" / hwmonDir;
+            break;
+        case Type::DeviceDebug:
+            auto dir = driverName + "." + std::to_string(instance);
+            return debugPath / dir;
             break;
     }
 }
diff --git a/pmbus.hpp b/pmbus.hpp
index 82e2ffc..9c7a0b5 100644
--- a/pmbus.hpp
+++ b/pmbus.hpp
@@ -13,14 +13,16 @@
 
 /**
  * If the access should be done in the base
- * device directory, the hwmon directory, or
- * the debug director.
+ * device directory, the hwmon directory, the
+ * pmbus debug directory, or the device debug
+ * directory.
  */
 enum class Type
 {
     Base,
     Hwmon,
-    Debug
+    Debug,
+    DeviceDebug
 };
 
 /**
@@ -56,12 +58,32 @@
         }
 
         /**
+         * Constructor
+         *
+         * This version is required when DeviceDebug
+         * access will be used.
+         *
+         * @param[in] path - path to the sysfs directory
+         * @param[in] driverName - the device driver name
+         * @param[in] instance - chip instance number
+         */
+        PMBus(const std::string& path,
+              const std::string& driverName,
+              size_t instance) :
+            basePath(path),
+            driverName(driverName),
+            instance(instance)
+        {
+            findHwmonDir();
+        }
+
+        /**
          * Reads a file in sysfs that represents a single bit,
          * therefore doing a PMBus read.
          *
          * @param[in] name - path concatenated to
          *                   basePath to read
-         * @param[in] type - one of Base, Hwmon, or Debug (path type)
+         * @param[in] type - Path type
          *
          * @return bool - false if result was 0, else true
          */
@@ -75,7 +97,7 @@
          * @param[in] name - path concatenated to
          *                   basePath to read
          * @param[in] page - page number
-         * @param[in] type - one of Base, Hwmon, or Debug (path type)
+         * @param[in] type - Path type
          *
          * @return bool - false if result was 0, else true
          */
@@ -86,7 +108,7 @@
          * Read byte(s) from file in sysfs.
          *
          * @param[in] name   - path concatenated to basePath to read
-         * @param[in] type   - one of Base, Hwmon, or Debug (path type)
+         * @param[in] type   - Path type
          *
          * @return uint64_t - Up to 8 bytes of data read from file.
          */
@@ -99,7 +121,7 @@
          * @param[in] name - path concatenated to
          *                   basePath to write
          * @param[in] value - the value to write
-         * @param[in] type - one of Base, Hwmon, or Debug (path type)
+         * @param[in] type - Path type
          */
         void write(const std::string& name, int value, Type type);
 
@@ -136,9 +158,9 @@
         /**
          * Returns the path to use for the passed in type.
          *
-         * @param[in] type - one of Base, Hwmon, or Debug (path type)
+         * @param[in] type - Path type
          *
-         * @return fs::path - the full path to Base, Hwmon, or Debug path
+         * @return fs::path - the full path
          */
          fs::path getPath(Type type);
 
@@ -155,9 +177,25 @@
         fs::path hwmonDir;
 
         /**
+         * The device driver name.  Used for finding the device
+         * debug directory.  Not required if that directory
+         * isn't used.
+         */
+        std::string driverName;
+
+        /**
+         * The device instance number.
+         *
+         * Used in conjuction with the driver name for finding
+         * the debug directory.  Not required if that directory
+         * isn't used.
+         */
+        size_t instance = 0;
+
+        /**
          * The pmbus debug path with status files
          */
-        const fs::path debugPath = "/sys/kernel/debug/pmbus/";
+        const fs::path debugPath = "/sys/kernel/debug/";
 
 };