From patchwork Fri Oct 26 02:31:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 194341 X-Patchwork-Delegate: vanbaren@cideas.com 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 E75F62C0079 for ; Fri, 26 Oct 2012 13:34:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 523664A589; Fri, 26 Oct 2012 04:33:22 +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 hbTC6AwhUuj9; Fri, 26 Oct 2012 04:33:22 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D0F084A4C5; Fri, 26 Oct 2012 04:32:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B63574A47D for ; Fri, 26 Oct 2012 04:31:39 +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 2c+391WNzISQ for ; Fri, 26 Oct 2012 04:31:37 +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-fa0-f74.google.com (mail-fa0-f74.google.com [209.85.161.74]) by theia.denx.de (Postfix) with ESMTPS id 86E914A474 for ; Fri, 26 Oct 2012 04:31:25 +0200 (CEST) Received: by mail-fa0-f74.google.com with SMTP id t1so144705fae.3 for ; Thu, 25 Oct 2012 19:31:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=/SKYVPgyw+QTj2gS76kuB1kTFayLGHBR40zHbFIyo9Q=; b=WAsDUJhT6vzMHWOTTqqOHuHdsitrh/7fyqodcSDgCWZGt50AhQrmc7FpYS1NJiCRVU Jh5nqxVLbFzFX3YwW3DSQj3GUqhBzokBnIbJCfSi9/KG6Ll4qwzmsr/zoT2mBJ0LQ9Mr 9k8+xJkGnIgWeS8xQwoQ9bNG9j7u2hvf43oR+crTUkquZpdDB3mBP3VhrwLw/0EMOOQ5 qq4Abcq+ZgU7pIBNMDI+/qqRdj0Qgut/F+m951LFn7AZwl5EenOBoyeOD0mq//+EkGZK XqHUdYNI5282SSFDZZp9GX3XGxXpL5F886N1Q31OcUSlfBQhghUHsz3244+v9ot262iM 98Hw== Received: by 10.180.94.98 with SMTP id db2mr150235wib.2.1351218683108; Thu, 25 Oct 2012 19:31:23 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id bu8si25137wib.2.2012.10.25.19.31.23 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 25 Oct 2012 19:31:23 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id B3274200057; Thu, 25 Oct 2012 19:31:22 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 1C74416189A; Thu, 25 Oct 2012 19:31:22 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 25 Oct 2012 19:31:06 -0700 Message-Id: <1351218671-15228-10-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351218671-15228-1-git-send-email-sjg@chromium.org> References: <1351218671-15228-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlvOBY/UJlSZB6/NJvleKWs37mUD9vvPoPuX9QT3yEJaodJbtpB8xv7ovf+lZ4bQ85aFX4SZyIfQNauM3c39Rfk4ZlTic7/b3sEJHWVbTTWxb+EirQCH/cdXo7I7VPLwq5YIBoyh+Uy4UFItOnZJfh8B005Nvu7hcVky6uZ80wd0QT5ZwC+++EbSCcFs9+MYkFRy/Na Cc: Tom Rini , Jerry Van Baren , Sean Paul , Devicetree Discuss Subject: [U-Boot] [PATCH 09/14] fdt: Add polarity-aware gpio functions to fdtdec 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: Sean Paul Add get and set gpio functions to fdtdec that take into account the polarity field in fdtdec_gpio_state.flags. Signed-off-by: Sean Paul Signed-off-by: Simon Glass --- include/fdtdec.h | 16 ++++++++++++++++ lib/fdtdec.c | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index 12f73a7..17daa99 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -90,6 +90,22 @@ struct fdt_gpio_state { #define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE) /** + * Read the GPIO taking into account the polarity of the pin. + * + * @param gpio pointer to the decoded gpio + * @return value of the gpio if successful, < 0 if unsuccessful + */ +int fdtdec_get_gpio(struct fdt_gpio_state *gpio); + +/** + * Write the GPIO taking into account the polarity of the pin. + * + * @param gpio pointer to the decoded gpio + * @return 0 if successful + */ +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val); + +/** * Find the next numbered alias for a peripheral. This is used to enumerate * all the peripherals of a certain type. * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 6c417d2..91ba558 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -487,6 +487,26 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name, return err == 1 ? 0 : err; } +int fdtdec_get_gpio(struct fdt_gpio_state *gpio) +{ + int val; + + if (!fdt_gpio_isvalid(gpio)) + return -1; + + val = gpio_get_value(gpio->gpio); + return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; +} + +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val) +{ + if (!fdt_gpio_isvalid(gpio)) + return -1; + + val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; + return gpio_set_value(gpio->gpio, val); +} + int fdtdec_setup_gpio(struct fdt_gpio_state *gpio) { /*