Input: elan_i2c - Fix regulator enable count imbalance after suspend/resume
Subsystems (2)
PATCH 1/1 Input: elan_i2c - Fix regulator enable count imbalance after suspend/resume
Before these changes elan_suspend() would only call elan_disable_power() when device_may_wakeup() returns false; whereas elan_resume() would unconditionally call elan_enable_power(), leading to an enable count imbalance when device_may_wakeup() returns true.
This triggers the "WARN_ON(regulator->enable_count)" in regulator_put() when the elan_i2c driver gets unbound, this happens e.g. with the hot-plugable dock with Elan I2C touchpad for the Asus TF103C 2-in-1.
Fix this by making the elan_enable_power() call also be conditional on device_may_wakeup() returning false.
--- drivers/input/mouse/elan_i2c_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/input/mouse/elan_i2c_core.c +7 -7
@@ -1412,17 +1412,17 @@ static int __maybe_unused elan_resume(struct device *dev)struct elan_tp_data *data =i2c_get_clientdata (client);int error; -if (device_may_wakeup (dev) && data->irq_wake) { +if (!device_may_wakeup (dev)) { + error =elan_enable_power (data); +if (error) { +dev_err (dev,"power up when resuming failed: %d\n" , error); + goto err; + } + }else if (data->irq_wake) {disable_irq_wake (client->irq); data->irq_wake = false; } - error =elan_enable_power (data); -if (error) { -dev_err (dev,"power up when resuming failed: %d\n" , error); - goto err; - } - error =elan_initialize (data, data->quirks &ETP_QUIRK_QUICK_WAKEUP );if (error)dev_err (dev,"initialize when resuming failed: %d\n" , error);
Signature · 1 line
2.33.1
Dmitry Torokhov
maintainerHi Hans,
Quoted 11 lines · Hans de Goede
Before these changes
elan_suspend()would only callelan_disable_power()whendevice_may_wakeup()returns false; whereaselan_resume()would unconditionally callelan_enable_power(), leading to an enable count imbalance whendevice_may_wakeup()returns true.This triggers the "
WARN_ON(regulator->enable_count)" inregulator_put()when theelan_i2cdriver gets unbound, this happens e.g. with the hot-plugable dock with Elan I2C touchpad for the Asus TF103C 2-in-1.Fix this by making the
elan_enable_power()call also be conditional ondevice_may_wakeup()returning false.
elan_enable_power() not only tries to toggle the regulator, but also tries to issue command to the controller to power/wake it up. I need confirmation from Jingle Wu that skipping this is OK for all Elan touchpad controllers, or if we need to add call to either power control or sleep control method to make sure the controller it fully resumed.
Jingle, what can you tell us here?
Quoted 38 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/input/mouse/elan_i2c_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/input/mouse/elan_i2c_core.c +7
-7@@ -1412,17 +1412,17 @@ static int __maybe_unused elan_resume(struct device *dev)struct elan_tp_data *data =i2c_get_clientdata (client);int error; -if (device_may_wakeup (dev) && data->irq_wake) { +if (!device_may_wakeup (dev)) { + error =elan_enable_power (data); +if (error) { +dev_err (dev,"power up when resuming failed: %d\n" , error); + goto err; + } + }else if (data->irq_wake) {disable_irq_wake (client->irq); data->irq_wake = false; } - error =elan_enable_power (data); -if (error) { -dev_err (dev,"power up when resuming failed: %d\n" , error); - goto err; - } - error =elan_initialize (data, data->quirks &ETP_QUIRK_QUICK_WAKEUP );if (error)dev_err (dev,"initialize when resuming failed: %d\n" , error);Signature · 1 line
2.33.1
Thanks.
Signature · 1 line
Dmitry
Hi Hans/Dmitry:
It is not OK to skip elan_enable_power() for all Elan touchpad controllers.
I suggest to deal with this touchpad module ID as "quirk" case to support this special case.
Thanks
Jingle
-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Tuesday, January 4, 2022 8:30 AM
To: Hans de Goede <[email protected]>
Cc: Jingle Wu <[email protected]>; [email protected]
Subject: Re: [PATCH] Input: elan_i2c - Fix regulator enable count imbalance after suspend/resume
Hi Hans,
Quoted 8 lines · Hans de Goede
Before these changes
elan_suspend()would only callelan_disable_power()whendevice_may_wakeup()returns false; whereaselan_resume()would unconditionally callelan_enable_power(), leading to an enable count imbalance whendevice_may_wakeup()returns true.This triggers the "
WARN_ON(regulator->enable_count)" inregulator_put()when theelan_i2cdriver gets unbound, this happens e.g. with the hot-plugable dock with Elan I2C touchpad for the Asus TF103C
2-in-1.
Quoted 3 lines
Fix this by making the
elan_enable_power()call also be conditional ondevice_may_wakeup()returning false.
elan_enable_power() not only tries to toggle the regulator, but also tries to issue command to the controller to power/wake it up. I need confirmation from Jingle Wu that skipping this is OK for all Elan touchpad controllers, or if we need to add call to either power control or sleep control method to make sure the controller it fully resumed.
Jingle, what can you tell us here?
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct
Quoted 12 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/input/mouse/elan_i2c_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/input/mouse/elan_i2c_core.c +0
-0@@ -1412,17 +1412,17 @@ static int __maybe_unused elan_resume(struct
device *dev)
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct device *dev)
Quoted 8 lines
drivers/input/mouse/elan_i2c_core.c +4
-1struct elan_tp_data *data =i2c_get_clientdata (client);int error; -if (device_may_wakeup (dev) && data->irq_wake) { +if (!device_may_wakeup (dev)) { + error =elan_enable_power (data); +if (error) { + dev_err(dev, "power up when resuming failed: %d\n",
error);
Quoted 4 lines
drivers/input/mouse/elan_i2c_core.c +3
-0+ goto err; + } + }else if (data->irq_wake) {disable_irq_wake (client->irq);
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct device *dev)
Quoted 10 lines
drivers/input/mouse/elan_i2c_core.c +0
-6data->irq_wake = false; } - error =elan_enable_power (data); -if (error) { -dev_err (dev,"power up when resuming failed: %d\n" , error); - goto err; - } - error = elan_initialize(data, data->quirks &
ETP_QUIRK_QUICK_WAKEUP);
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct · line 1428
Quoted 2 lines
drivers/input/mouse/elan_i2c_core.c +0
-0if (error) dev_err(dev, "initialize when resuming failed: %d\n",
error);
Quoted 3 lines
--
2.33.1
Thanks.
Signature · 1 line
Dmitry
Hi,
Quoted 6 lines · Jingle.Wu
Hi Hans/Dmitry:
It is not OK to skip
elan_enable_power()for all Elan touchpad controllers.I suggest to deal with this touchpad module ID as "quirk" case to support this special case.
There is nothing special / quirky about this, regulator enable imbalances simply must not happen / must be fixed.
I'll prepare a new version of the patch which adds a parameter to elan_enable_power() to skip the regulator enable if the regulator was not disabled on suspend.
This will allow still always calling elan_enable_power() on resume, while also fixing the regulator imbalance.
Note that this will also help save power, the regulator imbalance also means that the regulator will no longer get disabled _ever_ after the first suspend/resume cycle where device_may_wakeup() returns true.
Regards,
Hans
Quoted 78 lines
-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Tuesday, January 4, 2022 8:30 AM
To: Hans de Goede <[email protected]>
Cc: Jingle Wu <[email protected]>; [email protected]
Subject: Re: [PATCH] Input:elan_i2c- Fix regulator enable count imbalance after suspend/resumeHi Hans,
Quoted 8 lines · Hans de Goede
Before these changes
elan_suspend()would only callelan_disable_power()whendevice_may_wakeup()returns false; whereaselan_resume()would unconditionally callelan_enable_power(), leading to an enable count imbalance whendevice_may_wakeup()returns true.This triggers the "
WARN_ON(regulator->enable_count)" inregulator_put()when theelan_i2cdriver gets unbound, this happens e.g. with the hot-plugable dock with Elan I2C touchpad for the Asus TF103C2-in-1.
Quoted 3 lines
Fix this by making the
elan_enable_power()call also be conditional ondevice_may_wakeup()returning false.
elan_enable_power()not only tries to toggle the regulator, but also tries to issue command to the controller to power/wake it up. I need confirmation from Jingle Wu that skipping this is OK for all Elan touchpad controllers, or if we need to add call to either power control or sleep control method to make sure the controller it fully resumed.Jingle, what can you tell us here?
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct
Quoted 12 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/input/mouse/elan_i2c_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/input/mouse/elan_i2c_core.c +0
-0@@ -1412,17 +1412,17 @@ static int __maybe_unused elan_resume(structdevice *dev)
drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct device *dev)
Quoted 8 lines
drivers/input/mouse/elan_i2c_core.c +4
-1struct elan_tp_data *data =i2c_get_clientdata (client);int error; -if (device_may_wakeup (dev) && data->irq_wake) { +if (!device_may_wakeup (dev)) { + error =elan_enable_power (data); +if (error) { + dev_err(dev, "power up when resuming failed: %d\n",error);
Quoted 4 lines
drivers/input/mouse/elan_i2c_core.c +3
-0+ goto err; + } + }else if (data->irq_wake) {disable_irq_wake (client->irq);drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct device *dev)
Quoted 10 lines
drivers/input/mouse/elan_i2c_core.c +0
-6data->irq_wake = false; } - error =elan_enable_power (data); -if (error) { -dev_err (dev,"power up when resuming failed: %d\n" , error); - goto err; - } - error = elan_initialize(data, data->quirks &
ETP_QUIRK_QUICK_WAKEUP);drivers/input/mouse/elan_i2c_core.c static int __maybe_unused elan_resume(struct · line 1428
Quoted 2 lines
drivers/input/mouse/elan_i2c_core.c +0
-0if (error) dev_err(dev, "initialize when resuming failed: %d\n",error);
Quoted 3 lines
--
2.33.1Thanks.