Input: drv260x: Fix suspend and resume sequencing
Subsystems (2)
PATCH 1/1 Input: drv260x: Fix suspend and resume sequencing
Force-feedback playback is queued asynchronously, but system suspend can cut the enable GPIO and vbat supply while the worker is pending. Quiesce the worker and reject new playback requests after suspend begins.
The enable pin also disables I2C and resets volatile configuration. Raise it before communicating on resume, observe the startup delay, and rerun device initialization. Restore the same state if regulator shutdown aborts suspend.
---
Tested on a Lenovo Yoga Book YB1-X91L with both DRV2604 devices. The system completed an RTC-timed suspend-to-RAM and resumed without rebooting; both force-feedback devices then uploaded and played sine effects without drv260x, I2C or configuration-restore errors.
drivers/input/misc/drv260x.c | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-)
drivers/input/misc/drv260x.c +33 -9
@@ -181,6 +181,7 @@* @work: Work item used to off load the enable/disable of the vibration * @enable_gpio: Pointer to the gpio used for enable/disabling * @regulator: Pointer to the regulator for the IC +* @suspended: Whether force-feedback work must remain quiesced * @magnitude: Magnitude of the vibration event * @mode: The operating mode of the IC (LRA_NO_CAL, ERM or LRA) * @library: The vibration library to be used
@@ -194,6 +195,7 @@ struct drv260x_data {struct work_struct work;struct gpio_desc *enable_gpio;struct regulator *regulator; +bool suspended;u8 magnitude;u32 mode;u32 library;
@@ -215,6 +217,13 @@ static int drv260x_calculate_voltage(unsigned int voltage)return (voltage *255 /5600 ); } +static void drv260x_set_suspended (struct drv260x_data *haptics, +bool suspended) +{ +scoped_guard (spinlock_irqsave, &haptics->input_dev->event_lock) + haptics->suspended = suspended; +} +static void drv260x_worker (struct work_struct *work) { struct drv260x_data *haptics = container_of(work, struct drv260x_data, work);
@@ -243,6 +252,9 @@ static int drv260x_haptics_play(struct input_dev *input, void *data, {struct drv260x_data *haptics =input_get_drvdata (input); +if (haptics->suspended) +return 0 ; + haptics->mode =DRV260X_LRA_NO_CAL_MODE ;/* Scale u16 magnitude into u8 register value */
@@ -569,17 +581,21 @@ static int drv260x_probe(struct i2c_client *client)static int drv260x_suspend (struct device *dev) {struct drv260x_data *haptics =dev_get_drvdata (dev); -int error; +int error, restore_error;guard (mutex)(&haptics->input_dev->mutex);if (input_device_enabled (haptics->input_dev)) { +drv260x_set_suspended (haptics, true); +cancel_work_sync (&haptics->work); + error =regmap_update_bits (haptics->regmap,DRV260X_MODE ,DRV260X_STANDBY_MASK ,DRV260X_STANDBY );if (error) {dev_err (dev,"Failed to set standby mode\n" ); +drv260x_set_suspended (haptics, false);return error; }
@@ -588,9 +604,15 @@ static int drv260x_suspend(struct device *dev) error =regulator_disable (haptics->regulator);if (error) {dev_err (dev,"Failed to disable regulator\n" ); -regmap_update_bits (haptics->regmap, -DRV260X_MODE , -DRV260X_STANDBY_MASK ,0 ); + +gpiod_set_value (haptics->enable_gpio,1 ); +usleep_range (250 ,500 ); + restore_error =drv260x_init (haptics); +if (restore_error) +dev_err (dev,"Failed to restore configuration: %d\n" , + restore_error); + +drv260x_set_suspended (haptics, false);return error; } }
@@ -612,16 +634,18 @@ static int drv260x_resume(struct device *dev)return error; } - error =regmap_update_bits (haptics->regmap, -DRV260X_MODE , -DRV260X_STANDBY_MASK ,0 ); +gpiod_set_value (haptics->enable_gpio,1 ); +usleep_range (250 ,500 ); + + error =drv260x_init (haptics);if (error) { -dev_err (dev,"Failed to unset standby mode\n" ); +dev_err (dev,"Failed to restore configuration: %d\n" , error); +gpiod_set_value (haptics->enable_gpio,0 );regulator_disable (haptics->regulator);return error; } -gpiod_set_value (haptics->enable_gpio,1 ); +drv260x_set_suspended (haptics, false); }return 0 ;
base-commit: 9a29ee801f525bcad71fea021bfe2a030885c8df
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The device mode is permanently overwritten during playback, breaking resume initialization for ERM actuators.
Pre-existing issues:
- [High] Volatile configuration is wiped on device close but is never restored on subsequent playbacks. --
commit f2bc5aa859d35cc4439e1699724bc7b8924e6f2a
Author: Maurizio Casciano <[email protected]>
Input: drv260x: Fix suspend and resume sequencing
This commit fixes system suspend and resume for the drv260x haptics driver. It quiesces the worker and rejects new playback requests during suspend, and restores the volatile configuration by reinitializing the device on resume.
Quoted 4 lines
drivers/input/misc/drv260x.c +0
-0
[ ... ]
drivers/input/misc/drv260x.c static int drv260x_haptics_play(struct input_dev *input, void *data, · line 258
Quoted 8 lines
drivers/input/misc/drv260x.c +3
-0@@ -243,6 +252,9 @@ static int drv260x_haptics_play(struct input_dev *input, void *data, {struct drv260x_data *haptics =input_get_drvdata (input); +if (haptics->suspended) +return 0 ; + haptics->mode =DRV260X_LRA_NO_CAL_MODE ;
[Severity: High]
Does this code permanently overwrite the device mode during playback, breaking the newly added resume initialization for ERM actuators?
When a user triggers a haptic playback, drv260x_haptics_play() permanently overwrites haptics->mode to DRV260X_LRA_NO_CAL_MODE.
When the system suspends and resumes, the newly added drv260x_init() call in drv260x_resume() reads the overwritten haptics->mode and executes the wrong initialization sequence (the default switch case).
This will cause ERM actuators and calibrated LRA modes to fail to reinitialize properly upon system resume, leading to haptic malfunction and incorrect drive signals for ERM hardware.
Quoted 2 lines
drivers/input/misc/drv260x.c +0
-0/* Scale u16 magnitude into u8 register value */
[ ... ]
Quoted 1 line
drivers/input/misc/drv260x.c +0
-0@@ -612,16 +634,18 @@ static int drv260x_resume(struct device *dev)
[ ... ]
drivers/input/misc/drv260x.c static int drv260x_resume(struct device *dev) · line 640
Quoted 12 lines
drivers/input/misc/drv260x.c +4
-3if (error) {dev_err (dev,"Failed to enable regulator\n" );return error; } - error =regmap_update_bits (haptics->regmap, -DRV260X_MODE , -DRV260X_STANDBY_MASK ,0 ); +gpiod_set_value (haptics->enable_gpio,1 ); +usleep_range (250 ,500 ); + + error =drv260x_init (haptics);
[Severity: High]
This is a pre-existing issue, but is the volatile configuration wiped on device close and never restored on subsequent playbacks?
When the last user closes the device, drv260x_close() pulls the enable_gpio low, which powers down the chip and clears its configuration:
drivers/input/misc/drv260x.c:drv260x_close() {
...
gpiod_set_value(haptics->enable_gpio, 0);
...
}A subsequent program can open the device and play an effect, but since there is no open() callback to call drv260x_init(), drv260x_worker() executes playback on an uninitialized chip:
drivers/input/misc/drv260x.c:drv260x_worker() {
...
gpiod_set_value(haptics->enable_gpio, 1);
/* Data sheet says to wait 250us before trying to communicate */
udelay(250);
error = regmap_write(haptics->regmap,
DRV260X_MODE, DRV260X_RT_PLAYBACK);
...
}Because there is no open callback in drv260x_probe() that symmetrically calls drv260x_init(), the haptic actuator loses its calibration, rated voltage, and overdrive voltage configuration after the device is closed. Subsequent playbacks run on power-on reset defaults.
Any unprivileged user with access to the input device node can trigger this behavior by opening and closing the device, potentially causing hardware damage if the default voltages exceed the actuator's limits.
Quoted 7 lines
drivers/input/misc/drv260x.c +2
-1if (error) { -dev_err (dev,"Failed to unset standby mode\n" ); +dev_err (dev,"Failed to restore configuration: %d\n" , error); +gpiod_set_value (haptics->enable_gpio,0 );regulator_disable (haptics->regulator);return error; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1