]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/hid-sensor-hub.h
cpufreq: Rename cpufreq_can_do_remote_dvfs()
[mirror_ubuntu-bionic-kernel.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.
f9d904ac
SP
36 * @logical_minimum: Logical minimum value for this attribute.
37 * @logical_maximum: Logical maximum value for this attribute.
401ca24f 38 */
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;
9f740ffa
SP
47 s32 logical_minimum;
48 s32 logical_maximum;
401ca24f 49};
50
e651a1da
SP
51/**
52 * struct sensor_hub_pending - Synchronous read pending information
53 * @status: Pending status true/false.
54 * @ready: Completion synchronization data.
55 * @usage_id: Usage id for physical device, E.g. Gyro usage id.
56 * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro.
57 * @raw_size: Response size for a read request.
58 * @raw_data: Place holder for received response.
59 */
60struct sensor_hub_pending {
61 bool status;
62 struct completion ready;
63 u32 usage_id;
64 u32 attr_usage_id;
65 int raw_size;
66 u8 *raw_data;
67};
68
401ca24f 69/**
70 * struct hid_sensor_hub_device - Stores the hub instance data
71 * @hdev: Stores the hid instance.
72 * @vendor_id: Vendor id of hub device.
73 * @product_id: Product id of hub device.
e651a1da 74 * @usage: Usage id for this hub device instance.
ca2ed12f
SP
75 * @start_collection_index: Starting index for a phy type collection
76 * @end_collection_index: Last index for a phy type collection
2d94e522 77 * @mutex_ptr: synchronizing mutex pointer.
e651a1da 78 * @pending: Holds information of pending sync read request.
401ca24f 79 */
80struct hid_sensor_hub_device {
81 struct hid_device *hdev;
82 u32 vendor_id;
83 u32 product_id;
e651a1da 84 u32 usage;
ca2ed12f
SP
85 int start_collection_index;
86 int end_collection_index;
2d94e522 87 struct mutex *mutex_ptr;
e651a1da 88 struct sensor_hub_pending pending;
401ca24f 89};
90
91/**
92 * struct hid_sensor_hub_callbacks - Client callback functions
93 * @pdev: Platform device instance of the client driver.
94 * @suspend: Suspend callback.
95 * @resume: Resume callback.
96 * @capture_sample: Callback to get a sample.
97 * @send_event: Send notification to indicate all samples are
98 * captured, process and send event
99 */
100struct hid_sensor_hub_callbacks {
101 struct platform_device *pdev;
102 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
103 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
104 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
105 u32 usage_id, size_t raw_len, char *raw_data,
106 void *priv);
107 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
108 void *priv);
109};
110
1df3a401
SP
111/**
112* sensor_hub_device_open() - Open hub device
113* @hsdev: Hub device instance.
114*
115* Used to open hid device for sensor hub.
116*/
117int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
118
119/**
120* sensor_hub_device_clode() - Close hub device
121* @hsdev: Hub device instance.
122*
123* Used to clode hid device for sensor hub.
124*/
125void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
126
401ca24f 127/* Registration functions */
128
129/**
130* sensor_hub_register_callback() - Register client callbacks
131* @hsdev: Hub device instance.
132* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
133* @usage_callback: Callback function storage
134*
135* Used to register callbacks by client processing drivers. Sensor
136* hub core driver will call these callbacks to offload processing
137* of data streams and notifications.
138*/
139int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
140 u32 usage_id,
141 struct hid_sensor_hub_callbacks *usage_callback);
142
143/**
144* sensor_hub_remove_callback() - Remove client callbacks
145* @hsdev: Hub device instance.
146* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
147*
148* If there is a callback registred, this call will remove that
149* callbacks, so that it will stop data and event notifications.
150*/
151int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
152 u32 usage_id);
153
154
155/* Hid sensor hub core interfaces */
156
157/**
158* sensor_hub_input_get_attribute_info() - Get an attribute information
159* @hsdev: Hub device instance.
160* @type: Type of this attribute, input/output/feature
161* @usage_id: Attribute usage id of parent physical device as per spec
162* @attr_usage_id: Attribute usage id as per spec
163* @info: return information about attribute after parsing report
164*
165* Parses report and returns the attribute information such as report id,
166* field index, units and exponet etc.
167*/
168int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
169 u8 type,
170 u32 usage_id, u32 attr_usage_id,
171 struct hid_sensor_hub_attribute_info *info);
172
173/**
174* sensor_hub_input_attr_get_raw_value() - Synchronous read request
f9d904ac 175* @hsdev: Hub device instance.
401ca24f 176* @usage_id: Attribute usage id of parent physical device as per spec
177* @attr_usage_id: Attribute usage id as per spec
178* @report_id: Report id to look for
b3f4737d 179* @flag: Synchronous or asynchronous read
2af33e6f 180* @is_signed: If true then fields < 32 bits will be sign-extended
401ca24f 181*
b3f4737d
SP
182* Issues a synchronous or asynchronous read request for an input attribute.
183* Returns data upto 32 bits.
401ca24f 184*/
185
b3f4737d
SP
186enum sensor_hub_read_flags {
187 SENSOR_HUB_SYNC,
188 SENSOR_HUB_ASYNC,
189};
190
401ca24f 191int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
b3f4737d
SP
192 u32 usage_id,
193 u32 attr_usage_id, u32 report_id,
2af33e6f
HG
194 enum sensor_hub_read_flags flag,
195 bool is_signed
b3f4737d
SP
196);
197
401ca24f 198/**
199* sensor_hub_set_feature() - Feature set request
f9d904ac 200* @hsdev: Hub device instance.
401ca24f 201* @report_id: Report id to look for
202* @field_index: Field index inside a report
3950e033
SP
203* @buffer_size: size of the buffer
204* @buffer: buffer to use in the feature set
401ca24f 205*
206* Used to set a field in feature report. For example this can set polling
207* interval, sensitivity, activate/deactivate state.
208*/
209int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
3950e033 210 u32 field_index, int buffer_size, void *buffer);
401ca24f 211
212/**
213* sensor_hub_get_feature() - Feature get request
f9d904ac 214* @hsdev: Hub device instance.
401ca24f 215* @report_id: Report id to look for
216* @field_index: Field index inside a report
6adc83fc
SP
217* @buffer_size: size of the buffer
218* @buffer: buffer to copy output
401ca24f 219*
220* Used to get a field in feature report. For example this can get polling
6adc83fc
SP
221* interval, sensitivity, activate/deactivate state. On success it returns
222* number of bytes copied to buffer. On failure, it returns value < 0.
401ca24f 223*/
224int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
6adc83fc 225 u32 field_index, int buffer_size, void *buffer);
2974cdf2
AH
226
227/* hid-sensor-attributes */
228
229/* Common hid sensor iio structure */
e07c6d17 230struct hid_sensor_common {
2974cdf2
AH
231 struct hid_sensor_hub_device *hsdev;
232 struct platform_device *pdev;
233 unsigned usage_id;
56ff6be6 234 atomic_t data_ready;
1e25aa96 235 atomic_t user_requested_state;
ad7532ce 236 atomic_t runtime_pm_enable;
5d9854ea
SP
237 int poll_interval;
238 int raw_hystersis;
138bc796 239 int latency_ms;
ec7f68e0 240 struct iio_trigger *trigger;
a96cd0f9 241 int timestamp_ns_scale;
2974cdf2
AH
242 struct hid_sensor_hub_attribute_info poll;
243 struct hid_sensor_hub_attribute_info report_state;
244 struct hid_sensor_hub_attribute_info power_state;
245 struct hid_sensor_hub_attribute_info sensitivity;
138bc796 246 struct hid_sensor_hub_attribute_info report_latency;
7f6cf741 247 struct work_struct work;
2974cdf2
AH
248};
249
15261f6d 250/* Convert from hid unit expo to regular exponent */
2974cdf2
AH
251static inline int hid_sensor_convert_exponent(int unit_expo)
252{
253 if (unit_expo < 0x08)
254 return unit_expo;
255 else if (unit_expo <= 0x0f)
256 return -(0x0f-unit_expo+1);
257 else
258 return 0;
259}
260
261int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
262 u32 usage_id,
e07c6d17
AH
263 struct hid_sensor_common *st);
264int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 265 int val1, int val2);
e07c6d17 266int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
2974cdf2 267 int *val1, int *val2);
e07c6d17 268int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
2974cdf2 269 int val1, int val2);
e07c6d17 270int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
2974cdf2
AH
271 int *val1, int *val2);
272
e02cee48
SP
273int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
274 u32 report_id, int field_index, u32 usage_id);
275
5d02edfc
SP
276int hid_sensor_format_scale(u32 usage_id,
277 struct hid_sensor_hub_attribute_info *attr_info,
278 int *val0, int *val1);
279
90309245
SP
280s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
281
a96cd0f9
SP
282int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st,
283 int64_t raw_value);
138bc796
SP
284bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st);
285int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency);
286int hid_sensor_get_report_latency(struct hid_sensor_common *st);
a96cd0f9 287
401ca24f 288#endif