Remove gpio-util

The gpio-util directory is not widely used in the community, and its
only known usage[1] has been removed, and so we agreed with the
maintainer to delete this directory.

[1] https://gerrit.openbmc.org/c/openbmc/openbmc/+/65642

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I61294b6a456e95532414687427b0c1cf36d58b4a
diff --git a/gpio-util/argument.cpp b/gpio-util/argument.cpp
deleted file mode 100644
index 913313c..0000000
--- a/gpio-util/argument.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "argument.hpp"
-
-#include <algorithm>
-#include <iostream>
-#include <iterator>
-
-namespace phosphor
-{
-namespace gpio
-{
-
-ArgumentParser::ArgumentParser(int argc, char** argv)
-{
-    int option = 0;
-    while (-1 != (option = getopt_long(argc, argv, optionStr, options, NULL)))
-    {
-        if ((option == '?') || (option == 'h'))
-        {
-            usage(argv);
-            exit(-1);
-        }
-
-        auto i = &options[0];
-        while ((i->val != option) && (i->val != 0))
-        {
-            ++i;
-        }
-
-        if (i->val)
-        {
-            arguments[i->name] = (i->has_arg ? optarg : trueString);
-        }
-    }
-}
-
-const std::string& ArgumentParser::operator[](const std::string& opt)
-{
-    auto i = arguments.find(opt);
-    if (i == arguments.end())
-    {
-        return emptyString;
-    }
-    else
-    {
-        return i->second;
-    }
-}
-
-void ArgumentParser::usage(char** argv)
-{
-    std::cerr << "Usage: " << argv[0] << " [options]\n";
-    std::cerr << "Options:\n";
-    std::cerr << "    --help            Print this menu.\n";
-    std::cerr << "    --gpio=<gpio>     The GPIO number.  Example: 1\n";
-    std::cerr << "    --path=<path>     The path to the GPIO device."
-                 "  Example: /dev/gpiochip0\n";
-    std::cerr << "    --delay=<delay>   The delay in ms in between a toggle."
-                 "  Example: 5\n";
-    std::cerr << "    --action=<action> The action to do.\n";
-    std::cerr << "                      Valid actions: low, high, low_high, "
-                 "high_low\n";
-    std::cerr << std::flush;
-}
-
-const option ArgumentParser::options[] = {
-    {"action", required_argument, NULL, 'a'},
-    {"gpio", required_argument, NULL, 'g'},
-    {"delay", required_argument, NULL, 'd'},
-    {"path", required_argument, NULL, 'p'},
-    {"help", no_argument, NULL, 'h'},
-    {0, 0, 0, 0},
-};
-
-const char* ArgumentParser::optionStr = "a:g:d:p:h?";
-
-const std::string ArgumentParser::trueString = "true";
-const std::string ArgumentParser::emptyString = "";
-
-} // namespace gpio
-} // namespace phosphor
diff --git a/gpio-util/argument.hpp b/gpio-util/argument.hpp
deleted file mode 100644
index 7917b8a..0000000
--- a/gpio-util/argument.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#pragma once
-
-#include <getopt.h>
-
-#include <map>
-#include <string>
-
-namespace phosphor
-{
-namespace gpio
-{
-/** @brief Class - Encapsulates parsing command line options and
- *                 populating arguments
- */
-class ArgumentParser
-{
-  public:
-    ArgumentParser() = delete;
-    ~ArgumentParser() = default;
-    ArgumentParser(const ArgumentParser&) = delete;
-    ArgumentParser& operator=(const ArgumentParser&) = delete;
-    ArgumentParser(ArgumentParser&&) = default;
-    ArgumentParser& operator=(ArgumentParser&&) = default;
-
-    /** @brief Constructs Argument object
-     *
-     *  @param argc - the main function's argc passed as is
-     *  @param argv - the main function's argv passed as is
-     *  @return Object constructed
-     */
-    ArgumentParser(int argc, char** argv);
-
-    /** @brief Given an option, returns its argument(optarg)
-     *
-     *  @param opt - command line option string
-     *
-     *  @return argument which is a standard optarg
-     */
-    const std::string& operator[](const std::string& opt);
-
-    /** @brief Displays usage
-     *
-     *  @param argv - the main function's argv passed as is
-     */
-    static void usage(char** argv);
-
-    /** @brief Set to 'true' when an option is passed */
-    static const std::string trueString;
-
-    /** @brief Set to '' when an option is not passed */
-    static const std::string emptyString;
-
-  private:
-    /** @brief Option to argument mapping */
-    std::map<const std::string, std::string> arguments;
-
-    /** @brief Array of struct options as needed by getopt_long */
-    static const option options[];
-
-    /** @brief optstring as needed by getopt_long */
-    static const char* optionStr;
-};
-
-} // namespace gpio
-} // namespace phosphor
diff --git a/gpio-util/gpio.cpp b/gpio-util/gpio.cpp
deleted file mode 100644
index 0e825b9..0000000
--- a/gpio-util/gpio.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "gpio.hpp"
-
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-#include <phosphor-logging/lg2.hpp>
-
-#include <cassert>
-#include <cstring>
-
-namespace phosphor
-{
-namespace gpio
-{
-
-void GPIO::set(Value value)
-{
-    assert(direction == Direction::output);
-
-    requestLine(value);
-
-    gpiohandle_data data{};
-    data.values[0] = static_cast<gpioValue_t>(value);
-
-    auto rc = ioctl(lineFD(), GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
-    if (rc == -1)
-    {
-        lg2::error("Failed SET_LINE_VALUES ioctl: {ERRNO}", "ERRNO", errno);
-        throw std::runtime_error("Failed SET_LINE_VALUES ioctl");
-    }
-}
-
-void GPIO::requestLine(Value defaultValue)
-{
-    // Only need to do this once
-    if (lineFD)
-    {
-        return;
-    }
-
-    FileDescriptor fd{open(device.c_str(), 0)};
-    if (fd() == -1)
-    {
-        lg2::error("Failed opening {DEVICE}: {ERRNO}", "DEVICE", device,
-                   "ERRNO", errno);
-        throw std::runtime_error("Failed opening GPIO device");
-    }
-
-    // Make an ioctl call to request the GPIO line, which will
-    // return the descriptor to use to access it.
-    gpiohandle_request request{};
-    strncpy(request.consumer_label, "phosphor-gpio-util",
-            sizeof(request.consumer_label));
-
-    request.flags = (direction == Direction::output) ? GPIOHANDLE_REQUEST_OUTPUT
-                                                     : GPIOHANDLE_REQUEST_INPUT;
-
-    request.lineoffsets[0] = gpio;
-    request.lines = 1;
-
-    if (direction == Direction::output)
-    {
-        request.default_values[0] = static_cast<gpioValue_t>(defaultValue);
-    }
-
-    auto rc = ioctl(fd(), GPIO_GET_LINEHANDLE_IOCTL, &request);
-    if (rc == -1)
-    {
-        lg2::error("Failed GET_LINEHANDLE ioctl {GPIO}: {ERRNO}", "GPIO", gpio,
-                   "ERRNO", errno);
-        throw std::runtime_error("Failed GET_LINEHANDLE ioctl");
-    }
-
-    lineFD.set(request.fd);
-}
-
-} // namespace gpio
-} // namespace phosphor
diff --git a/gpio-util/gpio.hpp b/gpio-util/gpio.hpp
deleted file mode 100644
index 46b6fba..0000000
--- a/gpio-util/gpio.hpp
+++ /dev/null
@@ -1,105 +0,0 @@
-#pragma once
-
-#include "file.hpp"
-
-#include <linux/gpio.h>
-
-#include <string>
-#include <type_traits>
-
-namespace phosphor
-{
-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;
-
-/**
- * Represents a GPIO.
- *
- * Operations are setting low or high.
- *
- * Read support may be added in the future.
- */
-class GPIO
-{
-  public:
-    /**
-     * If the GPIO is an input or output
-     */
-    enum class Direction
-    {
-        input,
-        output
-    };
-
-    /**
-     * The possible values - low or high
-     */
-    enum class Value
-    {
-        low,
-        high
-    };
-
-    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)
-    {}
-
-    /**
-     * Sets the GPIO value
-     *
-     * Requests the GPIO line if it hasn't been done already.
-     */
-    void set(Value value);
-
-  private:
-    /**
-     * Requests a GPIO line from the GPIO device
-     *
-     * @param[in] defaultValue - The default value, required for
-     *                           output GPIOs only.
-     */
-    void requestLine(Value defaultValue = Value::high);
-
-    /**
-     * 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
-     */
-    FileDescriptor lineFD;
-};
-
-} // namespace gpio
-} // namespace phosphor
diff --git a/gpio-util/main.cpp b/gpio-util/main.cpp
deleted file mode 100644
index d7cdc3d..0000000
--- a/gpio-util/main.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This program is a utility for accessing GPIOs.
- * Actions:
- *   low:  Set a GPIO low
- *   high: Set a GPIO high
- *   low_high: Set a GPIO low, delay if requested, set it high
- *   high_low: Set a GPIO high, delay if requested, set it low
- */
-
-#include "argument.hpp"
-#include "gpio.hpp"
-
-#include <algorithm>
-#include <chrono>
-#include <iostream>
-#include <map>
-#include <thread>
-
-using namespace phosphor::gpio;
-
-typedef void (*gpioFunction)(GPIO&, unsigned int);
-using gpioFunctionMap = std::map<std::string, gpioFunction>;
-
-/**
- * Sets a GPIO low
- *
- * @param[in] gpio - the GPIO object
- * @param[in] delayInMS - Unused in this function
- */
-void low(GPIO& gpio, unsigned int)
-{
-    gpio.set(GPIO::Value::low);
-}
-
-/**
- * Sets a GPIO high
- *
- * @param[in] gpio - the GPIO object
- * @param[in] delayInMS - Unused in this function
- */
-void high(GPIO& gpio, unsigned int)
-{
-    gpio.set(GPIO::Value::high);
-}
-
-/**
- * Sets a GPIO high, then delays, then sets it low
- *
- * @param[in] gpio - the GPIO object
- * @param[in] delayInMS - The delay in between the sets
- */
-void highLow(GPIO& gpio, unsigned int delayInMS)
-{
-    gpio.set(GPIO::Value::high);
-
-    std::chrono::milliseconds delay{delayInMS};
-    std::this_thread::sleep_for(delay);
-
-    gpio.set(GPIO::Value::low);
-}
-
-/**
- * Sets a GPIO low, then delays, then sets it high
- *
- * @param[in] gpio - the GPIO to write
- * @param[in] delayInMS - The delay in between the sets
- */
-void lowHigh(GPIO& gpio, unsigned int delayInMS)
-{
-    gpio.set(GPIO::Value::low);
-
-    std::chrono::milliseconds delay{delayInMS};
-    std::this_thread::sleep_for(delay);
-
-    gpio.set(GPIO::Value::high);
-}
-
-/**
- * The actions supported by this program
- */
-static const gpioFunctionMap functions{
-    {"low", low}, {"high", high}, {"low_high", lowHigh}, {"high_low", highLow}};
-
-/**
- * Prints usage and exits the program
- *
- * @param[in] err - the error message to print
- * @param[in] argv - argv from main()
- */
-void exitWithError(const char* err, char** argv)
-{
-    std::cerr << "ERROR: " << err << "\n";
-    ArgumentParser::usage(argv);
-    exit(EXIT_FAILURE);
-}
-
-/**
- * Returns the number value of the argument passed in.
- *
- * @param[in] name - the argument name
- * @param[in] parser - the argument parser
- * @param[in] argv - arv from main()
- */
-template <typename T>
-T getValueFromArg(const char* name, ArgumentParser& parser, char** argv)
-{
-    char* p = NULL;
-    auto val = strtol(parser[name].c_str(), &p, 10);
-
-    // strol sets p on error, also we don't allow negative values
-    if (*p || (val < 0))
-    {
-        using namespace std::string_literals;
-        std::string msg = "Invalid "s + name + " value passed in";
-        exitWithError(msg.c_str(), argv);
-    }
-    return static_cast<T>(val);
-}
-
-int main(int argc, char** argv)
-{
-    ArgumentParser args(argc, argv);
-
-    auto path = args["path"];
-    if (path == ArgumentParser::emptyString)
-    {
-        exitWithError("GPIO device path not specified", argv);
-    }
-
-    auto action = args["action"];
-    if (action == ArgumentParser::emptyString)
-    {
-        exitWithError("Action not specified", argv);
-    }
-
-    if (args["gpio"] == ArgumentParser::emptyString)
-    {
-        exitWithError("GPIO not specified", argv);
-    }
-
-    auto gpioNum = getValueFromArg<gpioNum_t>("gpio", args, argv);
-
-    // Not all actions require a delay, so not required
-    unsigned int delay = 0;
-    if (args["delay"] != ArgumentParser::emptyString)
-    {
-        delay = getValueFromArg<decltype(delay)>("delay", args, argv);
-    }
-
-    auto function = functions.find(action);
-    if (function == functions.end())
-    {
-        exitWithError("Invalid action value passed in", argv);
-    }
-
-    GPIO gpio{path, gpioNum, GPIO::Direction::output};
-
-    try
-    {
-        function->second(gpio, delay);
-    }
-    catch (const std::runtime_error& e)
-    {
-        std::cerr << e.what();
-        return -1;
-    }
-
-    return 0;
-}
diff --git a/gpio-util/meson.build b/gpio-util/meson.build
deleted file mode 100644
index d14cbc3..0000000
--- a/gpio-util/meson.build
+++ /dev/null
@@ -1,12 +0,0 @@
-executable(
-    'phosphor-gpio-util',
-    'argument.cpp',
-    'gpio.cpp',
-    'main.cpp',
-    dependencies: [
-        phosphor_logging,
-    ],
-    include_directories: '..',
-    implicit_include_directories: false,
-    install: true,
-)
diff --git a/meson.build b/meson.build
index ffb3442..0164b88 100644
--- a/meson.build
+++ b/meson.build
@@ -154,6 +154,5 @@
     install: true,
 )
 
-subdir('gpio-util')
 subdir('presence')
 subdir('test')