OSDN Git Service

STPK-1429 Initial version of iio-sensors-hal component
[android-x86/hardware-intel-libsensors.git] / entry.c
1 /*
2  * Copyright (C) 2014 Intel Corporation.
3  */
4
5 #include <hardware/sensors.h>
6 #include <utils/Log.h>
7 #include "enumeration.h"
8 #include "control.h"
9
10 /* This is the IIO Sensors HAL module entry points file */
11
12 static int init_count;
13
14 static int activate(struct sensors_poll_device_t* dev, int handle, int enabled)
15 {
16         if (init_count == 0 || handle < 0 || handle >= sensor_count)
17                 return -EINVAL;
18
19         return sensor_activate(handle, enabled);
20 }
21
22
23 static int set_delay(struct sensors_poll_device_t* dev, int handle, int64_t ns)
24 {
25         if (init_count == 0 || handle < 0 || handle >= sensor_count)
26                 return -EINVAL;
27
28         return sensor_set_delay(handle, ns);
29 }
30
31
32 static int poll(struct sensors_poll_device_t* dev, sensors_event_t* data,
33                 int count)
34 {
35         if (init_count == 0 || !data || count < 1)
36                 return -EINVAL;
37
38         return sensor_poll(data, count);
39 }
40
41
42 static int close_module(hw_device_t *device)
43 {
44         if (init_count == 0)
45                 return -EINVAL;
46
47         init_count--;
48
49         if (init_count == 0) {
50                 ALOGI("Closing IIO sensors HAL module\n");
51                 delete_enumeration_data();
52                 delete_control_data();
53         }
54
55         return 0;
56 }
57
58
59 static int initialize_module(const struct hw_module_t *module, const char *id,
60                                 struct hw_device_t** device)
61 {
62         static struct sensors_poll_device_t poll_device;
63
64         if (strcmp(id, SENSORS_HARDWARE_POLL))
65                 return -EINVAL;
66
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;
71
72         poll_device.activate            = activate;
73         poll_device.setDelay            = set_delay;
74         poll_device.poll                = poll;
75
76         *device = &poll_device.common;
77
78         if (init_count == 0) {
79                 ALOGI("Initializing IIO sensors HAL module\n");
80                 allocate_control_data();
81                 enumerate_sensors();
82         }
83
84         init_count++;
85         return 0;
86 }
87
88
89 static struct hw_module_methods_t module_methods = {
90         .open = initialize_module
91 };
92
93
94 /* Externally visible module descriptor */
95 struct sensors_module_t __attribute__ ((visibility ("default")))
96         HAL_MODULE_INFO_SYM = {
97                 .common = {
98                         .tag = HARDWARE_MODULE_TAG,
99                         .version_major = 1,
100                         .version_minor = 0,
101                         .id = SENSORS_HARDWARE_MODULE_ID,
102                         .name = "IIO sensors HAL",
103                         .author = "Intel",
104                         .methods = &module_methods,
105                 },
106                 .get_sensors_list = get_sensors_list
107 };
108