HID: hid-sensor-hub: Add support for application collection
[deliverable/linux.git] / include / linux / hid-sensor-hub.h
CommitLineData
401ca24f 1/*
2 * HID Sensors Driver
3 * Copyright (c) 2012, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19#ifndef _HID_SENSORS_HUB_H
20#define _HID_SENSORS_HUB_H
21
22#include <linux/hid.h>
23#include <linux/hid-sensor-ids.h>
ec7f68e0
SP
24#include <linux/iio/iio.h>
25#include <linux/iio/trigger.h>
401ca24f 26
27/**
28 * struct hid_sensor_hub_attribute_info - Attribute info
29 * @usage_id: Parent usage id of a physical device.
30 * @attrib_id: Attribute id for this attribute.
31 * @report_id: Report id in which this information resides.
32 * @index: Field index in the report.
33 * @units: Measurment unit for this attribute.
34 * @unit_expo: Exponent used in the data.
35 * @size: Size in bytes for data size.
36 */
37struct hid_sensor_hub_attribute_info {
38 u32 usage_id;
39 u32 attrib_id;
40 s32 report_id;
41 s32 index;
42 s32 units;
43 s32 unit_expo;
44 s32 size;
9f740ffa
SP
45 s32 logical_minimum;
46 s32 logical_maximum;
401ca24f 47};
48
e651a1da
SP
49/**
50 * struct sensor_hub_pending - Synchronous read pending information
51 * @status: Pending status true/false.
52 * @ready: Completion synchronization data.
53 * @usage_id: Usage id for physical device, E.g. Gyro usage id.
54 * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro.
55 * @raw_size: Response size for a read request.
56 * @raw_data: Place holder for received response.
57 */
58struct sensor_hub_pending {
59 bool status;
60 struct completion ready;
61 u32 usage_id;
62 u32 attr_usage_id;
63 int raw_size;
64 u8 *raw_data;
65};
66
401ca24f 67/**
68 * struct hid_sensor_hub_device - Stores the hub instance data
69 * @hdev: Stores the hid instance.
70 * @vendor_id: Vendor id of hub device.
71 * @product_id: Product id of hub device.
e651a1da 72 * @usage: Usage id for this hub device instance.
ca2ed12f
SP
73 * @start_collection_index: Starting index for a phy type collection
74 * @end_collection_index: Last index for a phy type collection
e651a1da
SP
75 * @mutex: synchronizing mutex.
76 * @pending: Holds information of pending sync read request.
401ca24f 77 */
78struct hid_sensor_hub_device {
79 struct hid_device *hdev;
80 u32 vendor_id;
81 u32 product_id;
e651a1da 82 u32 usage;
ca2ed12f
SP
83 int start_collection_index;
84 int end_collection_index;
e651a1da
SP
85 struct mutex mutex;
86 struct sensor_hub_pending pending;
401ca24f 87};
88
89/**
90 * struct hid_sensor_hub_callbacks - Client callback functions
91 * @pdev: Platform device instance of the client driver.
92 * @suspend: Suspend callback.
93 * @resume: Resume callback.
94 * @capture_sample: Callback to get a sample.
95 * @send_event: Send notification to indicate all samples are
96 * captured, process and send event
97 */
98struct hid_sensor_hub_callbacks {
99 struct platform_device *pdev;
100 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
101 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
102 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
103 u32 usage_id, size_t raw_len, char *raw_data,
104 void *priv);
105 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
106 void *priv);
107};
108
1df3a401
SP
109/**
110* sensor_hub_device_open() - Open hub device
111* @hsdev: Hub device instance.
112*
113* Used to open hid device for sensor hub.
114*/
115int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
116
117/**
118* sensor_hub_device_clode() - Close hub device
119* @hsdev: Hub device instance.
120*
121* Used to clode hid device for sensor hub.
122*/
123void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
124
401ca24f 125/* Registration functions */
126
127/**
128* sensor_hub_register_callback() - Register client callbacks
129* @hsdev: Hub device instance.
130* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
131* @usage_callback: Callback function storage
132*
133* Used to register callbacks by client processing drivers. Sensor
134* hub core driver will call these callbacks to offload processing
135* of data streams and notifications.
136*/
137int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
138 u32 usage_id,
139 struct hid_sensor_hub_callbacks *usage_callback);
140
141/**
142* sensor_hub_remove_callback() - Remove client callbacks
143* @hsdev: Hub device instance.
144* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
145*
146* If there is a callback registred, this call will remove that
147* callbacks, so that it will stop data and event notifications.
148*/
149int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
150 u32 usage_id);
151
152
153/* Hid sensor hub core interfaces */
154
155/**
156* sensor_hub_input_get_attribute_info() - Get an attribute information
157* @hsdev: Hub device instance.
158* @type: Type of this attribute, input/output/feature
159* @usage_id: Attribute usage id of parent physical device as per spec
160* @attr_usage_id: Attribute usage id as per spec
161* @info: return information about attribute after parsing report
162*
163* Parses report and returns the attribute information such as report id,
164* field index, units and exponet etc.
165*/
166int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
167 u8 type,
168 u32 usage_id, u32 attr_usage_id,
169 struct hid_sensor_hub_attribute_info *info);
170
171/**
172* sensor_hub_input_attr_get_raw_value() - Synchronous read request
173* @usage_id: Attribute usage id of parent physical device as per spec
174* @attr_usage_id: Attribute usage id as per spec
175* @report_id: Report id to look for
176*
177* Issues a synchronous read request for an input attribute. Returns
178* data upto 32 bits. Since client can get events, so this call should
179* not be used for data paths, this will impact performance.
180*/
181
182int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
183 u32 usage_id,
184 u32 attr_usage_id, u32 report_id);
185/**
186* sensor_hub_set_feature() - Feature set request
187* @report_id: Report id to look for
188* @field_index: Field index inside a report
189* @value: Value to set
190*
191* Used to set a field in feature report. For example this can set polling
192* interval, sensitivity, activate/deactivate state.
193*/
194int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
195 u32 field_index, s32 value);
196
197/**
198* sensor_hub_get_feature() - Feature get request
199* @report_id: Report id to look for
200* @field_index: Field index inside a report
201* @value: Place holder for return value
202*
203* Used to get a field in feature report. For example this can get polling
204* interval, sensitivity, activate/deactivate state.
205*/
206int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
207 u32 field_index, s32 *value);
2974cdf2
AH
208
209/* hid-sensor-attributes */
210
211/* Common hid sensor iio structure */
e07c6d17 212struct hid_sensor_common {
2974cdf2
AH
213 struct hid_sensor_hub_device *hsdev;
214 struct platform_device *pdev;
215 unsigned usage_id;
56ff6be6 216 atomic_t data_ready;
ec7f68e0 217 struct iio_trigger *trigger;
2974cdf2
AH
218 struct hid_sensor_hub_attribute_info poll;
219 struct hid_sensor_hub_attribute_info report_state;
220 struct hid_sensor_hub_attribute_info power_state;
221 struct hid_sensor_hub_attribute_info sensitivity;
222};
223
15261f6d 224/* Convert from hid unit expo to regular exponent */
2974cdf2
AH
225static inline int hid_sensor_convert_exponent(int unit_expo)
226{
227 if (unit_expo < 0x08)
228 return unit_expo;
229 else if (unit_expo <= 0x0f)
230 return -(0x0f-unit_expo+1);
231 else
232 return 0;
233}
234
235int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
236 u32 usage_id,
e07c6d17
AH
237 struct hid_sensor_common *st);
238int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 239 int val1, int val2);
e07c6d17 240int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 241 int *val1, int *val2);
e07c6d17 242int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
2974cdf2 243 int val1, int val2);
e07c6d17 244int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
2974cdf2
AH
245 int *val1, int *val2);
246
e02cee48
SP
247int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
248 u32 report_id, int field_index, u32 usage_id);
249
5d02edfc
SP
250int hid_sensor_format_scale(u32 usage_id,
251 struct hid_sensor_hub_attribute_info *attr_info,
252 int *val0, int *val1);
253
90309245
SP
254s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
255
401ca24f 256#endif
This page took 0.243019 seconds and 5 git commands to generate.