platform/x86: hp_accel: Clean up and convert
v2 cover platform/x86: hp_accel: Clean up and convert
The pure ACPI drivers are not needed since we have a platform glue layer in place. This allow to drop a lot of boiler plate code and duplication.
Patch 1 remove confusing call to _INI method and citing myself from v1:
"Not sure what buys us to run _INI on PM calls. It's against the spec
AFAICT. In any case ACPICA runs _INI as per specification when devices are instantiated."
Patch 2 converts to platform driver.
Both needs to be tested, that's why Hans mentioned Kai-Heng.
Changelog v2:
- split to two patches (Hans)
- Cc'ed to Kai-Heng (Hans)
- removed stale data structure field in the header file
Andy Shevchenko (2):
platform/x86: hp_accel: Remove _INI method call platform/x86: hp_accel: Convert to be a platform driver
drivers/misc/lis3lv02d/lis3lv02d.h | 1 - drivers/platform/x86/hp_accel.c | 78 ++++++------------------------ 2 files changed, 15 insertions(+), 64 deletions(-)
Signature · 1 line
2.32.0
PATCH v2 1/2 platform/x86: hp_accel: Remove _INI method call
According to ACPI specification the _INI method must be called when device is enumerated first time. After that there is no need to repeat the procedure. Convert the lis3lv02d_acpi_init() to be a stub (Note, we may not remove it because it is called unconditionally by the accelerometer main driver).
--- drivers/misc/lis3lv02d/lis3lv02d.h | 1 - drivers/platform/x86/hp_accel.c | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-)
drivers/misc/lis3lv02d/lis3lv02d.h +0 -1
@@ -271,7 +271,6 @@ struct lis3lv02d {int regs_size;u8 *reg_cache;bool regs_stored; -bool init_required;u8 odr_mask;/* ODR bit mask */ u8 whoami;/* indicates measurement precision */ s16 (*read_data) (struct lis3lv02d *lis3,int reg);
drivers/platform/x86/hp_accel.c +1 -13
@@ -78,23 +78,14 @@ static const struct acpi_device_id lis3lv02d_device_ids[] = { };MODULE_DEVICE_TABLE (acpi, lis3lv02d_device_ids); -/** -* lis3lv02d_acpi_init - ACPI _INI method: initialize the device. +* lis3lv02d_acpi_init - initialize the device for ACPI * @lis3: pointer to the device struct * * Returns 0 on success. */ static int lis3lv02d_acpi_init (struct lis3lv02d *lis3) { -struct acpi_device *dev = lis3->bus_priv; -if (!lis3->init_required) -return 0 ; - -if (acpi_evaluate_object (dev->handle,METHOD_NAME__INI , -NULL ,NULL ) !=AE_OK ) -return -EINVAL ; -return 0 ; }
@@ -359,7 +350,6 @@ static int lis3lv02d_add(struct acpi_device *device) }/* call the core layer do its init */ - lis3_dev.init_required = true; ret =lis3lv02d_init_device (&lis3_dev);if (ret)return ret;
@@ -407,14 +397,12 @@ static int lis3lv02d_suspend(struct device *dev)static int lis3lv02d_resume (struct device *dev) { - lis3_dev.init_required = false;lis3lv02d_poweron (&lis3_dev);return 0 ; }static int lis3lv02d_restore (struct device *dev) { - lis3_dev.init_required = true;lis3lv02d_poweron (&lis3_dev);return 0 ; }
Signature · 1 line
2.32.0
Re: [PATCH v2 1/2] platform/x86: hp_accel: Remove _INI method call
Quoted 8 lines · Andy Shevchenko
According to ACPI specification the
_INImethod must be called when device is enumerated first time. After that there is no need to repeat the procedure. Convert thelis3lv02d_acpi_init()to be a stub (Note, we may not remove it because it is called unconditionally by the accelerometer main driver).Signed-off-by Andy Shevchenko <[email protected]>
The lis3lv02d still works after boot and after resume.
Quoted 72 lines
--- drivers/misc/lis3lv02d/lis3lv02d.h | 1 - drivers/platform/x86/hp_accel.c | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-)drivers/misc/lis3lv02d/lis3lv02d.h +0
-1@@ -271,7 +271,6 @@ struct lis3lv02d {int regs_size;u8 *reg_cache;bool regs_stored; -bool init_required;u8 odr_mask;/* ODR bit mask */ u8 whoami;/* indicates measurement precision */ s16 (*read_data) (struct lis3lv02d *lis3,int reg);drivers/platform/x86/hp_accel.c +1
-14@@ -78,23 +78,14 @@ static const struct acpi_device_id lis3lv02d_device_ids[] = { };MODULE_DEVICE_TABLE (acpi, lis3lv02d_device_ids); -/** -* lis3lv02d_acpi_init - ACPI _INI method: initialize the device. +* lis3lv02d_acpi_init - initialize the device for ACPI * @lis3: pointer to the device struct * * Returns 0 on success. */ static int lis3lv02d_acpi_init (struct lis3lv02d *lis3) { -struct acpi_device *dev = lis3->bus_priv; -if (!lis3->init_required) -return 0 ; - -if (acpi_evaluate_object (dev->handle,METHOD_NAME__INI , -NULL ,NULL ) !=AE_OK ) -return -EINVAL ; -return 0 ; }@@ -359,7 +350,6 @@ static int lis3lv02d_add(struct acpi_device *device) }/* call the core layer do its init */ - lis3_dev.init_required = true; ret =lis3lv02d_init_device (&lis3_dev);if (ret)return ret;@@ -407,14 +397,12 @@ static int lis3lv02d_suspend(struct device *dev)static int lis3lv02d_resume (struct device *dev) { - lis3_dev.init_required = false;lis3lv02d_poweron (&lis3_dev);return 0 ; }static int lis3lv02d_restore (struct device *dev) { - lis3_dev.init_required = true;lis3lv02d_poweron (&lis3_dev);return 0 ; } --2.32.0
PATCH v2 2/2 platform/x86: hp_accel: Convert to be a platform driver
In reply to Andy ShevchenkoACPI core in conjunction with platform driver core provides an infrastructure to enumerate ACPI devices. Use it in order to remove a lot of boilerplate code.
--- drivers/platform/x86/hp_accel.c | 64 ++++++++------------------------- 1 file changed, 14 insertions(+), 50 deletions(-)
drivers/platform/x86/hp_accel.c +14 -50
@@ -28,9 +28,6 @@#include <linux/serio.h> #include "../../misc/lis3lv02d/lis3lv02d.h" -#define DRIVER_NAME "hp_accel" -#define ACPI_MDPS_CLASS "accelerometer" -/* Delayed LEDs infrastructure ------------------------------------ */ /* Special LED class that can defer work */
@@ -269,30 +266,6 @@ static struct delayed_led_classdev hpled_led = { .set_brightness = hpled_set, }; -static acpi_status -lis3lv02d_get_resource (struct acpi_resource *resource,void *context) -{ -if (resource->type ==ACPI_RESOURCE_TYPE_EXTENDED_IRQ ) { -struct acpi_resource_extended_irq *irq; -u32 *device_irq = context; - - irq = &resource->data.extended_irq; - *device_irq = irq->interrupts[0 ]; - } - -return AE_OK ; -} - -static void lis3lv02d_enum_resources (struct acpi_device *device) -{ -acpi_status status; - - status =acpi_walk_resources (device->handle,METHOD_NAME__CRS , - lis3lv02d_get_resource, &lis3_dev.irq); -if (ACPI_FAILURE (status)) - printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n"); -} -static bool hp_accel_i8042_filter (unsigned char data,unsigned char str,struct serio *port) {
@@ -322,23 +295,19 @@ static bool hp_accel_i8042_filter(unsigned char data, unsigned char str,return false; } -static int lis3lv02d_add (struct acpi_device *device) +static int lis3lv02d_probe (struct platform_device *device) {int ret; -if (!device) -return -EINVAL ; - - lis3_dev.bus_priv = device; + lis3_dev.bus_priv =ACPI_COMPANION (&device->dev); lis3_dev.init = lis3lv02d_acpi_init; lis3_dev.read = lis3lv02d_acpi_read; lis3_dev.write = lis3lv02d_acpi_write; -strcpy (acpi_device_name (device),DRIVER_NAME ); -strcpy (acpi_device_class (device),ACPI_MDPS_CLASS ); - device->driver_data = &lis3_dev;/* obtain IRQ number of our device from ACPI */ -lis3lv02d_enum_resources (device); + ret =platform_get_irq_optional (device,0 ); +if (ret >0 ) + lis3_dev.irq = ret;/* If possible use a "standard" axes order */ if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) {
@@ -371,11 +340,8 @@ static int lis3lv02d_add(struct acpi_device *device)return ret; } -static int lis3lv02d_remove (struct acpi_device *device) +static int lis3lv02d_remove (struct platform_device *device) { -if (!device) -return -EINVAL ; -i8042_remove_filter (hp_accel_i8042_filter);lis3lv02d_joystick_disable (&lis3_dev);lis3lv02d_poweroff (&lis3_dev);
@@ -386,7 +352,6 @@ static int lis3lv02d_remove(struct acpi_device *device)return lis3lv02d_remove_fs (&lis3_dev); } -#ifdef CONFIG_PM_SLEEP static int lis3lv02d_suspend (struct device *dev) {
@@ -422,17 +387,16 @@ static const struct dev_pm_ops hp_accel_pm = {#endif /* For the HP MDPS aka 3D Driveguard */ -static struct acpi_driver lis3lv02d_driver = { - .name =DRIVER_NAME , - .class =ACPI_MDPS_CLASS , - .ids = lis3lv02d_device_ids, - .ops = { - .add = lis3lv02d_add, - .remove = lis3lv02d_remove, +static struct platform_driver lis3lv02d_driver = { + .probe = lis3lv02d_probe, + .remove = lis3lv02d_remove, + .driver = { + .name ="hp_accel" , + .pm =HP_ACCEL_PM , + .acpi_match_table = lis3lv02d_device_ids, }, - .drv.pm =HP_ACCEL_PM , }; -module_acpi_driver (lis3lv02d_driver); +module_platform_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" );
Signature · 1 line
2.32.0
Re: [PATCH v2 2/2] platform/x86: hp_accel: Convert to be a platform driver
Quoted 6 lines · Andy Shevchenko
ACPI core in conjunction with platform driver core provides an infrastructure to enumerate ACPI devices. Use it in order to remove a lot of boilerplate code.
Signed-off-by Andy Shevchenko <[email protected]>
The lis3lv02d still works with this patch.
Quoted 128 lines
--- drivers/platform/x86/hp_accel.c | 64 ++++++++------------------------- 1 file changed, 14 insertions(+), 50 deletions(-)drivers/platform/x86/hp_accel.c +14
-51@@ -28,9 +28,6 @@#include <linux/serio.h> #include "../../misc/lis3lv02d/lis3lv02d.h" -#define DRIVER_NAME "hp_accel" -#define ACPI_MDPS_CLASS "accelerometer" -/* Delayed LEDs infrastructure ------------------------------------ */ /* Special LED class that can defer work */ @@ -269,30 +266,6 @@ static struct delayed_led_classdev hpled_led = { .set_brightness = hpled_set, }; -static acpi_status -lis3lv02d_get_resource (struct acpi_resource *resource,void *context) -{ -if (resource->type ==ACPI_RESOURCE_TYPE_EXTENDED_IRQ ) { -struct acpi_resource_extended_irq *irq; -u32 *device_irq = context; - - irq = &resource->data.extended_irq; - *device_irq = irq->interrupts[0 ]; - } - -return AE_OK ; -} - -static void lis3lv02d_enum_resources (struct acpi_device *device) -{ -acpi_status status; - - status =acpi_walk_resources (device->handle,METHOD_NAME__CRS , - lis3lv02d_get_resource, &lis3_dev.irq); -if (ACPI_FAILURE (status)) - printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n"); -} -static bool hp_accel_i8042_filter (unsigned char data,unsigned char str,struct serio *port) {@@ -322,23 +295,19 @@ static bool hp_accel_i8042_filter(unsigned char data, unsigned char str,return false; } -static int lis3lv02d_add (struct acpi_device *device) +static int lis3lv02d_probe (struct platform_device *device) {int ret; -if (!device) -return -EINVAL ; - - lis3_dev.bus_priv = device; + lis3_dev.bus_priv =ACPI_COMPANION (&device->dev); lis3_dev.init = lis3lv02d_acpi_init; lis3_dev.read = lis3lv02d_acpi_read; lis3_dev.write = lis3lv02d_acpi_write; -strcpy (acpi_device_name (device),DRIVER_NAME ); -strcpy (acpi_device_class (device),ACPI_MDPS_CLASS ); - device->driver_data = &lis3_dev;/* obtain IRQ number of our device from ACPI */ -lis3lv02d_enum_resources (device); + ret =platform_get_irq_optional (device,0 ); +if (ret >0 ) + lis3_dev.irq = ret;/* If possible use a "standard" axes order */ if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) {@@ -371,11 +340,8 @@ static int lis3lv02d_add(struct acpi_device *device)return ret; } -static int lis3lv02d_remove (struct acpi_device *device) +static int lis3lv02d_remove (struct platform_device *device) { -if (!device) -return -EINVAL ; -i8042_remove_filter (hp_accel_i8042_filter);lis3lv02d_joystick_disable (&lis3_dev);lis3lv02d_poweroff (&lis3_dev);@@ -386,7 +352,6 @@ static int lis3lv02d_remove(struct acpi_device *device)return lis3lv02d_remove_fs (&lis3_dev); } -#ifdef CONFIG_PM_SLEEP static int lis3lv02d_suspend (struct device *dev) {@@ -422,17 +387,16 @@ static const struct dev_pm_ops hp_accel_pm = {#endif /* For the HP MDPS aka 3D Driveguard */ -static struct acpi_driver lis3lv02d_driver = { - .name =DRIVER_NAME , - .class =ACPI_MDPS_CLASS , - .ids = lis3lv02d_device_ids, - .ops = { - .add = lis3lv02d_add, - .remove = lis3lv02d_remove, +static struct platform_driver lis3lv02d_driver = { + .probe = lis3lv02d_probe, + .remove = lis3lv02d_remove, + .driver = { + .name ="hp_accel" , + .pm =HP_ACCEL_PM , + .acpi_match_table = lis3lv02d_device_ids, }, - .drv.pm =HP_ACCEL_PM , }; -module_acpi_driver (lis3lv02d_driver); +module_platform_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" ); --2.32.0
Re: [PATCH v2 2/2] platform/x86: hp_accel: Convert to be a platform driver
Quoted 8 lines · Kai-Heng Feng
Quoted 5 lines · Andy Shevchenko
ACPI core in conjunction with platform driver core provides an infrastructure to enumerate ACPI devices. Use it in order to remove a lot of boilerplate code.
Quoted 5 lines
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>The lis3lv02d still works with this patch.
Tested-by Kai-Heng Feng <[email protected]>
Thank you, Kai-Heng!
Hans, I think it's good to go.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 9 lines · Andy Shevchenko
The pure ACPI drivers are not needed since we have a platform glue layer in place. This allow to drop a lot of boiler plate code and duplication.
Patch 1 remove confusing call to
_INImethod and citing myself from v1:
"Not sure what buys us to run_INIon PM calls. It's against the spec
AFAICT. In any case ACPICA runs_INIas per specification when devices are instantiated."Patch 2 converts to platform driver.
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans