Support host selector using cpld definitions

Description:
- Support host selector using cpld definitions

Design:
- Because the current structure only supports config defined by GPIO
  (Yosemite V2), but there are also have the system (Yosemite V3.5)
  gets the host-selector's selection from CPLD.

- So this commit is to extend the current configuration to use CPLD
  definitions. Also, support adding event io from the register file
  which was exported from the CLD driver.

- For example with config json below:
{
   "cpld_definitions": [
        {
            "name": "HOST_SELECTOR",
            "i2c_address": 15,
            "i2c_bus": 12,
            "register_name": "uart-selection-debug-card",
            "max_position": 4
        }
   ]
}

Dependency:
- CLD driver is required (link: https://lore.kernel.org/lkml/20230117094425.19004-1-Delphine_CC_Chiu@Wiwynn.com/)

Test Case:
- When ocp debug card uart button is pressed the position property on
  dbus is correct.

Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Change-Id: I6746afa6d905bd3c681e2921c643b3cd4cb9944c
diff --git a/src/cpld.cpp b/src/cpld.cpp
new file mode 100644
index 0000000..af1bbd9
--- /dev/null
+++ b/src/cpld.cpp
@@ -0,0 +1,38 @@
+
+#include "config.h"
+
+#include "button_config.hpp"
+
+#include <error.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <phosphor-logging/lg2.hpp>
+
+const std::string cpldDev = "/sys/bus/i2c/devices/";
+
+std::string getCpldDevPath(const CpldInfo& info)
+{
+    std::stringstream devPath;
+    devPath << cpldDev << info.i2cBus << "-" << std::hex << std::setw(4)
+            << std::setfill('0') << info.i2cAddress << "/" << info.registerName;
+    return devPath.str();
+}
+
+int configCpld(ButtonConfig& buttonIFConfig)
+{
+    std::string devPath = getCpldDevPath(buttonIFConfig.cpld);
+
+    auto fd = ::open(devPath.c_str(), O_RDONLY | O_NONBLOCK);
+
+    if (fd < 0)
+    {
+        lg2::error("Open {PATH} error: {ERROR}", "PATH", devPath, "ERROR",
+                   errno);
+        return -1;
+    }
+
+    buttonIFConfig.cpld.cpldMappedFd = fd;
+    buttonIFConfig.fds.push_back(fd);
+    return 0;
+}