iio: imu: bmi160: added mount-matrix support

Add mount-matrix binding support. As chip could have different orientations
a mount matrix support is needed to correctly translate these differences.

Signed-off-by: Jonathan Albrieux <jonathan.albrieux@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Jonathan Albrieux 2020-05-25 18:46:04 +02:00 committed by Jonathan Cameron
parent 5dea3fb066
commit 812a46b7ff
2 changed files with 21 additions and 0 deletions

View File

@ -9,6 +9,7 @@ struct bmi160_data {
struct regmap *regmap;
struct iio_trigger *trig;
struct regulator_bulk_data supplies[2];
struct iio_mount_matrix orientation;
};
extern const struct regmap_config bmi160_regmap_config;

View File

@ -110,6 +110,7 @@
.storagebits = 16, \
.endianness = IIO_LE, \
}, \
.ext_info = bmi160_ext_info, \
}
/* scan indexes follow DATA register order */
@ -265,6 +266,20 @@ static const struct bmi160_odr_item bmi160_odr_table[] = {
},
};
static const struct iio_mount_matrix *
bmi160_get_mount_matrix(const struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
struct bmi160_data *data = iio_priv(indio_dev);
return &data->orientation;
}
static const struct iio_chan_spec_ext_info bmi160_ext_info[] = {
IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bmi160_get_mount_matrix),
{ }
};
static const struct iio_chan_spec bmi160_channels[] = {
BMI160_CHANNEL(IIO_ACCEL, X, BMI160_SCAN_ACCEL_X),
BMI160_CHANNEL(IIO_ACCEL, Y, BMI160_SCAN_ACCEL_Y),
@ -839,6 +854,11 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,
return ret;
}
ret = iio_read_mount_matrix(dev, "mount-matrix",
&data->orientation);
if (ret)
return ret;
ret = bmi160_chip_init(data, use_spi);
if (ret)
return ret;