2 * Copyright (C) 2014 Intel Corporation.
5 #include <hardware/sensors.h>
7 #include "enumeration.h"
10 /* This is the IIO Sensors HAL module entry points file */
12 static int init_count;
14 static int activate(struct sensors_poll_device_t* dev, int handle, int enabled)
16 if (init_count == 0 || handle < 0 || handle >= sensor_count)
19 return sensor_activate(handle, enabled);
23 static int set_delay(struct sensors_poll_device_t* dev, int handle, int64_t ns)
25 if (init_count == 0 || handle < 0 || handle >= sensor_count)
28 return sensor_set_delay(handle, ns);
32 static int poll(struct sensors_poll_device_t* dev, sensors_event_t* data,
35 if (init_count == 0 || !data || count < 1)
38 return sensor_poll(data, count);
42 static int close_module(hw_device_t *device)
49 if (init_count == 0) {
50 ALOGI("Closing IIO sensors HAL module\n");
51 delete_enumeration_data();
52 delete_control_data();
59 static int initialize_module(const struct hw_module_t *module, const char *id,
60 struct hw_device_t** device)
62 static struct sensors_poll_device_t poll_device;
64 if (strcmp(id, SENSORS_HARDWARE_POLL))
67 poll_device.common.tag = HARDWARE_DEVICE_TAG;
68 poll_device.common.version = 0;
69 poll_device.common.module = (struct hw_module_t*) module;
70 poll_device.common.close = close_module;
72 poll_device.activate = activate;
73 poll_device.setDelay = set_delay;
74 poll_device.poll = poll;
76 *device = &poll_device.common;
78 if (init_count == 0) {
79 ALOGI("Initializing IIO sensors HAL module\n");
80 allocate_control_data();
89 static struct hw_module_methods_t module_methods = {
90 .open = initialize_module
94 /* Externally visible module descriptor */
95 struct sensors_module_t __attribute__ ((visibility ("default")))
96 HAL_MODULE_INFO_SYM = {
98 .tag = HARDWARE_MODULE_TAG,
101 .id = SENSORS_HARDWARE_MODULE_ID,
102 .name = "IIO sensors HAL",
104 .methods = &module_methods,
106 .get_sensors_list = get_sensors_list