OSDN Git Service

Better coordinate frequencies of co-located iio sensors
authorPatrick Porlan <patrick.porlan@intel.com>
Wed, 17 Dec 2014 14:54:52 +0000 (15:54 +0100)
committerGerrit Code Review <gerrit2@irsgerrit001.ir.intel.com>
Thu, 18 Dec 2014 08:35:48 +0000 (08:35 +0000)
This is in the case where several sensors share a single frequency
knob (that was the case on the Invensense MPU chip used by the T100)
rather than have differenciated rate settings.

Change-Id: Id92c6f0b2811a76eb4550fd801e0bee2bb70a48b
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
control.c

index 917c32d..5c95008 100644 (file)
--- a/control.c
+++ b/control.c
@@ -794,15 +794,6 @@ static int setup_delay_sysfs (int s, float requested_rate)
                return -ENOSYS;
        }
 
-       /* Coordinate with others active sensors on the same device, if any */
-       if (per_device_sampling_rate)
-               for (n=0; n<sensor_count; n++)
-                       if (n != s && sensor[n].dev_num == dev_num &&
-                           sensor[n].num_channels &&
-                           is_enabled(s) &&
-                           sensor[n].sampling_rate > arb_sampling_rate)
-                               arb_sampling_rate = sensor[n].sampling_rate;
-
        /* Check if we have contraints on allowed sampling rates */
 
        sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
@@ -855,6 +846,31 @@ static int setup_delay_sysfs (int s, float requested_rate)
                arb_sampling_rate = max_supported_rate;
        }
 
+
+       /* Coordinate with others active sensors on the same device, if any */
+       if (per_device_sampling_rate)
+               for (n=0; n<sensor_count; n++)
+                       if (n != s && sensor[n].dev_num == dev_num &&
+                           sensor[n].num_channels && is_enabled(n) &&
+                           sensor[n].sampling_rate > arb_sampling_rate) {
+       ALOGV("Sampling rate shared between %s and %s, using %g instead of %g\n"
+             , sensor[s].friendly_name, sensor[n].friendly_name,
+             sensor[n].sampling_rate, arb_sampling_rate);
+                               arb_sampling_rate = sensor[n].sampling_rate;
+                       }
+
+       sensor[s].sampling_rate = arb_sampling_rate;
+
+       /*
+        * Update actual sampling rate field for this sensor and others which
+        * may be sharing the same sampling rate.
+        */
+       if (per_device_sampling_rate)
+               for (n=0; n<sensor_count; n++)
+                       if (sensor[n].dev_num == dev_num && n != s &&
+                           sensor[n].num_channels)
+                               sensor[n].sampling_rate = arb_sampling_rate;
+
        /* If the desired rate is already active we're all set */
        if (arb_sampling_rate == cur_sampling_rate)
                return 0;