From patchwork Mon Sep 22 15:48:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 392039 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 3C44B140174 for ; Tue, 23 Sep 2014 01:53:47 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E6EA9AB57C; Mon, 22 Sep 2014 17:53:44 +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 52Qcd7ErpaVl; Mon, 22 Sep 2014 17:53:44 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 84A75A747B; Mon, 22 Sep 2014 17:53:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4DEFCA73F7 for ; Mon, 22 Sep 2014 17:53:21 +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 OVjg7LHGUDEP for ; Mon, 22 Sep 2014 17:53:16 +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-ig0-f201.google.com (mail-ig0-f201.google.com [209.85.213.201]) by theia.denx.de (Postfix) with ESMTPS id 1E8B2A73EF for ; Mon, 22 Sep 2014 17:53:13 +0200 (CEST) Received: by mail-ig0-f201.google.com with SMTP id h15so485860igd.4 for ; Mon, 22 Sep 2014 08:53:12 -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=Hxt3ZC53SVGmU5WG87oaCx1Owbr//pkL0xv8kk8+wUk=; b=GQ4a8WoszldcRVt8atY0KCKtUqdXZ5a9g9rrD7k7QRuu7VLXOWp8TRkYZP/odFUmNQ nCqBgleasBCjDUCguHwIQbWf7KHwMpJF9SLNoUrIHBt9ZIhUjSFxfPyqFUmQisIOBqds AyWKDMyDjD0ZOCbX2AQS6o8RMjXmCE+X2tiDcZITwS2kCSnzQRoFWr2Xa75v6WGQc4Ou UswKhE7F17QgYgOX4+lRtQs/RLfjf3Cr0in2a1cLjtXTZUH/A7mG4ExlitYhrLRT+2YR kGywQHSUnd54UZst5wK3gl8A+a+e62KynwlljsjNpSLBhnIIlsMOVgrv8YTC/pRRYKUR /eVg== X-Gm-Message-State: ALoCoQkMQ8YN9e3iBfaQbrpZn06viGITYrD5qm0Rix+uzBNJirTe0kmArYjptMe1RZhoPysOoMNv X-Received: by 10.42.133.2 with SMTP id f2mr24569605ict.14.1411401191970; Mon, 22 Sep 2014 08:53:11 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id l45si501750yha.2.2014.09.22.08.53.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Sep 2014 08:53:11 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id kkDtSXBF.1; Mon, 22 Sep 2014 08:53:11 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 0E305221206; Mon, 22 Sep 2014 09:53:10 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 22 Sep 2014 09:48:41 -0600 Message-Id: <1411400934-7754-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1411400934-7754-1-git-send-email-sjg@chromium.org> References: <1411400934-7754-1-git-send-email-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 01/14] dm: gpio: Support numbered GPIOs 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 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 --- 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; } /**