accel: Apply mount-matrix from udev ACCEL_MOUNT_MATRIX property
Mount-matrix for devices that require them are now read from udev. In some cases, the information is already available in the device's firmware, but the kernel does not export it. Bear this in mind when writing quirks.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "drivers.h"
|
||||
#include "iio-buffer-utils.h"
|
||||
#include "accel-mount-matrix.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -22,6 +23,7 @@ typedef struct {
|
||||
GUdevDevice *dev;
|
||||
const char *dev_path;
|
||||
const char *name;
|
||||
IioAccelVec3 *mount_matrix;
|
||||
int device_id;
|
||||
BufferDrvData *buffer_data;
|
||||
} DrvData;
|
||||
@@ -182,6 +184,7 @@ iio_buffer_accel_open (GUdevDevice *device,
|
||||
gpointer user_data)
|
||||
{
|
||||
char *trigger_name;
|
||||
const char *mount_matrix;
|
||||
|
||||
drv_data = g_new0 (DrvData, 1);
|
||||
|
||||
@@ -199,6 +202,13 @@ iio_buffer_accel_open (GUdevDevice *device,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mount_matrix = g_udev_device_get_property (device, "ACCEL_MOUNT_MATRIX");
|
||||
if (!parse_mount_matrix (mount_matrix, &drv_data->mount_matrix)) {
|
||||
g_warning ("Invalid mount-matrix ('%s'), falling back to identity",
|
||||
mount_matrix);
|
||||
parse_mount_matrix (NULL, &drv_data->mount_matrix);
|
||||
}
|
||||
|
||||
drv_data->dev = g_object_ref (device);
|
||||
drv_data->dev_path = g_udev_device_get_device_file (device);
|
||||
drv_data->name = g_udev_device_get_property (device, "NAME");
|
||||
@@ -217,6 +227,7 @@ iio_buffer_accel_close (void)
|
||||
iio_buffer_accel_set_polling (FALSE);
|
||||
g_clear_pointer (&drv_data->buffer_data, buffer_drv_data_free);
|
||||
g_clear_object (&drv_data->dev);
|
||||
g_clear_pointer (&drv_data->mount_matrix, g_free);
|
||||
g_clear_pointer (&drv_data, g_free);
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "drivers.h"
|
||||
#include "accel-mount-matrix.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -21,6 +22,7 @@ typedef struct DrvData {
|
||||
gpointer user_data;
|
||||
GUdevDevice *dev;
|
||||
const char *name;
|
||||
IioAccelVec3 *mount_matrix;
|
||||
|
||||
double scale;
|
||||
} DrvData;
|
||||
@@ -105,10 +107,19 @@ iio_poll_accel_open (GUdevDevice *device,
|
||||
ReadingsUpdateFunc callback_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
const char *mount_matrix;
|
||||
|
||||
drv_data = g_new0 (DrvData, 1);
|
||||
drv_data->dev = g_object_ref (device);
|
||||
drv_data->name = g_udev_device_get_property (device, "NAME");
|
||||
|
||||
mount_matrix = g_udev_device_get_property (device, "ACCEL_MOUNT_MATRIX");
|
||||
if (!parse_mount_matrix (mount_matrix, &drv_data->mount_matrix)) {
|
||||
g_warning ("Invalid mount-matrix ('%s'), falling back to identity",
|
||||
mount_matrix);
|
||||
parse_mount_matrix (NULL, &drv_data->mount_matrix);
|
||||
}
|
||||
|
||||
drv_data->callback_func = callback_func;
|
||||
drv_data->user_data = user_data;
|
||||
drv_data->scale = g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale");
|
||||
@@ -123,6 +134,7 @@ iio_poll_accel_close (void)
|
||||
{
|
||||
iio_poll_accel_set_polling (FALSE);
|
||||
g_clear_object (&drv_data->dev);
|
||||
g_clear_pointer (&drv_data->mount_matrix, g_free);
|
||||
g_clear_pointer (&drv_data, g_free);
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "drivers.h"
|
||||
#include "accel-mount-matrix.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,6 +26,7 @@ typedef struct DrvData {
|
||||
GUdevDevice *dev, *parent;
|
||||
const char *dev_path;
|
||||
const char *name;
|
||||
IioAccelVec3 *mount_matrix;
|
||||
gboolean sends_kevent;
|
||||
} DrvData;
|
||||
|
||||
@@ -119,6 +121,7 @@ input_accel_open (GUdevDevice *device,
|
||||
gpointer user_data)
|
||||
{
|
||||
const gchar * const subsystems[] = { "input", NULL };
|
||||
const char *mount_matrix;
|
||||
|
||||
drv_data = g_new0 (DrvData, 1);
|
||||
drv_data->dev = g_object_ref (device);
|
||||
@@ -127,6 +130,13 @@ input_accel_open (GUdevDevice *device,
|
||||
drv_data->name = g_udev_device_get_property (device, "NAME");
|
||||
drv_data->client = g_udev_client_new (subsystems);
|
||||
|
||||
mount_matrix = g_udev_device_get_property (device, "ACCEL_MOUNT_MATRIX");
|
||||
if (!parse_mount_matrix (mount_matrix, &drv_data->mount_matrix)) {
|
||||
g_warning ("Invalid mount-matrix ('%s'), falling back to identity",
|
||||
mount_matrix);
|
||||
parse_mount_matrix (NULL, &drv_data->mount_matrix);
|
||||
}
|
||||
|
||||
drv_data->callback_func = callback_func;
|
||||
drv_data->user_data = user_data;
|
||||
|
||||
@@ -171,6 +181,7 @@ input_accel_close (void)
|
||||
g_clear_object (&drv_data->client);
|
||||
g_clear_object (&drv_data->dev);
|
||||
g_clear_object (&drv_data->parent);
|
||||
g_clear_pointer (&drv_data->mount_matrix, g_free);
|
||||
g_clear_pointer (&drv_data->dev_path, g_free);
|
||||
|
||||
g_clear_pointer (&drv_data, g_free);
|
||||
|
Reference in New Issue
Block a user