From patchwork Tue Sep 1 00:55:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 512664 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 783861401E7 for ; Tue, 1 Sep 2015 10:56:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=IFJCENNy; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 88A1D4B766; Tue, 1 Sep 2015 02:56:16 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0HRpLKp6p9uZ; Tue, 1 Sep 2015 02:56:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B21914B752; Tue, 1 Sep 2015 02:56:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6564A4B77C for ; Tue, 1 Sep 2015 02:56:00 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VGhCupUsjQyS for ; Tue, 1 Sep 2015 02:56:00 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f173.google.com (mail-io0-f173.google.com [209.85.223.173]) by theia.denx.de (Postfix) with ESMTPS id 2C0F24B758 for ; Tue, 1 Sep 2015 02:55:54 +0200 (CEST) Received: by iod35 with SMTP id 35so48320174iod.3 for ; Mon, 31 Aug 2015 17:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nFaQPdz3GmbupJDETiayZYEWJBfxlreMb+HhH5pMMpA=; b=IFJCENNyuAjvuZi8xR48nYfXp4bR9zbC2etONmwf3RXcr/wGEYRKtM6NBzAe16CIFY nDBOCzE72CmR7H78X+2/+bDhAb8Sx95JpLvqTrhE+h7f/TpS0aVqNJHAL6eAa0IWc7v2 giOI9pSPBSfRwaAPChnxamE3EJ8Z0lTVNvAKVIa26t3taXAwginwnQKhTLQxcZcX6DLJ dW4LHZtBQf9RbIYCWT0u9IGvClLvVQ9uelmEQJAFtq6bTKAVtlrPx5AarlagQepgbPRU 5ikElAhsRBkRHskqvfLqbduYZSPI486Svw1BV2MfkQYpa8oaatNCYiWFwr/D8oxboeAR l0Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nFaQPdz3GmbupJDETiayZYEWJBfxlreMb+HhH5pMMpA=; b=BtJhaUfTy0kbNjoMdBq/oIEjgeN42jXkANW28dcEfyWJV29cPZGM1tkVdrDt+FwoA5 PjCrXt+pVTIhalBadqxBq596RgLmjem7HvBjbC4LCR1fhteRx+Rr1PHwcgRNvqru5frV EsUGVutqGH1wMNWUP47W7Vbbc7gclYveubOWYAPKwTM2QHzzQg4Eq0B9grjIr9j4UpJL SQe6yHHBWWj4mt2Co+yHQQdsUh1kP6LGbleI6VYdBnCw24CtkJh3f6x+ciyVhCJ/LqiT A1/JRJoVur6ORnE1leGgHkjFMGEWt/4XxqZt0HHCWekhqNYBE3FRkqe5T5cf36BuhH0Y +36Q== X-Gm-Message-State: ALoCoQnyT1dRGs/ai5lkOquxhZqTnPTsf9ntoAdW0gk5jqgbw3xsm5RbT5o3kmT7Twx52gVatFF5 X-Received: by 10.107.40.200 with SMTP id o191mr26097069ioo.83.1441068953373; Mon, 31 Aug 2015 17:55:53 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:1100:7959:8963:ef6b:cc8]) by smtp.gmail.com with ESMTPSA id u4sm128925igz.8.2015.08.31.17.55.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Aug 2015 17:55:52 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 323BF22113F; Mon, 31 Aug 2015 18:55:52 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 31 Aug 2015 18:55:36 -0600 Message-Id: <1441068938-16305-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.457.gab17608 In-Reply-To: <1441068938-16305-1-git-send-email-sjg@chromium.org> References: <1441068938-16305-1-git-send-email-sjg@chromium.org> Cc: Jeroen Hofstee , Andrew Bradford , Tom Rini Subject: [U-Boot] [PATCH v3 2/4] gpio: Report errors when GPIOs cannot be read X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some controllers do not allow the output value to be read. Detect this and report the error in that case. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None common/cmd_gpio.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c index 65d6df4..7cd1ba1 100644 --- a/common/cmd_gpio.c +++ b/common/cmd_gpio.c @@ -119,7 +119,7 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned int gpio; enum gpio_cmd sub_cmd; - ulong value; + int value; const char *str_cmd, *str_gpio = NULL; int ret; #ifdef CONFIG_DM_GPIO @@ -195,15 +195,35 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) value = gpio_get_value(gpio); } else { switch (sub_cmd) { - case GPIO_SET: value = 1; break; - case GPIO_CLEAR: value = 0; break; - case GPIO_TOGGLE: value = !gpio_get_value(gpio); break; - default: goto show_usage; + case GPIO_SET: + value = 1; + break; + case GPIO_CLEAR: + value = 0; + break; + case GPIO_TOGGLE: + value = gpio_get_value(gpio); + if (!IS_ERR_VALUE(value)) + value = !value; + break; + default: + goto show_usage; } gpio_direction_output(gpio, value); } - printf("gpio: pin %s (gpio %i) value is %lu\n", - str_gpio, gpio, value); + printf("gpio: pin %s (gpio %i) value is ", str_gpio, gpio); + if (IS_ERR_VALUE(value)) + printf("unknown (ret=%d)\n", value); + else + printf("%d\n", value); + if (sub_cmd != GPIO_INPUT && !IS_ERR_VALUE(value)) { + int nval = gpio_get_value(gpio); + + if (IS_ERR_VALUE(nval)) + printf(" Warning: no access to GPIO output value\n"); + else if (nval != value) + printf(" Warning: value of pin is still %d\n", nval); + } if (ret != -EBUSY) gpio_free(gpio);