This source file includes following definitions.
- hid_sensor_convert_exponent
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
26 struct 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
47 struct 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
67 struct 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
87 struct 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
104 int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
105
106
107
108
109
110
111
112 void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
113
114
115
116
117
118
119
120
121
122
123
124
125
126 int 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
138 int 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
155 int 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
173 enum sensor_hub_read_flags {
174 SENSOR_HUB_SYNC,
175 SENSOR_HUB_ASYNC,
176 };
177
178 int 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
196 int 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 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
212 u32 field_index, int buffer_size, void *buffer);
213
214
215
216
217 struct hid_sensor_common {
218 struct hid_sensor_hub_device *hsdev;
219 struct platform_device *pdev;
220 unsigned usage_id;
221 atomic_t data_ready;
222 atomic_t user_requested_state;
223 atomic_t runtime_pm_enable;
224 int poll_interval;
225 int raw_hystersis;
226 int latency_ms;
227 struct iio_trigger *trigger;
228 int timestamp_ns_scale;
229 struct hid_sensor_hub_attribute_info poll;
230 struct hid_sensor_hub_attribute_info report_state;
231 struct hid_sensor_hub_attribute_info power_state;
232 struct hid_sensor_hub_attribute_info sensitivity;
233 struct hid_sensor_hub_attribute_info report_latency;
234 struct work_struct work;
235 };
236
237
238 static inline int hid_sensor_convert_exponent(int unit_expo)
239 {
240 if (unit_expo < 0x08)
241 return unit_expo;
242 else if (unit_expo <= 0x0f)
243 return -(0x0f-unit_expo+1);
244 else
245 return 0;
246 }
247
248 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
249 u32 usage_id,
250 struct hid_sensor_common *st);
251 int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
252 int val1, int val2);
253 int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
254 int *val1, int *val2);
255 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
256 int val1, int val2);
257 int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
258 int *val1, int *val2);
259
260 int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
261 u32 report_id, int field_index, u32 usage_id);
262
263 int hid_sensor_format_scale(u32 usage_id,
264 struct hid_sensor_hub_attribute_info *attr_info,
265 int *val0, int *val1);
266
267 s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
268
269 int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st,
270 int64_t raw_value);
271 bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st);
272 int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency);
273 int hid_sensor_get_report_latency(struct hid_sensor_common *st);
274
275 #endif