blob: 7e2eaff8c8d6826315717bdc21d1c7460c9c0b21 [file] [log] [blame]
Anthony Wilsond1c35322018-12-12 16:10:35 -06001#pragma once
2
Anthony Wilsonb8f3c232018-12-12 16:19:04 -06003#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 Wilsond1c35322018-12-12 16:10:35 -06008#include <string>
9
10namespace 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 */
21bool gpioSetValue(const std::string& gpioName, bool activeLow, bool asserted)
22{
Anthony Wilsonb8f3c232018-12-12 16:19:04 -060023 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 Wilsond1c35322018-12-12 16:10:35 -060057 return true;
58}
59
60} // namespace utility