X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=enumeration.c;h=55fe165c572601b53e6c13ff45323dee6e3e2da9;hb=6dd7dd1b4b8fb2e833671956ad936cbd635ed4db;hp=f3e6752793dd0539119170a58ef9e0d9382742fc;hpb=115f76c8fe40f5e1ece9349b1da4fe1514767aee;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/enumeration.c b/enumeration.c index f3e6752..55fe165 100644 --- a/enumeration.c +++ b/enumeration.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "enumeration.h" #include "description.h" @@ -16,6 +17,8 @@ #include "control.h" #include "calibration.h" +#include + /* * This table maps syfs entries in scan_elements directories to sensor types, * and will also be used to determine other sysfs names as well as the iio @@ -32,6 +35,7 @@ sensor_catalog_entry_t sensor_catalog[] = { { .tag = "accel", + .shorthand = "", .type = SENSOR_TYPE_ACCELEROMETER, .num_channels = 3, .is_virtual = 0, @@ -43,6 +47,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "anglvel", + .shorthand = "", .type = SENSOR_TYPE_GYROSCOPE, .num_channels = 3, .is_virtual = 0, @@ -54,6 +59,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "magn", + .shorthand = "", .type = SENSOR_TYPE_MAGNETIC_FIELD, .num_channels = 3, .is_virtual = 0, @@ -65,7 +71,8 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "intensity", - .type = SENSOR_TYPE_LIGHT, + .shorthand = "", + .type = SENSOR_TYPE_INTERNAL_INTENSITY, .num_channels = 1, .is_virtual = 0, .channel = { @@ -74,7 +81,8 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "illuminance", - .type = SENSOR_TYPE_LIGHT, + .shorthand = "", + .type = SENSOR_TYPE_INTERNAL_ILLUMINANCE, .num_channels = 1, .is_virtual = 0, .channel = { @@ -83,6 +91,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "incli", + .shorthand = "", .type = SENSOR_TYPE_ORIENTATION, .num_channels = 3, .is_virtual = 0, @@ -94,6 +103,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "rot", + .shorthand = "", .type = SENSOR_TYPE_ROTATION_VECTOR, .num_channels = 4, .is_virtual = 0, @@ -106,6 +116,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "temp", + .shorthand = "", .type = SENSOR_TYPE_AMBIENT_TEMPERATURE, .num_channels = 1, .is_virtual = 0, @@ -115,6 +126,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "proximity", + .shorthand = "prox", .type = SENSOR_TYPE_PROXIMITY, .num_channels = 1, .is_virtual = 0, @@ -124,6 +136,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "", + .shorthand = "", .type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED, .num_channels = 0, .is_virtual = 1, @@ -134,6 +147,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "", + .shorthand = "", .type = SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, .num_channels = 0, .is_virtual = 1, @@ -143,6 +157,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "steps", + .shorthand = "", .type = SENSOR_TYPE_STEP_COUNTER, .num_channels = 1, .is_virtual = 0, @@ -152,6 +167,7 @@ sensor_catalog_entry_t sensor_catalog[] = { }, { .tag = "steps", + .shorthand = "", .type = SENSOR_TYPE_STEP_DETECTOR, .num_channels = 1, .is_virtual = 0, @@ -165,15 +181,55 @@ sensor_catalog_entry_t sensor_catalog[] = { }, }, }, + { + .tag = "proximity", + .shorthand = "prox", + .type = SENSOR_TYPE_PROXIMITY, + .num_channels = 4, + .is_virtual = 0, + .channel = { + { + DECLARE_VOID_CHANNEL("proximity0") + .num_events = 1, + .event = { + { DECLARE_EVENT("proximity0", "_", "", "", "thresh", "_", "either") }, + }, + }, + { + DECLARE_VOID_CHANNEL("proximity1") + .num_events = 1, + .event = { + { DECLARE_EVENT("proximity1", "_", "", "", "thresh", "_", "either") }, + }, + }, + { + DECLARE_VOID_CHANNEL("proximity2") + .num_events = 1, + .event = { + { DECLARE_EVENT("proximity2", "_", "", "", "thresh", "_", "either") }, + }, + }, + { + DECLARE_VOID_CHANNEL("proximity3") + .num_events = 1, + .event = { + { DECLARE_EVENT("proximity3", "_", "", "", "thresh", "_", "either") }, + }, + }, + }, + }, }; -#define CATALOG_SIZE ARRAY_SIZE(sensor_catalog) +unsigned int catalog_size = ARRAY_SIZE(sensor_catalog); /* ACPI PLD (physical location of device) definitions, as used with sensors */ #define PANEL_FRONT 4 #define PANEL_BACK 5 +/* Buffer default length */ +#define BUFFER_LENGTH 16 + /* We equate sensor handles to indices in these tables */ struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */ @@ -340,6 +396,20 @@ static void decode_placement_information (int dev_num, int num_channels, int s) } +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; @@ -350,7 +420,7 @@ static void populate_descriptors (int s, int sensor_type) 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 = sensor_type; + 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); @@ -410,7 +480,7 @@ static void add_virtual_sensor (int catalog_index) } -static void add_sensor (int dev_num, int catalog_index, int mode) +static int add_sensor (int dev_num, int catalog_index, int mode) { int s; int sensor_type; @@ -424,10 +494,11 @@ static void add_sensor (int dev_num, int catalog_index, int mode) int num_channels; char suffix[MAX_NAME_SIZE + 8]; int calib_bias; + int buffer_length; if (sensor_count == MAX_SENSORS) { ALOGE("Too many sensors!\n"); - return; + return -1; } sensor_type = sensor_catalog[catalog_index].type; @@ -444,6 +515,7 @@ static void add_sensor (int dev_num, int catalog_index, int mode) sensor[s].catalog_index = catalog_index; sensor[s].type = sensor_type; sensor[s].mode = mode; + sensor[s].trigger_nr = -1; /* -1 means no trigger - we'll populate these at a later time */ num_channels = sensor_catalog[catalog_index].num_channels; @@ -452,13 +524,24 @@ static void add_sensor (int dev_num, int catalog_index, int mode) else sensor[s].num_channels = num_channels; + /* Populate the quirks array */ + sensor_get_quirks(s); + + /* Reject interfaces that may have been disabled through a quirk for this driver */ + if ((mode == MODE_EVENT && (sensor[s].quirks & QUIRK_NO_EVENT_MODE)) || + (mode == MODE_TRIGGER && (sensor[s].quirks & QUIRK_NO_TRIG_MODE )) || + (mode == MODE_POLL && (sensor[s].quirks & QUIRK_NO_POLL_MODE ))) { + memset(&sensor[s], 0, sizeof(sensor[0])); + return -1; + } + prefix = sensor_catalog[catalog_index].tag; /* * receiving the illumination sensor calibration inputs from * the Android properties and setting it within sysfs */ - if (sensor_type == SENSOR_TYPE_LIGHT) { + if (sensor_type == SENSOR_TYPE_INTERNAL_ILLUMINANCE) { retval = sensor_get_illumincalib(s); if (retval > 0) { sprintf(sysfs_path, ILLUMINATION_CALIBPATH, dev_num); @@ -488,6 +571,19 @@ static void add_sensor (int dev_num, int catalog_index, int mode) sysfs_write_int(sysfs_path, calib_bias); } + /* Change buffer length according to the property or use default value */ + if (mode == MODE_TRIGGER) { + if (sensor_get_prop(s, "buffer_length", &buffer_length)) { + buffer_length = BUFFER_LENGTH; + } + + sprintf(sysfs_path, BUFFER_LENGTH_PATH, dev_num); + + if (sysfs_write_int(sysfs_path, buffer_length) <= 0) { + ALOGE("Failed to set buffer length on dev%d", dev_num); + } + } + /* Read name attribute, if available */ sprintf(sysfs_path, NAME_PATH, dev_num); sysfs_read_str(sysfs_path, sensor[s].internal_name, MAX_NAME_SIZE); @@ -559,34 +655,37 @@ static void add_sensor (int dev_num, int catalog_index, int mode) sensor[s].channel[c].raw_path_present = (access(sysfs_path, R_OK) != -1); } - /* Read ACPI _PLD attributes for this sensor, if there are any */ - decode_placement_information(dev_num, num_channels, s); + sensor_get_available_frequencies(s); - /* - * See if we have optional correction scaling factors for each of the - * channels of this sensor. These would be expressed using properties - * like iio.accel.y.opt_scale = -1. In case of a single channel we also - * support things such as iio.temp.opt_scale = -1. Note that this works - * for all types of sensors, and whatever transform is selected, on top - * of any previous conversions. - */ + if (sensor_get_mounting_matrix(s, sensor[s].mounting_matrix)) + sensor[s].quirks |= QUIRK_MOUNTING_MATRIX; + else + /* Read ACPI _PLD attributes for this sensor, if there are any */ + decode_placement_information(dev_num, num_channels, s); - if (num_channels) { + /* + * See if we have optional correction scaling factors for each of the + * channels of this sensor. These would be expressed using properties + * like iio.accel.y.opt_scale = -1. In case of a single channel we also + * support things such as iio.temp.opt_scale = -1. Note that this works + * for all types of sensors, and whatever transform is selected, on top + * of any previous conversions. + */ + + if (num_channels) { for (c = 0; c < num_channels; c++) { ch_name = sensor_catalog[catalog_index].channel[c].name; sprintf(suffix, "%s.opt_scale", ch_name); if (!sensor_get_fl_prop(s, suffix, &opt_scale)) sensor[s].channel[c].opt_scale = opt_scale; } - } else + } else { if (!sensor_get_fl_prop(s, "opt_scale", &opt_scale)) sensor[s].channel[0].opt_scale = opt_scale; + } populate_descriptors(s, sensor_type); - /* Populate the quirks array */ - sensor_get_quirks(s); - if (sensor[s].internal_name[0] == '\0') { /* * In case the kernel-mode driver doesn't expose a name for @@ -598,7 +697,13 @@ static void add_sensor (int dev_num, int catalog_index, int mode) } switch (sensor_type) { - case SENSOR_TYPE_GYROSCOPE: + case SENSOR_TYPE_ACCELEROMETER: + /* Only engage accelerometer bias compensation if really needed */ + if (sensor_get_quirks(s) & QUIRK_BIASED) + sensor[s].cal_data = calloc(1, sizeof(accel_cal_t)); + break; + + case SENSOR_TYPE_GYROSCOPE: sensor[s].cal_data = malloc(sizeof(gyro_cal_t)); break; @@ -624,75 +729,7 @@ static void add_sensor (int dev_num, int catalog_index, int mode) sensor[s].needs_enable = get_needs_enable(dev_num, sensor_catalog[catalog_index].tag); sensor_count++; -} - - -static void discover_sensors (int dev_num, char *sysfs_base_path, char map[CATALOG_SIZE], - void (*discover_sensor)(int, char*, char*)) -{ - char sysfs_dir[PATH_MAX]; - DIR *dir; - struct dirent *d; - unsigned int i; - - memset(map, 0, CATALOG_SIZE); - - snprintf(sysfs_dir, sizeof(sysfs_dir), sysfs_base_path, dev_num); - - dir = opendir(sysfs_dir); - if (!dir) { - return; - } - - /* Enumerate entries in this iio device's base folder */ - - while ((d = readdir(dir))) { - if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) - continue; - - /* If the name matches a catalog entry, flag it */ - for (i = 0; i < CATALOG_SIZE; i++) { - - /* No discovery for virtual sensors */ - if (sensor_catalog[i].is_virtual) - continue; - discover_sensor(i, d->d_name, map); - } - } - - closedir(dir); -} - -static void check_poll_sensors (int i, char *sysfs_file, char map[CATALOG_SIZE]) -{ - int c; - - for (c = 0; c < sensor_catalog[i].num_channels; c++) - if (!strcmp(sysfs_file, sensor_catalog[i].channel[c].raw_path) || - !strcmp(sysfs_file, sensor_catalog[i].channel[c].input_path)) { - map[i] = 1; - break; - } -} -static void check_trig_sensors (int i, char *sysfs_file, char map[CATALOG_SIZE]) -{ - - if (!strcmp(sysfs_file, sensor_catalog[i].channel[0].en_path)) { - map[i] = 1; - return; - } -} - -static void check_event_sensors(int i, char *sysfs_file, char map[CATALOG_SIZE]) -{ - int j, k; - - for (j = 0; j < sensor_catalog[i].num_channels; j++) - for (k = 0; k < sensor_catalog[i].channel[j].num_events; k++) - if (!strcmp(sysfs_file, sensor_catalog[i].channel[j].event[k].ev_en_path)) { - map[i] = 1; - return ; - } + return 0; } static void virtual_sensors_check (void) @@ -703,9 +740,9 @@ static void virtual_sensors_check (void) int has_mag = 0; int has_rot = 0; int has_ori = 0; - int catalog_size = CATALOG_SIZE; int gyro_cal_idx = 0; int magn_cal_idx = 0; + unsigned int j; for (i=0; i temp */ + memcpy(&temp_sensor, &sensor[s1], sizeof(sensor_info_t)); + memcpy(&temp_sensor_desc, &sensor_desc[s1], sizeof(struct sensor_t)); + + /* S2 -> S1 */ + memcpy(&sensor[s1], &sensor[s2], sizeof(sensor_info_t)); + memcpy(&sensor_desc[s1], &sensor_desc[s2], sizeof(struct sensor_t)); + + /* temp -> S2 */ + memcpy(&sensor[s2], &temp_sensor, sizeof(sensor_info_t)); + memcpy(&sensor_desc[s2], &temp_sensor_desc, sizeof(struct sensor_t)); + + /* Fix-up sensor id mapping, which is stale */ + sensor_desc[s1].handle = s1; + sensor_desc[s2].handle = s2; + + /* Fix up name and vendor buffer pointers, which are potentially stale pointers */ + sensor_desc[s1].name = sensor_get_name(s1); + sensor_desc[s1].vendor = sensor_get_vendor(s1); + sensor_desc[s2].name = sensor_get_name(s2); + sensor_desc[s2].vendor = sensor_get_vendor(s2); +} + + +static void reorder_sensors (void) +{ + /* Some sensors may be marked as secondary - these need to be listed after other sensors of the same type */ + int s1, s2; + + for (s1=0; s1