For some devices especially on platform/I2C/SPI bus, they want to be initialized earlier than other devices, so the driver use initcall such as subsys_initcall to make this device initialize earlier.
But for those drivers, lots of them just do nothing special in xxx_initcall/exit, so introduce a helper macro initcall_driver() to eliminate lots of boilerplate just like module_driver() did.
Signed-off-by: Hanjun Guo hanjun.guo@linaro.org --- include/linux/device.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/include/linux/device.h b/include/linux/device.h index 2a9d6ed..1903f7f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1198,4 +1198,31 @@ static void __exit __driver##_exit(void) \ } \ module_exit(__driver##_exit);
+/** + * initcall_driver() - Helper macro for drivers that don't do anything + * special in buid-in module xxx_initcall/exit. This eliminates a lot + * of boilerplate. Each driver may only use this macro once, and calling + * it replaces xxx_initcall() and module_exit(). + * + * @__type: initcall type + * @__driver: driver name + * @__register: register function for this driver type + * @__unregister: unregister function for this driver type + * @...: Additional arguments to be passed to __register and __unregister. + * + * Use this macro to construct bus specific macros for registering + * drivers, and do not use it on its own. + */ +#define initcall_driver(__type, __driver, __register, __unregister, ...) \ +static int __init __driver##_init(void) \ +{ \ + return __register(&(__driver) , ##__VA_ARGS__); \ +} \ +__type##_initcall(__driver##_init); \ +static void __exit __driver##_exit(void) \ +{ \ + __unregister(&(__driver) , ##__VA_ARGS__); \ +} \ +module_exit(__driver##_exit); + #endif /* _DEVICE_H_ */