[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200411045918.179455-1-saravanak@google.com>
Date: Fri, 10 Apr 2020 21:59:18 -0700
From: Saravana Kannan <saravanak@...gle.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Jason Cooper <jason@...edaemon.net>,
Marc Zyngier <maz@...nel.org>
Cc: Saravana Kannan <saravanak@...gle.com>,
John Stultz <john.stultz@...aro.org>, kernel-team@...roid.com,
linux-kernel@...r.kernel.org
Subject: [RFC PATCH v1] irqchip: Add IRQCHIP_MODULE_BEGIN/END helper macros
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@...aro.org>
Signed-off-by: Saravana Kannan <saravanak@...gle.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
Powered by blists - more mailing lists