nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.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>
24
25/**
26 * struct hid_sensor_hub_attribute_info - Attribute info
27 * @usage_id: Parent usage id of a physical device.
28 * @attrib_id: Attribute id for this attribute.
29 * @report_id: Report id in which this information resides.
30 * @index: Field index in the report.
31 * @units: Measurment unit for this attribute.
32 * @unit_expo: Exponent used in the data.
33 * @size: Size in bytes for data size.
34 */
35struct hid_sensor_hub_attribute_info {
36 u32 usage_id;
37 u32 attrib_id;
38 s32 report_id;
39 s32 index;
40 s32 units;
41 s32 unit_expo;
42 s32 size;
43};
44
45/**
46 * struct hid_sensor_hub_device - Stores the hub instance data
47 * @hdev: Stores the hid instance.
48 * @vendor_id: Vendor id of hub device.
49 * @product_id: Product id of hub device.
50 */
51struct hid_sensor_hub_device {
52 struct hid_device *hdev;
53 u32 vendor_id;
54 u32 product_id;
55};
56
57/**
58 * struct hid_sensor_hub_callbacks - Client callback functions
59 * @pdev: Platform device instance of the client driver.
60 * @suspend: Suspend callback.
61 * @resume: Resume callback.
62 * @capture_sample: Callback to get a sample.
63 * @send_event: Send notification to indicate all samples are
64 * captured, process and send event
65 */
66struct hid_sensor_hub_callbacks {
67 struct platform_device *pdev;
68 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
69 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
70 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
71 u32 usage_id, size_t raw_len, char *raw_data,
72 void *priv);
73 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
74 void *priv);
75};
76
77/* Registration functions */
78
79/**
80* sensor_hub_register_callback() - Register client callbacks
81* @hsdev: Hub device instance.
82* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
83* @usage_callback: Callback function storage
84*
85* Used to register callbacks by client processing drivers. Sensor
86* hub core driver will call these callbacks to offload processing
87* of data streams and notifications.
88*/
89int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
90 u32 usage_id,
91 struct hid_sensor_hub_callbacks *usage_callback);
92
93/**
94* sensor_hub_remove_callback() - Remove client callbacks
95* @hsdev: Hub device instance.
96* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
97*
98* If there is a callback registred, this call will remove that
99* callbacks, so that it will stop data and event notifications.
100*/
101int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
102 u32 usage_id);
103
104
105/* Hid sensor hub core interfaces */
106
107/**
108* sensor_hub_input_get_attribute_info() - Get an attribute information
109* @hsdev: Hub device instance.
110* @type: Type of this attribute, input/output/feature
111* @usage_id: Attribute usage id of parent physical device as per spec
112* @attr_usage_id: Attribute usage id as per spec
113* @info: return information about attribute after parsing report
114*
115* Parses report and returns the attribute information such as report id,
116* field index, units and exponet etc.
117*/
118int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
119 u8 type,
120 u32 usage_id, u32 attr_usage_id,
121 struct hid_sensor_hub_attribute_info *info);
122
123/**
124* sensor_hub_input_attr_get_raw_value() - Synchronous read request
125* @usage_id: Attribute usage id of parent physical device as per spec
126* @attr_usage_id: Attribute usage id as per spec
127* @report_id: Report id to look for
128*
129* Issues a synchronous read request for an input attribute. Returns
130* data upto 32 bits. Since client can get events, so this call should
131* not be used for data paths, this will impact performance.
132*/
133
134int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
135 u32 usage_id,
136 u32 attr_usage_id, u32 report_id);
137/**
138* sensor_hub_set_feature() - Feature set request
139* @report_id: Report id to look for
140* @field_index: Field index inside a report
141* @value: Value to set
142*
143* Used to set a field in feature report. For example this can set polling
144* interval, sensitivity, activate/deactivate state.
145*/
146int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
147 u32 field_index, s32 value);
148
149/**
150* sensor_hub_get_feature() - Feature get request
151* @report_id: Report id to look for
152* @field_index: Field index inside a report
153* @value: Place holder for return value
154*
155* Used to get a field in feature report. For example this can get polling
156* interval, sensitivity, activate/deactivate state.
157*/
158int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
159 u32 field_index, s32 *value);
2974cdf2
AH
160
161/* hid-sensor-attributes */
162
163/* Common hid sensor iio structure */
e07c6d17 164struct hid_sensor_common {
2974cdf2
AH
165 struct hid_sensor_hub_device *hsdev;
166 struct platform_device *pdev;
167 unsigned usage_id;
168 bool data_ready;
169 struct hid_sensor_hub_attribute_info poll;
170 struct hid_sensor_hub_attribute_info report_state;
171 struct hid_sensor_hub_attribute_info power_state;
172 struct hid_sensor_hub_attribute_info sensitivity;
173};
174
175/*Convert from hid unit expo to regular exponent*/
176static inline int hid_sensor_convert_exponent(int unit_expo)
177{
178 if (unit_expo < 0x08)
179 return unit_expo;
180 else if (unit_expo <= 0x0f)
181 return -(0x0f-unit_expo+1);
182 else
183 return 0;
184}
185
186int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
187 u32 usage_id,
e07c6d17
AH
188 struct hid_sensor_common *st);
189int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 190 int val1, int val2);
e07c6d17 191int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 192 int *val1, int *val2);
e07c6d17 193int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
2974cdf2 194 int val1, int val2);
e07c6d17 195int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
2974cdf2
AH
196 int *val1, int *val2);
197
401ca24f 198#endif