From patchwork Sat Feb 2 17:25:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14424 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 87DFC23F96 for ; Sat, 2 Feb 2013 17:26:40 +0000 (UTC) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by fiordland.canonical.com (Postfix) with ESMTP id 2D512A18D77 for ; Sat, 2 Feb 2013 17:26:40 +0000 (UTC) Received: by mail-ve0-f171.google.com with SMTP id b10so3684379vea.16 for ; Sat, 02 Feb 2013 09:26:39 -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=H1eS7ecx6cUjA5FyCwix3Rv87nj78vTuAC3b61wzdZ0=; b=aE//eF9oh7JEBvZV3sG639/sa7U/NZDZjAi379+C7RAVG6JM4EwmFED8ENWCcswkUd xtXP2YJ5LODIyNZwHUhue116R3GbXhCIkCxWk5/UqDzGcKNIcuIpE589TLq3JWDp9y40 eW+xpnDtloy9hn9WT18fGPCmoryWKe5Ix+VdUXuft9/Cqgv4Q23OYWTMZlRGCfMYSnEz +1/Z8p6apffjeriEtoXS8STGcfWfHp4qr/P90Si2u4Rra/GXdeC9V92GFV3evlyFbhMs MIK9N1HclrFyPPPJcvs8iuvA2tf9d+MCXIkUtx3G37B6MxSYD/mldzr7sdXSjFpCOrtP m8SQ== X-Received: by 10.59.7.65 with SMTP id da1mr10860292ved.4.1359825999649; Sat, 02 Feb 2013 09:26:39 -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 zo8csp16821vec; Sat, 2 Feb 2013 09:26:39 -0800 (PST) X-Received: by 10.66.83.8 with SMTP id m8mr17057695pay.40.1359825998880; Sat, 02 Feb 2013 09:26:38 -0800 (PST) Received: from mail-da0-f54.google.com (mail-da0-f54.google.com [209.85.210.54]) by mx.google.com with ESMTPS id n6si11610767paw.109.2013.02.02.09.26.38 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 09:26:38 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.54 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.210.54; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.54 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-f54.google.com with SMTP id n2so2138735dad.41 for ; Sat, 02 Feb 2013 09:26:38 -0800 (PST) X-Received: by 10.66.52.79 with SMTP id r15mr39321785pao.46.1359825998476; Sat, 02 Feb 2013 09:26:38 -0800 (PST) Received: from localhost.localdomain ([27.115.121.35]) by mx.google.com with ESMTPS id b3sm10434040pax.14.2013.02.02.09.26.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Feb 2013 09:26:37 -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 05/12] pinctrl: verify whether gpio chip overlapps range Date: Sun, 3 Feb 2013 01:25:46 +0800 Message-Id: <1359825953-15663-6-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: ALoCoQmvx2baIB1FEul5Mg36VH7j5m172yf/zzMMf8cFQdboRNWz7U6vDZnx9m+QQ9kuY4JqTWvV 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 5a2fe9a..f5814cf 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; }