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

iio: accel: kxcjk1013: Support orientation matrix

Hardware could be physically mounted in any possible direction and
userpspace needs to be aware of the mounting orientation in order to
process sensor's data correctly. In particular this helps iio-sensor-proxy
to report display's orientation properly on a phone/tablet devices.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Dmitry Osipenko and committed by
Jonathan Cameron
1bde330c 04e6fedb

+28 -2
+25 -2
drivers/iio/accel/kxcjk-1013.c
··· 130 130 struct i2c_client *client; 131 131 struct iio_trigger *dready_trig; 132 132 struct iio_trigger *motion_trig; 133 + struct iio_mount_matrix orientation; 133 134 struct mutex mutex; 134 135 s16 buffer[8]; 135 136 u8 odr_bits; ··· 984 983 BIT(IIO_EV_INFO_PERIOD) 985 984 }; 986 985 986 + static const struct iio_mount_matrix * 987 + kxcjk1013_get_mount_matrix(const struct iio_dev *indio_dev, 988 + const struct iio_chan_spec *chan) 989 + { 990 + struct kxcjk1013_data *data = iio_priv(indio_dev); 991 + 992 + return &data->orientation; 993 + } 994 + 995 + static const struct iio_chan_spec_ext_info kxcjk1013_ext_info[] = { 996 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, kxcjk1013_get_mount_matrix), 997 + { } 998 + }; 999 + 987 1000 #define KXCJK1013_CHANNEL(_axis) { \ 988 1001 .type = IIO_ACCEL, \ 989 1002 .modified = 1, \ ··· 1014 999 .endianness = IIO_LE, \ 1015 1000 }, \ 1016 1001 .event_spec = &kxcjk1013_event, \ 1002 + .ext_info = kxcjk1013_ext_info, \ 1017 1003 .num_event_specs = 1 \ 1018 1004 } 1019 1005 ··· 1283 1267 data->client = client; 1284 1268 1285 1269 pdata = dev_get_platdata(&client->dev); 1286 - if (pdata) 1270 + if (pdata) { 1287 1271 data->active_high_intr = pdata->active_high_intr; 1288 - else 1272 + data->orientation = pdata->orientation; 1273 + } else { 1289 1274 data->active_high_intr = true; /* default polarity */ 1275 + 1276 + ret = iio_read_mount_matrix(&client->dev, "mount-matrix", 1277 + &data->orientation); 1278 + if (ret) 1279 + return ret; 1280 + } 1290 1281 1291 1282 if (id) { 1292 1283 data->chipset = (enum kx_chipset)(id->driver_data);
+3
include/linux/iio/accel/kxcjk_1013.h
··· 7 7 #ifndef __IIO_KXCJK_1013_H__ 8 8 #define __IIO_KXCJK_1013_H__ 9 9 10 + #include <linux/iio/iio.h> 11 + 10 12 struct kxcjk_1013_platform_data { 11 13 bool active_high_intr; 14 + struct iio_mount_matrix orientation; 12 15 }; 13 16 14 17 #endif