2012-06-28 10:57:57

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 00/12] 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(-)

--
1.7.10


2012-06-28 10:57:58

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 02/12] ACPI/button: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/acpi/button.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index d27d072..15968ef 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -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);
--
1.7.10

2012-06-28 10:58:00

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 08/12] hp_accel: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/platform/x86/hp_accel.c | 25 +------------------------
1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
index 22b2dfa..7246e66 100644
--- a/drivers/platform/x86/hp_accel.c
+++ b/drivers/platform/x86/hp_accel.c
@@ -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);
--
1.7.10

2012-06-28 10:58:07

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 12/12] xo15-ebook: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/platform/x86/xo15-ebook.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/platform/x86/xo15-ebook.c b/drivers/platform/x86/xo15-ebook.c
index fad153d..11a0f30 100644
--- a/drivers/platform/x86/xo15-ebook.c
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -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);
--
1.7.10

2012-06-28 10:58:05

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 11/12] toshiba_bluetooth: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/platform/x86/toshiba_bluetooth.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/drivers/platform/x86/toshiba_bluetooth.c b/drivers/platform/x86/toshiba_bluetooth.c
index 5fb7186..c871a35 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -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);
--
1.7.10

2012-06-28 10:59:05

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 09/12] ideapad: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/platform/x86/ideapad-laptop.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 4f20f8d..b469654 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -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);
--
1.7.10

2012-06-28 10:59:03

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 10/12] topstar-laptop: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/platform/x86/topstar-laptop.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/drivers/platform/x86/topstar-laptop.c b/drivers/platform/x86/topstar-laptop.c
index d528daa..d727bfe 100644
--- a/drivers/platform/x86/topstar-laptop.c
+++ b/drivers/platform/x86/topstar-laptop.c
@@ -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");
--
1.7.10

2012-06-28 10:59:42

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 07/12] Input: atlas_btns - convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/input/misc/atlas_btns.c | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
index 601f737..26f1313 100644
--- a/drivers/input/misc/atlas_btns.c
+++ b/drivers/input/misc/atlas_btns.c
@@ -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");
--
1.7.10

2012-06-28 11:00:03

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 06/12] i2c-scmi: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/i2c/busses/i2c-scmi.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index 388cbdc..6aafa3d 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -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]>");
--
1.7.10

2012-06-28 11:00:30

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 05/12] ACPI/sbshc: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/acpi/sbshc.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
index f8d2a47..cf6129a 100644
--- a/drivers/acpi/sbshc.c
+++ b/drivers/acpi/sbshc.c
@@ -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");
--
1.7.10

2012-06-28 11:00:50

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 04/12] ACPI/hed: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/acpi/hed.c | 20 +-------------------
1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/drivers/acpi/hed.c b/drivers/acpi/hed.c
index d0c1967..20a0f2c 100644
--- a/drivers/acpi/hed.c
+++ b/drivers/acpi/hed.c
@@ -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");
--
1.7.10

2012-06-28 10:57:55

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 01/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).

Signed-off-by: Mika Westerberg <[email protected]>
---
include/acpi/acpi_bus.h | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 9e6e1c6..45d3249 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -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
*/
--
1.7.10

2012-06-28 11:01:15

by Mika Westerberg

[permalink] [raw]
Subject: [PATCH 03/12] ACPI/fan: convert to module_acpi_driver()

Signed-off-by: Mika Westerberg <[email protected]>
---
drivers/acpi/fan.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 0f0356c..b142797 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -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);
--
1.7.10

2012-06-28 23:19:14

by Dmitry Torokhov

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

On Thu, Jun 28, 2012 at 01:59:26PM +0300, Mika Westerberg wrote:
> Signed-off-by: Mika Westerberg <[email protected]>

Acked-by: Dmitry Torokhov <[email protected]>

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

Thanks!

> ---
> drivers/input/misc/atlas_btns.c | 17 +----------------
> 1 file changed, 1 insertion(+), 16 deletions(-)
>
> diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
> index 601f737..26f1313 100644
> --- a/drivers/input/misc/atlas_btns.c
> +++ b/drivers/input/misc/atlas_btns.c
> @@ -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");
> --
> 1.7.10
>

--
Dmitry

2012-06-29 07:53:04

by Éric Piel

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

On 28-06-12 12:59, Mika Westerberg wrote:
> Signed-off-by: Mika Westerberg <[email protected]>
Hello,
Looks fine from my point of view.

Reviewed-by: Éric Piel <[email protected]>

Éric

> ---
> drivers/platform/x86/hp_accel.c | 25 +------------------------
> 1 file changed, 1 insertion(+), 24 deletions(-)
>
> diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
> index 22b2dfa..7246e66 100644
> --- a/drivers/platform/x86/hp_accel.c
> +++ b/drivers/platform/x86/hp_accel.c
> @@ -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);
>

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

On Thu, Jun 28, 2012 at 01:59:29PM +0300, Mika Westerberg wrote:
> Signed-off-by: Mika Westerberg <[email protected]>
> ---
> drivers/platform/x86/topstar-laptop.c | 22 +---------------------
> 1 file changed, 1 insertion(+), 21 deletions(-)

Acked-by: Herton R. Krzesinski <[email protected]>

>
> diff --git a/drivers/platform/x86/topstar-laptop.c b/drivers/platform/x86/topstar-laptop.c
> index d528daa..d727bfe 100644
> --- a/drivers/platform/x86/topstar-laptop.c
> +++ b/drivers/platform/x86/topstar-laptop.c
> @@ -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");
> --
> 1.7.10
>

--
[]'s
Herton