aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorcodeworkx <daniel.hillenbrand@codeworkx.de>2012-10-16 00:55:20 -0300
committerZiyan <jaraidaniel@gmail.com>2014-12-16 12:19:46 +0100
commit240ea5d7f770040a97a7e333ee913f06a8696297 (patch)
treee842921048679f43f2d9bbf95061b6074f16c7f4 /arch
parent61c6c77b105e323514d56c786ef97b1e9e30df0b (diff)
downloadkernel_samsung_tuna-240ea5d7f770040a97a7e333ee913f06a8696297.zip
kernel_samsung_tuna-240ea5d7f770040a97a7e333ee913f06a8696297.tar.gz
kernel_samsung_tuna-240ea5d7f770040a97a7e333ee913f06a8696297.tar.bz2
Add sysfs vibrator intensity controls
Patch Set 2 Removed unused variable Patch Set 3 Use pwm_old variable Patch Set 4 Add authorship Change-Id: Ibcb887fe2c78cfd5740f363d33d1ed997c98b9c6
Diffstat (limited to 'arch')
-rwxr-xr-xarch/arm/mach-omap2/board-tuna-vibrator.c80
1 files changed, 78 insertions, 2 deletions
diff --git a/arch/arm/mach-omap2/board-tuna-vibrator.c b/arch/arm/mach-omap2/board-tuna-vibrator.c
index cd0edfd..c9d3055 100755
--- a/arch/arm/mach-omap2/board-tuna-vibrator.c
+++ b/arch/arm/mach-omap2/board-tuna-vibrator.c
@@ -31,8 +31,10 @@
#define GPIO_MOTOR_EN_REV05 54
#define VIB_GPTIMER_NUM 10
-#define PWM_DUTY_MAX 1450
+#define PWM_DUTY_MAX 1463
#define MAX_TIMEOUT 10000 /* 10s */
+static unsigned long pwmval = 127;
+static unsigned long oldpwmval;
static struct vibrator {
struct wake_lock wklock;
@@ -43,6 +45,50 @@ static struct vibrator {
unsigned gpio_en;
} vibdata;
+static ssize_t pwmvalue_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int count;
+
+ count = sprintf(buf, "%lu\n", pwmval);
+ pr_info("vibrator: pwmval: %lu\n", pwmval);
+
+ return count;
+}
+
+ssize_t pwmvalue_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ if (kstrtoul(buf, 0, &pwmval))
+ pr_err("vibrator: error in storing pwm value\n");
+
+ pr_info("vibrator: pwmval: %lu\n", pwmval);
+
+ return size;
+}
+
+static DEVICE_ATTR(pwmvalue, S_IRUGO | S_IWUGO,
+ pwmvalue_show, pwmvalue_store);
+
+static int tuna_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_pwmvalue.attr);
+ if (unlikely(ret < 0)) {
+ pr_err("vibrator: sysfs_create_file failed: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
static void vibrator_off(void)
{
if (!vibdata.enabled)
@@ -66,6 +112,20 @@ static int vibrator_get_time(struct timed_output_dev *dev)
static int vibrator_timer_init(void)
{
int ret;
+ int pwm_duty;
+
+ /*
+ * Formula for matching the user space force (-127 to +127)
+ * to Duty cycle.
+ * Duty cycle will vary from 0 to 45('0' means 0% duty cycle,
+ * '45' means 100% duty cycle.
+ * Also if user space force equals to -127 then duty
+ * cycle will be 0 (0%), if force equals to 0 duty cycle
+ * will be 22.5(50%), if +127 then duty cycle will
+ * be 45(100%)
+ */
+
+ pwm_duty = ((pwmval + 128) * (PWM_DUTY_MAX >> 1)/128);
ret = omap_dm_timer_set_source(vibdata.gptimer,
OMAP_TIMER_SRC_SYS_CLK);
@@ -73,7 +133,7 @@ static int vibrator_timer_init(void)
return ret;
omap_dm_timer_set_load(vibdata.gptimer, 1, -PWM_DUTY_MAX);
- omap_dm_timer_set_match(vibdata.gptimer, 1, -PWM_DUTY_MAX+10);
+ omap_dm_timer_set_match(vibdata.gptimer, 1, -pwm_duty);
omap_dm_timer_set_pwm(vibdata.gptimer, 0, 1,
OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE);
omap_dm_timer_enable(vibdata.gptimer);
@@ -86,10 +146,24 @@ static void vibrator_enable(struct timed_output_dev *dev, int value)
{
mutex_lock(&vibdata.lock);
+ /* make sure pwmval is between 0 and 127 */
+ if( pwmval > 127 ) {
+ pwmval = 127;
+ } else if ( pwmval < 0 ) {
+ pwmval = 0;
+ }
+
+ /* set the current pwmval */
+ if (pwmval != oldpwmval) {
+ vibrator_timer_init();
+ oldpwmval = pwmval;
+ }
+
/* cancel previous timer and set GPIO according to value */
hrtimer_cancel(&vibdata.timer);
if (value) {
+ pr_info("vibrator: value=%d, pwmval=%lu\n", value, pwmval);
wake_lock(&vibdata.wklock);
vibrator_timer_init();
gpio_set_value(vibdata.gpio_en, 1);
@@ -146,6 +220,8 @@ static int __init vibrator_init(void)
wake_lock_init(&vibdata.wklock, WAKE_LOCK_SUSPEND, "vibrator");
mutex_init(&vibdata.lock);
+ tuna_create_vibrator_sysfs();
+
ret = timed_output_dev_register(&to_dev);
if (ret < 0)
goto err_to_dev_reg;