From e11bb33e7b179e2a8198653ee7bf4c044f3eff1e Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Sat, 18 Jan 2020 19:29:08 +0300 Subject: [PATCH] mount-matrix: Support IIO sysfs in_mount_matrix Linux kernel IIO drivers provide mount matrix via standardized sysfs interface. The IIO mount matrix could specified by "directory" and by "type", this patch adds support for the "directory" type which may be used by drivers that use the same shared matrix for all of the sensors or if driver provides only one accelerometer sensor at all. --- src/accel-mount-matrix.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/accel-mount-matrix.c b/src/accel-mount-matrix.c index c66b440..25a0ea5 100644 --- a/src/accel-mount-matrix.c +++ b/src/accel-mount-matrix.c @@ -50,6 +50,21 @@ setup_mount_matrix (GUdevDevice *device) g_clear_pointer (&ret, g_free); } + /* Linux kernel IIO accelerometer drivers provide mount matrix + * via standardized sysfs interface. + * + * See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio + * for more details. */ + mount_matrix = g_udev_device_get_sysfs_attr (device, "in_mount_matrix"); + if (mount_matrix) { + if (parse_mount_matrix (mount_matrix, &ret)) + return ret; + + g_warning ("Failed to parse in_mount_matrix ('%s') from sysfs", + mount_matrix); + g_clear_pointer (&ret, g_free); + } + g_debug ("Failed to auto-detect mount matrix, falling back to identity"); parse_mount_matrix (NULL, &ret); return ret;