blob: 51f7ccadf923c337ddb5627491a958c5e74fa610 [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.
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;
Srinivas Pandruvada9f740ff2013-11-27 22:19:00 +000045 s32 logical_minimum;
46 s32 logical_maximum;
srinivas pandruvada401ca242012-09-05 13:56:00 +010047};
48
49/**
50 * struct hid_sensor_hub_device - Stores the hub instance data
51 * @hdev: Stores the hid instance.
52 * @vendor_id: Vendor id of hub device.
53 * @product_id: Product id of hub device.
Srinivas Pandruvadaca2ed122014-01-31 12:04:10 -080054 * @start_collection_index: Starting index for a phy type collection
55 * @end_collection_index: Last index for a phy type collection
srinivas pandruvada401ca242012-09-05 13:56:00 +010056 */
57struct hid_sensor_hub_device {
58 struct hid_device *hdev;
59 u32 vendor_id;
60 u32 product_id;
Srinivas Pandruvadaca2ed122014-01-31 12:04:10 -080061 int start_collection_index;
62 int end_collection_index;
srinivas pandruvada401ca242012-09-05 13:56:00 +010063};
64
65/**
66 * struct hid_sensor_hub_callbacks - Client callback functions
67 * @pdev: Platform device instance of the client driver.
68 * @suspend: Suspend callback.
69 * @resume: Resume callback.
70 * @capture_sample: Callback to get a sample.
71 * @send_event: Send notification to indicate all samples are
72 * captured, process and send event
73 */
74struct hid_sensor_hub_callbacks {
75 struct platform_device *pdev;
76 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
77 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
78 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
79 u32 usage_id, size_t raw_len, char *raw_data,
80 void *priv);
81 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
82 void *priv);
83};
84
Srinivas Pandruvada1df3a402013-09-18 18:13:00 +010085/**
86* sensor_hub_device_open() - Open hub device
87* @hsdev: Hub device instance.
88*
89* Used to open hid device for sensor hub.
90*/
91int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
92
93/**
94* sensor_hub_device_clode() - Close hub device
95* @hsdev: Hub device instance.
96*
97* Used to clode hid device for sensor hub.
98*/
99void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
100
srinivas pandruvada401ca242012-09-05 13:56:00 +0100101/* Registration functions */
102
103/**
104* sensor_hub_register_callback() - Register client callbacks
105* @hsdev: Hub device instance.
106* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
107* @usage_callback: Callback function storage
108*
109* Used to register callbacks by client processing drivers. Sensor
110* hub core driver will call these callbacks to offload processing
111* of data streams and notifications.
112*/
113int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
114 u32 usage_id,
115 struct hid_sensor_hub_callbacks *usage_callback);
116
117/**
118* sensor_hub_remove_callback() - Remove client callbacks
119* @hsdev: Hub device instance.
120* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
121*
122* If there is a callback registred, this call will remove that
123* callbacks, so that it will stop data and event notifications.
124*/
125int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
126 u32 usage_id);
127
128
129/* Hid sensor hub core interfaces */
130
131/**
132* sensor_hub_input_get_attribute_info() - Get an attribute information
133* @hsdev: Hub device instance.
134* @type: Type of this attribute, input/output/feature
135* @usage_id: Attribute usage id of parent physical device as per spec
136* @attr_usage_id: Attribute usage id as per spec
137* @info: return information about attribute after parsing report
138*
139* Parses report and returns the attribute information such as report id,
140* field index, units and exponet etc.
141*/
142int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
143 u8 type,
144 u32 usage_id, u32 attr_usage_id,
145 struct hid_sensor_hub_attribute_info *info);
146
147/**
148* sensor_hub_input_attr_get_raw_value() - Synchronous read request
149* @usage_id: Attribute usage id of parent physical device as per spec
150* @attr_usage_id: Attribute usage id as per spec
151* @report_id: Report id to look for
152*
153* Issues a synchronous read request for an input attribute. Returns
154* data upto 32 bits. Since client can get events, so this call should
155* not be used for data paths, this will impact performance.
156*/
157
158int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
159 u32 usage_id,
160 u32 attr_usage_id, u32 report_id);
161/**
162* sensor_hub_set_feature() - Feature set request
163* @report_id: Report id to look for
164* @field_index: Field index inside a report
165* @value: Value to set
166*
167* Used to set a field in feature report. For example this can set polling
168* interval, sensitivity, activate/deactivate state.
169*/
170int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
171 u32 field_index, s32 value);
172
173/**
174* sensor_hub_get_feature() - Feature get request
175* @report_id: Report id to look for
176* @field_index: Field index inside a report
177* @value: Place holder for return value
178*
179* Used to get a field in feature report. For example this can get polling
180* interval, sensitivity, activate/deactivate state.
181*/
182int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
183 u32 field_index, s32 *value);
Alexander Holler2974cdf2012-12-15 12:45:00 +0000184
185/* hid-sensor-attributes */
186
187/* Common hid sensor iio structure */
Alexander Hollere07c6d12012-12-15 12:45:00 +0000188struct hid_sensor_common {
Alexander Holler2974cdf2012-12-15 12:45:00 +0000189 struct hid_sensor_hub_device *hsdev;
190 struct platform_device *pdev;
191 unsigned usage_id;
Srinivas Pandruvada56ff6be2014-04-19 00:22:00 +0100192 atomic_t data_ready;
Srinivas Pandruvadaec7f68e2013-10-30 22:48:00 +0000193 struct iio_trigger *trigger;
Alexander Holler2974cdf2012-12-15 12:45:00 +0000194 struct hid_sensor_hub_attribute_info poll;
195 struct hid_sensor_hub_attribute_info report_state;
196 struct hid_sensor_hub_attribute_info power_state;
197 struct hid_sensor_hub_attribute_info sensitivity;
198};
199
Andy Shevchenko15261f62013-08-14 11:07:08 +0300200/* Convert from hid unit expo to regular exponent */
Alexander Holler2974cdf2012-12-15 12:45:00 +0000201static inline int hid_sensor_convert_exponent(int unit_expo)
202{
203 if (unit_expo < 0x08)
204 return unit_expo;
205 else if (unit_expo <= 0x0f)
206 return -(0x0f-unit_expo+1);
207 else
208 return 0;
209}
210
211int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
212 u32 usage_id,
Alexander Hollere07c6d12012-12-15 12:45:00 +0000213 struct hid_sensor_common *st);
214int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000215 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000216int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000217 int *val1, int *val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000218int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000219 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000220int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000221 int *val1, int *val2);
222
Srinivas Pandruvadae02cee42014-01-23 18:50:21 -0800223int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
224 u32 report_id, int field_index, u32 usage_id);
225
Srinivas Pandruvada5d02edfc2014-04-19 00:22:00 +0100226int hid_sensor_format_scale(u32 usage_id,
227 struct hid_sensor_hub_attribute_info *attr_info,
228 int *val0, int *val1);
229
Srinivas Pandruvada90309242014-04-19 00:22:00 +0100230s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
231
srinivas pandruvada401ca242012-09-05 13:56:00 +0100232#endif