From 4cd52d87bc3225cc2b0716ceaa63cda059bb0bc1 Mon Sep 17 00:00:00 2001 From: yangjq Date: Thu, 18 Jul 2019 18:27:26 +0800 Subject: [PATCH] aw8695: Add wakelock to make vibration stop on time Without wakelock, system would suspend when vibration is on going, which may cause the STOP command failed to be sent and in turn leave the phone vibrating for a long time. Signed-off-by: yangjq Change-Id: Iee5d2691954f960f203f4be8c82c9198304f5977 Reviewed-on: https://gerrit.mot.com/1387741 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Jianqi Yang Submit-Approved: Jira Key --- drivers/misc/awinic/aw8695/aw8695.c | 14 ++++++++++++-- drivers/misc/awinic/aw8695/aw8695.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/misc/awinic/aw8695/aw8695.c b/drivers/misc/awinic/aw8695/aw8695.c index 5f22b6ce66c4..506def7ffcb8 100644 --- a/drivers/misc/awinic/aw8695/aw8695.c +++ b/drivers/misc/awinic/aw8695/aw8695.c @@ -1837,8 +1837,11 @@ static void aw8695_vibrate(struct aw8695 *aw8695, int value) mutex_lock(&aw8695->lock); aw8695_haptic_stop(aw8695); + if (aw8695->index == 0x02) + __pm_relax(aw8695->ws); + seq = aw8695->seq[0]; - pr_info("%s: value=%d, seq=%d\n", __FUNCTION__, value, seq); + pr_info("%s: value=%d, seq=%d, index=%x\n", __FUNCTION__, value, seq, aw8695->index); if (value > 0 || seq > 2) { @@ -1867,6 +1870,7 @@ static void aw8695_vibrate(struct aw8695 *aw8695, int value) case HAPTIC_SHORT: if (aw8695->seq[0] == 0) aw8695->seq[0] = 0x01; + aw8695->index = 0x01; aw8695_haptic_set_wav_seq(aw8695, 0x00, aw8695->seq[0]); aw8695_haptic_set_wav_loop(aw8695, 0x00, 0x00); aw8695_haptic_ram_vbat_comp(aw8695, false); @@ -1877,7 +1881,7 @@ static void aw8695_vibrate(struct aw8695 *aw8695, int value) /* wav index config */ aw8695->index = 0x02; aw8695_haptic_set_repeat_wav_seq(aw8695, aw8695->index); - //__pm_wakeup_event(aw8695->ws, value + 100); + __pm_wakeup_event(aw8695->ws, value + 100); /* run ms timer */ hrtimer_cancel(&aw8695->timer); aw8695->state = 0x01; @@ -3225,6 +3229,10 @@ static int aw8695_vibrator_init(struct aw8695 *aw8695) INIT_WORK(&aw8695->rtp_work, aw8695_rtp_work_routine); + aw8695->ws = wakeup_source_register("vibrator"); + if (!aw8695->ws) + return -ENOMEM; + mutex_init(&aw8695->lock); return 0; @@ -3690,6 +3698,8 @@ static int aw8695_i2c_remove(struct i2c_client *i2c) if (gpio_is_valid(aw8695->reset_gpio)) devm_gpio_free(&i2c->dev, aw8695->reset_gpio); + wakeup_source_unregister(aw8695->ws); + devm_kfree(&i2c->dev, aw8695); aw8695 = NULL; diff --git a/drivers/misc/awinic/aw8695/aw8695.h b/drivers/misc/awinic/aw8695/aw8695.h index 8cbd21bc4e24..4d6220310537 100644 --- a/drivers/misc/awinic/aw8695/aw8695.h +++ b/drivers/misc/awinic/aw8695/aw8695.h @@ -295,6 +295,7 @@ struct aw8695 { struct device *dev; struct input_dev *input; + struct wakeup_source *ws; struct mutex lock; struct hrtimer timer; struct work_struct vibrator_work;