+
+static int read_pld_from_properties (int s, int* panel, int* rotation)
+{
+ int p, r;
+
+ if (sensor_get_prop(s, "panel", &p))
+ return -1;
+
+ if (sensor_get_prop(s, "rotation", &r))
+ return -1;
+
+ if (!is_valid_pld(p, r))
+ return -1;
+
+ *panel = p;
+ *rotation = r;
+
+ ALOGI("S%d PLD from properties: panel=%d, rotation=%d\n", s, p, r);
+
+ return 0;
+}
+
+
+static int read_pld_from_sysfs (int s, int dev_num, int* panel, int* rotation)
+{
+ char sysfs_path[PATH_MAX];
+ int p,r;
+
+ sprintf(sysfs_path, BASE_PATH "../firmware_node/pld/panel", dev_num);
+
+ if (sysfs_read_int(sysfs_path, &p))
+ return -1;
+
+ sprintf(sysfs_path, BASE_PATH "../firmware_node/pld/rotation", dev_num);
+
+ if (sysfs_read_int(sysfs_path, &r))
+ return -1;
+
+ if (!is_valid_pld(p, r))
+ return -1;
+
+ *panel = p;
+ *rotation = r;
+
+ ALOGI("S%d PLD from sysfs: panel=%d, rotation=%d\n", s, p, r);
+
+ return 0;
+}
+
+
+static void decode_placement_information (int dev_num, int num_channels, int s)
+{
+ /*
+ * See if we have optional "physical location of device" ACPI tags.
+ * We're only interested in panel and rotation specifiers. Use the
+ * .panel and .rotation properties in priority, and the actual ACPI
+ * values as a second source.
+ */
+
+ int panel;
+ int rotation;
+
+ if (read_pld_from_properties(s, &panel, &rotation) &&
+ read_pld_from_sysfs(s, dev_num, &panel, &rotation))
+ return; /* No PLD data available */
+
+ /* Map that to field ordering and scaling mechanisms */
+ setup_properties_from_pld(s, panel, rotation, num_channels);
+}
+
+
+static int map_internal_to_external_type (int sensor_type)
+{
+ /* Most sensors are internally identified using the Android type, but for some we use a different type specification internally */
+
+ switch (sensor_type) {
+ case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
+ case SENSOR_TYPE_INTERNAL_INTENSITY:
+ return SENSOR_TYPE_LIGHT;
+
+ default:
+ return sensor_type;
+ }
+}
+
+static void populate_descriptors (int s, int sensor_type)
+{
+ int32_t min_delay_us;
+ max_delay_t max_delay_us;
+
+ /* Initialize Android-visible descriptor */
+ sensor_desc[s].name = sensor_get_name(s);
+ sensor_desc[s].vendor = sensor_get_vendor(s);
+ sensor_desc[s].version = sensor_get_version(s);
+ sensor_desc[s].handle = s;
+ sensor_desc[s].type = map_internal_to_external_type(sensor_type);
+
+ sensor_desc[s].maxRange = sensor_get_max_range(s);
+ sensor_desc[s].resolution = sensor_get_resolution(s);
+ sensor_desc[s].power = sensor_get_power(s);
+ sensor_desc[s].stringType = sensor_get_string_type(s);
+
+ /* None of our supported sensors requires a special permission */
+ sensor_desc[s].requiredPermission = "";
+
+ sensor_desc[s].flags = sensor_get_flags(s);
+ sensor_desc[s].minDelay = sensor_get_min_delay(s);
+ sensor_desc[s].maxDelay = sensor_get_max_delay(s);
+
+ ALOGV("Sensor %d (%s) type(%d) minD(%d) maxD(%d) flags(%2.2x)\n",
+ s, sensor[s].friendly_name, sensor_desc[s].type,
+ sensor_desc[s].minDelay, sensor_desc[s].maxDelay,
+ sensor_desc[s].flags);
+
+ /* We currently do not implement batching */
+ sensor_desc[s].fifoReservedEventCount = 0;
+ sensor_desc[s].fifoMaxEventCount = 0;
+
+ min_delay_us = sensor_desc[s].minDelay;
+ max_delay_us = sensor_desc[s].maxDelay;
+
+ sensor[s].min_supported_rate = max_delay_us ? 1000000.0 / max_delay_us : 1;
+ sensor[s].max_supported_rate = min_delay_us && min_delay_us != -1 ? 1000000.0 / min_delay_us : 0;
+}
+
+
+static void add_virtual_sensor (int catalog_index)
+{
+ int s;
+ int sensor_type;
+
+ if (sensor_count == MAX_SENSORS) {
+ ALOGE("Too many sensors!\n");
+ return;
+ }
+
+ sensor_type = sensor_catalog[catalog_index].type;
+
+ s = sensor_count;
+
+ sensor[s].is_virtual = 1;
+ sensor[s].catalog_index = catalog_index;
+ sensor[s].type = sensor_type;
+
+ populate_descriptors(s, sensor_type);
+
+ /* Initialize fields related to sysfs reads offloading */
+ sensor[s].thread_data_fd[0] = -1;
+ sensor[s].thread_data_fd[1] = -1;
+ sensor[s].acquisition_thread = -1;
+
+ sensor_count++;
+}
+
+
+static int add_sensor (int dev_num, int catalog_index, int mode)