From patchwork Wed Apr 9 11:48:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 28080 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2AD43202DD for ; Wed, 9 Apr 2014 11:48:53 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id bj1sf7436509pad.11 for ; Wed, 09 Apr 2014 04:48:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=VQP55UrxyihBAx+uFjgdzzTxShPtGlyVknVP6jHpJMk=; b=SR3aMEfWYdxQou4/hlBhZ3GngzC42t0S+SEYzsVGjK3o30W7lprCA+p9aHBNxeSt+8 YjglRhYw8pSBdPt9yWfZ7Tt3kYHoPx4TW2Hv0S4M5P/KEAhwA1cSWiD6o4xt7D7V1t3n dm3nOJiaW6CGOWHxPYFVdmebo5Te8hnb8JnNatma8OLIypY29PdsfqiaaMA+32Y5hcp3 9Z/Dm8cR9o+sIs0hKGzp72jF5b67KDoxnQAa0QkNLiZ/YZfQvAY29e2zVMYFaG6qWcSV XqkBK/CT2Yn7A5AEuwHc0kAigwhsYM+jNe4nlrlL5Kn5C3kn3I/Sf4Ng3jx23EIjjugx w10Q== X-Gm-Message-State: ALoCoQmCNRqtH/S2iTo6yLPe1tTwV3PfZ/01I/D9jXWQxSvFrhAJtZK5Yr3vercwyo6z+uXRcxzi X-Received: by 10.66.150.106 with SMTP id uh10mr4282555pab.13.1397044132239; Wed, 09 Apr 2014 04:48:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.133 with SMTP id v5ls538412qgv.23.gmail; Wed, 09 Apr 2014 04:48:52 -0700 (PDT) X-Received: by 10.58.186.71 with SMTP id fi7mr110314vec.32.1397044131997; Wed, 09 Apr 2014 04:48:51 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id u5si95590vdo.94.2014.04.09.04.48.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Apr 2014 04:48:51 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so1895230vcb.25 for ; Wed, 09 Apr 2014 04:48:51 -0700 (PDT) X-Received: by 10.52.33.176 with SMTP id s16mr76242vdi.49.1397044130982; Wed, 09 Apr 2014 04:48:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp322834vcv; Wed, 9 Apr 2014 04:48:50 -0700 (PDT) X-Received: by 10.68.231.196 with SMTP id ti4mr11643002pbc.48.1397044129966; Wed, 09 Apr 2014 04:48:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bs8si380087pad.53.2014.04.09.04.48.49; Wed, 09 Apr 2014 04:48:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932597AbaDILst (ORCPT + 1 other); Wed, 9 Apr 2014 07:48:49 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:50499 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932482AbaDILss (ORCPT ); Wed, 9 Apr 2014 07:48:48 -0400 Received: by mail-wi0-f172.google.com with SMTP id hi2so8701384wib.17 for ; Wed, 09 Apr 2014 04:48:47 -0700 (PDT) X-Received: by 10.180.8.136 with SMTP id r8mr9559065wia.60.1397044126884; Wed, 09 Apr 2014 04:48:46 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id h1sm1327768wjy.7.2014.04.09.04.48.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Apr 2014 04:48:45 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Alexandre Courbot , Linus Walleij , Thomas Gleixner Subject: [PATCH 1/4] gpio: support threaded interrupts in irqchip helpers Date: Wed, 9 Apr 2014 13:48:40 +0200 Message-Id: <1397044120-19222-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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.220.180 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some off-chip GPIO expanders need to be communicated by I2C or SPI traffic, but may still support IRQs. By the sleeping nature of such buses, such IRQ handlers need to be threaded. Support such handlers in the gpiochip irqchip helpers by flagging IRQs as threaded if the .can_sleep property of the gpiochip is true. Helpfully deny registration of chained IRQ handlers if the .can_sleep property is set, as such chips will invariably need a nested handler rather than a chained handler. Cc: Thomas Gleixner Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 12 ++++++++++++ include/linux/gpio/driver.h | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f48817d97480..5023541fefa0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1363,6 +1363,11 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, int parent_irq, irq_flow_handler_t parent_handler) { + if (chip->can_sleep) { + chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); + return; + } + irq_set_chained_handler(parent_irq, parent_handler); /* * The parent irqchip is already using the chip_data for this @@ -1389,6 +1394,9 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, irq_set_chip_data(irq, chip); irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); + /* Chips that can sleep need nested thread handlers */ + if (chip->can_sleep) + irq_set_nested_thread(irq, 1); #ifdef CONFIG_ARM set_irq_flags(irq, IRQF_VALID); #else @@ -1401,9 +1409,13 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) { + struct gpio_chip *chip = d->host_data; + #ifdef CONFIG_ARM set_irq_flags(irq, 0); #endif + if (chip->can_sleep) + irq_set_nested_thread(irq, 0); irq_set_chip_and_handler(irq, NULL, NULL); irq_set_chip_data(irq, NULL); } diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 1827b43966d9..573e4f3243d0 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -51,7 +51,10 @@ struct seq_file; * format specifier for an unsigned int. It is substituted by the actual * number of the gpio. * @can_sleep: flag must be set iff get()/set() methods sleep, as they - * must while accessing GPIO expander chips over I2C or SPI + * must while accessing GPIO expander chips over I2C or SPI. This + * implies that if the chip supports IRQs, these IRQs need to be threaded + * as the chip access may sleep when e.g. reading out the IRQ status + * registers. * @exported: flags if the gpiochip is exported for use from sysfs. Private. * * A gpio_chip can help platforms abstract various sources of GPIOs so