Add GPIO class

This class will be used for accessing GPIOs off of the
UCD90160 to check for PGOOD faults, and also later for
isolating GPU overtemps and PGOOD faults down to the specific
GPU that failed.

The FileDescriptor class is used by the GPIO class to manage
the lifetime of the GPIO file handles.

The class only supports reading a GPIO value.  At this point
there is no requirement for doing writes.

This class was copied from phosphor-gpio-monitor/gpio-util.

Change-Id: Iee276aed67e1cba549c3070c08238ab5f621c320
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/power-sequencer/gpio.hpp b/power-sequencer/gpio.hpp
new file mode 100644
index 0000000..2d3c6dd
--- /dev/null
+++ b/power-sequencer/gpio.hpp
@@ -0,0 +1,107 @@
+#pragma once
+
+#include <linux/gpio.h>
+#include "file.hpp"
+
+namespace witherspoon
+{
+namespace gpio
+{
+
+typedef std::remove_reference<decltype(
+     gpiohandle_request::lineoffsets[0])>::type gpioNum_t;
+
+typedef std::remove_reference<decltype(
+     gpiohandle_data::values[0])>::type gpioValue_t;
+
+/**
+ * If the GPIO is an input or output
+ */
+enum class Direction
+{
+    input,
+    output
+};
+
+/**
+ * The possible values - low or high
+ */
+enum class Value
+{
+    low,
+    high
+};
+
+/**
+ * Represents a GPIO.
+ *
+ * Currently supports reading a GPIO.
+ *
+ * Write support may be added in the future.
+ */
+class GPIO
+{
+    public:
+
+        GPIO() = delete;
+        GPIO(const GPIO&) = delete;
+        GPIO(GPIO&&) = default;
+        GPIO& operator=(const GPIO&) = delete;
+        GPIO& operator=(GPIO&&) = default;
+        ~GPIO() = default;
+
+        /**
+         * Constructor
+         *
+         * @param[in] device - the GPIO device file
+         * @param[in] gpio - the GPIO number
+         * @param[in] direction - the GPIO direction
+         */
+        GPIO(const std::string& device,
+             gpioNum_t gpio,
+             Direction direction) :
+            device(device),
+            gpio(gpio),
+            direction(direction)
+        {
+        }
+
+        /**
+         * Reads the GPIO value
+         *
+         * Requests the GPIO line if it hasn't been done already.
+         *
+         * @return Value - the GPIO value
+         */
+        Value read();
+
+    private:
+
+        /**
+         * Requests a GPIO line from the GPIO device
+         */
+        void requestLine();
+
+        /**
+         * The GPIO device name, like /dev/gpiochip0
+         */
+        const std::string device;
+
+        /**
+         * The GPIO number
+         */
+        const gpioNum_t gpio;
+
+        /**
+         * The GPIO direction
+         */
+        const Direction direction;
+
+        /**
+         * File descriptor for the GPIO line
+         */
+        power::util::FileDescriptor lineFD;
+};
+
+}
+}