From patchwork Fri Mar 28 19:44:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 27374 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B311720062 for ; Fri, 28 Mar 2014 19:44:27 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wp18sf19086299obc.8 for ; Fri, 28 Mar 2014 12:44:26 -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=lZCE+M0J9mga46F07CYdo2l/gZ3rXABWdJp7kgtkuqA=; b=QAgZjUlHr3ujfgzDk3Y8/e7+6BmtLTxF/Ekp4vI0YGDW3sad6S/Qqt8Gnuqz/3eR7Y AKsmMdnuNtQzci9ENHFaxDNq0cgP2dKwxuDYzqpD+5Syp5G98SijXO03Lxj9w0DPnW7n XF/VE0YmnQWBGg8wffIeiZRghwHNrXDtsln1qDGLnY9G0P7VEEj5Sb7MyaMLBfVB2gyI Gv0QqlTaUmH/uxZZe+CC2qZd2EuOS370/onjWZoA6gi1kMBBE3CCEl3qJA6YHYN/1u7F SkKff4eJV+OHXk8Oi3/KR1LfbUmJC0W9SZ9VXNRZSYrG8sxyeJMgKc3WkYgk4S7ncc7O 35sg== X-Gm-Message-State: ALoCoQkmNEgqNqWlwj2LiPN3PyFantVcZOlTKDbcSu6Ey91DNkuOdaE5YBRCEy86tskpmYJC6X40 X-Received: by 10.182.126.137 with SMTP id my9mr3979857obb.13.1396035866719; Fri, 28 Mar 2014 12:44:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.165 with SMTP id 34ls1824853qgb.30.gmail; Fri, 28 Mar 2014 12:44:26 -0700 (PDT) X-Received: by 10.58.4.68 with SMTP id i4mr8819125vei.8.1396035866603; Fri, 28 Mar 2014 12:44:26 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id fi2si1329503vcb.177.2014.03.28.12.44.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 12:44:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 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.178; Received: by mail-vc0-f178.google.com with SMTP id im17so6496826vcb.9 for ; Fri, 28 Mar 2014 12:44:26 -0700 (PDT) X-Received: by 10.58.207.74 with SMTP id lu10mr8634959vec.15.1396035866509; Fri, 28 Mar 2014 12:44:26 -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 v8csp34349vcv; Fri, 28 Mar 2014 12:44:26 -0700 (PDT) X-Received: by 10.66.227.193 with SMTP id sc1mr10635658pac.102.1396035865712; Fri, 28 Mar 2014 12:44:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mu18si4265765pab.149.2014.03.28.12.44.24; Fri, 28 Mar 2014 12:44:24 -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 S1752033AbaC1ToX (ORCPT + 1 other); Fri, 28 Mar 2014 15:44:23 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:58478 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbaC1ToX (ORCPT ); Fri, 28 Mar 2014 15:44:23 -0400 Received: by mail-wi0-f169.google.com with SMTP id hm4so1097008wib.2 for ; Fri, 28 Mar 2014 12:44:22 -0700 (PDT) X-Received: by 10.180.20.71 with SMTP id l7mr14621603wie.35.1396035861833; Fri, 28 Mar 2014 12:44:21 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id i9sm9653501wiy.17.2014.03.28.12.44.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Mar 2014 12:44:20 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Alexandre Courbot , Linus Walleij Subject: [PATCH] gpio: unmap gpio irqs properly Date: Fri, 28 Mar 2014 20:44:18 +0100 Message-Id: <1396035858-23758-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.5.3 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.178 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: , When using the irqchip helper inside the gpiolib, make sure the IRQs are unmapped/disposed before the irqdomain is removed as part of removing the gpiochip. Signed-off-by: Linus Walleij Acked-by: Alexandre Courbot --- drivers/gpio/gpiolib.c | 33 +++++++++++++++++++++++++++++---- include/linux/gpio/driver.h | 1 + 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f41cb4f3d715..761013f8b82f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1399,8 +1399,18 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, return 0; } +static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) +{ +#ifdef CONFIG_ARM + set_irq_flags(irq, 0); +#endif + irq_set_chip_and_handler(irq, NULL, NULL); + irq_set_chip_data(irq, NULL); +} + static const struct irq_domain_ops gpiochip_domain_ops = { .map = gpiochip_irq_map, + .unmap = gpiochip_irq_unmap, /* Virtually all GPIO irqchips are twocell:ed */ .xlate = irq_domain_xlate_twocell, }; @@ -1438,8 +1448,14 @@ static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) */ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) { - if (gpiochip->irqdomain) + unsigned int offset; + + /* Remove all IRQ mappings and delete the domain */ + if (gpiochip->irqdomain) { + for (offset = 0; offset < gpiochip->ngpio; offset++) + irq_dispose_mapping(gpiochip->irq_base + offset); irq_domain_remove(gpiochip->irqdomain); + } if (gpiochip->irqchip) { gpiochip->irqchip->irq_request_resources = NULL; @@ -1467,7 +1483,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) * translation. The gpiochip will need to be initialized and registered * before calling this function. * - * This function will handle two cell:ed simple IRQs. Everything else + * This function will handle two cell:ed simple IRQs and assumes all + * the pins on the gpiochip can generate a unique IRQ. Everything else * need to be open coded. */ int gpiochip_irqchip_add(struct gpio_chip *gpiochip, @@ -1478,6 +1495,7 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip, { struct device_node *of_node; unsigned int offset; + unsigned irq_base = 0; if (!gpiochip || !irqchip) return -EINVAL; @@ -1514,8 +1532,15 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip, * any gpiochip calls. If the first_irq was zero, this is * necessary to allocate descriptors for all IRQs. */ - for (offset = 0; offset < gpiochip->ngpio; offset++) - irq_create_mapping(gpiochip->irqdomain, offset); + for (offset = 0; offset < gpiochip->ngpio; offset++) { + irq_base = irq_create_mapping(gpiochip->irqdomain, offset); + if (offset == 0) + /* + * Store the base into the gpiochip to be used when + * unmapping the irqs. + */ + gpiochip->irq_base = irq_base; + } return 0; } diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index c1c5c2368fc8..1827b43966d9 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -107,6 +107,7 @@ struct gpio_chip { */ struct irq_chip *irqchip; struct irq_domain *irqdomain; + unsigned int irq_base; irq_flow_handler_t irq_handler; unsigned int irq_default_type; #endif