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: 14745 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 2488823DEA for ; Mon, 11 Feb 2013 17:11:42 +0000 (UTC) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id B8939A19245 for ; Mon, 11 Feb 2013 17:11:41 +0000 (UTC) Received: by mail-vc0-f180.google.com with SMTP id fo13so3821412vcb.25 for ; Mon, 11 Feb 2013 09:11:41 -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=fVRb9x1pCGQgzSxqPmATP5IgZ20sBKiRWIqv1VnTcTY=; b=U77c1/IJ9V6mQ0gDqvDjbhJ0upATEnBZ3Ss6+5LCJuc7AigntUTXr5Uw1BE3rfKIjx 5mZZk5c7zMTezAH60LxfRwdZjXCbw4w/UJNp0E2dC5RpKJOPh1GbumDiOB1vMyhAdT4p FnIwQyjseHzZb386D5goCgtQwOTXRlcq0xVuIRjQyuHDcG8T15JjoAgOWX/dI4JsHmGb 1IweMk3pYX/vchZkW7+l+NGDDHQSkMSdRmzCf668ATPqTMdVdhgwdu7Ai03MS8CN1QhV IhpWToHN60hMnaj9QJv5xGE2IRVAxhQldXCj89g/9CLj7LknE8O0a4yVcrelC28fZ9Sp 8JRg== X-Received: by 10.58.231.196 with SMTP id ti4mr19763756vec.25.1360602696161; Mon, 11 Feb 2013 09:11:36 -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 zo8csp107996vec; Mon, 11 Feb 2013 09:11:35 -0800 (PST) X-Received: by 10.66.73.5 with SMTP id h5mr42624539pav.11.1360602695208; Mon, 11 Feb 2013 09:11:35 -0800 (PST) Received: from mail-da0-f41.google.com (mail-da0-f41.google.com [209.85.210.41]) by mx.google.com with ESMTPS id p7si50530828pav.282.2013.02.11.09.11.34 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 11 Feb 2013 09:11:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.41 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.210.41; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.41 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-da0-f41.google.com with SMTP id e20so2787856dak.14 for ; Mon, 11 Feb 2013 09:11:34 -0800 (PST) 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 Cc: patches@linaro.org, Haojian Zhuang 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: ALoCoQlg3p/chRPmobcCLAKDMPJMuuc4wRYAlw6xtWV0q5PWm/YGXoS+55l58SkjXJINn+zU2Rnc 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; }