Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
qpnp-haptic: restore vmax sysfs node and add global vibration strengt…
Browse files Browse the repository at this point in the history
…h control

This will allow the system vibration setting to function normally. The new sysfs node controls the global vibration strength.
  • Loading branch information
flar2 authored and nathanchance committed Aug 19, 2017
1 parent 0c9356a commit 2da89b1
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions drivers/soc/qcom/qpnp-haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct qpnp_hap {
enum qpnp_hap_high_z lra_high_z;
u32 timeout_ms;
u32 vmax_mv;
u32 vmax_percent;
u32 ilim_ma;
u32 sc_deb_cycles;
u32 int_pwm_freq_khz;
Expand Down Expand Up @@ -1049,10 +1050,10 @@ static ssize_t qpnp_hap_rf_hz_store(struct device *dev,
static ssize_t qpnp_hap_vmax_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
u8 reg = 0;
int rc;
struct timed_output_dev *timed_dev = dev_get_drvdata(dev);
struct qpnp_hap *hap = container_of(timed_dev, struct qpnp_hap,
u8 reg = 0;
int rc;
struct timed_output_dev *timed_dev = dev_get_drvdata(dev);
struct qpnp_hap *hap = container_of(timed_dev, struct qpnp_hap,
timed_dev);
rc = qpnp_hap_read_reg(hap, &reg, QPNP_HAP_VMAX_REG(hap->base));
reg = (reg >> QPNP_HAP_VMAX_SHIFT);
Expand All @@ -1078,6 +1079,8 @@ static ssize_t qpnp_hap_vmax_store(struct device *dev,
else if (data > QPNP_HAP_VMAX_MAX_MV)
data = QPNP_HAP_VMAX_MAX_MV;

data = (data * hap->vmax_percent) / 100;

rc = qpnp_hap_read_reg(hap, &reg, QPNP_HAP_VMAX_REG(hap->base));
if (rc < 0)
return rc;
Expand All @@ -1091,9 +1094,45 @@ static ssize_t qpnp_hap_vmax_store(struct device *dev,
if (rc)
return rc;

hap->vmax_mv = data;
hap->vmax_mv = data;

return count;
}

static ssize_t qpnp_hap_vmax_mv_strong_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int temp;
struct timed_output_dev *timed_dev = dev_get_drvdata(dev);
struct qpnp_hap *hap = container_of(timed_dev, struct qpnp_hap,
timed_dev);

temp = ((QPNP_HAP_VMAX_MAX_MV - QPNP_HAP_VMAX_MIN_MV) *
hap->vmax_percent) / 100 + QPNP_HAP_VMAX_MIN_MV;

return snprintf(buf, PAGE_SIZE, "%d\n", temp);
}

static ssize_t qpnp_hap_vmax_mv_strong_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int data;
struct timed_output_dev *timed_dev = dev_get_drvdata(dev);
struct qpnp_hap *hap = container_of(timed_dev, struct qpnp_hap,
timed_dev);

if (sscanf(buf, "%d", &data) != 1)
return -EINVAL;

if (data < QPNP_HAP_VMAX_MIN_MV)
data = QPNP_HAP_VMAX_MIN_MV;
else if (data > QPNP_HAP_VMAX_MAX_MV)
data = QPNP_HAP_VMAX_MAX_MV;

hap->vmax_percent = 100 * (data - QPNP_HAP_VMAX_MIN_MV) /
(QPNP_HAP_VMAX_MAX_MV - QPNP_HAP_VMAX_MIN_MV);

return count;
return count;
}

/* sysfs show for wave form update */
Expand Down Expand Up @@ -1406,9 +1445,12 @@ static struct device_attribute qpnp_hap_attrs[] = {
__ATTR(rf_hz, (S_IRUGO | S_IWUSR | S_IWGRP),
qpnp_hap_rf_hz_show,
qpnp_hap_rf_hz_store),
__ATTR(vmax_mv_strong, (S_IRUGO | S_IWUSR | S_IWGRP),
__ATTR(vmax, (S_IRUGO | S_IWUSR | S_IWGRP),
qpnp_hap_vmax_show,
qpnp_hap_vmax_store),
__ATTR(vmax_mv_strong, (S_IRUGO | S_IWUSR | S_IWGRP),
qpnp_hap_vmax_mv_strong_show,
qpnp_hap_vmax_mv_strong_store),
__ATTR(wf_s0, 0664, qpnp_hap_wf_s0_show, qpnp_hap_wf_s0_store),
__ATTR(wf_s1, 0664, qpnp_hap_wf_s1_show, qpnp_hap_wf_s1_store),
__ATTR(wf_s2, 0664, qpnp_hap_wf_s2_show, qpnp_hap_wf_s2_store),
Expand Down Expand Up @@ -2228,6 +2270,8 @@ static int qpnp_hap_parse_dt(struct qpnp_hap *hap)
return rc;
}

hap->vmax_percent = 100;

hap->ilim_ma = QPNP_HAP_ILIM_MIN_MV;
rc = of_property_read_u32(pdev->dev.of_node, "qcom,ilim-ma", &temp);
if (!rc) {
Expand Down

0 comments on commit 2da89b1

Please sign in to comment.