Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30f10b23 authored by Fenglin Wu's avatar Fenglin Wu
Browse files

input: qti-haptics: Add a timer to stop playing when the time expired



Currently, when VMAX waveform source is chosen, the haptics would not
stop playing when playing timer is expired, it requires an explicit
calling with playback(0) to stop it. Add a timer to stop it when the
playing time is expired. This is not required when playing BUFFER
waveform source because haptics would stop playing after the pattern is
played.

Change-Id: I64659ea95478319cc39148443a229bcf56ad168c
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent cf1a1b92
Loading
Loading
Loading
Loading
+32 −0
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@


#include <linux/device.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/err.h>
#include <linux/hrtimer.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/interrupt.h>
@@ -213,6 +214,7 @@ struct qti_hap_chip {
	struct qti_hap_effect		*predefined;
	struct qti_hap_effect		*predefined;
	struct qti_hap_effect		constant;
	struct qti_hap_effect		constant;
	struct regulator		*vdd_supply;
	struct regulator		*vdd_supply;
	struct hrtimer			stop_timer;
	spinlock_t			bus_lock;
	spinlock_t			bus_lock;
	ktime_t				last_sc_time;
	ktime_t				last_sc_time;
	int				play_irq;
	int				play_irq;
@@ -901,6 +903,8 @@ static int qti_haptics_playback(struct input_dev *dev, int effect_id, int val)
{
{
	struct qti_hap_chip *chip = input_get_drvdata(dev);
	struct qti_hap_chip *chip = input_get_drvdata(dev);
	struct qti_hap_play_info *play = &chip->play;
	struct qti_hap_play_info *play = &chip->play;
	s64 secs;
	unsigned long nsecs;
	int rc = 0;
	int rc = 0;


	dev_dbg(chip->dev, "playback, val = %d\n", val);
	dev_dbg(chip->dev, "playback, val = %d\n", val);
@@ -919,6 +923,11 @@ static int qti_haptics_playback(struct input_dev *dev, int effect_id, int val)
				disable_irq_nosync(chip->play_irq);
				disable_irq_nosync(chip->play_irq);
				chip->play_irq_en = false;
				chip->play_irq_en = false;
			}
			}
			secs = play->length_us / USEC_PER_SEC;
			nsecs = (play->length_us % USEC_PER_SEC) *
				NSEC_PER_USEC;
			hrtimer_start(&chip->stop_timer, ktime_set(secs, nsecs),
					HRTIMER_MODE_REL);
		}
		}
	} else {
	} else {
		play->length_us = 0;
		play->length_us = 0;
@@ -1056,6 +1065,26 @@ static int qti_haptics_hw_init(struct qti_hap_chip *chip)
	return 0;
	return 0;
}
}


static enum hrtimer_restart qti_hap_stop_timer(struct hrtimer *timer)
{
	struct qti_hap_chip *chip = container_of(timer, struct qti_hap_chip,
			stop_timer);
	int rc;

	chip->play.length_us = 0;
	rc = qti_haptics_play(chip, false);
	if (rc < 0) {
		dev_err(chip->dev, "Stop playing failed, rc=%d\n", rc);
		goto err_out;
	}

	rc = qti_haptics_module_en(chip, false);
	if (rc < 0)
		dev_err(chip->dev, "Disable module failed, rc=%d\n", rc);
err_out:
	return HRTIMER_NORESTART;
}

static int qti_haptics_parse_dt(struct qti_hap_chip *chip)
static int qti_haptics_parse_dt(struct qti_hap_chip *chip)
{
{
	struct qti_hap_config *config = &chip->config;
	struct qti_hap_config *config = &chip->config;
@@ -1367,6 +1396,9 @@ static int qti_haptics_probe(struct platform_device *pdev)
		return rc;
		return rc;
	}
	}


	hrtimer_init(&chip->stop_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	chip->stop_timer.function = qti_hap_stop_timer;

	input_dev->name = "vibrator";
	input_dev->name = "vibrator";
	input_set_drvdata(input_dev, chip);
	input_set_drvdata(input_dev, chip);
	chip->input_dev = input_dev;
	chip->input_dev = input_dev;