aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2011-11-16 04:13:35 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-11-17 15:05:00 -0500
commit907d0ed1c84114d4e8dafd66af982515d3739c90 (patch)
treefaf964abead72d572d686e25945ec237c9e635d2 /include
parent377195c438fc5e9e4ca59e69382c10771d817d6a (diff)
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: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Jonathan Cameron <jic23@kernel.org> Acked-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include')
-rw-r--r--include/linux/device.h21
-rw-r--r--include/linux/platform_device.h12
2 files changed, 23 insertions, 10 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index c6335982774c..341fb740d851 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -922,4 +922,25 @@ extern long sysfs_deprecated;
922#define sysfs_deprecated 0 922#define sysfs_deprecated 0
923#endif 923#endif
924 924
925/**
926 * module_driver() - Helper macro for drivers that don't do anything
927 * special in module init/exit. This eliminates a lot of boilerplate.
928 * Each module may only use this macro once, and calling it replaces
929 * module_init() and module_exit().
930 *
931 * Use this macro to construct bus specific macros for registering
932 * drivers, and do not use it on its own.
933 */
934#define module_driver(__driver, __register, __unregister) \
935static int __init __driver##_init(void) \
936{ \
937 return __register(&(__driver)); \
938} \
939module_init(__driver##_init); \
940static void __exit __driver##_exit(void) \
941{ \
942 __unregister(&(__driver)); \
943} \
944module_exit(__driver##_exit);
945
925#endif /* _DEVICE_H_ */ 946#endif /* _DEVICE_H_ */
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 2a23f7d1a825..165a8d175370 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -196,16 +196,8 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data
196 * calling it replaces module_init() and module_exit() 196 * calling it replaces module_init() and module_exit()
197 */ 197 */
198#define module_platform_driver(__platform_driver) \ 198#define module_platform_driver(__platform_driver) \
199static int __init __platform_driver##_init(void) \ 199 module_driver(__platform_driver, platform_driver_register, \
200{ \ 200 platform_driver_unregister)
201 return platform_driver_register(&(__platform_driver)); \
202} \
203module_init(__platform_driver##_init); \
204static void __exit __platform_driver##_exit(void) \
205{ \
206 platform_driver_unregister(&(__platform_driver)); \
207} \
208module_exit(__platform_driver##_exit);
209 201
210extern struct platform_device *platform_create_bundle(struct platform_driver *driver, 202extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
211 int (*probe)(struct platform_device *), 203 int (*probe)(struct platform_device *),