diff options
author | Fahrzin Hemmati <fahhem@google.com> | 2013-03-18 18:38:48 -0700 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-03-28 06:24:24 +0000 |
commit | 5339dfe61136fe889b503d638d8c099d3469ec83 (patch) | |
tree | 660d41adc465379e5258b5872435713f63a679a3 | |
parent | 319e73069afce48adcec57837f807feaed48b782 (diff) | |
download | omap-5339dfe61136fe889b503d638d8c099d3469ec83.tar.gz |
Only perform IMU self test when sysfs file is written to.
Change-Id: I2d07b2e8c3783ee9551b35dec542208f42007d4b
-rw-r--r-- | drivers/staging/iio/imu/mpu/README | 6 | ||||
-rw-r--r-- | drivers/staging/iio/imu/mpu/inv_mpu_core.c | 19 | ||||
-rw-r--r-- | drivers/staging/iio/imu/mpu/inv_mpu_iio.h | 2 |
3 files changed, 16 insertions, 11 deletions
diff --git a/drivers/staging/iio/imu/mpu/README b/drivers/staging/iio/imu/mpu/README index e7dcc7a6dc33..d8f7a187d0a4 100644 --- a/drivers/staging/iio/imu/mpu/README +++ b/drivers/staging/iio/imu/mpu/README @@ -161,9 +161,9 @@ Check which clock-source is used by the chip. power_state (Read/write) turn on/off the power supply -self_test (read-only) -read this entry trigger self test. The return value is D. -D is the success/fail. +self_test (Read/write) +Write to this entry to trigger self test. Read to get result of self test. +The return value is D. D is the success/fail. For different chip, the result is different for success/fail. 1 means success 0 means fail. The LSB of D is for gyro; the bit next to LSB of D is for accel. The bit 2 of D is for compass result. diff --git a/drivers/staging/iio/imu/mpu/inv_mpu_core.c b/drivers/staging/iio/imu/mpu/inv_mpu_core.c index c9dd7ab60efa..11f22107d3a8 100644 --- a/drivers/staging/iio/imu/mpu/inv_mpu_core.c +++ b/drivers/staging/iio/imu/mpu/inv_mpu_core.c @@ -1122,11 +1122,7 @@ static ssize_t inv_attr_show(struct device *dev, f[st->chip_config.lpa_freq]); } case ATTR_SELF_TEST: - if (INV_MPU3050 == st->chip_type) - result = 0; - else - result = inv_hw_self_test(st); - return sprintf(buf, "%d\n", result); + return sprintf(buf, "%d\n", st->chip_config.self_test_result); case ATTR_KEY: key = st->plat_data.key; result = 0; @@ -1395,13 +1391,20 @@ static ssize_t inv_attr_store(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int data; int result; - if (check_enable(st)) + // Self-test doesn't require enable bit to already be set. + if (check_enable(st) && this_attr->address != ATTR_SELF_TEST) return -EPERM; result = kstrtoint(buf, 10, &data); if (result) return -EINVAL; switch (this_attr->address) { + case ATTR_SELF_TEST: + if (INV_MPU3050 != st->chip_type) + st->chip_config.self_test_result = inv_hw_self_test(st); + // Allow the next calibration-read to redo inv_do_test. + st->chip_config.self_test_run_once = 0; + break; case ATTR_GYRO_ENABLE: result = inv_gyro_enable(st, ring, !!data); break; @@ -1552,8 +1555,8 @@ static IIO_DEVICE_ATTR(lpa_mode, S_IRUGO | S_IWUGO, inv_attr_show, static IIO_DEVICE_ATTR(lpa_freq, S_IRUGO | S_IWUGO, inv_attr_show, inv_attr_store, ATTR_LPA_FREQ); static DEVICE_ATTR(reg_dump, S_IRUGO, inv_reg_dump_show, NULL); -static IIO_DEVICE_ATTR(self_test, S_IRUGO, inv_attr_show, NULL, - ATTR_SELF_TEST); +static IIO_DEVICE_ATTR(self_test, S_IRUGO | S_IWUGO, inv_attr_show, + inv_attr_store, ATTR_SELF_TEST); static IIO_DEVICE_ATTR(key, S_IRUGO, inv_attr_show, NULL, ATTR_KEY); static IIO_DEVICE_ATTR(gyro_matrix, S_IRUGO, inv_attr_show, NULL, ATTR_GYRO_MATRIX); diff --git a/drivers/staging/iio/imu/mpu/inv_mpu_iio.h b/drivers/staging/iio/imu/mpu/inv_mpu_iio.h index 655830438b9a..bc5e37e8f07b 100644 --- a/drivers/staging/iio/imu/mpu/inv_mpu_iio.h +++ b/drivers/staging/iio/imu/mpu/inv_mpu_iio.h @@ -120,6 +120,7 @@ struct inv_hw_s { * @lpf: Digital low pass filter frequency. * @accl_fs: accel full scale range. * @self_test_run_once flag for self test run ever. + * @self_test_result: result of last self_test * @has_footer: MPU3050 specific work around. * @has_compass: has compass or not. * @enable: master enable to enable output @@ -150,6 +151,7 @@ struct inv_chip_config_s { u32 lpf:3; u32 accl_fs:2; u32 self_test_run_once:1; + u32 self_test_result:3; u32 has_footer:1; u32 has_compass:1; u32 enable:1; |