+static int integrate_device_report_from_event(int dev_num, int fd)
+{
+ int len, s;
+ int64_t ts;
+ struct iio_event_data event;
+
+ /* There's an incoming report on the specified iio device char dev fd */
+ if (fd == -1) {
+ ALOGE("Ignoring stale report on event fd %d of device %d\n",
+ fd, dev_num);
+ return -1;
+ }
+
+ len = read(fd, &event, sizeof(event));
+
+ if (len == -1) {
+ ALOGE("Could not read event from fd %d of device %d (%s)\n",
+ fd, dev_num, strerror(errno));
+ return -1;
+ }
+
+ ts = event.timestamp;
+
+ ALOGV("Read event %lld from fd %d of iio device %d\n", event.id, fd, dev_num);
+
+ /* Map device report to sensor reports */
+ for (s = 0; s < MAX_SENSORS; s++)
+ if (sensor[s].dev_num == dev_num &&
+ is_enabled(s)) {
+ sensor[s].report_ts = ts;
+ sensor[s].report_pending = 1;
+ sensor[s].report_initialized = 1;
+ ALOGV("Sensor %d report available (1 byte)\n", s);
+ }
+ return 0;
+}
+
+static int integrate_device_report(int dev_num)
+{
+ int ret = 0;
+
+ if (dev_num < 0 || dev_num >= MAX_DEVICES) {
+ ALOGE("Event reported on unexpected iio device %d\n", dev_num);
+ return -1;
+ }
+
+ if (events_fd[dev_num] != -1) {
+ ret = integrate_device_report_from_event(dev_num, events_fd[dev_num]);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (device_fd[dev_num] != -1)
+ ret = integrate_device_report_from_dev(dev_num, device_fd[dev_num]);
+
+ return ret;
+}
+
+static int propagate_vsensor_report (int s, sensors_event_t *data)