OSDN Git Service

libsensors: retry more and deal with sensor hub quirk
authorDaniel Leung <daniel.leung@intel.com>
Thu, 27 Dec 2012 20:55:57 +0000 (12:55 -0800)
committerMattias Pettersson <mattias.pettersson@intel.com>
Wed, 4 Dec 2013 14:13:12 +0000 (15:13 +0100)
() Sometimes the ueventd has a hard time keeping up with all
   the uevents. It causes the permissions of the IIO sysfs nodes
   to remain unchanged. This causes the sensor HAL initialization
   to fail. Need to retry a few more times.

() There is a quirk with some sensor hubs, where you have to
   enable/disable/enable for it to start sending any events.
   This adds the code to "jump-start" the hub.

Issue: AXIA-1451
Change-Id: Iecfbf8589637eb16a8b80364b47c2527a69d7cd3
Depends-Change-Id: Ibfff2a60c5223b2018c106237365967471e00e89
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
common/libsensors/HidSensor_ALS.cpp
common/libsensors/HidSensor_Accel3D.cpp
common/libsensors/HidSensor_Compass3D.cpp
common/libsensors/HidSensor_Gyro3D.cpp
common/libsensors/SensorIIODev.cpp

index 8c6160f..dd1f47d 100644 (file)
@@ -36,7 +36,7 @@ const struct sensor_t ALSSensor::sSensorInfo_als = {
         50000.0f, 1.0f, 0.75f, 0, {}
     ,
 };
         50000.0f, 1.0f, 0.75f, 0, {}
     ,
 };
-const int retry_cnt = 5;
+const int retry_cnt = 10;
 
 ALSSensor::ALSSensor(): SensorIIODev("als", "in_intensity_scale", "in_intensity_offset", "in_intensity_", retry_cnt){
     ALOGV(">>ALSSensor 3D: constructor!");
 
 ALSSensor::ALSSensor(): SensorIIODev("als", "in_intensity_scale", "in_intensity_offset", "in_intensity_", retry_cnt){
     ALOGV(">>ALSSensor 3D: constructor!");
index 50ba0fc..e01a679 100644 (file)
@@ -43,7 +43,7 @@ const struct sensor_t AccelSensor::sSensorInfo_accel3D = {
 
 const long HID_USAGE_SENSOR_UNITS_G = 0x1A;
 const long HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD = (0x11, 0xE0);
 
 const long HID_USAGE_SENSOR_UNITS_G = 0x1A;
 const long HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD = (0x11, 0xE0);
-const int retry_cnt = 5;
+const int retry_cnt = 10;
 
 AccelSensor::AccelSensor(): SensorIIODev("accel_3d", "in_accel_scale", "in_accel_offset", "in_accel_", retry_cnt){
     ALOGV(">>AccelSensor 3D: constructor!");
 
 AccelSensor::AccelSensor(): SensorIIODev("accel_3d", "in_accel_scale", "in_accel_offset", "in_accel_", retry_cnt){
     ALOGV(">>AccelSensor 3D: constructor!");
index f9f03d0..981cecb 100644 (file)
@@ -40,7 +40,7 @@ const struct sensor_t CompassSensor::sSensorInfo_compass3D = {
     "HID_SENSOR Compass 3D", "Intel", 1, SENSORS_MAGNETIC_FIELD_HANDLE,
         SENSOR_TYPE_MAGNETIC_FIELD, RANGE_M, RESOLUTION_M, 0.1f, 23000, {}
 };
     "HID_SENSOR Compass 3D", "Intel", 1, SENSORS_MAGNETIC_FIELD_HANDLE,
         SENSOR_TYPE_MAGNETIC_FIELD, RANGE_M, RESOLUTION_M, 0.1f, 23000, {}
 };
-const int retry_cnt = 5;
+const int retry_cnt = 10;
 
 CompassSensor::CompassSensor(): SensorIIODev("magn_3d", "in_magn_scale", "in_magn_offset", "in_magn_", retry_cnt){
     ALOGV(">>ComassSensor 3D: constructor!");
 
 CompassSensor::CompassSensor(): SensorIIODev("magn_3d", "in_magn_scale", "in_magn_offset", "in_magn_", retry_cnt){
     ALOGV(">>ComassSensor 3D: constructor!");
index eeafe8b..d9f2382 100644 (file)
@@ -42,7 +42,7 @@ const struct sensor_t GyroSensor::sSensorInfo_gyro3D = {
 };
 const int HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND = 0x15;
 const int HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND = 0xF012;
 };
 const int HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND = 0x15;
 const int HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND = 0xF012;
-const int retry_cnt = 5;
+const int retry_cnt = 10;
 
 GyroSensor::GyroSensor(): SensorIIODev("gyro_3d", "in_anglvel_scale", "in_anglvel_offset", "in_anglvel_", retry_cnt){
     ALOGV("GyroSensor: constructor\n");
 
 GyroSensor::GyroSensor(): SensorIIODev("gyro_3d", "in_anglvel_scale", "in_anglvel_offset", "in_anglvel_", retry_cnt){
     ALOGV("GyroSensor: constructor\n");
index 38c28c5..669de2f 100644 (file)
@@ -117,6 +117,12 @@ int SensorIIODev::enable(int enabled)
         return 0;
     }
     if (enabled){
         return 0;
     }
     if (enabled){
+        // QUIRK: some sensor hubs need to be turned on and off and on
+        // before sending any information. So we turn it on and off first
+        // before enabling again later in this function.
+        EnableBuffer(1);
+        EnableBuffer(0);
+
         if (ReadHIDExponentValue(&unit_expo_value) < 0)
             goto err_ret;
         if (ReadHIDMeasurmentUnit(&units_value) < 0)
         if (ReadHIDExponentValue(&unit_expo_value) < 0)
             goto err_ret;
         if (ReadHIDMeasurmentUnit(&units_value) < 0)
@@ -498,6 +504,13 @@ int SensorIIODev::ParseIIODirectory(const std::string& name){
     ret = EnableChannels();
     if (ret < 0){
         ALOGE("ParseIIODirectory Failed due Enable Channels failed\n");
     ret = EnableChannels();
     if (ret < 0){
         ALOGE("ParseIIODirectory Failed due Enable Channels failed\n");
+       if (ret == -EACCES) {
+            // EACCES means the nodes do not have current owner.
+            // Need to retry, or else sensors won't power on.
+            // Other errors can be ignored, as these nodes are
+            // set once, and will return error when set again.
+            return ret;
+        }
     }
 
     // Parse the channels and build a list
     }
 
     // Parse the channels and build a list