linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1] irqchip: Add IRQCHIP_MODULE_BEGIN/END helper macros
@ 2020-04-11  4:59 Saravana Kannan
  2020-04-11  9:14 ` Marc Zyngier
  0 siblings, 1 reply; 11+ messages in thread
From: Saravana Kannan @ 2020-04-11  4:59 UTC (permalink / raw)
  To: Thomas Gleixner, Jason Cooper, Marc Zyngier
  Cc: Saravana Kannan, John Stultz, kernel-team, linux-kernel

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-07-17  2:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-11  4:59 [RFC PATCH v1] irqchip: Add IRQCHIP_MODULE_BEGIN/END helper macros Saravana Kannan
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).