OSDN Git Service

IRDA-2849: Add support for optional calibscale properties
authorPatrick Porlan <patrick.porlan@intel.com>
Thu, 29 Jan 2015 14:11:10 +0000 (15:11 +0100)
committerPatrick Porlan <patrick.porlan@intel.com>
Thu, 29 Jan 2015 14:40:32 +0000 (15:40 +0100)
If something like ro.iio.accel.x.calib_bias = -1015 is found,
and non-zero, store it in the relevant sysfs file, e.g. something
like /sys/bus/iio/devices/iio:deviceX/in_accel_x_calibbias.

The driver is then responsible for using that data as it wishes.

Change-Id: I7cfb21f00533d03f5a5b93cfe32f56c1e1fb9c37
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
Tracked-On: https://jira01.devtools.intel.com/browse/IRDA-2849
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
common.h
enumeration.c

index 01cb599..6ca822c 100644 (file)
--- a/common.h
+++ b/common.h
@@ -24,6 +24,7 @@
 #define DEVICE_SAMPLING_PATH   BASE_PATH "sampling_frequency"
 #define DEVICE_AVAIL_FREQ_PATH BASE_PATH "sampling_frequency_available"
 #define ILLUMINATION_CALIBPATH BASE_PATH "in_illuminance_calibscale"
+#define SENSOR_CALIB_BIAS_PATH BASE_PATH "in_%s_calibbias"
 
 #define PROP_BASE              "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
 
@@ -85,7 +86,7 @@ typedef struct
 {
        int offset;     /* Offset in bytes within the iio character device report */
        int size;       /* Field size in bytes */
-       float scale;    /* scale for each channel */
+       float scale;    /* Scale for each channel */
        char type_spec[MAX_TYPE_SPEC_LEN];      /* From driver; ex: le:u10/16>>0 */
        datum_info_t type_info;                 /* Decoded contents of type spec */
        float opt_scale; /*
index af72426..dce99cc 100644 (file)
@@ -283,6 +283,7 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        const char* ch_name;
        int num_channels;
        char suffix[MAX_NAME_SIZE + 8];
+       int calib_bias;
 
        if (sensor_count == MAX_SENSORS) {
                ALOGE("Too many sensors!\n");
@@ -325,6 +326,28 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
                 }
        }
 
+        /*
+         * See if we have optional calibration biases for each of the channels of this sensor. These would be expressed using properties like
+         * iio.accel.y.calib_bias = -1, or possibly something like iio.temp.calib_bias if the sensor has a single channel. This value gets stored in the
+         * relevant calibbias sysfs file if that file can be located and then used internally by the iio sensor driver.
+         */
+
+        if (num_channels) {
+               for (c = 0; c < num_channels; c++) {
+                       ch_name = sensor_catalog[catalog_index].channel[c].name;
+                       sprintf(suffix, "%s.calib_bias", ch_name);
+                       if (!sensor_get_prop(s, suffix, &calib_bias) && calib_bias) {
+                               sprintf(suffix, "%s_%s", prefix, sensor_catalog[catalog_index].channel[c].name);
+                               sprintf(sysfs_path, SENSOR_CALIB_BIAS_PATH, dev_num, suffix);
+                               sysfs_write_int(sysfs_path, calib_bias);
+                       }
+               }
+        } else
+               if (!sensor_get_prop(s, "calib_bias", &calib_bias) && calib_bias) {
+                               sprintf(sysfs_path, SENSOR_CALIB_BIAS_PATH, dev_num, prefix);
+                               sysfs_write_int(sysfs_path, calib_bias);
+                       }
+
        /* Read name attribute, if available */
        sprintf(sysfs_path, NAME_PATH, dev_num);
        sysfs_read_str(sysfs_path, sensor[s].internal_name, MAX_NAME_SIZE);