mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Saravana Kannan <saravanak@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Marc Zyngier <maz@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
	John Stultz <john.stultz@linaro.org>,
	kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1] irqchip: Add IRQCHIP_MODULE_BEGIN/END helper macros
Date: Fri, 10 Apr 2020 21:59:18 -0700	[thread overview]
Message-ID: <20200411045918.179455-1-saravanak@google.com> (raw)

Add helper macros IRQCHIP_MODULE_BEGIN and IRQCHIP_MODULE_END that add
the boilerplate code to be able to compile an irqchip driver as a
module.

The driver developer just needs to do add IRQCHIP_MODULE_BEGIN and
IRQCHIP_MODULE_END(driver_name) around the IRQCHIP_DECLARE macros, like
so:

IRQCHIP_MODULE_BEGIN
IRQCHIP_DECLARE(foo, "acme,foo", acme_foo_init)
IRQCHIP_DECLARE(bar, "acme,bar", acme_bar_init)
IRQCHIP_MODULE_END(acme_irq)

Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
I don't expect this patch to be perfect or the final version. But I'd
like to introduce macros like this that don't need the driver developer
to copy/paste or repeat the same thing (compat string, function name,
etc) in multiple places for the driver to work as a module. If the exact
style of my macros aren't appealing, I'm open to other suggestions.

There are some checkpatch warning about the > 80 columns that my patch
doesn't add. There are also checkpatch warnings about the trailing ; in
a macro, but I need those for IRQCHIP_DECLARE to work when the driver is
builtin.

Thanks,
Saravana

 drivers/irqchip/irqchip.c | 20 ++++++++++++++++++++
 include/linux/irqchip.h   | 30 +++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
index 2b35e68bea82..191b605c72ef 100644
--- a/drivers/irqchip/irqchip.c
+++ b/drivers/irqchip/irqchip.c
@@ -10,8 +10,10 @@
 
 #include <linux/acpi.h>
 #include <linux/init.h>
+#include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/irqchip.h>
+#include <linux/platform_device.h>
 
 /*
  * This special of_device_id is the sentinel at the end of the
@@ -29,3 +31,21 @@ void __init irqchip_init(void)
 	of_irq_init(__irqchip_of_table);
 	acpi_probe_device_table(irqchip);
 }
+
+#ifdef CONFIG_MODULES
+int platform_irqchip_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct device_node *pnp = of_irq_find_parent(np);
+	of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev);
+
+	if (!irq_init_cb)
+		return -EINVAL;
+
+	if (pnp == np)
+		pnp = NULL;
+
+	return irq_init_cb(np, pnp);
+}
+EXPORT_SYMBOL_GPL(platform_irqchip_probe);
+#endif
diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h
index 950e4b2458f0..26b62843cade 100644
--- a/include/linux/irqchip.h
+++ b/include/linux/irqchip.h
@@ -13,6 +13,7 @@
 
 #include <linux/acpi.h>
 #include <linux/of.h>
+#include <linux/platform_device.h>
 
 /*
  * This macro must be used by the different irqchip drivers to declare
@@ -24,7 +25,34 @@
  * @compstr: compatible string of the irqchip driver
  * @fn: initialization function
  */
-#define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)
+#ifndef MODULE
+
+#define IRQCHIP_MODULE_BEGIN
+#define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn);
+#define IRQCHIP_MODULE_END(drv_name)
+
+#else
+
+extern int platform_irqchip_probe(struct platform_device *pdev);
+
+#define IRQCHIP_MODULE_BEGIN	\
+static const struct of_device_id __irqchip_match_table[] = {
+
+#define IRQCHIP_DECLARE(name, compat, fn) { .compatible = compat, .data = fn },
+
+#define IRQCHIP_MODULE_END(drv_name)			\
+	{},						\
+};							\
+MODULE_DEVICE_TABLE(of, __irqchip_match_table);		\
+static struct platform_driver drv_name##_driver = {	\
+	.probe  = platform_irqchip_probe,		\
+	.driver = {					\
+		.name = #drv_name,			\
+		.of_match_table = __irqchip_match_table,\
+	},						\
+};							\
+module_platform_driver(drv_name##_driver);
+#endif
 
 /*
  * This macro must be used by the different irqchip drivers to declare
-- 
2.26.0.110.g2183baf09c-goog


             reply	other threads:[~2020-04-11  4:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11  4:59 Saravana Kannan [this message]
2020-04-11  9:14 ` Marc Zyngier
2020-04-13 22:13   ` John Stultz
2020-04-13 22:43     ` Saravana Kannan
2020-04-29  9:28       ` Marc Zyngier
2020-04-29 19:04         ` Saravana Kannan
2020-05-01  8:48           ` Marc Zyngier
2020-05-01 20:23             ` Saravana Kannan
2020-06-03  1:59               ` Saravana Kannan
2020-06-03 10:12               ` Marc Zyngier
2020-07-17  2:55                 ` Saravana Kannan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200411045918.179455-1-saravanak@google.com \
    --to=saravanak@google.com \
    --cc=jason@lakedaemon.net \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome