Blame view

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