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

* [PATCH 2/3] drivers: gpio: pcf857x: use subsys_spi_driver()
  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 ` 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
  2 siblings, 1 reply; 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>

Reduce driver init boilerplate by using the new
subsys_spi_driver() macro.

Signed-off-by: Enrico Weigelt <info@metux.net>
---
 drivers/gpio/gpio-max7301.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-max7301.c b/drivers/gpio/gpio-max7301.c
index 647dfbb..30815cf 100644
--- a/drivers/gpio/gpio-max7301.c
+++ b/drivers/gpio/gpio-max7301.c
@@ -86,21 +86,10 @@ static int max7301_remove(struct spi_device *spi)
 	.remove = max7301_remove,
 	.id_table = max7301_id,
 };
-
-static int __init max7301_init(void)
-{
-	return spi_register_driver(&max7301_driver);
-}
 /* register after spi postcore initcall and before
  * subsys initcalls that may rely on these GPIOs
  */
-subsys_initcall(max7301_init);
-
-static void __exit max7301_exit(void)
-{
-	spi_unregister_driver(&max7301_driver);
-}
-module_exit(max7301_exit);
+subsys_spi_driver(max7301_driver);
 
 MODULE_AUTHOR("Juergen Beisert, Wolfram Sang");
 MODULE_LICENSE("GPL v2");
-- 
1.9.1


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

* [PATCH 3/3] drivers: gpio: mc33880: use subsys_spi_driver()
  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-17 18:40 ` Enrico Weigelt, metux IT consult
  2019-06-19 12:14 ` [PATCH 1/3] include: linux: spi: more helpers for declaring spi drivers Mark Brown
  2 siblings, 0 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>

Reduce driver init boilerplate by using the new
subsys_spi_driver() macro.

Signed-off-by: Enrico Weigelt <info@metux.net>
---
 drivers/gpio/gpio-mc33880.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-mc33880.c b/drivers/gpio/gpio-mc33880.c
index f8194f7..1b9434c 100644
--- a/drivers/gpio/gpio-mc33880.c
+++ b/drivers/gpio/gpio-mc33880.c
@@ -156,21 +156,10 @@ static int mc33880_remove(struct spi_device *spi)
 	.remove		= mc33880_remove,
 };
 
-static int __init mc33880_init(void)
-{
-	return spi_register_driver(&mc33880_driver);
-}
 /* register after spi postcore initcall and before
  * subsys initcalls that may rely on these GPIOs
  */
-subsys_initcall(mc33880_init);
-
-static void __exit mc33880_exit(void)
-{
-	spi_unregister_driver(&mc33880_driver);
-}
-module_exit(mc33880_exit);
+subsys_spi_driver(mc33880_driver);
 
 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
 MODULE_LICENSE("GPL v2");
-
-- 
1.9.1


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

* Re: [PATCH 2/3] drivers: gpio: pcf857x: use subsys_spi_driver()
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2019-06-18 13:48 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult
  Cc: Linux Kernel Mailing List, Linus Walleij, Bartosz Golaszewski,
	Mark Brown, open list:GPIO SUBSYSTEM, linux-spi

Hi Enrico,

On Mon, Jun 17, 2019 at 8:41 PM Enrico Weigelt, metux IT consult
<info@metux.net> wrote:
> From: Enrico Weigelt <info@metux.net>
>
> Reduce driver init boilerplate by using the new
> subsys_spi_driver() macro.
>
> Signed-off-by: Enrico Weigelt <info@metux.net>

Thanks for your patch!

>  drivers/gpio/gpio-max7301.c | 13 +------------

s/pcf857x/max7301/ in subject.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/3] include: linux: spi: more helpers for declaring spi drivers
  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-17 18:40 ` [PATCH 3/3] drivers: gpio: mc33880: " Enrico Weigelt, metux IT consult
@ 2019-06-19 12:14 ` Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2019-06-19 12:14 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult
  Cc: linux-kernel, linus.walleij, bgolaszewski, linux-gpio, linux-spi

[-- Attachment #1: Type: text/plain, Size: 825 bytes --]

On Mon, Jun 17, 2019 at 08:40:38PM +0200, Enrico Weigelt, metux IT consult wrote:

> +/* 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) \

I'm not convinced we want to be encouraging anyone to be using
subsys_initcall() for SPI drivers in the first place - my guess would be
that with deferred probing none of that is needed anyway and the driver
could just use module_spi_driver().  Certainly if the drivers do
actually need subsys_initcall() I'd like to understand why before going
forward with something like this, and ideally we'd be able to remove the
need.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[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).