accel: Fix getting scale for sensors with IIO_SHARED_BY_ALL mask

Properties with the IIO_SHARED_BY_ALL mask don't have the sensor type prefix
before the filename, causing some devices to not have a scale set from sysfs.

Fix this by searching through sysfs for both properties name: scale and
in_accel_scale.

Tested on: Cyan (Acer Chromebook R11, with 2 accelerometers)
Affects: All chromebooks with cros-ec sensors
https://github.com/torvalds/linux/tree/master/drivers/iio/common/cros_ec_sensors
This commit is contained in:
Daniel Stuart
2019-10-04 13:38:45 -03:00
committed by hadess
parent eb8fde8fd2
commit 43e5ff769e
6 changed files with 34 additions and 13 deletions

View File

@@ -28,8 +28,8 @@ iio_sensor_proxy_SOURCES = \
iio-buffer-utils.c \ iio-buffer-utils.c \
accel-mount-matrix.h \ accel-mount-matrix.h \
accel-mount-matrix.c \ accel-mount-matrix.c \
accel-location.h \ accel-attributes.h \
accel-location.c \ accel-attributes.c \
$(BUILT_SOURCES) $(BUILT_SOURCES)
iio_sensor_proxy_CPPFLAGS = \ iio_sensor_proxy_CPPFLAGS = \
@@ -63,8 +63,8 @@ test_mount_matrix_LDADD = $(IIO_SENSOR_PROXY_LIBS)
test_accel_location_SOURCES = \ test_accel_location_SOURCES = \
test-accel-location.c \ test-accel-location.c \
accel-location.h \ accel-attributes.h \
accel-location.c accel-attributes.c
test_accel_location_CPPFLAGS = \ test_accel_location_CPPFLAGS = \
$(IIO_SENSOR_PROXY_CFLAGS) \ $(IIO_SENSOR_PROXY_CFLAGS) \

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2019 Luís Ferreira <luis@aurorafoss.org> * Copyright (c) 2019 Luís Ferreira <luis@aurorafoss.org>
* Copyright (c) 2019 Daniel Stuart <daniel.stuart@pucpr.edu.br>
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published by * under the terms of the GNU General Public License version 3 as published by
@@ -7,7 +8,7 @@
* *
*/ */
#include "accel-location.h" #include "accel-attributes.h"
AccelLocation AccelLocation
setup_accel_location (GUdevDevice *device) setup_accel_location (GUdevDevice *device)
@@ -55,3 +56,23 @@ parse_accel_location (const char *location, AccelLocation *value)
return FALSE; return FALSE;
} }
} }
gdouble
get_accel_scale (GUdevDevice *device)
{
gdouble scale;
scale = g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale");
if (scale != 0.0) {
g_debug ("Attribute in_accel_scale ('%f') found on sysfs", scale);
return scale;
}
scale = g_udev_device_get_sysfs_attr_as_double (device, "scale");
if (scale != 0.0) {
g_debug ("Attribute scale ('%f') found on sysfs", scale);
return scale;
}
g_debug ("Failed to auto-detect scale, falling back to 1.0");
return 1.0;
}

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2019 Luís Ferreira <luis@aurorafoss.org> * Copyright (c) 2019 Luís Ferreira <luis@aurorafoss.org>
* Copyright (c) 2019 Daniel Stuart <daniel.stuart@pucpr.edu.br>
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published by * under the terms of the GNU General Public License version 3 as published by
@@ -19,3 +20,5 @@ AccelLocation setup_accel_location (GUdevDevice *device);
gboolean parse_accel_location (const char *location, gboolean parse_accel_location (const char *location,
AccelLocation *value); AccelLocation *value);
gdouble get_accel_scale (GUdevDevice *device);

View File

@@ -9,7 +9,7 @@
#include <glib.h> #include <glib.h>
#include <gudev/gudev.h> #include <gudev/gudev.h>
#include "accel-location.h" #include "accel-attributes.h"
typedef enum { typedef enum {
DRIVER_TYPE_ACCEL, DRIVER_TYPE_ACCEL,

View File

@@ -25,8 +25,7 @@ typedef struct DrvData {
const char *name; const char *name;
AccelVec3 *mount_matrix; AccelVec3 *mount_matrix;
AccelLocation location; AccelLocation location;
gdouble scale;
double scale;
} DrvData; } DrvData;
static DrvData *drv_data = NULL; static DrvData *drv_data = NULL;
@@ -128,9 +127,7 @@ iio_poll_accel_open (GUdevDevice *device,
drv_data->location = setup_accel_location (device); drv_data->location = setup_accel_location (device);
drv_data->callback_func = callback_func; drv_data->callback_func = callback_func;
drv_data->user_data = user_data; drv_data->user_data = user_data;
drv_data->scale = g_udev_device_get_sysfs_attr_as_double (device, "in_accel_scale"); drv_data->scale = get_accel_scale (device);
if (drv_data->scale == 0.0)
drv_data->scale = 1.0;
return TRUE; return TRUE;
} }

View File

@@ -7,7 +7,7 @@
* *
*/ */
#include "accel-location.h" #include "accel-attributes.h"
#define VALID_DISPLAY_LOCATION "display" #define VALID_DISPLAY_LOCATION "display"
#define VALID_BASE_LOCATION "base" #define VALID_BASE_LOCATION "base"