blob: 4173a8fdad9efd052870b8738547ac1fa1962526 [file] [log] [blame]
srinivas pandruvada401ca242012-09-05 13:56:00 +01001/*
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>
Srinivas Pandruvadaec7f68e2013-10-30 22:48:00 +000024#include <linux/iio/iio.h>
25#include <linux/iio/trigger.h>
srinivas pandruvada401ca242012-09-05 13:56:00 +010026
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.
Srinivas Pandruvadaf9d904a2015-01-07 10:14:43 -080036 * @logical_minimum: Logical minimum value for this attribute.
37 * @logical_maximum: Logical maximum value for this attribute.
srinivas pandruvada401ca242012-09-05 13:56:00 +010038 */
39struct hid_sensor_hub_attribute_info {
40 u32 usage_id;
41 u32 attrib_id;
42 s32 report_id;
43 s32 index;
44 s32 units;
45 s32 unit_expo;
46 s32 size;
Srinivas Pandruvada9f740ff2013-11-27 22:19:00 +000047 s32 logical_minimum;
48 s32 logical_maximum;
srinivas pandruvada401ca242012-09-05 13:56:00 +010049};
50
51/**
52 * struct hid_sensor_hub_device - Stores the hub instance data
53 * @hdev: Stores the hid instance.
54 * @vendor_id: Vendor id of hub device.
55 * @product_id: Product id of hub device.
Srinivas Pandruvadaca2ed122014-01-31 12:04:10 -080056 * @start_collection_index: Starting index for a phy type collection
57 * @end_collection_index: Last index for a phy type collection
srinivas pandruvada401ca242012-09-05 13:56:00 +010058 */
59struct hid_sensor_hub_device {
60 struct hid_device *hdev;
61 u32 vendor_id;
62 u32 product_id;
Srinivas Pandruvadaca2ed122014-01-31 12:04:10 -080063 int start_collection_index;
64 int end_collection_index;
srinivas pandruvada401ca242012-09-05 13:56:00 +010065};
66
67/**
68 * struct hid_sensor_hub_callbacks - Client callback functions
69 * @pdev: Platform device instance of the client driver.
70 * @suspend: Suspend callback.
71 * @resume: Resume callback.
72 * @capture_sample: Callback to get a sample.
73 * @send_event: Send notification to indicate all samples are
74 * captured, process and send event
75 */
76struct hid_sensor_hub_callbacks {
77 struct platform_device *pdev;
78 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
79 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
80 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
81 u32 usage_id, size_t raw_len, char *raw_data,
82 void *priv);
83 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
84 void *priv);
85};
86
Srinivas Pandruvada1df3a402013-09-18 18:13:00 +010087/**
88* sensor_hub_device_open() - Open hub device
89* @hsdev: Hub device instance.
90*
91* Used to open hid device for sensor hub.
92*/
93int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
94
95/**
96* sensor_hub_device_clode() - Close hub device
97* @hsdev: Hub device instance.
98*
99* Used to clode hid device for sensor hub.
100*/
101void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
102
srinivas pandruvada401ca242012-09-05 13:56:00 +0100103/* Registration functions */
104
105/**
106* sensor_hub_register_callback() - Register client callbacks
107* @hsdev: Hub device instance.
108* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
109* @usage_callback: Callback function storage
110*
111* Used to register callbacks by client processing drivers. Sensor
112* hub core driver will call these callbacks to offload processing
113* of data streams and notifications.
114*/
115int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
116 u32 usage_id,
117 struct hid_sensor_hub_callbacks *usage_callback);
118
119/**
120* sensor_hub_remove_callback() - Remove client callbacks
121* @hsdev: Hub device instance.
122* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
123*
124* If there is a callback registred, this call will remove that
125* callbacks, so that it will stop data and event notifications.
126*/
127int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
128 u32 usage_id);
129
130
131/* Hid sensor hub core interfaces */
132
133/**
134* sensor_hub_input_get_attribute_info() - Get an attribute information
135* @hsdev: Hub device instance.
136* @type: Type of this attribute, input/output/feature
137* @usage_id: Attribute usage id of parent physical device as per spec
138* @attr_usage_id: Attribute usage id as per spec
139* @info: return information about attribute after parsing report
140*
141* Parses report and returns the attribute information such as report id,
142* field index, units and exponet etc.
143*/
144int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
145 u8 type,
146 u32 usage_id, u32 attr_usage_id,
147 struct hid_sensor_hub_attribute_info *info);
148
149/**
150* sensor_hub_input_attr_get_raw_value() - Synchronous read request
Srinivas Pandruvadaf9d904a2015-01-07 10:14:43 -0800151* @hsdev: Hub device instance.
srinivas pandruvada401ca242012-09-05 13:56:00 +0100152* @usage_id: Attribute usage id of parent physical device as per spec
153* @attr_usage_id: Attribute usage id as per spec
154* @report_id: Report id to look for
155*
156* Issues a synchronous read request for an input attribute. Returns
157* data upto 32 bits. Since client can get events, so this call should
158* not be used for data paths, this will impact performance.
159*/
160
161int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
162 u32 usage_id,
163 u32 attr_usage_id, u32 report_id);
164/**
165* sensor_hub_set_feature() - Feature set request
Srinivas Pandruvadaf9d904a2015-01-07 10:14:43 -0800166* @hsdev: Hub device instance.
srinivas pandruvada401ca242012-09-05 13:56:00 +0100167* @report_id: Report id to look for
168* @field_index: Field index inside a report
169* @value: Value to set
170*
171* Used to set a field in feature report. For example this can set polling
172* interval, sensitivity, activate/deactivate state.
173*/
174int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
175 u32 field_index, s32 value);
176
177/**
178* sensor_hub_get_feature() - Feature get request
Srinivas Pandruvadaf9d904a2015-01-07 10:14:43 -0800179* @hsdev: Hub device instance.
srinivas pandruvada401ca242012-09-05 13:56:00 +0100180* @report_id: Report id to look for
181* @field_index: Field index inside a report
182* @value: Place holder for return value
183*
184* Used to get a field in feature report. For example this can get polling
185* interval, sensitivity, activate/deactivate state.
186*/
187int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
188 u32 field_index, s32 *value);
Alexander Holler2974cdf2012-12-15 12:45:00 +0000189
190/* hid-sensor-attributes */
191
192/* Common hid sensor iio structure */
Alexander Hollere07c6d12012-12-15 12:45:00 +0000193struct hid_sensor_common {
Alexander Holler2974cdf2012-12-15 12:45:00 +0000194 struct hid_sensor_hub_device *hsdev;
195 struct platform_device *pdev;
196 unsigned usage_id;
Srinivas Pandruvada56ff6be2014-04-19 00:22:00 +0100197 atomic_t data_ready;
Srinivas Pandruvadaec7f68e2013-10-30 22:48:00 +0000198 struct iio_trigger *trigger;
Alexander Holler2974cdf2012-12-15 12:45:00 +0000199 struct hid_sensor_hub_attribute_info poll;
200 struct hid_sensor_hub_attribute_info report_state;
201 struct hid_sensor_hub_attribute_info power_state;
202 struct hid_sensor_hub_attribute_info sensitivity;
203};
204
Andy Shevchenko15261f62013-08-14 11:07:08 +0300205/* Convert from hid unit expo to regular exponent */
Alexander Holler2974cdf2012-12-15 12:45:00 +0000206static inline int hid_sensor_convert_exponent(int unit_expo)
207{
208 if (unit_expo < 0x08)
209 return unit_expo;
210 else if (unit_expo <= 0x0f)
211 return -(0x0f-unit_expo+1);
212 else
213 return 0;
214}
215
216int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
217 u32 usage_id,
Alexander Hollere07c6d12012-12-15 12:45:00 +0000218 struct hid_sensor_common *st);
219int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000220 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000221int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000222 int *val1, int *val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000223int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000224 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000225int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000226 int *val1, int *val2);
227
Srinivas Pandruvadae02cee42014-01-23 18:50:21 -0800228int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
229 u32 report_id, int field_index, u32 usage_id);
230
Srinivas Pandruvada5d02edfc2014-04-19 00:22:00 +0100231int hid_sensor_format_scale(u32 usage_id,
232 struct hid_sensor_hub_attribute_info *attr_info,
233 int *val0, int *val1);
234
Srinivas Pandruvada90309242014-04-19 00:22:00 +0100235s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
236
srinivas pandruvada401ca242012-09-05 13:56:00 +0100237#endif