Anthony Wilson | d1c3532 | 2018-12-12 16:10:35 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Anthony Wilson | b8f3c23 | 2018-12-12 16:19:04 -0600 | [diff] [blame] | 3 | #include <gpioplus/chip.hpp> |
| 4 | #include <gpioplus/handle.hpp> |
| 5 | #include <gpioplus/utility/aspeed.hpp> |
| 6 | #include <phosphor-logging/log.hpp> |
| 7 | #include <exception> |
Anthony Wilson | d1c3532 | 2018-12-12 16:10:35 -0600 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | namespace utility |
| 11 | { |
| 12 | |
| 13 | /** @brief Set the value of a specified gpio |
| 14 | * |
| 15 | * @param[in] gpioName - GPIO to set |
| 16 | * @param[in] activeLow - is pin active at low voltage |
| 17 | * @param[in] asserted - is pin in active state |
| 18 | * |
| 19 | * @return bool - success of setting the GPIO |
| 20 | */ |
| 21 | bool gpioSetValue(const std::string& gpioName, bool activeLow, bool asserted) |
| 22 | { |
Anthony Wilson | b8f3c23 | 2018-12-12 16:19:04 -0600 | [diff] [blame] | 23 | uint32_t gpioOffset; |
| 24 | try |
| 25 | { |
| 26 | gpioOffset = gpioplus::utility::aspeed::nameToOffset(gpioName); |
| 27 | } |
| 28 | catch(const std::logic_error& e) |
| 29 | { |
| 30 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 31 | "Error in gpioplus - nameToOffset", |
| 32 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | try |
| 37 | { |
| 38 | //TODO: openbmc/phosphor-power-control#1 - Handle cases where gpiochip |
| 39 | // could be non-zero. |
| 40 | gpioplus::Chip chip(0); |
| 41 | gpioplus::HandleFlags flags(chip.getLineInfo(gpioOffset).flags); |
| 42 | flags.output = true; |
| 43 | gpioplus::Handle handle(chip, {{gpioOffset, 0}}, flags, |
| 44 | "chassiskill"); |
| 45 | |
| 46 | bool value = (asserted ^ activeLow); |
| 47 | handle.setValues({value}); |
| 48 | } |
| 49 | catch (const std::exception& e) |
| 50 | { |
| 51 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 52 | "Error in gpioplus", |
| 53 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 54 | return false; |
| 55 | } |
| 56 | |
Anthony Wilson | d1c3532 | 2018-12-12 16:10:35 -0600 | [diff] [blame] | 57 | return true; |
| 58 | } |
| 59 | |
| 60 | } // namespace utility |