2 * Copyright (C) 2014 Intel Corporation.
5 #include <hardware/sensors.h>
7 #include "enumeration.h"
9 #include "description.h"
11 /* This is the IIO Sensors HAL module entry points file */
13 static int init_count;
15 static int activate(struct sensors_poll_device_t* dev, int handle, int enabled)
17 if (init_count == 0 || handle < 0 || handle >= sensor_count)
21 * The Intel sensor hub seems to have trouble enabling sensors before
22 * a sampling rate has been configured, and setting the sampling rate
23 * after it's been enabled does not seem to revive affected sensors.
24 * The issue does not show up with an up to date ISH firmware but as the
25 * updater is a Windows only tool and is not widely available, implement
26 * a workaround for this behavior. We set the initial sampling rate to
27 * 10 events per second when the sensor is enabled for the first time.
29 if (enabled && sensor_get_quirks(handle) & QUIRK_INITIAL_RATE) {
30 ALOGI("Forcing initial sampling rate\n");
31 sensor_activate(handle, 1);
32 sensor_set_delay(handle, 100000000L); /* Start with 100 ms */
33 sensor_activate(handle, 0);
35 /* Clear flag for this sensor as do this only once */
36 sensor_info[handle].quirks ^= QUIRK_INITIAL_RATE;
39 return sensor_activate(handle, enabled);
43 static int set_delay(struct sensors_poll_device_t* dev, int handle, int64_t ns)
45 if (init_count == 0 || handle < 0 || handle >= sensor_count)
48 return sensor_set_delay(handle, ns);
52 static int poll(struct sensors_poll_device_t* dev, sensors_event_t* data,
55 if (init_count == 0 || !data || count < 1)
58 return sensor_poll(data, count);
62 static int close_module(hw_device_t *device)
69 if (init_count == 0) {
70 ALOGI("Closing IIO sensors HAL module\n");
71 delete_enumeration_data();
72 delete_control_data();
79 static int initialize_module(const struct hw_module_t *module, const char *id,
80 struct hw_device_t** device)
82 static struct sensors_poll_device_t poll_device;
84 if (strcmp(id, SENSORS_HARDWARE_POLL))
87 poll_device.common.tag = HARDWARE_DEVICE_TAG;
88 poll_device.common.version = SENSORS_DEVICE_API_VERSION_0_1;
89 poll_device.common.module = (struct hw_module_t*) module;
90 poll_device.common.close = close_module;
92 poll_device.activate = activate;
93 poll_device.setDelay = set_delay;
94 poll_device.poll = poll;
96 *device = &poll_device.common;
98 if (init_count == 0) {
99 ALOGI("Initializing IIO sensors HAL module\n");
100 allocate_control_data();
109 static struct hw_module_methods_t module_methods = {
110 .open = initialize_module
114 /* Externally visible module descriptor */
115 struct sensors_module_t __attribute__ ((visibility ("default")))
116 HAL_MODULE_INFO_SYM = {
118 .tag = HARDWARE_MODULE_TAG,
121 .id = SENSORS_HARDWARE_MODULE_ID,
122 .name = "IIO sensors HAL",
124 .methods = &module_methods,
126 .get_sensors_list = get_sensors_list