diff --git a/fboss/lib/GpiodLine.cpp b/fboss/lib/GpiodLine.cpp index 7f014587f82e1..bcecbbbeb6c8a 100644 --- a/fboss/lib/GpiodLine.cpp +++ b/fboss/lib/GpiodLine.cpp @@ -74,4 +74,28 @@ void GpiodLine::setValue(int defaultVal, int targetVal) { } } +int GpiodLine::getLineValue() { + struct gpiod_line_request_config config = { + .consumer = name_.c_str(), + .request_type = GPIOD_LINE_REQUEST_DIRECTION_AS_IS, + .flags = 0}; + + if (gpiod_line_request(line_, &config, 0) != 0) { + throw GpiodLineError( + fmt::format( + "GpiodLineTrace: gpiod_line_request() failed for {}", name_)); + } + + int val = gpiod_line_get_value(line_); // Read the line value + + if (-1 == val) { + throw GpiodLineError( + fmt::format( + "GpiodLineTrace: gpiod_line_get_value() failed to get {} value, errno = {}", + name_, + folly::errnoStr(errno))); + } + + return val; +} } // namespace facebook::fboss diff --git a/fboss/lib/GpiodLine.h b/fboss/lib/GpiodLine.h index d34a84d236a36..fd82a766f03e5 100644 --- a/fboss/lib/GpiodLine.h +++ b/fboss/lib/GpiodLine.h @@ -26,6 +26,7 @@ class GpiodLine { ~GpiodLine(); int getValue(); void setValue(int defaultVal, int targetVal); + int getLineValue(); // Forbidden copy constructor and assignment operator GpiodLine(GpiodLine const&) = delete; diff --git a/fboss/platform/rma-showtech/Utils.cpp b/fboss/platform/rma-showtech/Utils.cpp index 90a0def0addc8..9fb9bef65feb5 100644 --- a/fboss/platform/rma-showtech/Utils.cpp +++ b/fboss/platform/rma-showtech/Utils.cpp @@ -464,8 +464,9 @@ void Utils::printGpio(const Gpio& gpio) { std::cout << fmt::format( "line {:>3}: {:<15} -> ", *line.lineIndex(), *line.name()); try { - std::cout << GpiodLine(chip, *line.lineIndex(), *line.name()).getValue() - << std::endl; + std::cout + << GpiodLine(chip, *line.lineIndex(), *line.name()).getLineValue() + << std::endl; } catch (const std::exception& e) { std::cout << fmt::format("Error: failed to read gpio line: {}", e.what()) << std::endl;