mpu6050: code clean and calibration support
Subsystems (2)
cover mpu6050: code clean and calibration support
The patchset series cleans up several documentation, return code issues, incorrect timing delays, and adds accl/gyro offset support.
Matt Ranostay (5):
iio: imu: mpu6050: use inv_mpu6050_sensor_show return code
iio: imu: mpu6050: fix INV_MPU6050_REG_UP_TIME delay
iio: imu: mpu6050: add missing docstring for int_pin_cfg
iio: imu: mpu6050: add calibration offset support
iio: imu: mpu6050: add mpu6500 register settings
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 88 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 20 ++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 +- 4 files changed, 105 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/5 iio: imu: mpu6050: use inv_mpu6050_sensor_show return code
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1 -1
@@ -275,7 +275,7 @@ static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,case IIO_TEMP :/* wait for stablization */ msleep (INV_MPU6050_SENSOR_UP_TIME ); -inv_mpu6050_sensor_show (st, st->reg->temperature, + ret =inv_mpu6050_sensor_show (st, st->reg->temperature,IIO_MOD_X , val);break ;default :
Signature · 1 line
1.9.1
PATCH 2/5 iio: imu: mpu6050: fix INV_MPU6050_REG_UP_TIME delay
In reply to Matt Ranostayreplace msleep(INV_MPU6050_REG_UP_TIME) with usleep_range calls due to fact the wait time is under 20 milliseconds.
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +2 -1
@@ -148,7 +148,8 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)return result;if (power_on) -msleep (INV_MPU6050_REG_UP_TIME ); +usleep_range (INV_MPU6050_REG_UP_TIME_MIN , +INV_MPU6050_REG_UP_TIME_MAX );return 0 ; }
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 -1
@@ -68,7 +68,8 @@ static int inv_mpu6050_select_bypass(struct i2c_adapter *adap, void *mux_priv,if (ret) goto write_error; -msleep (INV_MPU6050_REG_UP_TIME ); +usleep_range (INV_MPU6050_REG_UP_TIME_MIN , +INV_MPU6050_REG_UP_TIME_MAX ); }if (!ret) { st->powerup_count++;
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +6 -1
@@ -172,10 +172,15 @@ struct inv_mpu6050_state {#define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6#define INV_MPU6050_FIFO_COUNT_BYTE 2#define INV_MPU6050_FIFO_THRESHOLD 500 + +/* delay time in milliseconds */ #define INV_MPU6050_POWER_UP_TIME 100#define INV_MPU6050_TEMP_UP_TIME 100#define INV_MPU6050_SENSOR_UP_TIME 30 -#define INV_MPU6050_REG_UP_TIME 5 + +/* delay time in microseconds */ +#define INV_MPU6050_REG_UP_TIME_MIN 5000 +#define INV_MPU6050_REG_UP_TIME_MAX 10000#define INV_MPU6050_TEMP_OFFSET 12421#define INV_MPU6050_TEMP_SCALE 2941
Signature · 1 line
1.9.1
PATCH 3/5 iio: imu: mpu6050: add missing docstring for int_pin_cfg
In reply to Matt Ranostay--- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 + 1 file changed, 1 insertion(+)
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +1 -0
@@ -39,6 +39,7 @@* @int_enable: Interrupt enable register. * @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. */ struct inv_mpu6050_reg_map {u8 sample_rate_div;
Signature · 1 line
1.9.1
PATCH 4/5 iio: imu: mpu6050: add calibration offset support
In reply to Matt RanostayAllow setting of the x/y/z axes calibration offsets for the gyroscope and accelerometer.
--- 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(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +49 -2
@@ -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', \
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +10 -0
@@ -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
Signature · 1 line
1.9.1
PATCH 5/5 iio: imu: mpu6050: add mpu6500 register settings
In reply to Matt Ranostay--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 32 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +29 -3
@@ -39,6 +39,26 @@ static const int gyro_scale_6050[] = {133090, 266181, 532362, 1064724};*/ static const int accel_scale[] = {598 ,1196 ,2392 ,4785 }; +static const struct inv_mpu6050_reg_map reg_set_6500 = { + .sample_rate_div =INV_MPU6050_REG_SAMPLE_RATE_DIV , + .lpf =INV_MPU6050_REG_CONFIG , + .user_ctrl =INV_MPU6050_REG_USER_CTRL , + .fifo_en =INV_MPU6050_REG_FIFO_EN , + .gyro_config =INV_MPU6050_REG_GYRO_CONFIG , + .accl_config =INV_MPU6050_REG_ACCEL_CONFIG , + .fifo_count_h =INV_MPU6050_REG_FIFO_COUNT_H , + .fifo_r_w =INV_MPU6050_REG_FIFO_R_W , + .raw_gyro =INV_MPU6050_REG_RAW_GYRO , + .raw_accl =INV_MPU6050_REG_RAW_ACCEL , + .temperature =INV_MPU6050_REG_TEMPERATURE , + .int_enable =INV_MPU6050_REG_INT_ENABLE , + .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_MPU6500_REG_ACCEL_OFFSET , + .gyro_offset =INV_MPU6050_REG_GYRO_OFFSET , +}; +static const struct inv_mpu6050_reg_map reg_set_6050 = { .sample_rate_div =INV_MPU6050_REG_SAMPLE_RATE_DIV , .lpf =INV_MPU6050_REG_CONFIG ,
@@ -68,7 +88,13 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = { .accl_fs = INV_MPU6050_FS_02G, }; -static const struct inv_mpu6050_hw hw_info[INV_NUM_PARTS ] = { +static const struct inv_mpu6050_hw hw_info[] = { + { + .num_reg =117 , + .name ="MPU6500" , + .reg = ®_set_6500, + .config = &chip_config_6050, + }, { .num_reg =117 , .name ="MPU6050" ,
@@ -692,7 +718,6 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) {int result; - st->chip_type =INV_MPU6050 ; st->hw = &hw_info[st->chip_type]; st->reg = hw_info[st->chip_type].reg;
@@ -726,7 +751,7 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) }int inv_mpu_core_probe (struct regmap *regmap,int irq,const char *name, -int (*inv_mpu_bus_setup)(struct iio_dev *)) +int (*inv_mpu_bus_setup)(struct iio_dev *),int chip_type) {struct inv_mpu6050_state *st;struct iio_dev *indio_dev;
@@ -739,6 +764,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,return -ENOMEM ; st =iio_priv (indio_dev); + st->chip_type = chip_type; st->powerup_count =0 ; st->irq = irq; st->map = regmap;
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 -1
@@ -130,7 +130,8 @@ static int inv_mpu_probe(struct i2c_client *client,return PTR_ERR (regmap); } - result =inv_mpu_core_probe (regmap, client->irq, name,NULL ); + result =inv_mpu_core_probe (regmap, client->irq, name, +NULL , id->driver_data);if (result <0 )return result;
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +1 -1
@@ -277,7 +277,7 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on);int inv_mpu_acpi_create_mux_client (struct i2c_client *client);void inv_mpu_acpi_delete_mux_client (struct i2c_client *client);int inv_mpu_core_probe (struct regmap *regmap,int irq,const char *name, -int (*inv_mpu_bus_setup)(struct iio_dev *)); +int (*inv_mpu_bus_setup)(struct iio_dev *),int chip_type);int inv_mpu_core_remove (struct device *dev);int inv_mpu6050_set_power_itg (struct inv_mpu6050_state *st,bool power_on);extern const struct dev_pm_ops inv_mpu_pmops;
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2 -1
@@ -54,7 +54,8 @@ static int inv_mpu_probe(struct spi_device *spi)return PTR_ERR (regmap); } -return inv_mpu_core_probe (regmap, spi->irq, name, inv_mpu_i2c_disable); +return inv_mpu_core_probe (regmap, spi->irq, name, + inv_mpu_i2c_disable, id->driver_data); }static int inv_mpu_remove (struct spi_device *spi)
Signature · 1 line
1.9.1
Re: [PATCH 1/5] iio: imu: mpu6050: use inv_mpu6050_sensor_show return code
In reply to Matt Ranostaydrivers/iio/imu/inv_mpu6050/inv_mpu_core.c static int inv_mpu6050_read_raw(struct iio_dev *indio_dev, · line 276
Quoted 12 lines · Matt Ranostay
Signed-off-by Matt Ranostay <[email protected]>--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0
-0@@ -275,7 +275,7 @@ static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,case IIO_TEMP :/* wait for stablization */
While at it please also fix this type :D.
Quoted 13 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-2msleep (INV_MPU6050_SENSOR_UP_TIME ); -inv_mpu6050_sensor_show (st, st->reg->temperature, + ret =inv_mpu6050_sensor_show (st, st->reg->temperature,IIO_MOD_X , val);break ;default : --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] iio: imu: mpu6050: use inv_mpu6050_sensor_show return code
Quoted 6 lines · Daniel Baluta
Quoted 5 lines · Matt Ranostay
Signed-off-by Matt Ranostay <[email protected]>--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c static int inv_mpu6050_read_raw(struct iio_dev *indio_dev, · line 276
Quoted 7 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0
-0@@ -275,7 +275,7 @@ static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,case IIO_TEMP :/* wait for stablization */ While at it please also fix this type :D.
s/type/typo :)))
Jonathan Cameron
maintainerQuoted 11 lines · Matt Ranostay
The patchset series cleans up several documentation, return code issues, incorrect timing delays, and adds accl/gyro offset support.
Matt Ranostay (5):
iio: imu: mpu6050: useinv_mpu6050_sensor_showreturn code
iio: imu: mpu6050: fixINV_MPU6050_REG_UP_TIMEdelay
iio: imu: mpu6050: add missing docstring forint_pin_cfg
iio: imu: mpu6050: add calibration offset support
iio: imu: mpu6050: add mpu6500 register settings
Quoted 6 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 88 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 20 ++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 +- 4 files changed, 105 insertions(+), 12 deletions(-)
Whole series looks good to me (the typo fix can follow if you like :)
Ideally I'd like Ge to take a look as well (+ anyone else who fancies doing so!) so will leave it on list for a few days more.
Jonathan
Daniel Baluta
Acked-by Ge GaoQuoted 4 lines · Ge Gao
Dear all,
It looks good to me.
Thanks.
Hi Ge :),
Thanks for having a look at this. For next patches please also add the kernel formal
Acked-by tag, like this:
so that Jonathan can mark your collaboration into the commit message.
Quoted 35 lines
Best Regards,
Ge Gao
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Wednesday, February 24, 2016 1:08 PM
To: Matt Ranostay
Cc: [email protected]; [email protected]; [email protected]; Ge Gao
Subject: Re: [PATCH 0/5] mpu6050: code clean and calibration supportQuoted 10 lines · Matt Ranostay
The patchset series cleans up several documentation, return code issues, incorrect timing delays, and adds accl/gyro offset support.
Matt Ranostay (5):
iio: imu: mpu6050: useinv_mpu6050_sensor_showreturn code
iio: imu: mpu6050: fixINV_MPU6050_REG_UP_TIMEdelay
iio: imu: mpu6050: add missing docstring forint_pin_cfg
iio: imu: mpu6050: add calibration offset support
iio: imu: mpu6050: add mpu6500 register settingsQuoted 7 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 88 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 20 ++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 +- 4 files changed, 105 insertions(+), 12 deletions(-)Whole series looks good to me (the typo fix can follow if you like :)
Ideally I'd like Ge to take a look as well (+ anyone else who fancies doing so!) so will leave it on list for a few days more.
Jonathan
Ge Gao
Acked-bySure. I will do that.
Thanks.:-)
Ge
________________________________________
From: [email protected] <[email protected]> on behalf of Daniel Baluta <[email protected]>
Sent: Thursday, February 25, 2016 12:45 AM
To: Ge Gao
Cc: Jonathan Cameron; Matt Ranostay; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/5] mpu6050: code clean and calibration support
Quoted 4 lines · Ge Gao
Dear all,
It looks good to me.
Thanks.
Hi Ge :),
Thanks for having a look at this. For next patches please also add the kernel formal
Acked-by tag, like this:
so that Jonathan can mark your collaboration into the commit message.
Quoted 35 lines
Best Regards,
Ge Gao
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Wednesday, February 24, 2016 1:08 PM
To: Matt Ranostay
Cc: [email protected]; [email protected]; [email protected]; Ge Gao
Subject: Re: [PATCH 0/5] mpu6050: code clean and calibration supportQuoted 10 lines · Matt Ranostay
The patchset series cleans up several documentation, return code issues, incorrect timing delays, and adds accl/gyro offset support.
Matt Ranostay (5):
iio: imu: mpu6050: useinv_mpu6050_sensor_showreturn code
iio: imu: mpu6050: fixINV_MPU6050_REG_UP_TIMEdelay
iio: imu: mpu6050: add missing docstring forint_pin_cfg
iio: imu: mpu6050: add calibration offset support
iio: imu: mpu6050: add mpu6500 register settingsQuoted 7 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 88 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 20 ++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 +- 4 files changed, 105 insertions(+), 12 deletions(-)Whole series looks good to me (the typo fix can follow if you like :)
Ideally I'd like Ge to take a look as well (+ anyone else who fancies doing so!) so will leave it on list for a few days more.
Jonathan
Jonathan Cameron
maintainerRe: [PATCH 1/5] iio: imu: mpu6050: use inv_mpu6050_sensor_show return code
In reply to Matt RanostayQuoted 1 line · Matt Ranostay
Signed-off-by Matt Ranostay <[email protected]>
Wouldn't apply automatically so I did it manually.
Anyhow, applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play tennis with it.
J
Quoted 18 lines
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-1@@ -275,7 +275,7 @@ static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,case IIO_TEMP :/* wait for stablization */ msleep (INV_MPU6050_SENSOR_UP_TIME ); -inv_mpu6050_sensor_show (st, st->reg->temperature, + ret =inv_mpu6050_sensor_show (st, st->reg->temperature,IIO_MOD_X , val);break ;default :
Re: [PATCH 2/5] iio: imu: mpu6050: fix INV_MPU6050_REG_UP_TIME delay
In reply to Matt RanostayQuoted 4 lines · Matt Ranostay
replace
msleep(INV_MPU6050_REG_UP_TIME)withusleep_rangecalls due to fact the wait time is under 20 milliseconds.Signed-off-by Matt Ranostay <[email protected]>
Applied.
Quoted 56 lines
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-)drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +2
-1@@ -148,7 +148,8 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)return result;if (power_on) -msleep (INV_MPU6050_REG_UP_TIME ); +usleep_range (INV_MPU6050_REG_UP_TIME_MIN , +INV_MPU6050_REG_UP_TIME_MAX );return 0 ; }drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2
-1@@ -68,7 +68,8 @@ static int inv_mpu6050_select_bypass(struct i2c_adapter *adap, void *mux_priv,if (ret) goto write_error; -msleep (INV_MPU6050_REG_UP_TIME ); +usleep_range (INV_MPU6050_REG_UP_TIME_MIN , +INV_MPU6050_REG_UP_TIME_MAX ); }if (!ret) { st->powerup_count++;drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +6
-1@@ -172,10 +172,15 @@ struct inv_mpu6050_state {#define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6#define INV_MPU6050_FIFO_COUNT_BYTE 2#define INV_MPU6050_FIFO_THRESHOLD 500 + +/* delay time in milliseconds */ #define INV_MPU6050_POWER_UP_TIME 100#define INV_MPU6050_TEMP_UP_TIME 100#define INV_MPU6050_SENSOR_UP_TIME 30 -#define INV_MPU6050_REG_UP_TIME 5 + +/* delay time in microseconds */ +#define INV_MPU6050_REG_UP_TIME_MIN 5000 +#define INV_MPU6050_REG_UP_TIME_MAX 10000#define INV_MPU6050_TEMP_OFFSET 12421#define INV_MPU6050_TEMP_SCALE 2941
Re: [PATCH 3/5] iio: imu: mpu6050: add missing docstring for int_pin_cfg
In reply to Matt RanostayQuoted 1 line · Matt Ranostay
Signed-off-by Matt Ranostay <[email protected]>
Applied.
Quoted 17 lines
--- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 + 1 file changed, 1 insertion(+)drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +1
-0@@ -39,6 +39,7 @@* @int_enable: Interrupt enable register. * @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. */ struct inv_mpu6050_reg_map {u8 sample_rate_div;
Jonathan Cameron
maintainerRe: [PATCH 4/5] iio: imu: mpu6050: add calibration offset support
In reply to Matt RanostayQuoted 4 lines · Matt Ranostay
Allow setting of the x/y/z axes calibration offsets for the gyroscope and accelerometer.
Signed-off-by Matt Ranostay <[email protected]>
Applied - again minor fuzz, but I think it went on top fine.
Jonathan
Quoted 149 lines
--- 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(-)drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +49
-2@@ -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', \drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +10
-0@@ -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
Jonathan Cameron
maintainerRe: [PATCH 5/5] iio: imu: mpu6050: add mpu6500 register settings
In reply to Matt RanostayQuoted 1 line · Matt Ranostay
Signed-off-by Matt Ranostay <[email protected]>
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 120 lines
--- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 32 +++++++++++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-)drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +29
-3@@ -39,6 +39,26 @@ static const int gyro_scale_6050[] = {133090, 266181, 532362, 1064724};*/ static const int accel_scale[] = {598 ,1196 ,2392 ,4785 }; +static const struct inv_mpu6050_reg_map reg_set_6500 = { + .sample_rate_div =INV_MPU6050_REG_SAMPLE_RATE_DIV , + .lpf =INV_MPU6050_REG_CONFIG , + .user_ctrl =INV_MPU6050_REG_USER_CTRL , + .fifo_en =INV_MPU6050_REG_FIFO_EN , + .gyro_config =INV_MPU6050_REG_GYRO_CONFIG , + .accl_config =INV_MPU6050_REG_ACCEL_CONFIG , + .fifo_count_h =INV_MPU6050_REG_FIFO_COUNT_H , + .fifo_r_w =INV_MPU6050_REG_FIFO_R_W , + .raw_gyro =INV_MPU6050_REG_RAW_GYRO , + .raw_accl =INV_MPU6050_REG_RAW_ACCEL , + .temperature =INV_MPU6050_REG_TEMPERATURE , + .int_enable =INV_MPU6050_REG_INT_ENABLE , + .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_MPU6500_REG_ACCEL_OFFSET , + .gyro_offset =INV_MPU6050_REG_GYRO_OFFSET , +}; +static const struct inv_mpu6050_reg_map reg_set_6050 = { .sample_rate_div =INV_MPU6050_REG_SAMPLE_RATE_DIV , .lpf =INV_MPU6050_REG_CONFIG ,@@ -68,7 +88,13 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = { .accl_fs = INV_MPU6050_FS_02G, }; -static const struct inv_mpu6050_hw hw_info[INV_NUM_PARTS ] = { +static const struct inv_mpu6050_hw hw_info[] = { + { + .num_reg =117 , + .name ="MPU6500" , + .reg = ®_set_6500, + .config = &chip_config_6050, + }, { .num_reg =117 , .name ="MPU6050" ,@@ -692,7 +718,6 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) {int result; - st->chip_type =INV_MPU6050 ; st->hw = &hw_info[st->chip_type]; st->reg = hw_info[st->chip_type].reg;@@ -726,7 +751,7 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) }int inv_mpu_core_probe (struct regmap *regmap,int irq,const char *name, -int (*inv_mpu_bus_setup)(struct iio_dev *)) +int (*inv_mpu_bus_setup)(struct iio_dev *),int chip_type) {struct inv_mpu6050_state *st;struct iio_dev *indio_dev;@@ -739,6 +764,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,return -ENOMEM ; st =iio_priv (indio_dev); + st->chip_type = chip_type; st->powerup_count =0 ; st->irq = irq; st->map = regmap;drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2
-1@@ -130,7 +130,8 @@ static int inv_mpu_probe(struct i2c_client *client,return PTR_ERR (regmap); } - result =inv_mpu_core_probe (regmap, client->irq, name,NULL ); + result =inv_mpu_core_probe (regmap, client->irq, name, +NULL , id->driver_data);if (result <0 )return result;drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +1
-1@@ -277,7 +277,7 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on);int inv_mpu_acpi_create_mux_client (struct i2c_client *client);void inv_mpu_acpi_delete_mux_client (struct i2c_client *client);int inv_mpu_core_probe (struct regmap *regmap,int irq,const char *name, -int (*inv_mpu_bus_setup)(struct iio_dev *)); +int (*inv_mpu_bus_setup)(struct iio_dev *),int chip_type);int inv_mpu_core_remove (struct device *dev);int inv_mpu6050_set_power_itg (struct inv_mpu6050_state *st,bool power_on);extern const struct dev_pm_ops inv_mpu_pmops;drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2
-1@@ -54,7 +54,8 @@ static int inv_mpu_probe(struct spi_device *spi)return PTR_ERR (regmap); } -return inv_mpu_core_probe (regmap, spi->irq, name, inv_mpu_i2c_disable); +return inv_mpu_core_probe (regmap, spi->irq, name, + inv_mpu_i2c_disable, id->driver_data); }static int inv_mpu_remove (struct spi_device *spi)