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