Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
aw8697: Add haptic level adjustment
Browse files Browse the repository at this point in the history
Change-Id: Iec780ad06b8407f073e6204a70e0682bc9722504
Signed-off-by: Vaisakh Murali <[email protected]>
  • Loading branch information
engstk authored and mvaisakh committed Mar 16, 2023
1 parent 0d8fd7a commit ae4d87b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
58 changes: 57 additions & 1 deletion drivers/misc/aw8697_haptic/aw8697.c
Original file line number Diff line number Diff line change
Expand Up @@ -5109,9 +5109,20 @@ static int aw8697_haptic_set_bst_peak_cur(struct aw8697 *aw8697, unsigned char p
return 0;
}

static unsigned char aw8697_haptic_set_level(struct aw8697 *aw8697, int gain)
{
int val = 80;

val = aw8697->level * gain / 3;
if (val > 255)
val = 255;

return val;
}

static int aw8697_haptic_set_gain(struct aw8697 *aw8697, unsigned char gain)
{
aw8697_i2c_write(aw8697, AW8697_REG_DATDBG, gain);
aw8697_i2c_write(aw8697, AW8697_REG_DATDBG, aw8697_haptic_set_level(aw8697, gain));
return 0;
}

Expand Down Expand Up @@ -8008,6 +8019,7 @@ static int aw8697_haptic_init(struct aw8697 *aw8697)

aw8697->activate_mode = AW8697_HAPTIC_ACTIVATE_CONT_MODE;
aw8697->vibration_style = AW8697_HAPTIC_VIBRATION_CRISP_STYLE;
aw8697->level = 3;

ret = aw8697_i2c_read(aw8697, AW8697_REG_WAVSEQ1, &reg_val);
aw8697->index = reg_val & 0x7F;
Expand Down Expand Up @@ -8677,6 +8689,48 @@ static ssize_t aw8697_gain_store(struct device *dev,
return count;
}

static ssize_t aw8697_level_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
#ifdef TIMED_OUTPUT
struct timed_output_dev *to_dev = dev_get_drvdata(dev);
struct aw8697 *aw8697 = container_of(to_dev, struct aw8697, to_dev);
#else
struct led_classdev *cdev = dev_get_drvdata(dev);
struct aw8697 *aw8697 = container_of(cdev, struct aw8697, cdev);
#endif

return snprintf(buf, PAGE_SIZE, "%d\n", aw8697->level);
}

static ssize_t aw8697_level_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
#ifdef TIMED_OUTPUT
struct timed_output_dev *to_dev = dev_get_drvdata(dev);
struct aw8697 *aw8697 = container_of(to_dev, struct aw8697, to_dev);
#else
struct led_classdev *cdev = dev_get_drvdata(dev);
struct aw8697 *aw8697 = container_of(cdev, struct aw8697, cdev);
#endif
unsigned int val = 0;
int rc = 0;

rc = kstrtouint(buf, 0, &val);
if (rc < 0)
return rc;

if (val < 0 || val > 10)
val = 3;

pr_info("%s: value=%d\n", __FUNCTION__, val);
mutex_lock(&aw8697->lock);
aw8697->level = val;
aw8697_haptic_set_gain(aw8697, aw8697->gain);
mutex_unlock(&aw8697->lock);
return count;
}

static ssize_t aw8697_seq_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Expand Down Expand Up @@ -10423,6 +10477,7 @@ static DEVICE_ATTR(activate_mode, S_IWUSR | S_IRUGO, aw8697_activate_mode_show,
static DEVICE_ATTR(index, S_IWUSR | S_IRUGO, aw8697_index_show, aw8697_index_store);
static DEVICE_ATTR(vmax, S_IWUSR | S_IRUGO, aw8697_vmax_show, aw8697_vmax_store);
static DEVICE_ATTR(gain, S_IWUSR | S_IRUGO, aw8697_gain_show, aw8697_gain_store);
static DEVICE_ATTR(level, S_IWUSR | S_IRUGO, aw8697_level_show, aw8697_level_store);
static DEVICE_ATTR(seq, S_IWUSR | S_IRUGO, aw8697_seq_show, aw8697_seq_store);
static DEVICE_ATTR(loop, S_IWUSR | S_IRUGO, aw8697_loop_show, aw8697_loop_store);
static DEVICE_ATTR(register, S_IWUSR | S_IRUGO, aw8697_reg_show, aw8697_reg_store);
Expand Down Expand Up @@ -10475,6 +10530,7 @@ static struct attribute *aw8697_vibrator_attributes[] = {
&dev_attr_index.attr,
&dev_attr_vmax.attr,
&dev_attr_gain.attr,
&dev_attr_level.attr,
&dev_attr_seq.attr,
&dev_attr_loop.attr,
&dev_attr_register.attr,
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/aw8697_haptic/aw8697.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ struct aw8697 {
int index;
int vmax;
int gain;
int level;
unsigned int gun_type; //hch 20190917
unsigned int bullet_nr; //hch 20190917
unsigned int gun_mode;
Expand Down

0 comments on commit ae4d87b

Please sign in to comment.