Subject: [PATCH] [acpi driver model] Add macro helpers for drivers - Create declaration macros for reducing the busywork of defining a driver. - declare_acpi_driver(name, ...) declares - a struct acpi_device_driver - An ID structure (an array of char * ids passed the macro) - The init/exit functions, along with module_{init,exit} declarations Signed-off-by: Patrick Mochel --- include/acpi/driver.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) applies-to: ebeba82107a40297655c99ce876bfef40e53b756 15f9dc60ffd7d019aaf33c3fb13efa19c62c684d diff --git a/include/acpi/driver.h b/include/acpi/driver.h index b387aa8..e7d3312 100644 --- a/include/acpi/driver.h +++ b/include/acpi/driver.h @@ -24,4 +24,49 @@ struct acpi_device_driver { }; +extern int acpi_driver_register(struct acpi_device_driver *); +extern void acpi_driver_unregister(struct acpi_device_driver *); + + + +#define __decl_acpi_ids(__name, ...) \ + static const char * __name##_ids[] = { __VA_ARGS__ } + +#define __decl_acpi_driver(__name) \ +static struct acpi_device_driver __name##_driver = { \ + .d_ids = __name##_ids, \ + .d_num_ids = ARRAY_SIZE(__name##_ids), \ + \ + .d_add = __name##_add, \ + .d_remove = __name##_remove, \ + \ + .d_start = __name##_start, \ + .d_stop = __name##_stop, \ + \ + .d_shutdown = __name##_shutdown, \ + .d_suspend = __name##_suspend, \ + .d_resume = __name##_resume, \ + \ + .d_drv = { \ + .name = __stringify(__name), \ + }, \ +} + +#define __acpi_driver_init(__name) \ +static int acpi_##__name##_init(void) \ +{ \ + return acpi_driver_register(&__name##_driver); \ +} \ +module_init(acpi_##__name##_init); \ +static void acpi_##__name##_exit(void) \ +{ \ + acpi_driver_unregister(&__name##_driver); \ +} \ +module_exit(acpi_##__name##_exit); + +#define declare_acpi_driver(__name, ...) \ + __decl_acpi_ids(__name, __VA_ARGS__ ); \ + __decl_acpi_driver(__name); \ + __acpi_driver_init(__name); + #endif /* _INCLUDE_ACPI_DRIVER_ */ --- 0.99.9.GIT