Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: accel: mma7660: add mount-matrix support

Allow using the mount-matrix device tree property to align the
accelerometer relative to the whole device.

Signed-off-by: Val Packett <val@packett.cool>
Link: https://lore.kernel.org/r/20240527080043.2709-1-val@packett.cool
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Val Packett and committed by
Jonathan Cameron
f4bed1ce c4ec8ded

+35 -15
+35 -15
drivers/iio/accel/mma7660.c
··· 38 38 39 39 static const int mma7660_nscale = 467142857; 40 40 41 - #define MMA7660_CHANNEL(reg, axis) { \ 42 - .type = IIO_ACCEL, \ 43 - .address = reg, \ 44 - .modified = 1, \ 45 - .channel2 = IIO_MOD_##axis, \ 46 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 47 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 48 - } 49 - 50 - static const struct iio_chan_spec mma7660_channels[] = { 51 - MMA7660_CHANNEL(MMA7660_REG_XOUT, X), 52 - MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), 53 - MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), 54 - }; 55 - 56 41 enum mma7660_mode { 57 42 MMA7660_MODE_STANDBY, 58 43 MMA7660_MODE_ACTIVE ··· 47 62 struct i2c_client *client; 48 63 struct mutex lock; 49 64 enum mma7660_mode mode; 65 + struct iio_mount_matrix orientation; 66 + }; 67 + 68 + static const struct iio_mount_matrix * 69 + mma7660_get_mount_matrix(const struct iio_dev *indio_dev, 70 + const struct iio_chan_spec *chan) 71 + { 72 + struct mma7660_data *data = iio_priv(indio_dev); 73 + 74 + return &data->orientation; 75 + } 76 + 77 + static const struct iio_chan_spec_ext_info mma7660_ext_info[] = { 78 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mma7660_get_mount_matrix), 79 + { } 50 80 }; 51 81 52 82 static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL); ··· 73 73 74 74 static const struct attribute_group mma7660_attribute_group = { 75 75 .attrs = mma7660_attributes 76 + }; 77 + 78 + #define MMA7660_CHANNEL(reg, axis) { \ 79 + .type = IIO_ACCEL, \ 80 + .address = reg, \ 81 + .modified = 1, \ 82 + .channel2 = IIO_MOD_##axis, \ 83 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 84 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 85 + .ext_info = mma7660_ext_info, \ 86 + } 87 + 88 + static const struct iio_chan_spec mma7660_channels[] = { 89 + MMA7660_CHANNEL(MMA7660_REG_XOUT, X), 90 + MMA7660_CHANNEL(MMA7660_REG_YOUT, Y), 91 + MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z), 76 92 }; 77 93 78 94 static int mma7660_set_mode(struct mma7660_data *data, ··· 202 186 i2c_set_clientdata(client, indio_dev); 203 187 mutex_init(&data->lock); 204 188 data->mode = MMA7660_MODE_STANDBY; 189 + 190 + ret = iio_read_mount_matrix(&client->dev, &data->orientation); 191 + if (ret) 192 + return ret; 205 193 206 194 indio_dev->info = &mma7660_info; 207 195 indio_dev->name = MMA7660_DRIVER_NAME;