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);
61 static int batch (struct sensors_poll_device_1* dev,
62 int sensor_handle, int flags, int64_t sampling_period_ns,
63 int64_t max_report_latency_ns)
65 return set_delay ((struct sensors_poll_device_t*)dev,
66 sensor_handle, sampling_period_ns);
69 static int flush(struct sensors_poll_device_1* dev, int handle)
71 return sensor_flush (handle);
73 static int close_module(hw_device_t *device)
80 if (init_count == 0) {
81 ALOGI("Closing IIO sensors HAL module\n");
82 delete_enumeration_data();
83 delete_control_data();
90 static int initialize_module(const struct hw_module_t *module, const char *id,
91 struct hw_device_t** device)
93 static struct sensors_poll_device_1 poll_device;
95 if (strcmp(id, SENSORS_HARDWARE_POLL))
98 poll_device.common.tag = HARDWARE_DEVICE_TAG;
99 poll_device.common.version = SENSORS_DEVICE_API_VERSION_1_3;
100 poll_device.common.module = (struct hw_module_t*) module;
101 poll_device.common.close = close_module;
103 poll_device.activate = activate;
104 poll_device.setDelay = set_delay;
105 poll_device.poll = poll;
106 poll_device.batch = batch;
107 poll_device.flush = flush;
109 *device = &poll_device.common;
111 if (init_count == 0) {
112 ALOGI("Initializing IIO sensors HAL module\n");
113 allocate_control_data();
122 static struct hw_module_methods_t module_methods = {
123 .open = initialize_module
127 /* Externally visible module descriptor */
128 struct sensors_module_t __attribute__ ((visibility ("default")))
129 HAL_MODULE_INFO_SYM = {
131 .tag = HARDWARE_MODULE_TAG,
134 .id = SENSORS_HARDWARE_MODULE_ID,
135 .name = "IIO sensors HAL",
137 .methods = &module_methods,
139 .get_sensors_list = get_sensors_list