From patchwork Thu Oct 23 03:37:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 402350 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 7D27B14003E for ; Thu, 23 Oct 2014 14:39:22 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F9594C117; Thu, 23 Oct 2014 05:38:54 +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 tYj9kKAqHeT6; Thu, 23 Oct 2014 05:38:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A4F2E4C132; Thu, 23 Oct 2014 05:38:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D2164C0F1 for ; Thu, 23 Oct 2014 05:38:04 +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 JYYH2q0X2K16 for ; Thu, 23 Oct 2014 05:38:04 +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-pa0-f73.google.com (mail-pa0-f73.google.com [209.85.220.73]) by theia.denx.de (Postfix) with ESMTPS id 5C0E24C102 for ; Thu, 23 Oct 2014 05:37:58 +0200 (CEST) Received: by mail-pa0-f73.google.com with SMTP id et14so31926pad.4 for ; Wed, 22 Oct 2014 20:37:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7u6+79JduNI5gICyugg7eEqKGTaqZb0otpTg8EPkU3I=; b=U++TEcsKCobNQPuNBgQIZZ6KpGlB6dLGZdVjxlEenWaWm4QxE0YktxqsVrMvIrKK9d dEde+uokLOQe3CCKpX0QNd3AlWpEPaY0LsUR4NGiLPXNNCG8f6R3lXlbAzXGki8DJh1v G6JKgIwAkRpWqyw1oKREAUZAFE9QUlmPPrbwqkfo58WMTwFGiqRTnMEpMbJH/dipljSM 3Hbhm9aTG3thDO9nPOp0u4PNcjD72U+JsyrgQxrshjXKmLQxifXdcHd/2T7Ry5DM3S73 VbItXQZzNd6mTJ/EbwVUTku1dt1GmMug1ZQlmSriPLUyulUcZpjj5KVyd/oa63sLyrV+ v0wg== X-Gm-Message-State: ALoCoQkuRSt+vieUTWTPDclYHZKcWcYnMYbTyj24F6pUMMgnDCktgLBQmz51VArN//PspD9DUfo6 X-Received: by 10.67.4.3 with SMTP id ca3mr61239pad.23.1414035476604; Wed, 22 Oct 2014 20:37:56 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n24si44216yha.6.2014.10.22.20.37.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Oct 2014 20:37:56 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id dNlxgutz.1; Wed, 22 Oct 2014 20:37:56 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id DADDC2211FB; Wed, 22 Oct 2014 21:37:55 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 22 Oct 2014 21:37:01 -0600 Message-Id: <1414035435-17897-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1414035435-17897-1-git-send-email-sjg@chromium.org> References: <1414035435-17897-1-git-send-email-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH v2 01/15] dm: gpio: Support numbered GPIOs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 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 At present banks must be named and it is not possible to refer to GPIOs by number in driver model. Some boards use numbering - e.g. OMAP. It is fairly easy to support by detecting the absense of a bank name (which starts with a letter). Add support for numbered GPIOs in addition to the existing bank support. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- Changes in v2: None drivers/gpio/gpio-uclass.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index f1bbc58..a5ffd85 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -8,6 +8,7 @@ #include #include #include +#include /** * gpio_to_device() - Convert global GPIO number to device, number @@ -43,35 +44,47 @@ static int gpio_to_device(unsigned int gpio, struct udevice **devp, int gpio_lookup_name(const char *name, struct udevice **devp, unsigned int *offsetp, unsigned int *gpiop) { - struct gpio_dev_priv *uc_priv; + struct gpio_dev_priv *uc_priv = NULL; struct udevice *dev; + ulong offset; + int numeric; int ret; if (devp) *devp = NULL; + numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1; for (ret = uclass_first_device(UCLASS_GPIO, &dev); dev; ret = uclass_next_device(&dev)) { - ulong offset; int len; uc_priv = dev->uclass_priv; + if (numeric != -1) { + offset = numeric - uc_priv->gpio_base; + /* Allow GPIOs to be numbered from 0 */ + if (offset >= 0 && offset < uc_priv->gpio_count) + break; + } + len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0; if (!strncasecmp(name, uc_priv->bank_name, len)) { - if (strict_strtoul(name + len, 10, &offset)) - continue; - if (devp) - *devp = dev; - if (offsetp) - *offsetp = offset; - if (gpiop) - *gpiop = uc_priv->gpio_base + offset; - return 0; + if (!strict_strtoul(name + len, 10, &offset)) + break; } } - return ret ? ret : -EINVAL; + if (!dev) + return ret ? ret : -EINVAL; + + if (devp) + *devp = dev; + if (offsetp) + *offsetp = offset; + if (gpiop) + *gpiop = uc_priv->gpio_base + offset; + + return 0; } /**