From patchwork Sat Feb 2 17:25:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14422 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D69F023F96 for ; Sat, 2 Feb 2013 17:26:27 +0000 (UTC) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by fiordland.canonical.com (Postfix) with ESMTP id 94568A18D77 for ; Sat, 2 Feb 2013 17:26:27 +0000 (UTC) Received: by mail-ve0-f179.google.com with SMTP id da11so2560453veb.24 for ; Sat, 02 Feb 2013 09:26:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=+HtHaZmkCvs69V7R1HdqrTax41tda6XG8bok4OmmUkU=; b=Nqhk4KM3yPVsHIlntnqdx8yMzsbnZG+cGPrOVBHIBao56b0rs/VWzFYKh7lGPb9lqT Xr5mkx7Efa+A+9DG+DppsnYt5m2NZ2EnxOgOgk1iUnQrDExMBl2ttbnK3CQg2RwtHb2E UPm1nqkltDIcHPJNLk1OTGkr+p9CfZLyvdKHvqnv68bjqbxeLpqj/PRCxb2FAnvcwtRF F23OLTqxskVzFvImJskfhMyhJrhF7Oh2eTlZ8wxtk4Eyo5E/jmsIVaOeTy5D6DcUi1dw jLBkNh1mfoHK3+0zGJrm7pJY/rzLA2Jn2baAcAp4Fd2pP9fImXtXkYu8/ae3mf2BaIR+ seIA== X-Received: by 10.220.149.200 with SMTP id u8mr13795794vcv.7.1359825987047; Sat, 02 Feb 2013 09:26:27 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp16815vec; Sat, 2 Feb 2013 09:26:26 -0800 (PST) X-Received: by 10.66.75.66 with SMTP id a2mr39183150paw.65.1359825986303; Sat, 02 Feb 2013 09:26:26 -0800 (PST) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by mx.google.com with ESMTPS id a9si11593331paz.200.2013.02.02.09.26.26 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 09:26:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.51 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.220.51; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.51 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) smtp.mail=haojian.zhuang@linaro.org Received: by mail-pa0-f51.google.com with SMTP id hz1so1797227pad.10 for ; Sat, 02 Feb 2013 09:26:26 -0800 (PST) X-Received: by 10.66.83.165 with SMTP id r5mr39523950pay.3.1359825985944; Sat, 02 Feb 2013 09:26:25 -0800 (PST) Received: from localhost.localdomain ([27.115.121.35]) by mx.google.com with ESMTPS id b3sm10434040pax.14.2013.02.02.09.26.20 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 09:26:25 -0800 (PST) From: Haojian Zhuang To: shiraz.hashim@st.com, shiraz.linux.kernel@gmail.com, linux@arm.linux.org.uk, tony@atomide.com, linux-arm-kernel@lists.infradead.org, swarren@nvidia.com Cc: patches@linaro.org, Haojian Zhuang Subject: [PATCH v8 03/12] gpio: find gpio base by ascend order Date: Sun, 3 Feb 2013 01:25:44 +0800 Message-Id: <1359825953-15663-4-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359825953-15663-1-git-send-email-haojian.zhuang@linaro.org> References: <1359825953-15663-1-git-send-email-haojian.zhuang@linaro.org> X-Gm-Message-State: ALoCoQmNeblLCkEThmClHx39CfyI4xU4flxPwx5GiBqwLaLNlHhQDEy5WoXyZA+uoVr4WuK0sfWU gpiochip_find_base() always tries to find valid gpio with descend order. It's inconvient if gpio information is passing from DTS. Now try to find valid gpio with ascend order. Signed-off-by: Haojian Zhuang --- drivers/gpio/gpiolib.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 199fca1..8af57e7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -128,20 +128,21 @@ static int gpiochip_find_base(int ngpio) int spare = 0; int base = -ENOSPC; - for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) { + for (i = 0, base = 0; i < ARCH_NR_GPIOS; i++) { struct gpio_desc *desc = &gpio_desc[i]; struct gpio_chip *chip = desc->chip; - if (!chip && !test_bit(FLAG_RESERVED, &desc->flags)) { + if (chip) { + spare = 0; + i += chip->ngpio - 1; + base = i + 1; + } else if (test_bit(FLAG_RESERVED, &desc->flags)) { + spare = 0; + base = i + 1; + } else { spare++; - if (spare == ngpio) { - base = i; + if (spare == ngpio) break; - } - } else { - spare = 0; - if (chip) - i -= chip->ngpio - 1; } }