From patchwork Sun Feb 17 11:42:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14933 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 B7CE123E1A for ; Sun, 17 Feb 2013 11:44:30 +0000 (UTC) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 5B29DA18D4A for ; Sun, 17 Feb 2013 11:44:30 +0000 (UTC) Received: by mail-vb0-f52.google.com with SMTP id fa15so2970957vbb.39 for ; Sun, 17 Feb 2013 03:44:29 -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=akOiEHbn2qKnbRp+gbwYfKUcZSHpWK8ZEYx3Qq8cLgU=; b=UNRXPbTlruSjBbY39CntcKzC6A+s+wfVF2og06ZF2ePHHeY0TylHp0HoTPviLoNnHG +X+vZwSHNmRXKesVbkgrftZXN/MRKkNGILfxuIKvAlkbHGnhMIM8dGbp+NE87qGoI7cz HzC1T1WygwhBdmfHIc+L8LsgjuPBJ3TjBDVe+TBU7KFL0q3unso/XrmcgxdrE2awCZqh e8LrksBB3ZOuVpywWqqwK6iVZ+6vfiqiV4rkflWR0fUYTPj6xclWNfHqwBwTTiCEmwtD JRo3hn3bYFoKUYAFbtw/1CkQcatq9M0RmIJImzP2IcaNBvsQKJRaFta9WRmWqN8uPLfG 9Vng== X-Received: by 10.52.88.237 with SMTP id bj13mr9664617vdb.75.1361101469852; Sun, 17 Feb 2013 03:44:29 -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.145.101 with SMTP id st5csp43086veb; Sun, 17 Feb 2013 03:44:29 -0800 (PST) X-Received: by 10.66.81.68 with SMTP id y4mr27194604pax.66.1361101468915; Sun, 17 Feb 2013 03:44:28 -0800 (PST) Received: from mail-da0-f52.google.com (mail-da0-f52.google.com [209.85.210.52]) by mx.google.com with ESMTPS id d10si17471903paz.345.2013.02.17.03.44.28 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 17 Feb 2013 03:44:28 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.52 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.210.52; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.52 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-f52.google.com with SMTP id f10so2061718dak.39 for ; Sun, 17 Feb 2013 03:44:28 -0800 (PST) X-Received: by 10.68.39.129 with SMTP id p1mr3763765pbk.19.1361101468535; Sun, 17 Feb 2013 03:44:28 -0800 (PST) Received: from localhost.localdomain ([67.198.145.34]) by mx.google.com with ESMTPS id hp7sm10927800pbc.8.2013.02.17.03.44.24 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 17 Feb 2013 03:44:27 -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 v9 04/10] pinctrl: check pinctrl ready for gpio range Date: Sun, 17 Feb 2013 19:42:50 +0800 Message-Id: <1361101376-3783-5-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1361101376-3783-1-git-send-email-haojian.zhuang@linaro.org> References: <1361101376-3783-1-git-send-email-haojian.zhuang@linaro.org> X-Gm-Message-State: ALoCoQmzqL0ND/TmHuPjPdQMiJBYH+qd6KxNAEAMQPdGAZZTTcXUzX6jH6u9so+2sPFvUWQcFYIj 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. For example, gpio159 isn't related to back-end pinctrl device in Hi3620 while other GPIO pins are related to back-end pinctrl device. Append pinctrl_ready_for_gpio_range() that is used to check whether pinctrl device with GPIO range is ready. This function will be called after pinctrl_get_device_gpio_range() fails. If pinctrl device with GPIO range is found, it means that pinctrl device is already launched and a certain GPIO pin just 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..e333dde 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_ready_for_gpio_range() - check if other GPIO pins of + * the same GPIO chip are in 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 + * of the same GPIO chip 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_ready_for_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_ready_for_gpio_range(gpio)) + ret = 0; mutex_unlock(&pinctrl_mutex); return ret; }