Skip to contentSkip to conversation

ACPI: add module_acpi_driver() and convert drivers to it

PATCH Superseded Mika Westerberg 6 participants 19 messages Jun 28, 2012 – Jul 13, 2012

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover ACPI: add module_acpi_driver() and convert drivers to it

This is similar than what is done for other busses before (PCI, I2C, SPI, platform). It reduces a lot of unnecessary boilerplate code from modules.

We also remove following redundant check on few drivers:

	if (acpi_disabled)
		return -ENODEV;

as this same check is already done at the beginning of acpi_bus_register_driver().

I think these should all go via ACPI tree because they all depend on the first patch which adds the macro to the ACPI subsystem.

Mika Westerberg (12):
ACPI: introduce module_acpi_driver() helper macro ACPI/button: convert to module_acpi_driver() ACPI/fan: convert to module_acpi_driver() ACPI/hed: convert to module_acpi_driver() ACPI/sbshc: convert to module_acpi_driver()
i2c-scmi: convert to module_acpi_driver()
Input: atlas_btns - convert to module_acpi_driver()
hp_accel: convert to module_acpi_driver()
ideapad: convert to module_acpi_driver()
topstar-laptop: convert to module_acpi_driver()
toshiba_bluetooth: convert to module_acpi_driver()
xo15-ebook: convert to module_acpi_driver()

 drivers/acpi/button.c                    |   13 +------------
 drivers/acpi/fan.c                       |   22 +---------------------
 drivers/acpi/hed.c                       |   20 +-------------------
 drivers/acpi/sbshc.c                     |   18 +-----------------
 drivers/i2c/busses/i2c-scmi.c            |   14 +-------------
 drivers/input/misc/atlas_btns.c          |   17 +----------------
 drivers/platform/x86/hp_accel.c          |   25 +------------------------
 drivers/platform/x86/ideapad-laptop.c    |   14 +-------------
 drivers/platform/x86/topstar-laptop.c    |   22 +---------------------
 drivers/platform/x86/toshiba_bluetooth.c |   22 +---------------------
 drivers/platform/x86/xo15-ebook.c        |   14 +-------------
 include/acpi/acpi_bus.h                  |   13 +++++++++++++
 12 files changed, 24 insertions(+), 190 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/12 ACPI: introduce module_acpi_driver() helper macro

Add a helper macro module_acpi_driver() which reduces the boilerplate code for ACPI drivers. This is similar what is done for other busses (PCI, SPI, I2C etc).

---
 include/acpi/acpi_bus.h |   13 +++++++++++++
 1 file changed, 13 insertions(+)
include/acpi/acpi_bus.h +13 -0
index 9e6e1c6..45d3249 100644
@@ -376,6 +376,19 @@ int acpi_match_device_ids(struct acpi_device *device,
 int acpi_create_dir(struct acpi_device *);
 void acpi_remove_dir(struct acpi_device *);
 
+
+/**
+ * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver
+ * @__acpi_driver: acpi_driver struct
+ *
+ * Helper macro for ACPI drivers which do not 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_acpi_driver(__acpi_driver) \
+	module_driver(__acpi_driver, acpi_bus_register_driver, \
+		      acpi_bus_unregister_driver)
+
 /*
  * Bind physical devices with ACPI devices
  */
Signature · 1 line
1.7.10
#2 lore raw

PATCH 2/12 ACPI/button: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/acpi/button.c |   13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/acpi/button.c +1 -12
index d27d072..15968ef 100644
@@ -443,15 +443,4 @@ static int acpi_button_remove(struct acpi_device *device, int type)
 	return 0;
 }
 
-static int __init acpi_button_init(void)
-{
-	return acpi_bus_register_driver(&acpi_button_driver);
-}
-
-static void __exit acpi_button_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_button_driver);
-}
-
-module_init(acpi_button_init);
-module_exit(acpi_button_exit);
+module_acpi_driver(acpi_button_driver);
Signature · 1 line
1.7.10
#3 lore raw

PATCH 3/12 ACPI/fan: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/acpi/fan.c |   22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/acpi/fan.c +1 -21
index 0f0356c..b142797 100644
@@ -207,24 +207,4 @@ static int acpi_fan_resume(struct acpi_device *device)
 	return result;
 }
 
-static int __init acpi_fan_init(void)
-{
-	int result = 0;
-
-	result = acpi_bus_register_driver(&acpi_fan_driver);
-	if (result < 0)
-		return -ENODEV;
-
-	return 0;
-}
-
-static void __exit acpi_fan_exit(void)
-{
-
-	acpi_bus_unregister_driver(&acpi_fan_driver);
-
-	return;
-}
-
-module_init(acpi_fan_init);
-module_exit(acpi_fan_exit);
+module_acpi_driver(acpi_fan_driver);
Signature · 1 line
1.7.10
#4 lore raw

PATCH 4/12 ACPI/hed: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/acpi/hed.c |   20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/acpi/hed.c +1 -19
index d0c1967..20a0f2c 100644
@@ -86,25 +86,7 @@ static struct acpi_driver acpi_hed_driver = {
 		.notify = acpi_hed_notify,
 	},
 };
-
-static int __init acpi_hed_init(void)
-{
-	if (acpi_disabled)
-		return -ENODEV;
-
-	if (acpi_bus_register_driver(&acpi_hed_driver) < 0)
-		return -ENODEV;
-
-	return 0;
-}
-
-static void __exit acpi_hed_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_hed_driver);
-}
-
-module_init(acpi_hed_init);
-module_exit(acpi_hed_exit);
+module_acpi_driver(acpi_hed_driver);
 
 ACPI_MODULE_NAME("hed");
 MODULE_AUTHOR("Huang Ying");
Signature · 1 line
1.7.10
#5 lore raw

PATCH 5/12 ACPI/sbshc: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/acpi/sbshc.c |   18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/acpi/sbshc.c +1 -17
index f8d2a47..cf6129a 100644
@@ -310,23 +310,7 @@ static int acpi_smbus_hc_remove(struct acpi_device *device, int type)
 	return 0;
 }
 
-static int __init acpi_smb_hc_init(void)
-{
-	int result;
-
-	result = acpi_bus_register_driver(&acpi_smb_hc_driver);
-	if (result < 0)
-		return -ENODEV;
-	return 0;
-}
-
-static void __exit acpi_smb_hc_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_smb_hc_driver);
-}
-
-module_init(acpi_smb_hc_init);
-module_exit(acpi_smb_hc_exit);
+module_acpi_driver(acpi_smb_hc_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Alexey Starikovskiy");
Signature · 1 line
1.7.10
#6 lore raw

PATCH 6/12 i2c-scmi: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/i2c/busses/i2c-scmi.c |   14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/i2c/busses/i2c-scmi.c +1 -13
index 388cbdc..6aafa3d 100644
@@ -426,19 +426,7 @@ static struct acpi_driver acpi_smbus_cmi_driver = {
 		.remove = acpi_smbus_cmi_remove,
 	},
 };
-
-static int __init acpi_smbus_cmi_init(void)
-{
-	return acpi_bus_register_driver(&acpi_smbus_cmi_driver);
-}
-
-static void __exit acpi_smbus_cmi_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_smbus_cmi_driver);
-}
-
-module_init(acpi_smbus_cmi_init);
-module_exit(acpi_smbus_cmi_exit);
+module_acpi_driver(acpi_smbus_cmi_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Crane Cai <[email protected]>");
Signature · 1 line
1.7.10
Acked-by on v1 6/12
#7 lore raw

Re: [PATCH 06/12] i2c-scmi: convert to module_acpi_driver()

Quoted 20 lines · Mika Westerberg
---
 drivers/i2c/busses/i2c-scmi.c |   14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/i2c/busses/i2c-scmi.c +0 -7
index 388cbdc..6aafa3d 100644
@@ -426,19 +426,7 @@ static struct acpi_driver acpi_smbus_cmi_driver = {
 		.remove = acpi_smbus_cmi_remove,
 	},
 };
-
-static int __init acpi_smbus_cmi_init(void)
-{
-	return acpi_bus_register_driver(&acpi_smbus_cmi_driver);
-}
-
-static void __exit acpi_smbus_cmi_exit(void)

drivers/i2c/busses/i2c-scmi.c static struct acpi_driver acpi_smbus_cmi_driver = { · line 432

Quoted 10 lines
drivers/i2c/busses/i2c-scmi.c +1 -6
-{
-	acpi_bus_unregister_driver(&acpi_smbus_cmi_driver);
-}
-
-module_init(acpi_smbus_cmi_init);
-module_exit(acpi_smbus_cmi_exit);
+module_acpi_driver(acpi_smbus_cmi_driver);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Crane Cai <[email protected]>");
Signature · 1 line
Jean Delvare
#8 lore raw

PATCH 7/12 Input: atlas_btns - convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/input/misc/atlas_btns.c |   17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
drivers/input/misc/atlas_btns.c +1 -16
index 601f737..26f1313 100644
@@ -151,22 +151,7 @@ static struct acpi_driver atlas_acpi_driver = {
 		.remove	= atlas_acpi_button_remove,
 	},
 };
-
-static int __init atlas_acpi_init(void)
-{
-	if (acpi_disabled)
-		return -ENODEV;
-
-	return acpi_bus_register_driver(&atlas_acpi_driver);
-}
-
-static void __exit atlas_acpi_exit(void)
-{
-	acpi_bus_unregister_driver(&atlas_acpi_driver);
-}
-
-module_init(atlas_acpi_init);
-module_exit(atlas_acpi_exit);
+module_acpi_driver(atlas_acpi_driver);
 
 MODULE_AUTHOR("Jaya Kumar");
 MODULE_LICENSE("GPL");
Signature · 1 line
1.7.10
maintainer Acked-by on v1 7/12
#9 lore raw

Re: [PATCH 07/12] Input: atlas_btns - convert to module_acpi_driver()

Quoted 1 line · Mika Westerberg

Please feel free to merge with the rest of the series.

Thanks!

Quoted 35 lines
---
 drivers/input/misc/atlas_btns.c |   17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
drivers/input/misc/atlas_btns.c +1 -16
index 601f737..26f1313 100644
@@ -151,22 +151,7 @@ static struct acpi_driver atlas_acpi_driver = {
 		.remove	= atlas_acpi_button_remove,
 	},
 };
-
-static int __init atlas_acpi_init(void)
-{
-	if (acpi_disabled)
-		return -ENODEV;
-
-	return acpi_bus_register_driver(&atlas_acpi_driver);
-}
-
-static void __exit atlas_acpi_exit(void)
-{
-	acpi_bus_unregister_driver(&atlas_acpi_driver);
-}
-
-module_init(atlas_acpi_init);
-module_exit(atlas_acpi_exit);
+module_acpi_driver(atlas_acpi_driver);
 
 MODULE_AUTHOR("Jaya Kumar");
 MODULE_LICENSE("GPL");
Signature · 1 line
1.7.10
Signature · 1 line
Dmitry
#10 lore raw

PATCH 8/12 hp_accel: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/platform/x86/hp_accel.c |   25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
drivers/platform/x86/hp_accel.c +1 -24
index 22b2dfa..7246e66 100644
@@ -381,31 +381,8 @@ static struct acpi_driver lis3lv02d_driver = {
 		.resume  = lis3lv02d_resume,
 	}
 };
-
-static int __init lis3lv02d_init_module(void)
-{
-	int ret;
-
-	if (acpi_disabled)
-		return -ENODEV;
-
-	ret = acpi_bus_register_driver(&lis3lv02d_driver);
-	if (ret < 0)
-		return ret;
-
-	pr_info("driver loaded\n");
-
-	return 0;
-}
-
-static void __exit lis3lv02d_exit_module(void)
-{
-	acpi_bus_unregister_driver(&lis3lv02d_driver);
-}
+module_acpi_driver(lis3lv02d_driver);
 
 MODULE_DESCRIPTION("Glue between LIS3LV02Dx and HP ACPI BIOS and support for disk protection LED.");
 MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
 MODULE_LICENSE("GPL");
-
-module_init(lis3lv02d_init_module);
-module_exit(lis3lv02d_exit_module);
Signature · 1 line
1.7.10
Reviewed-by on v1 8/12
#11 lore raw

Re: [PATCH 08/12] hp_accel: convert to module_acpi_driver()

Quoted 1 line · Mika Westerberg

Hello,
Looks fine from my point of view.

Éric

Quoted 32 lines
---
  drivers/platform/x86/hp_accel.c |   25 +------------------------
  1 file changed, 1 insertion(+), 24 deletions(-)
drivers/platform/x86/hp_accel.c +0 -19
index 22b2dfa..7246e66 100644
@@ -381,31 +381,8 @@ static struct acpi_driver lis3lv02d_driver = {
  		.resume  = lis3lv02d_resume,
  	}
  };
-
-static int __init lis3lv02d_init_module(void)
-{
-	int ret;
-
-	if (acpi_disabled)
-		return -ENODEV;
-
-	ret = acpi_bus_register_driver(&lis3lv02d_driver);
-	if (ret < 0)
-		return ret;
-
-	pr_info("driver loaded\n");
-
-	return 0;
-}
-
-static void __exit lis3lv02d_exit_module(void)
-{

drivers/platform/x86/hp_accel.c static struct acpi_driver lis3lv02d_driver = { · line 411

Quoted 10 lines
drivers/platform/x86/hp_accel.c +1 -5
-	acpi_bus_unregister_driver(&lis3lv02d_driver);
-}
+module_acpi_driver(lis3lv02d_driver);
 
  MODULE_DESCRIPTION("Glue between LIS3LV02Dx and HP ACPI BIOS and support for disk protection LED.");
  MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
  MODULE_LICENSE("GPL");
-
-module_init(lis3lv02d_init_module);
-module_exit(lis3lv02d_exit_module);

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

PATCH 9/12 ideapad: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/platform/x86/ideapad-laptop.c |   14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/platform/x86/ideapad-laptop.c +1 -13
index 4f20f8d..b469654 100644
@@ -813,20 +813,8 @@ static struct acpi_driver ideapad_acpi_driver = {
 	.ops.notify = ideapad_acpi_notify,
 	.owner = THIS_MODULE,
 };
-
-static int __init ideapad_acpi_module_init(void)
-{
-	return acpi_bus_register_driver(&ideapad_acpi_driver);
-}
-
-static void __exit ideapad_acpi_module_exit(void)
-{
-	acpi_bus_unregister_driver(&ideapad_acpi_driver);
-}
+module_acpi_driver(ideapad_acpi_driver);
 
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
 MODULE_LICENSE("GPL");
-
-module_init(ideapad_acpi_module_init);
-module_exit(ideapad_acpi_module_exit);
Signature · 1 line
1.7.10
Acked-by on v1 9/12
#13 lore raw

Re: [PATCH 09/12] ideapad: convert to module_acpi_driver()

Quoted 1 line · Mika Westerberg
Quoted 31 lines
---
 drivers/platform/x86/ideapad-laptop.c |   14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/platform/x86/ideapad-laptop.c +1 -13
index 4f20f8d..b469654 100644
@@ -813,20 +813,8 @@ static struct acpi_driver ideapad_acpi_driver = {
 	.ops.notify = ideapad_acpi_notify,
 	.owner = THIS_MODULE,
 };
-
-static int __init ideapad_acpi_module_init(void)
-{
-	return acpi_bus_register_driver(&ideapad_acpi_driver);
-}
-
-static void __exit ideapad_acpi_module_exit(void)
-{
-	acpi_bus_unregister_driver(&ideapad_acpi_driver);
-}
+module_acpi_driver(ideapad_acpi_driver);
 
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
 MODULE_DESCRIPTION("IdeaPad ACPI Extras");
 MODULE_LICENSE("GPL");
-
-module_init(ideapad_acpi_module_init);
-module_exit(ideapad_acpi_module_exit);
#14 lore raw

PATCH 10/12 topstar-laptop: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/platform/x86/topstar-laptop.c |   22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/platform/x86/topstar-laptop.c +1 -21
index d528daa..d727bfe 100644
@@ -186,27 +186,7 @@ static struct acpi_driver acpi_topstar_driver = {
 		.notify = acpi_topstar_notify,
 	},
 };
-
-static int __init topstar_laptop_init(void)
-{
-	int ret;
-
-	ret = acpi_bus_register_driver(&acpi_topstar_driver);
-	if (ret < 0)
-		return ret;
-
-	pr_info("ACPI extras driver loaded\n");
-
-	return 0;
-}
-
-static void __exit topstar_laptop_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_topstar_driver);
-}
-
-module_init(topstar_laptop_init);
-module_exit(topstar_laptop_exit);
+module_acpi_driver(acpi_topstar_driver);
 
 MODULE_AUTHOR("Herton Ronaldo Krzesinski");
 MODULE_DESCRIPTION("Topstar Laptop ACPI Extras driver");
Signature · 1 line
1.7.10
Acked-by Herton R. Krzesinski on v1 10/12
#15 lore raw

Re: [PATCH 10/12] topstar-laptop: convert to module_acpi_driver()

Quoted 4 lines · Mika Westerberg
---
 drivers/platform/x86/topstar-laptop.c |   22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)
Quoted 37 lines
drivers/platform/x86/topstar-laptop.c +1 -21
index d528daa..d727bfe 100644
@@ -186,27 +186,7 @@ static struct acpi_driver acpi_topstar_driver = {
 		.notify = acpi_topstar_notify,
 	},
 };
-
-static int __init topstar_laptop_init(void)
-{
-	int ret;
-
-	ret = acpi_bus_register_driver(&acpi_topstar_driver);
-	if (ret < 0)
-		return ret;
-
-	pr_info("ACPI extras driver loaded\n");
-
-	return 0;
-}
-
-static void __exit topstar_laptop_exit(void)
-{
-	acpi_bus_unregister_driver(&acpi_topstar_driver);
-}
-
-module_init(topstar_laptop_init);
-module_exit(topstar_laptop_exit);
+module_acpi_driver(acpi_topstar_driver);
 
 MODULE_AUTHOR("Herton Ronaldo Krzesinski");
 MODULE_DESCRIPTION("Topstar Laptop ACPI Extras driver");
Signature · 1 line
1.7.10
Signature · 2 lines
[]'s
Herton
#16 lore raw

PATCH 11/12 toshiba_bluetooth: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/platform/x86/toshiba_bluetooth.c |   22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)
drivers/platform/x86/toshiba_bluetooth.c +1 -21
index 5fb7186..c871a35 100644
@@ -116,30 +116,10 @@ static int toshiba_bt_rfkill_add(struct acpi_device *device)
 	return result;
 }
 
-static int __init toshiba_bt_rfkill_init(void)
-{
-	int result;
-
-	result = acpi_bus_register_driver(&toshiba_bt_rfkill_driver);
-	if (result < 0) {
-		ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
-				  "Error registering driver\n"));
-		return result;
-	}
-
-	return 0;
-}
-
 static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type)
 {
 	/* clean up */
 	return 0;
 }
 
-static void __exit toshiba_bt_rfkill_exit(void)
-{
-	acpi_bus_unregister_driver(&toshiba_bt_rfkill_driver);
-}
-
-module_init(toshiba_bt_rfkill_init);
-module_exit(toshiba_bt_rfkill_exit);
+module_acpi_driver(toshiba_bt_rfkill_driver);
Signature · 1 line
1.7.10
#17 lore raw

PATCH 12/12 xo15-ebook: convert to module_acpi_driver()

In reply to Mika Westerberg
---
 drivers/platform/x86/xo15-ebook.c |   14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/platform/x86/xo15-ebook.c +1 -13
index fad153d..11a0f30 100644
@@ -166,16 +166,4 @@ static struct acpi_driver xo15_ebook_driver = {
 		.notify = ebook_switch_notify,
 	},
 };
-
-static int __init xo15_ebook_init(void)
-{
-	return acpi_bus_register_driver(&xo15_ebook_driver);
-}
-
-static void __exit xo15_ebook_exit(void)
-{
-	acpi_bus_unregister_driver(&xo15_ebook_driver);
-}
-
-module_init(xo15_ebook_init);
-module_exit(xo15_ebook_exit);
+module_acpi_driver(xo15_ebook_driver);
Signature · 1 line
1.7.10
#18 lore raw
In reply to Mika Westerberg
Quoted 5 lines · Mika Westerberg

This is similar than what is done for other busses before (PCI, I2C, SPI, platform). It reduces a lot of unnecessary boilerplate code from modules.

We also remove following redundant check on few drivers:

Quoted 8 lines
	if (acpi_disabled)
		return -ENODEV;

as this same check is already done at the beginning of acpi_bus_register_driver().

I think these should all go via ACPI tree because they all depend on the first patch which adds the macro to the ACPI subsystem.

Len, do you have any comments? Could you consider merging these patches?

Thanks.