linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] include: linux: spi: more helpers for declaring spi drivers
@ 2019-06-17 18:40 Enrico Weigelt, metux IT consult
  2019-06-17 18:40 ` [PATCH 2/3] drivers: gpio: pcf857x: use subsys_spi_driver() Enrico Weigelt, metux IT consult
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-17 18:40 UTC (permalink / raw)
  To: linux-kernel; +Cc: linus.walleij, bgolaszewski, broonie, linux-gpio, linux-spi

From: Enrico Weigelt <info@metux.net>

Add more helper macros for trivial driver init cases, similar to the
already existing module_spi_driver()+friends - now for those which
are initialized at other stages (eg. by subsys_initcall()).

This helps to further reduce driver init boilerplate.

Signed-off-by: Enrico Weigelt <info@metux.net>
---
 include/linux/spi/spi.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 053abd2..f55ba34 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -296,6 +296,23 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
 	module_driver(__spi_driver, spi_register_driver, \
 			spi_unregister_driver)
 
+/* subsys_spi_driver() - Helper macro for drivers that don't do
+ * anything special in module init/exit.  This eliminates a lot of
+ * boilerplate.  Each module may only use this macro once, and
+ * calling it replaces subsys_initcall() and module_exit()
+ */
+#define subsys_spi_driver(__spi_driver) \
+static int __init __spi_driver##_init(void) \
+{ \
+	return spi_register_driver(&(__spi_driver)); \
+} \
+subsys_initcall(__spi_driver##_init); \
+static void __exit __spi_driver##_exit(void) \
+{ \
+	spi_unregister_driver(&(__spi_driver)); \
+} \
+module_exit(__spi_driver##_exit);
+
 /**
  * struct spi_controller - interface to SPI master or slave controller
  * @dev: device interface to this driver
-- 
1.9.1


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

end of thread, other threads:[~2019-06-19 12:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17 18:40 [PATCH 1/3] include: linux: spi: more helpers for declaring spi drivers Enrico Weigelt, metux IT consult
2019-06-17 18:40 ` [PATCH 2/3] drivers: gpio: pcf857x: use subsys_spi_driver() Enrico Weigelt, metux IT consult
2019-06-18 13:48   ` Geert Uytterhoeven
2019-06-17 18:40 ` [PATCH 3/3] drivers: gpio: mc33880: " Enrico Weigelt, metux IT consult
2019-06-19 12:14 ` [PATCH 1/3] include: linux: spi: more helpers for declaring spi drivers Mark Brown

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).