From patchwork Tue Jul 21 13:50:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6836331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D1B80C05AC for ; Tue, 21 Jul 2015 13:56:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E0444206A4 for ; Tue, 21 Jul 2015 13:56:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5717D206A9 for ; Tue, 21 Jul 2015 13:56:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXzd-0005en-71; Tue, 21 Jul 2015 13:54:01 +0000 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXy1-0004hi-W9 for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2015 13:52:22 +0000 Received: by wicmv11 with SMTP id mv11so42321510wic.0 for ; Tue, 21 Jul 2015 06:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0oXP6D3hF4+ShuU0ZNLN/gQCYkqxkqLczk6lPpCo300=; b=xM9dv7JR14n3bdy74cJUL9vFHldePmZw7iY4fwxjmLhqAs8mIgts2jmeqL4MxLNWyg KUyXdQNWE2ThHpWt+hFVtiSuffT3NVlkc/zMWW65KtToMsgCvlflwfS73DnqNkJPRe1P P2yVriiBlddL/R4auh3wQrQ7DkS3EkhzXk+niEWHc3UEmO8rYmTFKISWjSo/UVaRYMfj FwCprquqro2J7ox8VYdSajFwq6ol2/pB/JhLCTU6E8bQay1O2APl13Bzzo15taKsA1pt k75RNn8nN6dp+RBBwy1PcEEUSshNU1oPrmmUwHhtW5+dCDNPLNgZn3U5lVuXwAeQ5Zfb wLwQ== X-Received: by 10.180.188.139 with SMTP id ga11mr31840828wic.87.1437486720392; Tue, 21 Jul 2015 06:52:00 -0700 (PDT) Received: from cizrna.lan ([109.72.12.178]) by smtp.gmail.com with ESMTPSA id pf4sm37172056wjb.23.2015.07.21.06.51.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:51:59 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 08/16] Add DEVM_IRQ() Date: Tue, 21 Jul 2015 15:50:50 +0200 Message-Id: <1437486658-28365-9-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> References: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150721_065222_192056_954546F6 X-CRM114-Status: GOOD ( 16.12 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Tomeu Vizoso , Stephen Warren , "Rafael J. Wysocki" , Mark Brown , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Tomeu Vizoso --- include/linux/interrupt.h | 24 ++++++++++++++++++++++ kernel/irq/devres.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index be7e75c945e9..d0075aee3197 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -19,6 +19,8 @@ #include #include +struct devm_resource; + /* * These correspond to the IORESOURCE_IRQ_* defines in * linux/ioport.h to select the interrupt line behaviour. When @@ -670,4 +672,26 @@ extern int early_irq_init(void); extern int arch_probe_nr_irqs(void); extern int arch_early_irq_init(void); +int devm_acquire_irq(struct device *dev, const struct devm_resource *resource); + +/* cause a build warning if 'ptr' isn't of 'type' */ +#define typecheck_ptr(ptr, type) \ + (void *)(ptr - (type)NULL) + +#define DEVM_IRQ(_struct, _member, _index, _handler, _flags) { \ + .initfunc = devm_acquire_irq, \ + .offset = offsetof_t(struct _struct, _member, int), \ + .index = _index, \ + .arg = typecheck_ptr((_handler), irq_handler_t), \ + .flags = _flags, \ +} + +#define DEVM_IRQ_NAMED(_struct, _member, _name, _handler, _flags) { \ + .initfunc = devm_acquire_irq, \ + .offset = offsetof_t(struct _struct, _member, int), \ + .name = _name, \ + .arg = typecheck_ptr((_handler), irq_handler_t), \ + .flags = _flags, \ +} + #endif diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c index 74d90a754268..36b38625a101 100644 --- a/kernel/irq/devres.c +++ b/kernel/irq/devres.c @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include /* @@ -137,3 +140,52 @@ void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id) free_irq(irq, dev_id); } EXPORT_SYMBOL(devm_free_irq); + +int devm_acquire_irq(struct device *dev, const struct devm_resource *resource) +{ + int irq; + int *irqp; + int index; + char *name; + + /* come up with a reasonable string for the irq name, + maybe create devm_kasprintf() to allow arbitrary length? */ + name = devm_kmalloc(dev, 32, GFP_KERNEL); + if (!name) + return -ENOMEM; + if (resource->name) + snprintf(name, 32 - 1, "%s:%s", dev_name(dev), resource->name); + else + snprintf(name, 32 - 1, "%s:%d", dev_name(dev), resource->index); + + /* find IRQ number from resource if platform device */ + irq = 0; + if (dev->bus == &platform_bus_type) { + struct platform_device *pdev = to_platform_device(dev); + + if (resource->name) + irq = platform_get_irq_byname(pdev, resource->name); + else + irq = platform_get_irq(pdev, resource->index); + } + + /* try getting irq number from device tree if that failed */ + if (!irq && dev->of_node) { + if (resource->name) + index = of_property_match_string(dev->of_node, + "interrupt-names", + resource->name); + else + index = resource->index; + + irq = irq_of_parse_and_map(dev->of_node, index); + } + + /* copy irq number to driver data */ + irqp = dev_get_drvdata(dev) + resource->offset; + *irqp = irq; + + return devm_request_irq(dev, irq, resource->arg, resource->flags, + name, dev); +} +EXPORT_SYMBOL_GPL(devm_acquire_irq);