From patchwork Tue Apr 27 15:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmad Fatoum X-Patchwork-Id: 428072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BB0BC433ED for ; Tue, 27 Apr 2021 15:42:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA6B7613C9 for ; Tue, 27 Apr 2021 15:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbhD0PnV (ORCPT ); Tue, 27 Apr 2021 11:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236398AbhD0PnP (ORCPT ); Tue, 27 Apr 2021 11:43:15 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E01C061574 for ; Tue, 27 Apr 2021 08:42:29 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbPr1-0004O9-8w; Tue, 27 Apr 2021 17:42:27 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lbPr0-0007uh-Lt; Tue, 27 Apr 2021 17:42:26 +0200 From: Ahmad Fatoum To: Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org Cc: kernel@pengutronix.de, Ahmad Fatoum Subject: [libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back Date: Tue, 27 Apr 2021 17:42:24 +0200 Message-Id: <20210427154224.30372-1-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: afa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Both legacy sysfs and new character device API support querying line state of a GPIO configured as output. But while sysfs /value can be read for these output GPIOs, gpioget unconditionally muxes the line as input. To ease migration to the new user API, add a new --dir-as-is parameter that doesn't force the line to input. This is especially useful for GPIO controllers that maintain their last configured output state. Signed-off-by: Ahmad Fatoum --- -n is chosen for the short option because it's the customary short option for dry runs, which sounds similar to what a gpio get without line state configuration is doing. --- tools/gpioget.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/gpioget.c b/tools/gpioget.c index ceeec566683a..bfbf5ea748be 100644 --- a/tools/gpioget.c +++ b/tools/gpioget.c @@ -13,11 +13,12 @@ static const struct option longopts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "active-low", no_argument, NULL, 'l' }, + { "dir-as-is", no_argument, NULL, 'n' }, { "bias", required_argument, NULL, 'B' }, { GETOPT_NULL_LONGOPT }, }; -static const char *const shortopts = "+hvlB:"; +static const char *const shortopts = "+hvlnB:"; static void print_help(void) { @@ -30,6 +31,7 @@ static void print_help(void) printf(" -h, --help:\t\tdisplay this message and exit\n"); printf(" -v, --version:\tdisplay the version and exit\n"); printf(" -l, --active-low:\tset the line active state to low\n"); + printf(" -n, --dir-as-is:\tdon't force-reconfigure line direction\n"); printf(" -B, --bias=[as-is|disable|pull-down|pull-up] (defaults to 'as-is'):\n"); printf(" set the line bias\n"); printf("\n"); @@ -40,6 +42,7 @@ int main(int argc, char **argv) { struct gpiod_line_request_config config; int *values, optc, opti, rv, flags = 0; + int request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT; unsigned int *offsets, i, num_lines; struct gpiod_line_bulk *lines; struct gpiod_chip *chip; @@ -60,6 +63,9 @@ int main(int argc, char **argv) case 'l': flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW; break; + case 'n': + request_type = GPIOD_LINE_REQUEST_DIRECTION_AS_IS; + break; case 'B': flags |= bias_flags(optarg); break; @@ -104,7 +110,7 @@ int main(int argc, char **argv) memset(&config, 0, sizeof(config)); config.consumer = "gpioget"; - config.request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT; + config.request_type = request_type; config.flags = flags; rv = gpiod_line_request_bulk(lines, &config, NULL);