diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2011-11-16 10:13:35 +0100 |
---|---|---|
committer | Rohan Somvanshi <rsomvanshi@nvidia.com> | 2012-04-16 03:49:10 -0700 |
commit | e05aca5fe7209a88c6af141cac4dd93365d1abf9 (patch) | |
tree | c733b0ae5ad1fd0b4611e1e2a3df5e24d10cafe6 /include | |
parent | 2354c8673da7a7d990803c966ad34e8880e177e5 (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>
Cherry-picked from mainline commit
907d0ed1c84114d4e8dafd66af982515d3739c90
Change-Id: Ib83ecc2ca10c53c84ab8ffbc94ee8212d72c2993
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/95640
Reviewed-by: Automatic_Commit_Validation_User
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/device.h | 21 | ||||
-rw-r--r-- | include/linux/platform_device.h | 9 |
2 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 28c35f876b19..62608d13da3c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -913,4 +913,25 @@ extern long sysfs_deprecated; #define sysfs_deprecated 0 #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_ */ diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 27bb05aae70d..6e25b3c1fc39 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -146,6 +146,15 @@ static inline void platform_set_drvdata(struct platform_device *pdev, void *data dev_set_drvdata(&pdev->dev, data); } +/* module_platform_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() + */ +#define module_platform_driver(__platform_driver) \ + module_driver(__platform_driver, platform_driver_register, \ + platform_driver_unregister) + extern struct platform_device *platform_create_bundle(struct platform_driver *driver, int (*probe)(struct platform_device *), struct resource *res, unsigned int n_res, |