aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuwei Zhou <b45643@freescale.com>2013-12-23 01:09:25 -0500
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 09:47:30 -0400
commite4e3609cd4c56d1f11d94aea54bd626d25e8e531 (patch)
treea4b807993fb44be84b1a498bed029296fda51fa7
parent74fc13798428613e7c996b3ab9bc26fbbff0e290 (diff)
ENGR00293101 hwmon: mma8451: add sys interface to set sensor scale mode.
mma8451 sensor driver on i.MX6Q/DL SabreSD/AUTO doesn't provide the interface to set sensor scale. The new sys interface name is "scalemode". The mode is defined as: MODE_2G : 0, MODE_4G : 1, MODE_8G : 2 Signed-off-by: Luwei Zhou <b45643@freescale.com>
-rw-r--r--drivers/hwmon/mxc_mma8451.c70
1 files changed, 65 insertions, 5 deletions
diff --git a/drivers/hwmon/mxc_mma8451.c b/drivers/hwmon/mxc_mma8451.c
index ddac67dd41a4..f4407bc5beba 100644
--- a/drivers/hwmon/mxc_mma8451.c
+++ b/drivers/hwmon/mxc_mma8451.c
@@ -179,14 +179,14 @@ static int mma8451_change_mode(struct i2c_client *client, int mode)
179 result = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, 0); 179 result = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, 0);
180 if (result < 0) 180 if (result < 0)
181 goto out; 181 goto out;
182 mma_status.active = MMA_STANDBY;
182 183
183 mma_status.mode = mode;
184 result = i2c_smbus_write_byte_data(client, MMA8451_XYZ_DATA_CFG, 184 result = i2c_smbus_write_byte_data(client, MMA8451_XYZ_DATA_CFG,
185 mma_status.mode); 185 mode);
186 if (result < 0) 186 if (result < 0)
187 goto out; 187 goto out;
188 mma_status.active = MMA_STANDBY;
189 mdelay(MODE_CHANGE_DELAY_MS); 188 mdelay(MODE_CHANGE_DELAY_MS);
189 mma_status.mode = mode;
190 190
191 return 0; 191 return 0;
192out: 192out:
@@ -331,14 +331,74 @@ static ssize_t mma8451_position_store(struct device *dev,
331 return count; 331 return count;
332} 332}
333 333
334static ssize_t mma8451_scalemode_show(struct device *dev,
335 struct device_attribute *attr,
336 char *buf)
337{
338 int mode = 0;
339 mutex_lock(&mma8451_lock);
340 mode = (int)mma_status.mode;
341 mutex_unlock(&mma8451_lock);
342
343 return sprintf(buf, "%d\n", mode);
344}
345
346static ssize_t mma8451_scalemode_store(struct device *dev,
347 struct device_attribute *attr,
348 const char *buf, size_t count)
349{
350 unsigned long mode;
351 int ret, active_save;
352 struct i2c_client *client = mma8451_i2c_client;
353
354 ret = strict_strtoul(buf, 10, &mode);
355 if (ret) {
356 dev_err(dev, "string transform error\n");
357 goto out;
358 }
359
360 if (mode > MODE_8G) {
361 dev_warn(dev, "not supported mode\n");
362 ret = count;
363 goto out;
364 }
365
366 mutex_lock(&mma8451_lock);
367 if (mode == mma_status.mode) {
368 ret = count;
369 goto out_unlock;
370 }
371
372 active_save = mma_status.active;
373 ret = mma8451_change_mode(client, mode);
374 if (ret)
375 goto out_unlock;
376
377 if (active_save == MMA_ACTIVED) {
378 ret = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, 1);
379
380 if (ret)
381 goto out_unlock;
382 mma_status.active = active_save;
383 }
384
385out_unlock:
386 mutex_unlock(&mma8451_lock);
387out:
388 return ret;
389}
390
334static DEVICE_ATTR(enable, S_IWUSR | S_IRUGO, 391static DEVICE_ATTR(enable, S_IWUSR | S_IRUGO,
335 mma8451_enable_show, mma8451_enable_store); 392 mma8451_enable_show, mma8451_enable_store);
336static DEVICE_ATTR(position, S_IWUSR | S_IRUGO, 393static DEVICE_ATTR(position, S_IWUSR | S_IRUGO,
337 mma8451_position_show, mma8451_position_store); 394 mma8451_position_show, mma8451_position_store);
395static DEVICE_ATTR(scalemode, S_IWUSR | S_IRUGO,
396 mma8451_scalemode_show, mma8451_scalemode_store);
338 397
339static struct attribute *mma8451_attributes[] = { 398static struct attribute *mma8451_attributes[] = {
340 &dev_attr_enable.attr, 399 &dev_attr_enable.attr,
341 &dev_attr_position.attr, 400 &dev_attr_position.attr,
401 &dev_attr_scalemode.attr,
342 NULL 402 NULL
343}; 403};
344 404