From 5dabd15e113634708030215b0494ce473a506d85 Mon Sep 17 00:00:00 2001 From: sbrissen Date: Tue, 25 Jun 2013 07:48:36 -0400 Subject: isa1200_vibrator: user configurable vibration intensity This patch was taken from maxx77693_haptic motor. Vibration is configured via DeviceSettings. Change-Id: Ibca1271798b22a6aacd6e81f2f2d128def69845e --- drivers/motor/isa1200_vibrator.c | 66 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/motor/isa1200_vibrator.c b/drivers/motor/isa1200_vibrator.c index 97ccfe11bfb..4b26dc335a6 100644 --- a/drivers/motor/isa1200_vibrator.c +++ b/drivers/motor/isa1200_vibrator.c @@ -36,6 +36,9 @@ #include #include +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); -- cgit v1.2.3