From patchwork Sat Sep 28 17:22:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 278752 X-Patchwork-Delegate: sbabic@denx.de 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 3F01B2C00B3 for ; Sun, 29 Sep 2013 03:23:28 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E6CD84A0AA; Sat, 28 Sep 2013 19:23:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 pPQJBYbjdw-w; Sat, 28 Sep 2013 19:23:23 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4264F4A09F; Sat, 28 Sep 2013 19:23:18 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 70B2A4A018 for ; Sat, 28 Sep 2013 19:23:11 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 7Bajmd7r1CPl for ; Sat, 28 Sep 2013 19:23:05 +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-qc0-f172.google.com (mail-qc0-f172.google.com [209.85.216.172]) by theia.denx.de (Postfix) with ESMTPS id 4815E4A09F for ; Sat, 28 Sep 2013 19:22:59 +0200 (CEST) Received: by mail-qc0-f172.google.com with SMTP id l13so2597871qcy.31 for ; Sat, 28 Sep 2013 10:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=7OqrAQgzW3lHvdaf4TNwG/lS3tlvlVqfN5nmxXoJ5fU=; b=kULqi/3LEAXVx1kSi8PbFHtGbVZJHJHD5yXYkFLyumY9RRyCEBCRkRgDK353nffsuq 3SfvGKra7WoI8LcT+OQZ0yJdEQ4dgBBK6DogKv1T+VAhGLwNMDZRLVySBSBWojB+sTkD myiAsQ0dp38/S2qpq/rQtjpPhht1MdkShJB+akh6spBgUIjOeDWy0CGCJjCt1/Jqjv7o V81KrCw/pAd1JE+jyyQupGAPnALICHcKe7d37T7ZB5Zc3X3XxfFe4rWfZOkANOFE6QDe PN85wJgdG8CWVcQBmihftfYZy3ErYz7OAvE0asB+dCJYsjPoTm2afGSB6UpI59mw1On5 HSqg== X-Received: by 10.229.116.197 with SMTP id n5mr17396172qcq.22.1380388977587; Sat, 28 Sep 2013 10:22:57 -0700 (PDT) Received: from localhost.localdomain ([186.207.93.139]) by mx.google.com with ESMTPSA id y9sm31607915qaj.9.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 28 Sep 2013 10:22:57 -0700 (PDT) From: Fabio Estevam To: sbabic@denx.de Date: Sat, 28 Sep 2013 14:22:44 -0300 Message-Id: <1380388964-26009-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.8.1.2 Cc: Fabio Estevam , u-boot@lists.denx.de, eric@eukrea.com, otavio@ossystems.com.br Subject: [U-Boot] [PATCH] gpio: mxc_gpio: Fix gpio_get_value() when the GPIO is an output X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Fabio Estevam When the GPIO is configured as an output, we should return the value from the DR register. This implements the same fix as in the following kernel commit from FSL BSP: http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/commit/arch/arm/plat-mxc/gpio.c?h=imx_3.0.35_4.1.0&id=d6f32393eaf455ce3c32d4e9bafd34d9091eaf45 Signed-off-by: Fabio Estevam Acked-by: Otavio Salvador --- Otavio, I don't have i.mx hardware access at the moment to try it, but this should fix your LED problem. drivers/gpio/mxc_gpio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index 6a572d5..debbecb 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -93,7 +93,7 @@ int gpio_get_value(unsigned gpio) { unsigned int port = GPIO_TO_PORT(gpio); struct gpio_regs *regs; - u32 val; + u32 direction; if (port >= ARRAY_SIZE(gpio_ports)) return -1; @@ -102,9 +102,12 @@ int gpio_get_value(unsigned gpio) regs = (struct gpio_regs *)gpio_ports[port]; - val = (readl(®s->gpio_psr) >> gpio) & 0x01; + direction = readl(®s->gpio_dir); - return val; + if ((direction >> gpio) & 1) + return (readl(®s->gpio_dr) >> gpio) & 1; /* output mode */ + else + return (readl(®s->gpio_psr) >> gpio) & 1; /* input mode */ } int gpio_request(unsigned gpio, const char *label)