Remove i2c support

I2c is only used for direct SMBus commands to the PCH which are
not really needed as the hardware power button override is
always expected to work.

Removing this command allows us to remove i2c support and greatly
simplify the x86-power-control build.

Tested:
Confirmed that ipmi power control commands all still work correctly.

Change-Id: I5fe48c4577efcb52530c5af699e9cdc26084e261
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8186017..a9089d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,4 @@
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/i2c/inc)
-
-add_subdirectory(i2c)
 add_subdirectory(power-control-x86)
diff --git a/i2c/CMakeLists.txt b/i2c/CMakeLists.txt
deleted file mode 100644
index 273a42a..0000000
--- a/i2c/CMakeLists.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
-project(chassisi2c CXX)
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-
-set(LIBRARY_NAME "${PROJECT_NAME}")
-set(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
-set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib)
-set(PROJECT_CMAKE_FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
-
-set(INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
-set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake)
-set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR})
-
-include(GNUInstallDirs)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
-
-add_library(${PROJECT_NAME} SHARED src/i2c.cpp)
-
-set_target_properties(${PROJECT_NAME} PROPERTIES VERSION "0.1.0")
-set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION "0")
-
-install(TARGETS ${PROJECT_NAME}
-  EXPORT "${PROJECT_NAME}EXPORT"
-  RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
-  LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
-  ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT stlib
-  COMPONENT dev)
-
-install(FILES "inc/i2c.hpp"
-  DESTINATION "${INSTALL_INCLUDE_DIR}/" )
-
-install(EXPORT "${PROJECT_NAME}EXPORT"
-  DESTINATION "lib/cmake"
-  FILE ${PROJECT_NAME}Targets.cmake)
-
-configure_file(${CMAKE_SOURCE_DIR}/cmake/Config.cmake.in
-  "${PROJECT_CMAKE_FILES}/${PROJECT_NAME}-config.cmake" @ONLY)
-
-install(FILES
-  "${PROJECT_CMAKE_FILES}/${PROJECT_NAME}-config.cmake"
-  DESTINATION "lib/cmake" COMPONENT dev)
diff --git a/i2c/inc/i2c.hpp b/i2c/inc/i2c.hpp
deleted file mode 100644
index e851194..0000000
--- a/i2c/inc/i2c.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-// Copyright (c) 2018 Intel 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.
-*/
-
-#pragma once
-#include <cstdint>
-
-extern "C"
-{
-#include <i2c/smbus.h>
-#include <linux/i2c-dev.h>
-}
-
-int i2cSet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, uint8_t value);
diff --git a/i2c/src/i2c.cpp b/i2c/src/i2c.cpp
deleted file mode 100644
index dcef067..0000000
--- a/i2c/src/i2c.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-// Copyright (c) 2018 Intel 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 "i2c.hpp"
-
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-
-#include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-// TODO Add 16-bit I2C support in the furture
-int i2cSet(uint8_t bus, uint8_t slaveAddr, uint8_t regAddr, uint8_t value)
-{
-    unsigned long funcs = 0;
-    std::string devPath = "/dev/i2c-" + std::to_string(bus);
-
-    int fd = ::open(devPath.c_str(), O_RDWR);
-    if (fd < 0)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Error in open!",
-            phosphor::logging::entry("PATH=%s", devPath.c_str()),
-            phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
-        return -1;
-    }
-
-    if (::ioctl(fd, I2C_FUNCS, &funcs) < 0)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Error in I2C_FUNCS!",
-            phosphor::logging::entry("PATH=%s", devPath.c_str()),
-            phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
-
-        ::close(fd);
-        return -1;
-    }
-
-    if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
-    {
-
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "i2c bus does not support write!",
-            phosphor::logging::entry("PATH=%s", devPath.c_str()),
-            phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
-        ::close(fd);
-        return -1;
-    }
-
-    if (::ioctl(fd, I2C_SLAVE_FORCE, slaveAddr) < 0)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Error in I2C_SLAVE_FORCE!",
-            phosphor::logging::entry("PATH=%s", devPath.c_str()),
-            phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
-        ::close(fd);
-        return -1;
-    }
-
-    if (::i2c_smbus_write_byte_data(fd, regAddr, value) < 0)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Error in i2c write!",
-            phosphor::logging::entry("PATH=%s", devPath.c_str()),
-            phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr));
-        ::close(fd);
-        return -1;
-    }
-
-    // TODO For testing, will remove the below debug loging in the future
-    phosphor::logging::log<phosphor::logging::level::DEBUG>(
-        "i2cset successfully",
-        phosphor::logging::entry("PATH=%s", devPath.c_str()),
-        phosphor::logging::entry("SLAVEADDR=0x%x", slaveAddr),
-        phosphor::logging::entry("REGADDR=0x%x", regAddr),
-        phosphor::logging::entry("VALUE=0x%x", value));
-    ::close(fd);
-    return 0;
-}
diff --git a/power-control-x86/CMakeLists.txt b/power-control-x86/CMakeLists.txt
index 0216891..edcccad 100644
--- a/power-control-x86/CMakeLists.txt
+++ b/power-control-x86/CMakeLists.txt
@@ -26,9 +26,6 @@
 set(SRC_FILES src/power_control.cpp)
 
 add_executable(${PROJECT_NAME} ${SRC_FILES})
-target_link_libraries(${PROJECT_NAME} -lstdc++fs)
-target_link_libraries(${PROJECT_NAME} chassisi2c)
-target_link_libraries(${PROJECT_NAME} i2c)
 target_link_libraries(${PROJECT_NAME} gpiodcxx)
 target_link_libraries(${PROJECT_NAME} systemd)
 target_link_libraries(${PROJECT_NAME} sdbusplus)
diff --git a/power-control-x86/src/power_control.cpp b/power-control-x86/src/power_control.cpp
index 91c2e5c..92ebb9d 100644
--- a/power-control-x86/src/power_control.cpp
+++ b/power-control-x86/src/power_control.cpp
@@ -13,8 +13,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 */
-#include "i2c.hpp"
-
 #include <sys/sysinfo.h>
 #include <systemd/sd-journal.h>
 
@@ -1334,8 +1332,7 @@
         return;
     }
 
-    // If the force off timer expires, then the PCH power-button override
-    // failed, so attempt the Unconditional Powerdown SMBus command.
+    // If the force off timer expires, then the power-button override failed
     gpioAssertTimer.async_wait([](const boost::system::error_code ec) {
         if (ec)
         {
@@ -1352,17 +1349,7 @@
         }
 
         phosphor::logging::log<phosphor::logging::level::INFO>(
-            "PCH Power-button override failed. Issuing Unconditional Powerdown SMBus command.");
-        const static constexpr size_t pchDevBusAddress = 3;
-        const static constexpr size_t pchDevSlaveAddress = 0x44;
-        const static constexpr size_t pchCmdReg = 0;
-        const static constexpr size_t pchPowerDownCmd = 0x02;
-        if (i2cSet(pchDevBusAddress, pchDevSlaveAddress, pchCmdReg,
-                   pchPowerDownCmd) < 0)
-        {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Unconditional Powerdown command failed! Not sure what to do now.");
-        }
+            "Power-button override failed. Not sure what to do now.");
     });
 }