From: Jonathan Cameron <jic23@kernel.org>
To: Matt Ranostay <matt.ranostay@intel.com>
Cc: linux-iio@vger.kernel.org, daniel.baluta@intel.com,
adriana.reus@intel.com
Subject: Re: [PATCH 4/5] iio: imu: mpu6050: add calibration offset support
Date: Thu, 25 Feb 2016 19:55:37 +0000 [thread overview]
Message-ID: <56CF5C39.4060805@kernel.org> (raw)
In-Reply-To: <1456177151-15881-5-git-send-email-matt.ranostay@intel.com>
On 22/02/16 21:39, Matt Ranostay wrote:
> Allow setting of the x/y/z axes calibration offsets for the gyroscope
> and accelerometer.
>
> Signed-off-by: Matt Ranostay <matt.ranostay@intel.com>
Applied - again minor fuzz, but I think it went on top fine.
Jonathan
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 51 ++++++++++++++++++++++++++++--
> drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 10 ++++++
> 2 files changed, 59 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 6d4b19dd16f8..3acf0863e558 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -55,6 +55,8 @@ static const struct inv_mpu6050_reg_map reg_set_6050 = {
> .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1,
> .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2,
> .int_pin_cfg = INV_MPU6050_REG_INT_PIN_CFG,
> + .accl_offset = INV_MPU6050_REG_ACCEL_OFFSET,
> + .gyro_offset = INV_MPU6050_REG_GYRO_OFFSET,
> };
>
> static const struct inv_mpu6050_chip_config chip_config_6050 = {
> @@ -200,6 +202,20 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
> return result;
> }
>
> +static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg,
> + int axis, int val)
> +{
> + int ind, result;
> + __be16 d = cpu_to_be16(val);
> +
> + ind = (axis - IIO_MOD_X) * 2;
> + result = regmap_bulk_write(st->map, reg + ind, (u8 *)&d, 2);
> + if (result)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg,
> int axis, int *val)
> {
> @@ -221,11 +237,12 @@ static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,
> int *val2,
> long mask) {
> struct inv_mpu6050_state *st = iio_priv(indio_dev);
> + int ret = 0;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> {
> - int ret, result;
> + int result;
>
> ret = IIO_VAL_INT;
> result = 0;
> @@ -321,6 +338,20 @@ error_read_raw:
> default:
> return -EINVAL;
> }
> + case IIO_CHAN_INFO_CALIBBIAS:
> + switch (chan->type) {
> + case IIO_ANGL_VEL:
> + ret = inv_mpu6050_sensor_show(st, st->reg->gyro_offset,
> + chan->channel2, val);
> + return IIO_VAL_INT;
> + case IIO_ACCEL:
> + ret = inv_mpu6050_sensor_show(st, st->reg->accl_offset,
> + chan->channel2, val);
> + return IIO_VAL_INT;
> +
> + default:
> + return -EINVAL;
> + }
> default:
> return -EINVAL;
> }
> @@ -416,6 +447,21 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
> break;
> }
> break;
> + case IIO_CHAN_INFO_CALIBBIAS:
> + switch (chan->type) {
> + case IIO_ANGL_VEL:
> + result = inv_mpu6050_sensor_set(st,
> + st->reg->gyro_offset,
> + chan->channel2, val);
> + break;
> + case IIO_ACCEL:
> + result = inv_mpu6050_sensor_set(st,
> + st->reg->accl_offset,
> + chan->channel2, val);
> + break;
> + default:
> + result = -EINVAL;
> + }
> default:
> result = -EINVAL;
> break;
> @@ -569,7 +615,8 @@ static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev,
> .modified = 1, \
> .channel2 = _channel2, \
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> + BIT(IIO_CHAN_INFO_CALIBBIAS), \
> .scan_index = _index, \
> .scan_type = { \
> .sign = 's', \
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index a6c45ce459ee..c4e24148c733 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -40,6 +40,8 @@
> * @pwr_mgmt_1: Controls chip's power state and clock source.
> * @pwr_mgmt_2: Controls power state of individual sensors.
> * @int_pin_cfg; Controls interrupt pin configuration.
> + * @accl_offset: Controls the accelerometer calibration offset.
> + * @gyro_offset: Controls the gyroscope calibration offset.
> */
> struct inv_mpu6050_reg_map {
> u8 sample_rate_div;
> @@ -57,6 +59,8 @@ struct inv_mpu6050_reg_map {
> u8 pwr_mgmt_1;
> u8 pwr_mgmt_2;
> u8 int_pin_cfg;
> + u8 accl_offset;
> + u8 gyro_offset;
> };
>
> /*device enum */
> @@ -133,6 +137,9 @@ struct inv_mpu6050_state {
> };
>
> /*register and associated bit definition*/
> +#define INV_MPU6050_REG_ACCEL_OFFSET 0x06
> +#define INV_MPU6050_REG_GYRO_OFFSET 0x13
> +
> #define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19
> #define INV_MPU6050_REG_CONFIG 0x1A
> #define INV_MPU6050_REG_GYRO_CONFIG 0x1B
> @@ -174,6 +181,9 @@ struct inv_mpu6050_state {
> #define INV_MPU6050_FIFO_COUNT_BYTE 2
> #define INV_MPU6050_FIFO_THRESHOLD 500
>
> +/* mpu6500 registers */
> +#define INV_MPU6500_REG_ACCEL_OFFSET 0x77
> +
> /* delay time in milliseconds */
> #define INV_MPU6050_POWER_UP_TIME 100
> #define INV_MPU6050_TEMP_UP_TIME 100
>
next prev parent reply other threads:[~2016-02-25 19:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-22 21:39 [PATCH 0/5] mpu6050: code clean and calibration support Matt Ranostay
2016-02-22 21:39 ` [PATCH 1/5] iio: imu: mpu6050: use inv_mpu6050_sensor_show return code Matt Ranostay
2016-02-22 21:49 ` Daniel Baluta
2016-02-22 21:50 ` Daniel Baluta
2016-02-25 19:50 ` Jonathan Cameron
2016-02-22 21:39 ` [PATCH 2/5] iio: imu: mpu6050: fix INV_MPU6050_REG_UP_TIME delay Matt Ranostay
2016-02-25 19:54 ` Jonathan Cameron
2016-02-22 21:39 ` [PATCH 3/5] iio: imu: mpu6050: add missing docstring for int_pin_cfg Matt Ranostay
2016-02-25 19:55 ` Jonathan Cameron
2016-02-22 21:39 ` [PATCH 4/5] iio: imu: mpu6050: add calibration offset support Matt Ranostay
2016-02-25 19:55 ` Jonathan Cameron [this message]
2016-02-22 21:39 ` [PATCH 5/5] iio: imu: mpu6050: add mpu6500 register settings Matt Ranostay
2016-02-25 19:56 ` Jonathan Cameron
2016-02-24 21:08 ` [PATCH 0/5] mpu6050: code clean and calibration support Jonathan Cameron
[not found] ` <DM3PR1201MB1072776083BB71F4F618555CAFA50@DM3PR1201MB1072.namprd12.prod.outlook.com>
2016-02-25 8:45 ` Daniel Baluta
2016-02-25 15:36 ` Ge Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56CF5C39.4060805@kernel.org \
--to=jic23@kernel.org \
--cc=adriana.reus@intel.com \
--cc=daniel.baluta@intel.com \
--cc=linux-iio@vger.kernel.org \
--cc=matt.ranostay@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).