1
2
3
4
5
6#ifndef _HID_SENSORS_HUB_H
7#define _HID_SENSORS_HUB_H
8
9#include <linux/hid.h>
10#include <linux/hid-sensor-ids.h>
11#include <linux/iio/iio.h>
12#include <linux/iio/trigger.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26struct hid_sensor_hub_attribute_info {
27 u32 usage_id;
28 u32 attrib_id;
29 s32 report_id;
30 s32 index;
31 s32 units;
32 s32 unit_expo;
33 s32 size;
34 s32 logical_minimum;
35 s32 logical_maximum;
36};
37
38
39
40
41
42
43
44
45
46
47struct sensor_hub_pending {
48 bool status;
49 struct completion ready;
50 u32 usage_id;
51 u32 attr_usage_id;
52 int raw_size;
53 u8 *raw_data;
54};
55
56
57
58
59
60
61
62
63
64
65
66
67struct hid_sensor_hub_device {
68 struct hid_device *hdev;
69 u32 vendor_id;
70 u32 product_id;
71 u32 usage;
72 int start_collection_index;
73 int end_collection_index;
74 struct mutex *mutex_ptr;
75 struct sensor_hub_pending pending;
76};
77
78
79
80
81
82
83
84
85
86
87struct hid_sensor_hub_callbacks {
88 struct platform_device *pdev;
89 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
90 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
91 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
92 u32 usage_id, size_t raw_len, char *raw_data,
93 void *priv);
94 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
95 void *priv);
96};
97
98
99
100
101
102
103
104int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
105
106
107
108
109
110
111
112void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
113
114
115
116
117
118
119
120
121
122
123
124
125
126int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
127 u32 usage_id,
128 struct hid_sensor_hub_callbacks *usage_callback);
129
130
131
132
133
134
135
136
137
138int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
139 u32 usage_id);
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
156 u8 type,
157 u32 usage_id, u32 attr_usage_id,
158 struct hid_sensor_hub_attribute_info *info);
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173enum sensor_hub_read_flags {
174 SENSOR_HUB_SYNC,
175 SENSOR_HUB_ASYNC,
176};
177
178int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
179 u32 usage_id,
180 u32 attr_usage_id, u32 report_id,
181 enum sensor_hub_read_flags flag,
182 bool is_signed
183);
184
185
186
187
188
189
190
191
192
193
194
195
196int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
197 u32 field_index, int buffer_size, void *buffer);
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
213 u32 field_index, int buffer_size, void *buffer);
214
215
216
217
218struct hid_sensor_common {
219 struct hid_sensor_hub_device *hsdev;
220 struct platform_device *pdev;
221 unsigned usage_id;
222 atomic_t data_ready;
223 atomic_t user_requested_state;
224 atomic_t runtime_pm_enable;
225 int poll_interval;
226 int raw_hystersis;
227 int latency_ms;
228 struct iio_trigger *trigger;
229 int timestamp_ns_scale;
230 struct hid_sensor_hub_attribute_info poll;
231 struct hid_sensor_hub_attribute_info report_state;
232 struct hid_sensor_hub_attribute_info power_state;
233 struct hid_sensor_hub_attribute_info sensitivity;
234 struct hid_sensor_hub_attribute_info sensitivity_rel;
235 struct hid_sensor_hub_attribute_info report_latency;
236 struct work_struct work;
237};
238
239
240static inline int hid_sensor_convert_exponent(int unit_expo)
241{
242 if (unit_expo < 0x08)
243 return unit_expo;
244 else if (unit_expo <= 0x0f)
245 return -(0x0f-unit_expo+1);
246 else
247 return 0;
248}
249
250int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
251 u32 usage_id,
252 struct hid_sensor_common *st,
253 const u32 *sensitivity_addresses,
254 u32 sensitivity_addresses_len);
255int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
256 int val1, int val2);
257int hid_sensor_write_raw_hyst_rel_value(struct hid_sensor_common *st, int val1,
258 int val2);
259int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
260 int *val1, int *val2);
261int hid_sensor_read_raw_hyst_rel_value(struct hid_sensor_common *st,
262 int *val1, int *val2);
263int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
264 int val1, int val2);
265int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
266 int *val1, int *val2);
267
268int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
269 u32 report_id, int field_index, u32 usage_id);
270
271int hid_sensor_format_scale(u32 usage_id,
272 struct hid_sensor_hub_attribute_info *attr_info,
273 int *val0, int *val1);
274
275s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
276
277int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st,
278 int64_t raw_value);
279bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st);
280int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency);
281int hid_sensor_get_report_latency(struct hid_sensor_common *st);
282
283#endif
284