提交 907d0ed1 编写于 作者: L Lars-Peter Clausen 提交者: Greg Kroah-Hartman

drivercore: Generalize module_platform_driver

This patch generalizes the module_platform_driver macro and introduces a new
module_driver macro. The module_driver macro takes a driver name, a register
and a unregister function for this driver type. Using these it construct the
module init and exit sections which register and unregister the driver. Since
such init/exit sections are commonly found in drivers this macro can be used
to eliminate a lot of boilerplate code.

The macro is not intended to be used by driver modules directly, instead it
should be used to generate bus specific macros for registering drivers like
the module_platform_driver macro.
Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
Acked-by: NGrant Likely <grant.likely@secretlab.ca>
Acked-by: NJonathan Cameron <jic23@kernel.org>
Acked-by: NWolfram Sang <w.sang@pengutronix.de>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 377195c4
...@@ -922,4 +922,25 @@ extern long sysfs_deprecated; ...@@ -922,4 +922,25 @@ extern long sysfs_deprecated;
#define sysfs_deprecated 0 #define sysfs_deprecated 0
#endif #endif
/**
* module_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
* module_init() and module_exit().
*
* Use this macro to construct bus specific macros for registering
* drivers, and do not use it on its own.
*/
#define module_driver(__driver, __register, __unregister) \
static int __init __driver##_init(void) \
{ \
return __register(&(__driver)); \
} \
module_init(__driver##_init); \
static void __exit __driver##_exit(void) \
{ \
__unregister(&(__driver)); \
} \
module_exit(__driver##_exit);
#endif /* _DEVICE_H_ */ #endif /* _DEVICE_H_ */
...@@ -196,16 +196,8 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data ...@@ -196,16 +196,8 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data
* calling it replaces module_init() and module_exit() * calling it replaces module_init() and module_exit()
*/ */
#define module_platform_driver(__platform_driver) \ #define module_platform_driver(__platform_driver) \
static int __init __platform_driver##_init(void) \ module_driver(__platform_driver, platform_driver_register, \
{ \ platform_driver_unregister)
return platform_driver_register(&(__platform_driver)); \
} \
module_init(__platform_driver##_init); \
static void __exit __platform_driver##_exit(void) \
{ \
platform_driver_unregister(&(__platform_driver)); \
} \
module_exit(__platform_driver##_exit);
extern struct platform_device *platform_create_bundle(struct platform_driver *driver, extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
int (*probe)(struct platform_device *), int (*probe)(struct platform_device *),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册