[PATCH 1/4] mod_devicetable: helper macro for declaring oftree module device table

From
Enrico Weigelt, metux IT consult <info@metux.net>
Date
2019-06-01 13:53:37
Also in
linux-block, linux-ide, lkml
Reply to
Enrico Weigelt, metux IT consult, 2019-06-01
Little helper macros that declares an oftree module device table,
if CONFIG_OF is enabled. Otherwise it's just noop. Helpful for
reducing the number of #ifdef's.

Instead of:
    MODULE_DEVICE_TABLE(of, foo);
now use:
    MODULE_OF_TABLE(foo);

Or declare the whole table via:
    MODULE_DECLARE_OF_TABLE(foo,
        { .compatible = "foo" },
        { .compatible = "bar" });

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 include/linux/mod_devicetable.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 448621c..5f4f2dc8 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -245,6 +245,19 @@ struct of_device_id {
 	const void *data;
 };
 
+/*
+ * macro for adding the of module device table only if CONFIG_OF enabled
+ */
+#ifdef CONFIG_OF
+#define MODULE_OF_TABLE(name)	MODULE_DEVICE_TABLE(of,name)
+#define MODULE_DECLARE_OF_TABLE(name,entries...) \
+static const struct of_device_id name[] = { entries, {} };
+#else
+#define MODULE_OF_TABLE(name)
+#define MODULE_DECLARE_OF_TABLE(name,entries...) \
+static const struct of_device_id *name = NULL;
+#endif /* CONFIG_OF */
+
 /* VIO */
 struct vio_device_id {
 	char type[32];
-- 
1.9.1
Thread (5 messages) 5 messages, 1 author, last reply 2019-06-01
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help