From patchwork Sat Feb 2 16:29:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 2084441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 9BC253FCA4 for ; Sat, 2 Feb 2013 16:31:40 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U1fxU-0002Fz-Qj; Sat, 02 Feb 2013 16:28:52 +0000 Received: from mail-pb0-f50.google.com ([209.85.160.50]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U1fwM-0001lV-NW for linux-arm-kernel@lists.infradead.org; Sat, 02 Feb 2013 16:27:48 +0000 Received: by mail-pb0-f50.google.com with SMTP id ro8so2591690pbb.9 for ; Sat, 02 Feb 2013 08:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=cya5FtTUMwDDPjj45enVrSpVSemiCcaeZvdSdEPwLEg=; b=V0o5ADYe/++cf/jLz02vxkQdC94GP4q6wiZRTLDbkKISUjdhbPF2I+GpwvgjaFKAXP gGLi/v3V86O48nLTuoCtqcSvuD/LCHnJCvIQh7Ma7V9688sGVKnr4XBI0RCUs75shrSb 2QFV7NmBEJf2/L8TWmxAefv+0KArdPfMM0LVTonrRqNP6Py/eZPWvpI6h3P4o0H0lBnf DxCkx/nmAEFtdG4GRSqmrknWNroWnR1FJDL5tIwfHiVXQMxYQvAN3IRua8rAPHqeWJ68 zIq93/4/F5Nn9q9B0hLpdxU1cNHCrWRQYIJIx+HVIhpflRUSQFZSArYpLNLJMEbJ0UaI JeCw== X-Received: by 10.66.76.37 with SMTP id h5mr38864991paw.33.1359822461275; Sat, 02 Feb 2013 08:27:41 -0800 (PST) Received: from localhost.localdomain (softbank126010191003.bbtec.net. [126.10.191.3]) by mx.google.com with ESMTPS id vn2sm12100769pbc.31.2013.02.02.08.27.39 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 08:27:40 -0800 (PST) From: Alexandre Courbot To: Grant Likely , Linus Walleij , Arnd Bergmann Subject: [PATCH 8/9] gpiolib: use gpio_chips list in gpio_to_desc Date: Sun, 3 Feb 2013 01:29:31 +0900 Message-Id: <1359822572-26009-10-git-send-email-acourbot@nvidia.com> X-Mailer: git-send-email 1.8.1.1 In-Reply-To: <1359822572-26009-1-git-send-email-acourbot@nvidia.com> References: <1359822572-26009-1-git-send-email-acourbot@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130202_112742_873290_2DAFAD96 X-CRM114-Status: GOOD ( 14.65 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.50 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (gnurou[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: linux-arch@vger.kernel.org, gnurou@gmail.com, Alexandre Courbot , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Parse the list of chips to find the descriptor corresponding to a GPIO number instead of directly picking the entry of the global gpio_desc[] array, which is due to be removed. This turns the complexity of converting a GPIO number into a descriptor from O(1) to O(n) where n is the number of GPIO chips in the system. Since n is ought to be small anyway, there should be no noticeable performance impact. Moreover, GPIO users who care for speed already have implemented their own gpio_get_value() and gpio_set_value() with a fast path for the GPIO numbers that matter and this change does not affect such use cases. The descriptor-based GPIO API, due to be introduced soon, will make this lookup unnecessary. Signed-off-by: Alexandre Courbot Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9599b9a..0247c48 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -122,10 +122,21 @@ static int gpio_chip_hwgpio(const struct gpio_desc *desc) */ static struct gpio_desc *gpio_to_desc(unsigned gpio) { - if (WARN(!gpio_is_valid(gpio), "invalid GPIO %d\n", gpio)) - return NULL; - else - return &gpio_desc[gpio]; + struct gpio_chip *chip; + + list_for_each_entry(chip, &gpio_chips, list) { + int gpio_min = chip->base; + int gpio_max = gpio_min + chip->ngpio; + if (gpio >= gpio_min && gpio < gpio_max) + return &chip->desc[gpio - gpio_min]; + else if (gpio < gpio_min) + /* gpio_chips are ordered by base, so we won't get any + * hit if we arrive here... */ + break; + } + + pr_warn("%s: no registered chip to handle GPIO %d\n", __func__, gpio); + return NULL; } /**