Commit 04e6fedb authored by Martin Kepplinger's avatar Martin Kepplinger Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: add mount matrix support

Allow to read the mount-matrix device tree property and provide the
mount_matrix file for userspace to read.
Signed-off-by: default avatarMartin Kepplinger <martin.kepplinger@puri.sm>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 622b4339
...@@ -76,6 +76,7 @@ enum st_lsm6dsx_hw_id { ...@@ -76,6 +76,7 @@ enum st_lsm6dsx_hw_id {
.endianness = IIO_LE, \ .endianness = IIO_LE, \
}, \ }, \
.event_spec = &st_lsm6dsx_event, \ .event_spec = &st_lsm6dsx_event, \
.ext_info = st_lsm6dsx_accel_ext_info, \
.num_event_specs = 1, \ .num_event_specs = 1, \
} }
...@@ -378,6 +379,7 @@ struct st_lsm6dsx_sensor { ...@@ -378,6 +379,7 @@ struct st_lsm6dsx_sensor {
* @enable_event: enabled event bitmask. * @enable_event: enabled event bitmask.
* @iio_devs: Pointers to acc/gyro iio_dev instances. * @iio_devs: Pointers to acc/gyro iio_dev instances.
* @settings: Pointer to the specific sensor settings in use. * @settings: Pointer to the specific sensor settings in use.
* @orientation: sensor chip orientation relative to main hardware.
*/ */
struct st_lsm6dsx_hw { struct st_lsm6dsx_hw {
struct device *dev; struct device *dev;
...@@ -404,6 +406,8 @@ struct st_lsm6dsx_hw { ...@@ -404,6 +406,8 @@ struct st_lsm6dsx_hw {
struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
const struct st_lsm6dsx_settings *settings; const struct st_lsm6dsx_settings *settings;
struct iio_mount_matrix orientation;
}; };
static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = { static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = {
...@@ -477,4 +481,19 @@ st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr, ...@@ -477,4 +481,19 @@ st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
return err; return err;
} }
static const inline struct iio_mount_matrix *
st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev,
const struct iio_chan_spec *chan)
{
struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
struct st_lsm6dsx_hw *hw = sensor->hw;
return &hw->orientation;
}
static const struct iio_chan_spec_ext_info st_lsm6dsx_accel_ext_info[] = {
IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_lsm6dsx_get_mount_matrix),
{ }
};
#endif /* ST_LSM6DSX_H */ #endif /* ST_LSM6DSX_H */
...@@ -2337,6 +2337,10 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, ...@@ -2337,6 +2337,10 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
return err; return err;
} }
err = iio_read_mount_matrix(hw->dev, "mount-matrix", &hw->orientation);
if (err)
return err;
for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
if (!hw->iio_devs[i]) if (!hw->iio_devs[i])
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment