From patchwork Fri Aug 16 23:54:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 19274 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gh0-f198.google.com (mail-gh0-f198.google.com [209.85.160.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0BAB5246AB for ; Fri, 16 Aug 2013 23:54:46 +0000 (UTC) Received: by mail-gh0-f198.google.com with SMTP id r13sf2771171ghr.1 for ; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=IxuAAefgobgtk8oaTTF6/H6/OPCq0tpoWHqrhhRX58o=; b=QBmwdopEaRLAARcwmELPWXgxSgc8A8Zz1S/f3Jconw/MMYwrAMZjPdii1y5Sahez4V lmGRL6JAn9OGxiHhiRFiP48V3qxk6UhMQIO2T3wAReegs9lU9tmr1+ah0CzAcBYiGZq1 r+Ifndo4xgJ0mqzniFRifIJjb175fwVE58zOdF/ecB6DiE504cpfYC7WaEmiGRUW1Mce ze16wxl3kMfwjkvI4/R39sHk7f816wHREoPBoyMYovlWjBTfpG6RsOWITITx/+vuUVe/ fFwa9RzH20vhNu2xoGXCfpCxbsDNcO/aZKaRemQ3WZ9NqGeOoSof+0p8QYHw88x5/NRZ KecQ== X-Received: by 10.236.31.2 with SMTP id l2mr60066yha.36.1376697285748; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.82.202 with SMTP id k10ls980990qey.10.gmail; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) X-Received: by 10.52.164.102 with SMTP id yp6mr208580vdb.14.1376697285605; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by mx.google.com with ESMTPS id o5si38177vcj.140.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Aug 2013 16:54:45 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.43; Received: by mail-vb0-f43.google.com with SMTP id h11so2086487vbh.30 for ; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) X-Gm-Message-State: ALoCoQmr+r1T/tAWY08yg7stwNQsbyKSfiSejLtjojz6tgH6V5amBXDkeSCJYaxgkEOff6/CqlN1 X-Received: by 10.220.237.208 with SMTP id kp16mr198210vcb.4.1376697285518; Fri, 16 Aug 2013 16:54:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp95232vcz; Fri, 16 Aug 2013 16:54:44 -0700 (PDT) X-Received: by 10.112.89.100 with SMTP id bn4mr162673lbb.16.1376697284472; Fri, 16 Aug 2013 16:54:44 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx.google.com with ESMTPS id d5si62821laf.90.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Aug 2013 16:54:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.217.179 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id v1so1792554lbd.38 for ; Fri, 16 Aug 2013 16:54:43 -0700 (PDT) X-Received: by 10.112.35.52 with SMTP id e20mr168538lbj.11.1376697283845; Fri, 16 Aug 2013 16:54:43 -0700 (PDT) Received: from localhost.localdomain (c83-249-208-76.bredband.comhem.se. [83.249.208.76]) by mx.google.com with ESMTPSA id pw4sm359945lbb.9.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 16 Aug 2013 16:54:42 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij Subject: [PATCH 2/3] pinctrl: nomadik: queue pinctrl_request_gpio() Date: Sat, 17 Aug 2013 01:54:38 +0200 Message-Id: <1376697278-18839-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.1.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Instead of deferring if pinctrl_request_gpio() returns -EPROBE_DEFER, queue the GPIO number and request it later, when the pinctrl part of the driver probes. This is because we will otherwise have a circular dependency between the GPIO and pinctrl parts of the driver: the new auto-reservation of IRQ pins from the DT code will attempt to request a GPIO line as soon as the gpiochip is added, but this calls pinctrl_request_gpio() which count on the pinctrl backend being present, and the pinctrl backend will not probe until all the GPIO blocks have probed. So we get locked up in a circular loop unless we do something like this. Signed-off-by: Linus Walleij --- drivers/pinctrl/pinctrl-nomadik.c | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c index 4a1cfdc..ee87e73 100644 --- a/drivers/pinctrl/pinctrl-nomadik.c +++ b/drivers/pinctrl/pinctrl-nomadik.c @@ -1010,6 +1010,31 @@ static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip) /* I/O Functions */ +struct nmk_gpio_req { + struct list_head node; + int gpio; +}; + +static LIST_HEAD(nmk_queued_gpio_requests); + +static void nmk_pinctrl_process_queued_gpio_requests(void) +{ + struct list_head *node, *tmp; + + list_for_each_safe(node, tmp, &nmk_queued_gpio_requests) { + struct nmk_gpio_req *req = + list_entry(node, struct nmk_gpio_req, node); + int ret; + ret = pinctrl_request_gpio(req->gpio); + if (ret) + pr_err("failed to request queued GPIO %d\n", req->gpio); + else + pr_info("requested queued GPIO %d\n", req->gpio); + list_del(node); + kfree(req); + } +} + static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset) { /* @@ -1017,8 +1042,28 @@ static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset) * parameter does not matter for this controller. */ int gpio = chip->base + offset; + int ret; + + ret = pinctrl_request_gpio(gpio); + if (ret == -EPROBE_DEFER) { + /* + * This may happen during system startup: we request a GPIO + * for being used for IRQ when registering the GPIO controller + * for example, but the pin controller is not yet online. + * Store the request on a list to be done when the + * pin controller comes online. In our driver the GPIO + * blocks must always probe before the pin controller. + */ + struct nmk_gpio_req *req = kzalloc(sizeof(struct nmk_gpio_req), GFP_KERNEL); - return pinctrl_request_gpio(gpio); + if (!req) + return -ENOMEM; + req->gpio = gpio; + list_add_tail(&req->node, &nmk_queued_gpio_requests); + pr_info("queueing pinctrl_request_gpio(%d)\n", req->gpio); + ret = 0; + } + return ret; } static void nmk_gpio_free(struct gpio_chip *chip, unsigned offset) @@ -2224,6 +2269,7 @@ static int nmk_pinctrl_probe(struct platform_device *pdev) platform_set_drvdata(pdev, npct); dev_info(&pdev->dev, "initialized Nomadik pin control driver\n"); + nmk_pinctrl_process_queued_gpio_requests(); return 0; }