summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGao Pan <gaopan@freescale.com>2015-07-01 14:38:20 +0800
committerGao Pan <gaopan@freescale.com>2015-07-03 17:07:49 +0800
commit6824cff93d368eafbf96c71fad541f9bc2502e3a (patch)
tree3d6bf2140abdb84391bde6296ba7816598e22f7d
parent74c9af0a5806fb5c926ffdab3145fc1680fc87e6 (diff)
MLK-11206: input: misc: fxls8471: support ±2g/±4g/±8g dynamically selection
Support ±2g/±4g/±8g dynamically selection for motion sensor fxls8471. Set the sensor mode to standby mode before changing the scale range with the command "echo 0 > enable". The scale range can be changed with the command "echo 0/1/2 > range". Signed-off-by: Gao Pan <b54642@freescale.com>
-rw-r--r--drivers/input/misc/fxls8471.c50
-rw-r--r--drivers/input/misc/fxls8471.h1
2 files changed, 50 insertions, 1 deletions
diff --git a/drivers/input/misc/fxls8471.c b/drivers/input/misc/fxls8471.c
index fd9e79a2ec08..9c9a9bbcd51b 100644
--- a/drivers/input/misc/fxls8471.c
+++ b/drivers/input/misc/fxls8471.c
@@ -169,6 +169,15 @@ static int fxls8471_set_delay(struct fxls8471_data *pdata, int delay)
return 0;
}
+static int fxls8471_change_range(struct fxls8471_data *pdata, int range)
+{
+ int ret;
+
+ ret = fxls8471_bus_write(pdata, FXLS8471_XYZ_DATA_CFG, range);
+
+ return ret;
+}
+
static int fxls8471_read_data(struct fxls8471_data *pdata,
struct fxls8471_data_axis *data)
{
@@ -319,7 +328,10 @@ static ssize_t fxls8471_enable_store(struct device *dev,
ret = fxls8471_change_mode(pdata, (enable > 0 ? ACTIVED : STANDBY));
if (!ret) {
atomic_set(&pdata->active, enable);
- printk(KERN_INFO "mma enable setting active\n");
+ if (enable)
+ printk(KERN_INFO "mma enable setting actived\n");
+ else
+ printk(KERN_INFO "mma enable setting standby\n");
}
return count;
}
@@ -386,6 +398,39 @@ static ssize_t fxls8471_data_show(struct device *dev,
return sprintf(buf, "%d,%d,%d\n", data.x, data.y, data.z);
}
+static ssize_t fxls8471_range_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct fxls8471_data *pdata = &fxls8471_dev;
+ int range = 0;
+
+ range = atomic_read(&pdata->range);
+ return sprintf(buf, "%d\n", range);
+}
+
+static ssize_t fxls8471_range_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct fxls8471_data *pdata = &fxls8471_dev;
+ int ret;
+ unsigned long range;
+
+ if (kstrtoul(buf, 10, &range) < 0)
+ return -EINVAL;
+
+ if (range == atomic_read(&pdata->range))
+ return count;
+
+ if (atomic_read(&pdata->active))
+ printk(KERN_INFO "Pls set the sensor standby and then actived\n");
+ ret = fxls8471_change_range(pdata, range);
+ if (!ret)
+ atomic_set(&pdata->range, range);
+
+ return count;
+}
+
static DEVICE_ATTR(enable, 0666, fxls8471_enable_show, fxls8471_enable_store);
static DEVICE_ATTR(poll_delay, 0666, fxls8471_poll_delay_show,
@@ -396,11 +441,14 @@ static DEVICE_ATTR(position, 0666, fxls8471_position_show,
static DEVICE_ATTR(data, 0666, fxls8471_data_show, NULL);
+static DEVICE_ATTR(range, 0666, fxls8471_range_show, fxls8471_range_store);
+
static struct attribute *fxls8471_attributes[] = {
&dev_attr_enable.attr,
&dev_attr_poll_delay.attr,
&dev_attr_position.attr,
&dev_attr_data.attr,
+ &dev_attr_range.attr,
NULL
};
diff --git a/drivers/input/misc/fxls8471.h b/drivers/input/misc/fxls8471.h
index adb0c31f892c..6820ad1c0517 100644
--- a/drivers/input/misc/fxls8471.h
+++ b/drivers/input/misc/fxls8471.h
@@ -80,6 +80,7 @@ struct fxls8471_data {
atomic_t active;
atomic_t delay;
atomic_t position;
+ atomic_t range;
u8 chip_id;
};