From: Chad Goodman Date: Mon, 26 Nov 2012 04:41:10 +0000 (-0800) Subject: VIBRATOR: allow SYSFS control over vibrator strength X-Git-Url: https://projects.ziggy471.com/git/gitweb.cgi?p=ziggy471-sgs3-jb.git;a=commitdiff;h=e0243d18f5ae0d6c4d9bc3a2fe42189870689165 VIBRATOR: allow SYSFS control over vibrator strength Signed-off-by: Ziggy --- --- a/drivers/motor/tspdrv.c +++ b/drivers/motor/tspdrv.c @@ -111,6 +111,7 @@ static int max_timeout = 10000; static int vibrator_value = -1; static int vibrator_work; +int8_t vibe_strength = 120; #define TEST_MODE_TIME 10000 @@ -129,7 +130,7 @@ static int set_vibetonz(int timeout) } else { DbgOut((KERN_INFO "tspdrv: ENABLE\n")); if (vibrator_drvdata.vib_model == HAPTIC_PWM) { - strength = 120; + strength = vibe_strength; /* 90% duty cycle */ ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ @@ -148,6 +149,28 @@ static void _set_vibetonz_work(struct wo return; } + +static ssize_t show_vibe_strength(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", vibe_strength); +} + +static ssize_t store_vibe_strength(struct device *dev, struct device_attribute *attr,const char *buf, size_t size) +{ + int value; + sscanf(buf, "%d", &value); + if(value < 5) + value = 5; + else if(value > 126) + value = 126; + + vibe_strength = value; + + return vibe_strength; +} + +static DEVICE_ATTR(vibe_strength, 0777, show_vibe_strength, store_vibe_strength); + static enum hrtimer_restart vibetonz_timer_func(struct hrtimer *timer) { /* set_vibetonz(0); */ @@ -213,6 +236,10 @@ static void vibetonz_start(void) if (ret) DbgOut((KERN_ERR "tspdrv: timed_output_dev_register is fail\n")); + + ret = device_create_file(timed_output_vt.dev, &dev_attr_vibe_strength); + if(ret) + printk(KERN_ERR "[ANTHRAX] vibe_strength device file create failed\n"); } /* File IO */