PSUSensor: Add smpro-hwmon sensor type

This commit adds smpro-hwmon driver as a new sensor type to the type
list of PSUSensor, as they have the same sysfs appearances and the same
way to read sensors.

But as there are 3 different drivers applied for the smpro MFD devices
of Ampere (smpro-hwmon is one). The hwmon path result from smpro-hwmon
will be different from other pmbus drivers that have device path points
directly to the i2c device path. The current implementation of PSUSensor
to get i2c bus, address only works for the later case, so this commit
uses regex to look for it instead and makes it work for wider cases.

Example:

`root@mtjade:/sys/class/hwmon# ls -la hwmon8 hwmon9
hwmon8 -> ../../devices/platform/xxx/1e78a0c0.i2c-bus/i2c-2/2-004e/\
smpro-hwmon.3.auto/hwmon/hwmon8

hwmon9 -> ../../devices/platform/xxx/1e78a1c0.i2c-bus/i2c-6/6-0058/\
hwmon/hwmon9

root@mtjade:/sys/class/hwmon# ls -la hwmon8/device hwmon9/device
hwmon8/device -> ../../2-004e/smpro-hwmon.3.auto
hwmon9/device -> ../../../6-0058

Tested on Ampere's Mt.Jade platform:
PSUSensor successfully maps Entity-Manager configurations with sysfs of
smpro-hwmon sensors, and reads values.

Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: I0ea0828e8726719969071a18bb27115c7cc71a9f
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index fb4e0d5..3795baa 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -61,6 +61,7 @@
 #include <vector>
 
 static constexpr bool debug = false;
+static std::regex i2cDevRegex(R"((\/i2c\-\d+\/\d+-[a-fA-F0-9]{4,4})(\/|$))");
 
 static const I2CDeviceTypeMap sensorTypes{
     {"ADC128D818", I2CDeviceType{"adc128d818", true}},
@@ -126,6 +127,7 @@
     {"RAA229126", I2CDeviceType{"raa229126", true}},
     {"RTQ6056", I2CDeviceType{"rtq6056", false}},
     {"SBRMI", I2CDeviceType{"sbrmi", true}},
+    {"smpro_hwmon", I2CDeviceType{"smpro", false}},
     {"TDA38640", I2CDeviceType{"tda38640", true}},
     {"TPS53679", I2CDeviceType{"tps53679", true}},
     {"TPS546D24", I2CDeviceType{"tps546d24", true}},
@@ -353,7 +355,18 @@
         std::string deviceName;
         if (directory.parent_path() == "/sys/class/hwmon")
         {
-            deviceName = fs::canonical(directory / "device").stem();
+            std::string devicePath = fs::canonical(directory / "device");
+            std::smatch match;
+            // Find /i2c-<bus>/<bus>-<address> match in device path
+            std::regex_search(devicePath, match, i2cDevRegex);
+            if (match.empty())
+            {
+                std::cerr << "Found bad device path " << devicePath << "\n";
+                continue;
+            }
+            // Extract <bus>-<address>
+            std::string matchStr = match[1];
+            deviceName = matchStr.substr(matchStr.find_last_of('/') + 1);
         }
         else
         {