From patchwork Mon Feb 11 17:10:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 2125081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 50064DF2A1 for ; Mon, 11 Feb 2013 17:14:47 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U4wvP-0001cq-QG; Mon, 11 Feb 2013 17:12:15 +0000 Received: from mail-da0-f50.google.com ([209.85.210.50]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U4wum-0001U6-Ho for linux-arm-kernel@lists.infradead.org; Mon, 11 Feb 2013 17:11:37 +0000 Received: by mail-da0-f50.google.com with SMTP id h15so2828632dan.23 for ; Mon, 11 Feb 2013 09:11:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=fVRb9x1pCGQgzSxqPmATP5IgZ20sBKiRWIqv1VnTcTY=; b=T6d6SuubSZ4+rmX97ZHHxwE7vpccIb27Xd5EVmWN7ozNMrUTEQ+navUccj/o0AJyS+ 7CzgLJnc8WRajVHqZxEvmjF7Sxi0T992zkiKBwjRUdemSFm4U8OuPDPThzSsuuPx13HZ ccnkegpcPa2ajbYWBMEzyzKHImJLG89UKCznwtYyLJhv2Nc4oo5iW7aWzQ0cqZXXPJ9A c6A30ibNc0cA52W3csEN5XcOY7Vkm+Qp10NSNHRq92eIQ5UpJDGxq/lwFtOOLJ2xLaI/ XhNi1/a7rism5zZZT9l9+Kiyz6/sZnPvGMKCnZjgHvr89HHixGNr8MNVwfZiX9QhGB7b ijuA== X-Received: by 10.66.82.67 with SMTP id g3mr42319455pay.58.1360602694661; Mon, 11 Feb 2013 09:11:34 -0800 (PST) Received: from localhost.localdomain ([27.115.121.35]) by mx.google.com with ESMTPS id m3sm67935973pav.4.2013.02.11.09.11.29 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 11 Feb 2013 09:11:33 -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, grant.likely@secretlab.ca, linus.walleij@linaro.org Subject: [PATCH v8 04/12] pinctrl: verify whether gpio chip overlapps range Date: Tue, 12 Feb 2013 01:10:51 +0800 Message-Id: <1360602659-4774-5-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360602659-4774-1-git-send-email-haojian.zhuang@linaro.org> References: <1360602659-4774-1-git-send-email-haojian.zhuang@linaro.org> X-Gm-Message-State: ALoCoQkg8H7cJIfKHFRAoobEi9qvcHOtc+bJfenjLKzVcwiGNKRbIjfmvcdSi7rpLLGmMi8E/cg3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130211_121136_702137_F26E9484 X-CRM114-Status: GOOD ( 16.74 ) 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.210.50 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Haojian Zhuang , patches@linaro.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 pinctrl_get_device_gpio_range() only checks whether a certain GPIO pin is in gpio range. But maybe some GPIO pins don't have back-end pinctrl interface, it means that these pins are always configured as GPIO function. Append pinctrl_overlapped_gpio_range() that is used to check whether the pins of GPIO chip are overlapped with pins in the GPIO range. This function will be called after pinctrl_get_device_gpio_range() fails. If overlapped GPIO pins are found, it means that pinctrl device is already launched and a certain GPIO pin don't have back-end pinctrl interface. Then pinctrl_request_gpio() shouldn't return -EPROBE_DEFER in this case. Signed-off-by: Haojian Zhuang --- drivers/pinctrl/core.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index b0a8e9a..140d6cb 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "core.h" #include "devicetree.h" #include "pinmux.h" @@ -293,6 +294,39 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio) } /** + * pinctrl_overlapped_gpio_range() - check if the GPIO chip of a certain GPIO + * pin is overlapped with gpio range. + * @gpio: gpio pin to check taken from the global GPIO pin space + * + * This function is complement of pinctrl_match_gpio_range(). If the return + * value of pinctrl_match_gpio_range() is NULL, this function could be used + * to check whether pinctrl device is ready or not. Maybe some GPIO pins + * don't have back-end pinctrl interface. + * If the return value is true, it means that pinctrl device is ready & the + * certain GPIO pin doesn't have back-end pinctrl device. If the return value + * is false, it means that pinctrl device may not be ready. + */ +static bool pinctrl_overlapped_gpio_range(unsigned gpio) +{ + struct pinctrl_dev *pctldev; + struct pinctrl_gpio_range *range = NULL; + struct gpio_chip *chip = gpio_to_chip(gpio); + + /* Loop over the pin controllers */ + list_for_each_entry(pctldev, &pinctrldev_list, node) { + /* Loop over the ranges */ + list_for_each_entry(range, &pctldev->gpio_ranges, node) { + /* Check if any gpio range overlapped with gpio chip */ + if (range->base + range->npins - 1 < chip->base || + range->base > chip->base + chip->ngpio - 1) + continue; + return true; + } + } + return false; +} + +/** * pinctrl_get_device_gpio_range() - find device for GPIO range * @gpio: the pin to locate the pin controller for * @outdev: the pin control device if found @@ -459,6 +493,8 @@ int pinctrl_request_gpio(unsigned gpio) ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); if (ret) { + if (pinctrl_overlapped_gpio_range(gpio)) + ret = 0; mutex_unlock(&pinctrl_mutex); return ret; }