OSDN Git Service

STPK-1429 Honor maximum rate if reported through sysfs
authorPatrick Porlan <patrick.porlan@intel.com>
Tue, 15 Apr 2014 09:41:08 +0000 (11:41 +0200)
committersuyyala <sridhar.uyyala@intel.com>
Sat, 10 May 2014 15:31:15 +0000 (08:31 -0700)
In case we have a list of supported rates, make sure that we
don't select a higher value than the maximum advertised one.

Issue: STPK-1429

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

index 56f3d0a..e9e4b0f 100644 (file)
--- a/control.c
+++ b/control.c
@@ -664,6 +664,8 @@ int sensor_set_delay(int s, int64_t ns)
        int req_sampling_rate;  /* Requested ; may be different from granted */
        int per_sensor_sampling_rate;
        int per_device_sampling_rate;
+       int max_supported_rate = 0;
+       int limit;
        char freqs_buf[100];
        char* cursor;
        int n;
@@ -731,6 +733,9 @@ int sensor_set_delay(int s, int64_t ns)
                        /* Decode a single integer value */
                        n = atoi(cursor);
 
+                       if (n > max_supported_rate)
+                               max_supported_rate = n;
+
                        /* If this matches the selected rate, we're happy */
                        if (new_sampling_rate == n)
                                break;
@@ -761,10 +766,16 @@ int sensor_set_delay(int s, int64_t ns)
                }
        }
 
-       /* Cap sampling rates at 1000/s for the time being */
-       if (new_sampling_rate > 1000000/POLL_MIN_INTERVAL) {
+       /* Cap sampling rate */
+
+       limit = 1000000/POLL_MIN_INTERVAL;
+
+       if (max_supported_rate && new_sampling_rate > max_supported_rate)
+               limit = max_supported_rate;
+
+       if (new_sampling_rate > limit) {
 
-               new_sampling_rate = 1000000/POLL_MIN_INTERVAL;
+               new_sampling_rate = limit;
 
                ALOGI(  "Can't support %d sampling rate, lowering to %d\n",
                        req_sampling_rate, new_sampling_rate);