+int sensor_get_available_frequencies (int s)
+{
+ int dev_num = sensor[s].dev_num, err, i;
+ char avail_sysfs_path[PATH_MAX], freqs_buf[100];
+ char *p, *end;
+ float f;
+
+ sensor[s].avail_freqs_count = 0;
+ sensor[s].avail_freqs = 0;
+
+ sprintf(avail_sysfs_path, DEVICE_AVAIL_FREQ_PATH, dev_num);
+
+ err = sysfs_read_str(avail_sysfs_path, freqs_buf, sizeof(freqs_buf));
+ if (err < 0)
+ return 0;
+
+ for (p = freqs_buf, f = strtof(p, &end); p != end; p = end, f = strtof(p, &end))
+ sensor[s].avail_freqs_count++;
+
+ if (sensor[s].avail_freqs_count) {
+ sensor[s].avail_freqs = (float*) calloc(sensor[s].avail_freqs_count, sizeof(float));
+
+ for (p = freqs_buf, f = strtof(p, &end), i = 0; p != end; p = end, f = strtof(p, &end), i++)
+ sensor[s].avail_freqs[i] = f;
+ }
+
+ return 0;
+}
+
+int sensor_get_mounting_matrix (int s, float mm[9])
+{
+ int dev_num = sensor[s].dev_num, err, i;
+ char mm_path[PATH_MAX], mm_buf[100];
+ char *tmp1 = mm_buf, *tmp2;
+
+ switch (sensor[s].type) {
+ case SENSOR_TYPE_ACCELEROMETER:
+ case SENSOR_TYPE_MAGNETIC_FIELD:
+ case SENSOR_TYPE_GYROSCOPE:
+ case SENSOR_TYPE_PROXIMITY:
+ break;
+ default:
+ return 0;
+ }
+
+ sprintf(mm_path, MOUNTING_MATRIX_PATH, dev_num);
+
+ err = sysfs_read_str(mm_path, mm_buf, sizeof(mm_buf));
+ if (err < 0)
+ return 0;
+
+ for(i = 0; i < 9; i++) {
+ float f;
+
+ f = strtof(tmp1, &tmp2);
+ if (!f && tmp1 == tmp2)
+ return 0;
+ mm[i] = f;
+ tmp1 = tmp2 + 1;
+ }
+
+ /*
+ * For proximity sensors, interpret a negative final z value as a hint that the sensor is back mounted. In that case, mark the sensor as secondary to
+ * ensure that it gets listed after other sensors of same type that would be front-mounted. Most applications will only ask for the default proximity
+ * sensor and it makes more sense to point to, say, the IR based proximity sensor rather than SAR based one if we have both, as on SoFIA LTE MRD boards.
+ */
+ if (sensor[s].type == SENSOR_TYPE_PROXIMITY) {
+ if (mm[8] < 0) {
+ sensor[s].quirks |= QUIRK_SECONDARY;
+ }
+ return 0;
+ }
+
+ ALOGI("%s: %f %f %f %f %f %f %f %f %f\n", __func__, mm[0], mm[1], mm[2], mm[3], mm[4], mm[5], mm[6], mm[7], mm[8]);
+ return 1;
+}
+