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