blob: a265af294ea49a28c0384af71aa5ee1a249b3be8 [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>
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.
Srinivas Pandruvada1df3a402013-09-18 18:13:00 +010050 * @ref_cnt: Number of MFD clients have opened this device
srinivas pandruvada401ca242012-09-05 13:56:00 +010051 */
52struct hid_sensor_hub_device {
53 struct hid_device *hdev;
54 u32 vendor_id;
55 u32 product_id;
Srinivas Pandruvada1df3a402013-09-18 18:13:00 +010056 int ref_cnt;
srinivas pandruvada401ca242012-09-05 13:56:00 +010057};
58
59/**
60 * struct hid_sensor_hub_callbacks - Client callback functions
61 * @pdev: Platform device instance of the client driver.
62 * @suspend: Suspend callback.
63 * @resume: Resume callback.
64 * @capture_sample: Callback to get a sample.
65 * @send_event: Send notification to indicate all samples are
66 * captured, process and send event
67 */
68struct hid_sensor_hub_callbacks {
69 struct platform_device *pdev;
70 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
71 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
72 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
73 u32 usage_id, size_t raw_len, char *raw_data,
74 void *priv);
75 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
76 void *priv);
77};
78
Srinivas Pandruvada1df3a402013-09-18 18:13:00 +010079/**
80* sensor_hub_device_open() - Open hub device
81* @hsdev: Hub device instance.
82*
83* Used to open hid device for sensor hub.
84*/
85int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
86
87/**
88* sensor_hub_device_clode() - Close hub device
89* @hsdev: Hub device instance.
90*
91* Used to clode hid device for sensor hub.
92*/
93void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
94
srinivas pandruvada401ca242012-09-05 13:56:00 +010095/* Registration functions */
96
97/**
98* sensor_hub_register_callback() - Register client callbacks
99* @hsdev: Hub device instance.
100* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
101* @usage_callback: Callback function storage
102*
103* Used to register callbacks by client processing drivers. Sensor
104* hub core driver will call these callbacks to offload processing
105* of data streams and notifications.
106*/
107int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
108 u32 usage_id,
109 struct hid_sensor_hub_callbacks *usage_callback);
110
111/**
112* sensor_hub_remove_callback() - Remove client callbacks
113* @hsdev: Hub device instance.
114* @usage_id: Usage id of the client (E.g. 0x200076 for Gyro).
115*
116* If there is a callback registred, this call will remove that
117* callbacks, so that it will stop data and event notifications.
118*/
119int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
120 u32 usage_id);
121
122
123/* Hid sensor hub core interfaces */
124
125/**
126* sensor_hub_input_get_attribute_info() - Get an attribute information
127* @hsdev: Hub device instance.
128* @type: Type of this attribute, input/output/feature
129* @usage_id: Attribute usage id of parent physical device as per spec
130* @attr_usage_id: Attribute usage id as per spec
131* @info: return information about attribute after parsing report
132*
133* Parses report and returns the attribute information such as report id,
134* field index, units and exponet etc.
135*/
136int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
137 u8 type,
138 u32 usage_id, u32 attr_usage_id,
139 struct hid_sensor_hub_attribute_info *info);
140
141/**
142* sensor_hub_input_attr_get_raw_value() - Synchronous read request
143* @usage_id: Attribute usage id of parent physical device as per spec
144* @attr_usage_id: Attribute usage id as per spec
145* @report_id: Report id to look for
146*
147* Issues a synchronous read request for an input attribute. Returns
148* data upto 32 bits. Since client can get events, so this call should
149* not be used for data paths, this will impact performance.
150*/
151
152int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
153 u32 usage_id,
154 u32 attr_usage_id, u32 report_id);
155/**
156* sensor_hub_set_feature() - Feature set request
157* @report_id: Report id to look for
158* @field_index: Field index inside a report
159* @value: Value to set
160*
161* Used to set a field in feature report. For example this can set polling
162* interval, sensitivity, activate/deactivate state.
163*/
164int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
165 u32 field_index, s32 value);
166
167/**
168* sensor_hub_get_feature() - Feature get request
169* @report_id: Report id to look for
170* @field_index: Field index inside a report
171* @value: Place holder for return value
172*
173* Used to get a field in feature report. For example this can get polling
174* interval, sensitivity, activate/deactivate state.
175*/
176int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
177 u32 field_index, s32 *value);
Alexander Holler2974cdf2012-12-15 12:45:00 +0000178
179/* hid-sensor-attributes */
180
181/* Common hid sensor iio structure */
Alexander Hollere07c6d12012-12-15 12:45:00 +0000182struct hid_sensor_common {
Alexander Holler2974cdf2012-12-15 12:45:00 +0000183 struct hid_sensor_hub_device *hsdev;
184 struct platform_device *pdev;
185 unsigned usage_id;
186 bool data_ready;
187 struct hid_sensor_hub_attribute_info poll;
188 struct hid_sensor_hub_attribute_info report_state;
189 struct hid_sensor_hub_attribute_info power_state;
190 struct hid_sensor_hub_attribute_info sensitivity;
191};
192
Andy Shevchenko15261f62013-08-14 11:07:08 +0300193/* Convert from hid unit expo to regular exponent */
Alexander Holler2974cdf2012-12-15 12:45:00 +0000194static inline int hid_sensor_convert_exponent(int unit_expo)
195{
196 if (unit_expo < 0x08)
197 return unit_expo;
198 else if (unit_expo <= 0x0f)
199 return -(0x0f-unit_expo+1);
200 else
201 return 0;
202}
203
204int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
205 u32 usage_id,
Alexander Hollere07c6d12012-12-15 12:45:00 +0000206 struct hid_sensor_common *st);
207int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000208 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000209int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000210 int *val1, int *val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000211int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000212 int val1, int val2);
Alexander Hollere07c6d12012-12-15 12:45:00 +0000213int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
Alexander Holler2974cdf2012-12-15 12:45:00 +0000214 int *val1, int *val2);
215
srinivas pandruvada401ca242012-09-05 13:56:00 +0100216#endif