From bc76fcaabb88a21a7db2b29a67cdd9b394423fd8 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Thu, 27 Dec 2012 12:55:57 -0800 Subject: [PATCH] libsensors: retry more and deal with sensor hub quirk () 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 --- common/libsensors/HidSensor_ALS.cpp | 2 +- common/libsensors/HidSensor_Accel3D.cpp | 2 +- common/libsensors/HidSensor_Compass3D.cpp | 2 +- common/libsensors/HidSensor_Gyro3D.cpp | 2 +- common/libsensors/SensorIIODev.cpp | 13 +++++++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/libsensors/HidSensor_ALS.cpp b/common/libsensors/HidSensor_ALS.cpp index 8c6160f..dd1f47d 100644 --- a/common/libsensors/HidSensor_ALS.cpp +++ b/common/libsensors/HidSensor_ALS.cpp @@ -36,7 +36,7 @@ const struct sensor_t ALSSensor::sSensorInfo_als = { 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!"); diff --git a/common/libsensors/HidSensor_Accel3D.cpp b/common/libsensors/HidSensor_Accel3D.cpp index 50ba0fc..e01a679 100644 --- a/common/libsensors/HidSensor_Accel3D.cpp +++ b/common/libsensors/HidSensor_Accel3D.cpp @@ -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 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!"); diff --git a/common/libsensors/HidSensor_Compass3D.cpp b/common/libsensors/HidSensor_Compass3D.cpp index f9f03d0..981cecb 100644 --- a/common/libsensors/HidSensor_Compass3D.cpp +++ b/common/libsensors/HidSensor_Compass3D.cpp @@ -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, {} }; -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!"); diff --git a/common/libsensors/HidSensor_Gyro3D.cpp b/common/libsensors/HidSensor_Gyro3D.cpp index eeafe8b..d9f2382 100644 --- a/common/libsensors/HidSensor_Gyro3D.cpp +++ b/common/libsensors/HidSensor_Gyro3D.cpp @@ -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 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"); diff --git a/common/libsensors/SensorIIODev.cpp b/common/libsensors/SensorIIODev.cpp index 38c28c5..669de2f 100644 --- a/common/libsensors/SensorIIODev.cpp +++ b/common/libsensors/SensorIIODev.cpp @@ -117,6 +117,12 @@ int SensorIIODev::enable(int 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) @@ -498,6 +504,13 @@ int SensorIIODev::ParseIIODirectory(const std::string& name){ 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 -- 2.11.0