Because of delayed module loading and USB enumeration time, IIO sensors
sysfs nodes may not yet be created by the time libsensors is asked to
initialize by the frameworks. This patch will wait up to 10 sec for the
sysfs nodes to appear before reporting "no sensors" to the framework on
the first boot of the device and set a system property based on whether
or not the iio sensors were found.
On subsequent boots, it will only consult this system property and thus
no delay in system services startup.
Change-Id: Ibb7b6d69ce1c1dcadd0ddaa361a4297489a044c7
Signed-off-by: Matt Gumbel <matthew.k.gumbel@linux.intel.com>
#include <fcntl.h>
#include <errno.h>
#include <cutils/log.h>
#include <fcntl.h>
#include <errno.h>
#include <cutils/log.h>
+#include <unistd.h>
+#include <cutils/properties.h>
int num_files(0);
DIR *dp(0);
struct dirent *dirp(0);
int num_files(0);
DIR *dp(0);
struct dirent *dirp(0);
+ char *key = "persist.sys.sensors.iio.present";
+ char value[PROPERTY_VALUE_MAX];
- if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
- ALOGI("/sys/bus/iio/devices doesn't exist. Reporting no sensors.");
- return 0;
+ if (property_get(key, value, "")) {
+ if (strncmp(value, "1", 1) == 0) {
+ ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
+ return ARRAY_SIZE(sSensorList);
+ } else {
+ ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
+ return 0;
+ }
- while ((dirp = readdir(dp)) != NULL){
- num_files++;
- }
- closedir(dp);
- if (num_files <= 2) {
- ALOGI("No entries found in /sys/bus/iio/devices. Reporting no sensors.");
- return 0;
+ for (int i=0; i<50; i++) {
+ num_files = 0;
+ if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
+ usleep(20000);
+ continue;
+ }
+ while ((dirp = readdir(dp)) != NULL){
+ num_files++;
+ }
+ closedir(dp);
+
+ if (num_files <= 2) {
+ usleep(20000);
+ continue;
+ }
+ ALOGI("Found IIO sensor hub.");
+ if (property_set(key, "1") != 0) {
+ ALOGE("Failed to set %s", key);
+ }
+ return ARRAY_SIZE(sSensorList);
- return ARRAY_SIZE(sSensorList);
+ ALOGI("Didn't find IIO sensor hub.");
+ if (property_set(key, "0") != 0) {
+ ALOGE("Failed to set %s", key);
+ }
+ return 0;
}
void BoardConfig::initSensors(SensorBase* sensors[])
}
void BoardConfig::initSensors(SensorBase* sensors[])