From patchwork Mon Aug 14 14:53:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 801218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="euKEaopn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xWJWt1Dmpz9t2y for ; Tue, 15 Aug 2017 00:53:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752487AbdHNOx1 (ORCPT ); Mon, 14 Aug 2017 10:53:27 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:34478 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752663AbdHNOx0 (ORCPT ); Mon, 14 Aug 2017 10:53:26 -0400 Received: by mail-wr0-f172.google.com with SMTP id l9so12676621wrl.1 for ; Mon, 14 Aug 2017 07:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ic/dEJbnu/uQXX+unGOF5AkNIDTQJih34RmNVodaWMY=; b=euKEaopnULBtxDldnQav1Wcvf+z4A41MP5jTRMjG03YinfSW7EjgR/Oyu0toaQwCUG b4VmcXB06ZJA46on5QJmdR45lJDP0IqCwV29WDffj4K5Ccx98Jrf/dtkqlapqE6YQW+e e1rmHTs+SSnre3L6gcTXcepxfFFPLR4Ua5FlRYOMiPCJBYX4w0fHeV9Xf6ig1LvJSE4w H3G3g1stvjZIJPegk/exmdestjnLFhF37GnOIhHXG1MMm5iXndGjFvbkSJ4wKvUPe+Te e2yfIw9odussaNsQGBXuRTfjmshOmLRJCY0G6f9O4QSw6nuDM8q0DpOVs4O0gnsokovz Kwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ic/dEJbnu/uQXX+unGOF5AkNIDTQJih34RmNVodaWMY=; b=QVOS55Mt8yDvI3eH54UowcsmAVJohk6u5Hxcf5TzIgw/BFiwDdgl+KVPrFbKEQ2HEA 8xf5PJkC6N6OCF4pDkgltI/ymd6YEK1XWXuj9WHX/zj6AzFgPU1KNqhS62lssDrJiQ5P uHZIV4qm4fDJzCltBZkCH3hWBWVHAWwjSM2/srUmYH3p2h/tZptLF6BwNUAJiHxCd1h6 Q4mlN4pGbLTBk58u2X8esO7ai1jGQ/SvmvXDSlpRfPL/Cf3SPTJtamlJf9COkrrDnVRw VeF8Ev7LvwUiPgA4q/V7eyqhHPLvKXy+GOi9nxK8Kscy9/HH2USkbvC/LZkzglDJaRyJ kUPA== X-Gm-Message-State: AHYfb5jNHi4PdBL2I9XZ5PDQiuZk8Qa/pB+r5Opr8CFEC58DVo9TTqOt fkPcl0T8s8AIvPIc X-Received: by 10.223.162.26 with SMTP id p26mr4214603wra.235.1502722405077; Mon, 14 Aug 2017 07:53:25 -0700 (PDT) Received: from bgdev-debian.lan (LFbn-1-7079-41.w90-116.abo.wanadoo.fr. [90.116.248.41]) by smtp.gmail.com with ESMTPSA id b125sm4554542wmc.41.2017.08.14.07.53.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 07:53:24 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , Jonathan Corbet , Bamvor Jian Zhang , Jonathan Cameron , Lars-Peter Clausen Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 2/3] irq/irq_sim: add a devres variant of irq_sim_init() Date: Mon, 14 Aug 2017 16:53:17 +0200 Message-Id: <20170814145318.6495-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170814145318.6495-1-brgl@bgdev.pl> References: <20170814145318.6495-1-brgl@bgdev.pl> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a resource managed version of irq_sim_init(). This can be conveniently used in device drivers. Signed-off-by: Bartosz Golaszewski Acked-by: Jonathan Cameron --- Documentation/driver-model/devres.txt | 1 + include/linux/irq_sim.h | 4 ++++ kernel/irq/irq_sim.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 30e04f7a690d..69f08c0f23a8 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -312,6 +312,7 @@ IRQ devm_irq_alloc_descs_from() devm_irq_alloc_generic_chip() devm_irq_setup_generic_chip() + devm_irq_sim_init() LED devm_led_classdev_register() diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 9ee1a4f8bd94..9ad634fcc662 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -11,6 +11,7 @@ #define _LINUX_IRQ_SIM_H #include +#include /* * Provides a framework for allocating simulated interrupts which can be @@ -37,6 +38,9 @@ struct irq_sim { int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs); void irq_sim_fini(struct irq_sim *sim); +int devm_irq_sim_init(struct device *dev, + struct irq_sim *sim, unsigned int num_irqs); + void irq_sim_fire(struct irq_sim *sim, unsigned int offset); int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset); diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 31a2c12a79ae..3daa10d62a27 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -92,6 +92,49 @@ void irq_sim_fini(struct irq_sim *sim) } EXPORT_SYMBOL_GPL(irq_sim_fini); +struct irq_sim_devres { + struct irq_sim *sim; +}; + +static void devm_irq_sim_release(struct device *dev, void *res) +{ + struct irq_sim_devres *this = res; + + irq_sim_fini(this->sim); +} + +/** + * irq_sim_init - Initialize the interrupt simulator for a managed device. + * + * @dev: Device to initialize the simulator object for. + * @sim: The interrupt simulator object to initialize. + * @num_irqs: Number of interrupts to allocate + * + * Returns 0 on success and a negative error number on failure. + */ +int devm_irq_sim_init(struct device *dev, + struct irq_sim *sim, unsigned int num_irqs) +{ + struct irq_sim_devres *dr; + int rv; + + dr = devres_alloc(devm_irq_sim_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rv = irq_sim_init(sim, num_irqs); + if (rv) { + devres_free(dr); + return rv; + } + + dr->sim = sim; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_irq_sim_init); + /** * irq_sim_fire - Enqueue an interrupt. *