Skip to content

Commit

Permalink
add sysfs for vibration intensity control
Browse files Browse the repository at this point in the history
Allows incredible ~3% increase in vibration intensity. :P
Going down to about a third of the original intensity
seems to be enough to disable the vibrator.

Based on codeworkx's commit somewhere.

Change-Id: Ie4f96362d774f596c7c013cfe38cf0d2c9502cc6
  • Loading branch information
KonstaT committed Sep 24, 2013
1 parent 54a013d commit 159550c
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions arch/arm/mach-msm/msm_vibrator.c
Expand Up @@ -46,7 +46,8 @@
//change rpc proc id
#define HTC_PROCEDURE_SET_VIB_ON_OFF 22
//ZTE_VIBRATOR_HP_01 end
#define PMIC_VIBRATOR_LEVEL (3000)
#define PMIC_VIBRATOR_LEVEL_MAX 3100
#define PMIC_VIBRATOR_LEVEL_MIN 1100

//add by stone 2010_0301
//#define STONE_DEBUG
Expand All @@ -56,8 +57,12 @@ static struct hrtimer vibe_timer;
static spinlock_t vibe_lock;
static int vibe_state;

/* default value for vibration intensity, 95% = 3000 in PMIC_VIBRATOR_LEVEL */
static unsigned long pwmval = 95;

static void set_pmic_vibrator(int on)
{
int pwm_duty;
static struct msm_rpc_endpoint *vib_endpoint;
struct set_vib_on_off_req {
struct rpc_request_hdr hdr;
Expand All @@ -77,8 +82,19 @@ static void set_pmic_vibrator(int on)
}
}

/* make sure pwmval is between 0 and 100 */
if (pwmval > 100) {
pwmval = 100;
} else if (pwmval < 0) {
pwmval = 0;
}

/* calculate vibration level */
pwm_duty = (PMIC_VIBRATOR_LEVEL_MIN +
(pwmval * (PMIC_VIBRATOR_LEVEL_MAX - PMIC_VIBRATOR_LEVEL_MIN) / 100));

if (on)
req.data = cpu_to_be32(PMIC_VIBRATOR_LEVEL);
req.data = cpu_to_be32(pwm_duty);
else
req.data = cpu_to_be32(0);

Expand Down Expand Up @@ -135,6 +151,50 @@ static enum hrtimer_restart vibrator_timer_func(struct hrtimer *timer)
return HRTIMER_NORESTART;
}

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 (sscanf(buf, "%lu", &pwmval) != 1)
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 blade_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 struct timed_output_dev pmic_vibrator = {
.name = "vibrator",
.get_time = vibrator_get_time,
Expand All @@ -155,6 +215,8 @@ void __init msm_init_pmic_vibrator(void)
hrtimer_init(&vibe_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
vibe_timer.function = vibrator_timer_func;

blade_create_vibrator_sysfs();

timed_output_dev_register(&pmic_vibrator);
}

Expand Down

0 comments on commit 159550c

Please sign in to comment.