diff options
author | sbrissen <sbrissen@hotmail.com> | 2013-06-25 07:48:36 -0400 |
---|---|---|
committer | sbrissen <sbrissen@hotmail.com> | 2013-06-25 07:52:57 -0400 |
commit | 5dabd15e113634708030215b0494ce473a506d85 (patch) | |
tree | 331f7ec4ea3249842255e7c71a0ee6e66508b9ad /drivers/motor | |
parent | 5b3cb3ccc3df3b6106b5ae91f1ca77fcb1d99064 (diff) | |
download | kernel_samsung_smdk4412-5dabd15e113634708030215b0494ce473a506d85.zip kernel_samsung_smdk4412-5dabd15e113634708030215b0494ce473a506d85.tar.gz kernel_samsung_smdk4412-5dabd15e113634708030215b0494ce473a506d85.tar.bz2 |
isa1200_vibrator: user configurable vibration intensity
This patch was taken from maxx77693_haptic motor.
Vibration is configured via DeviceSettings.
Change-Id: Ibca1271798b22a6aacd6e81f2f2d128def69845e
Diffstat (limited to 'drivers/motor')
-rw-r--r-- | drivers/motor/isa1200_vibrator.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/drivers/motor/isa1200_vibrator.c b/drivers/motor/isa1200_vibrator.c index 97ccfe1..4b26dc3 100644 --- a/drivers/motor/isa1200_vibrator.c +++ b/drivers/motor/isa1200_vibrator.c @@ -36,6 +36,9 @@ #include <linux/fs.h> #include <asm/uaccess.h> +static unsigned long pwm_val = 50; /* duty in percent */ +static int isapwm_duty = 999; /* duty value, 1000=100%, 500=50%, 0=0% Default is 999*/ + #if 0 #define MOTOR_DEBUG #endif @@ -221,7 +224,7 @@ static void isa1200_vibrator_work(struct work_struct *_work) return ; data->running = true; - vibtonz_clk_config(999); + vibtonz_clk_config(isapwm_duty); vibtonz_clk_enable(true); mdelay(1); isa1200_vibrator_on(data); @@ -266,6 +269,65 @@ static void isa1200_vibrator_enable(struct timed_output_dev *_dev, int value) spin_unlock_irqrestore(&data->lock, flags); } +static ssize_t pwm_val_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int count; + + pwm_val = ((isapwm_duty - 500) * 100) / 500; + + count = sprintf(buf, "%lu\n", pwm_val); + pr_debug("[VIB] pwm_val: %lu\n", pwm_val); + + return count; +} + +ssize_t pwm_val_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + if (kstrtoul(buf, 0, &pwm_val)) + pr_err("[VIB] %s: error on storing pwm_val\n", __func__); + + pr_info("[VIB] %s: pwm_val=%lu\n", __func__, pwm_val); + + isapwm_duty = (pwm_val * 500) / 100 + 500; + + /* make sure new pwm duty is in range */ + if(isapwm_duty > 1000) + { + isapwm_duty = 1000; + } + else if (isapwm_duty < 500) + { + isapwm_duty = 500; + } + + pr_info("[VIB] %s: isapwm_duty=%d\n", __func__, isapwm_duty); + + return size; +} +static DEVICE_ATTR(pwm_val, S_IRUGO | S_IWUSR, + pwm_val_show, pwm_val_store); + +static int create_vibrator_sysfs(void) +{ + int ret; + struct kobject *vibrator_kobj; + vibrator_kobj = kobject_create_and_add("vibrator", NULL); + if (unlikely(!vibrator_kobj)) + return -ENOMEM; + + ret = sysfs_create_file(vibrator_kobj, + &dev_attr_pwm_val.attr); + if (unlikely(ret < 0)) { + pr_err("[VIB] sysfs_create_file failed: %d\n", ret); + return ret; + } + + return 0; +} + static int __devinit isa1200_vibrator_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -315,6 +377,8 @@ static int __devinit isa1200_vibrator_i2c_probe(struct i2c_client *client, ddata->dev.get_time = isa1200_vibrator_get_time; ddata->dev.enable = isa1200_vibrator_enable; + create_vibrator_sysfs(); + hrtimer_init(&ddata->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ddata->timer.function = isa1200_vibrator_timer_func; INIT_WORK(&ddata->work, isa1200_vibrator_work); |