1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * HID Sensors Driver 2 * HID Sensors Driver 4 * Copyright (c) 2012, Intel Corporation. 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 * 5 */ 18 */ 6 #ifndef _HID_SENSORS_HUB_H 19 #ifndef _HID_SENSORS_HUB_H 7 #define _HID_SENSORS_HUB_H 20 #define _HID_SENSORS_HUB_H 8 21 9 #include <linux/hid.h> 22 #include <linux/hid.h> 10 #include <linux/hid-sensor-ids.h> 23 #include <linux/hid-sensor-ids.h> 11 #include <linux/iio/iio.h> 24 #include <linux/iio/iio.h> 12 #include <linux/iio/trigger.h> 25 #include <linux/iio/trigger.h> 13 26 14 /** 27 /** 15 * struct hid_sensor_hub_attribute_info - Attr 28 * struct hid_sensor_hub_attribute_info - Attribute info 16 * @usage_id: Parent usage id of a p 29 * @usage_id: Parent usage id of a physical device. 17 * @attrib_id: Attribute id for this 30 * @attrib_id: Attribute id for this attribute. 18 * @report_id: Report id in which thi 31 * @report_id: Report id in which this information resides. 19 * @index: Field index in the rep 32 * @index: Field index in the report. 20 * @units: Measurment unit for th 33 * @units: Measurment unit for this attribute. 21 * @unit_expo: Exponent used in the d 34 * @unit_expo: Exponent used in the data. 22 * @size: Size in bytes for data 35 * @size: Size in bytes for data size. 23 * @logical_minimum: Logical minimum value 36 * @logical_minimum: Logical minimum value for this attribute. 24 * @logical_maximum: Logical maximum value 37 * @logical_maximum: Logical maximum value for this attribute. 25 */ 38 */ 26 struct hid_sensor_hub_attribute_info { 39 struct hid_sensor_hub_attribute_info { 27 u32 usage_id; 40 u32 usage_id; 28 u32 attrib_id; 41 u32 attrib_id; 29 s32 report_id; 42 s32 report_id; 30 s32 index; 43 s32 index; 31 s32 units; 44 s32 units; 32 s32 unit_expo; 45 s32 unit_expo; 33 s32 size; 46 s32 size; 34 s32 logical_minimum; 47 s32 logical_minimum; 35 s32 logical_maximum; 48 s32 logical_maximum; 36 }; 49 }; 37 50 38 /** 51 /** 39 * struct sensor_hub_pending - Synchronous rea 52 * struct sensor_hub_pending - Synchronous read pending information 40 * @status: Pending status true/fa 53 * @status: Pending status true/false. 41 * @ready: Completion synchroniza 54 * @ready: Completion synchronization data. 42 * @usage_id: Usage id for physical 55 * @usage_id: Usage id for physical device, E.g. Gyro usage id. 43 * @attr_usage_id: Usage Id of a field, E 56 * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro. 44 * @raw_size: Response size for a re 57 * @raw_size: Response size for a read request. 45 * @raw_data: Place holder for recei 58 * @raw_data: Place holder for received response. 46 */ 59 */ 47 struct sensor_hub_pending { 60 struct sensor_hub_pending { 48 bool status; 61 bool status; 49 struct completion ready; 62 struct completion ready; 50 u32 usage_id; 63 u32 usage_id; 51 u32 attr_usage_id; 64 u32 attr_usage_id; 52 int raw_size; 65 int raw_size; 53 u8 *raw_data; 66 u8 *raw_data; 54 }; 67 }; 55 68 56 /** 69 /** 57 * struct hid_sensor_hub_device - Stores the h 70 * struct hid_sensor_hub_device - Stores the hub instance data 58 * @hdev: Stores the hid instanc 71 * @hdev: Stores the hid instance. 59 * @vendor_id: Vendor id of hub devic 72 * @vendor_id: Vendor id of hub device. 60 * @product_id: Product id of hub devi 73 * @product_id: Product id of hub device. 61 * @usage: Usage id for this hub 74 * @usage: Usage id for this hub device instance. 62 * @start_collection_index: Starting index for 75 * @start_collection_index: Starting index for a phy type collection 63 * @end_collection_index: Last index for a phy 76 * @end_collection_index: Last index for a phy type collection 64 * @mutex_ptr: synchronizing mutex po 77 * @mutex_ptr: synchronizing mutex pointer. 65 * @pending: Holds information of p 78 * @pending: Holds information of pending sync read request. 66 */ 79 */ 67 struct hid_sensor_hub_device { 80 struct hid_sensor_hub_device { 68 struct hid_device *hdev; 81 struct hid_device *hdev; 69 u32 vendor_id; 82 u32 vendor_id; 70 u32 product_id; 83 u32 product_id; 71 u32 usage; 84 u32 usage; 72 int start_collection_index; 85 int start_collection_index; 73 int end_collection_index; 86 int end_collection_index; 74 struct mutex *mutex_ptr; 87 struct mutex *mutex_ptr; 75 struct sensor_hub_pending pending; 88 struct sensor_hub_pending pending; 76 }; 89 }; 77 90 78 /** 91 /** 79 * struct hid_sensor_hub_callbacks - Client ca 92 * struct hid_sensor_hub_callbacks - Client callback functions 80 * @pdev: Platform device instan 93 * @pdev: Platform device instance of the client driver. 81 * @suspend: Suspend callback. 94 * @suspend: Suspend callback. 82 * @resume: Resume callback. 95 * @resume: Resume callback. 83 * @capture_sample: Callback to get a samp 96 * @capture_sample: Callback to get a sample. 84 * @send_event: Send notification to i 97 * @send_event: Send notification to indicate all samples are 85 * captured, process and 98 * captured, process and send event 86 */ 99 */ 87 struct hid_sensor_hub_callbacks { 100 struct hid_sensor_hub_callbacks { 88 struct platform_device *pdev; 101 struct platform_device *pdev; 89 int (*suspend)(struct hid_sensor_hub_d 102 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv); 90 int (*resume)(struct hid_sensor_hub_de 103 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv); 91 int (*capture_sample)(struct hid_senso 104 int (*capture_sample)(struct hid_sensor_hub_device *hsdev, 92 u32 usage_id, size_t r 105 u32 usage_id, size_t raw_len, char *raw_data, 93 void *priv); 106 void *priv); 94 int (*send_event)(struct hid_sensor_hu 107 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id, 95 void *priv); 108 void *priv); 96 }; 109 }; 97 110 98 /** 111 /** 99 * sensor_hub_device_open() - Open hub device 112 * sensor_hub_device_open() - Open hub device 100 * @hsdev: Hub device instance. 113 * @hsdev: Hub device instance. 101 * 114 * 102 * Used to open hid device for sensor hub. 115 * Used to open hid device for sensor hub. 103 */ 116 */ 104 int sensor_hub_device_open(struct hid_sensor_h 117 int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev); 105 118 106 /** 119 /** 107 * sensor_hub_device_clode() - Close hub device 120 * sensor_hub_device_clode() - Close hub device 108 * @hsdev: Hub device instance. 121 * @hsdev: Hub device instance. 109 * 122 * 110 * Used to clode hid device for sensor hub. 123 * Used to clode hid device for sensor hub. 111 */ 124 */ 112 void sensor_hub_device_close(struct hid_sensor 125 void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev); 113 126 114 /* Registration functions */ 127 /* Registration functions */ 115 128 116 /** 129 /** 117 * sensor_hub_register_callback() - Register cl 130 * sensor_hub_register_callback() - Register client callbacks 118 * @hsdev: Hub device instance. 131 * @hsdev: Hub device instance. 119 * @usage_id: Usage id of the client (E.g. 0 132 * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro). 120 * @usage_callback: Callback function storage 133 * @usage_callback: Callback function storage 121 * 134 * 122 * Used to register callbacks by client process 135 * Used to register callbacks by client processing drivers. Sensor 123 * hub core driver will call these callbacks to 136 * hub core driver will call these callbacks to offload processing 124 * of data streams and notifications. 137 * of data streams and notifications. 125 */ 138 */ 126 int sensor_hub_register_callback(struct hid_se 139 int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev, 127 u32 usage_id, 140 u32 usage_id, 128 struct hid_sensor_hub_ 141 struct hid_sensor_hub_callbacks *usage_callback); 129 142 130 /** 143 /** 131 * sensor_hub_remove_callback() - Remove client 144 * sensor_hub_remove_callback() - Remove client callbacks 132 * @hsdev: Hub device instance. 145 * @hsdev: Hub device instance. 133 * @usage_id: Usage id of the client (E.g. 0 146 * @usage_id: Usage id of the client (E.g. 0x200076 for Gyro). 134 * 147 * 135 * If there is a callback registred, this call 148 * If there is a callback registred, this call will remove that 136 * callbacks, so that it will stop data and eve 149 * callbacks, so that it will stop data and event notifications. 137 */ 150 */ 138 int sensor_hub_remove_callback(struct hid_sens 151 int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev, 139 u32 usage_id); 152 u32 usage_id); 140 153 141 154 142 /* Hid sensor hub core interfaces */ 155 /* Hid sensor hub core interfaces */ 143 156 144 /** 157 /** 145 * sensor_hub_input_get_attribute_info() - Get 158 * sensor_hub_input_get_attribute_info() - Get an attribute information 146 * @hsdev: Hub device instance. 159 * @hsdev: Hub device instance. 147 * @type: Type of this attribute, input/ 160 * @type: Type of this attribute, input/output/feature 148 * @usage_id: Attribute usage id of parent p 161 * @usage_id: Attribute usage id of parent physical device as per spec 149 * @attr_usage_id: Attribute usage id as 162 * @attr_usage_id: Attribute usage id as per spec 150 * @info: return information about attri 163 * @info: return information about attribute after parsing report 151 * 164 * 152 * Parses report and returns the attribute info 165 * Parses report and returns the attribute information such as report id, 153 * field index, units and exponent etc. !! 166 * field index, units and exponet etc. 154 */ 167 */ 155 int sensor_hub_input_get_attribute_info(struct 168 int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, 156 u8 type, 169 u8 type, 157 u32 usage_id, u32 attr 170 u32 usage_id, u32 attr_usage_id, 158 struct hid_sensor_hub_ 171 struct hid_sensor_hub_attribute_info *info); 159 172 160 /** 173 /** 161 * sensor_hub_input_attr_get_raw_value() - Sync 174 * sensor_hub_input_attr_get_raw_value() - Synchronous read request 162 * @hsdev: Hub device instance. 175 * @hsdev: Hub device instance. 163 * @usage_id: Attribute usage id of parent p 176 * @usage_id: Attribute usage id of parent physical device as per spec 164 * @attr_usage_id: Attribute usage id as 177 * @attr_usage_id: Attribute usage id as per spec 165 * @report_id: Report id to look for 178 * @report_id: Report id to look for 166 * @flag: Synchronous or asynchronous read 179 * @flag: Synchronous or asynchronous read 167 * @is_signed: If true then fields < 32 bits 180 * @is_signed: If true then fields < 32 bits will be sign-extended 168 * 181 * 169 * Issues a synchronous or asynchronous read re 182 * Issues a synchronous or asynchronous read request for an input attribute. 170 * Return: data up to 32 bits. !! 183 * Returns data upto 32 bits. 171 */ 184 */ 172 185 173 enum sensor_hub_read_flags { 186 enum sensor_hub_read_flags { 174 SENSOR_HUB_SYNC, 187 SENSOR_HUB_SYNC, 175 SENSOR_HUB_ASYNC, 188 SENSOR_HUB_ASYNC, 176 }; 189 }; 177 190 178 int sensor_hub_input_attr_get_raw_value(struct 191 int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, 179 u32 us 192 u32 usage_id, 180 u32 at 193 u32 attr_usage_id, u32 report_id, 181 enum s 194 enum sensor_hub_read_flags flag, 182 bool i 195 bool is_signed 183 ); 196 ); 184 197 185 /** 198 /** 186 * sensor_hub_set_feature() - Feature set reque 199 * sensor_hub_set_feature() - Feature set request 187 * @hsdev: Hub device instance. 200 * @hsdev: Hub device instance. 188 * @report_id: Report id to look for 201 * @report_id: Report id to look for 189 * @field_index: Field index inside a report 202 * @field_index: Field index inside a report 190 * @buffer_size: size of the buffer 203 * @buffer_size: size of the buffer 191 * @buffer: buffer to use in the feature s 204 * @buffer: buffer to use in the feature set 192 * 205 * 193 * Used to set a field in feature report. For e 206 * Used to set a field in feature report. For example this can set polling 194 * interval, sensitivity, activate/deactivate s 207 * interval, sensitivity, activate/deactivate state. 195 */ 208 */ 196 int sensor_hub_set_feature(struct hid_sensor_h 209 int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 197 u32 field_index, in 210 u32 field_index, int buffer_size, void *buffer); 198 211 199 /** 212 /** 200 * sensor_hub_get_feature() - Feature get reque 213 * sensor_hub_get_feature() - Feature get request 201 * @hsdev: Hub device instance. 214 * @hsdev: Hub device instance. 202 * @report_id: Report id to look for 215 * @report_id: Report id to look for 203 * @field_index: Field index inside a report 216 * @field_index: Field index inside a report 204 * @buffer_size: size of the buffer 217 * @buffer_size: size of the buffer 205 * @buffer: buffer to copy output 218 * @buffer: buffer to copy output 206 * 219 * 207 * Used to get a field in feature report. For e 220 * Used to get a field in feature report. For example this can get polling 208 * interval, sensitivity, activate/deactivate s !! 221 * interval, sensitivity, activate/deactivate state. On success it returns 209 * Return: On success, it returns the number of !! 222 * number of bytes copied to buffer. On failure, it returns value < 0. 210 * On failure, it returns value < 0. << 211 */ 223 */ 212 int sensor_hub_get_feature(struct hid_sensor_h 224 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 213 u32 field_index, in 225 u32 field_index, int buffer_size, void *buffer); 214 226 215 /* hid-sensor-attributes */ 227 /* hid-sensor-attributes */ 216 228 217 /* Common hid sensor iio structure */ 229 /* Common hid sensor iio structure */ 218 struct hid_sensor_common { 230 struct hid_sensor_common { 219 struct hid_sensor_hub_device *hsdev; 231 struct hid_sensor_hub_device *hsdev; 220 struct platform_device *pdev; 232 struct platform_device *pdev; 221 unsigned usage_id; 233 unsigned usage_id; 222 atomic_t data_ready; 234 atomic_t data_ready; 223 atomic_t user_requested_state; 235 atomic_t user_requested_state; 224 atomic_t runtime_pm_enable; 236 atomic_t runtime_pm_enable; 225 int poll_interval; 237 int poll_interval; 226 int raw_hystersis; 238 int raw_hystersis; 227 int latency_ms; 239 int latency_ms; 228 struct iio_trigger *trigger; 240 struct iio_trigger *trigger; 229 int timestamp_ns_scale; 241 int timestamp_ns_scale; 230 struct hid_sensor_hub_attribute_info p 242 struct hid_sensor_hub_attribute_info poll; 231 struct hid_sensor_hub_attribute_info r 243 struct hid_sensor_hub_attribute_info report_state; 232 struct hid_sensor_hub_attribute_info p 244 struct hid_sensor_hub_attribute_info power_state; 233 struct hid_sensor_hub_attribute_info s 245 struct hid_sensor_hub_attribute_info sensitivity; 234 struct hid_sensor_hub_attribute_info s << 235 struct hid_sensor_hub_attribute_info r 246 struct hid_sensor_hub_attribute_info report_latency; 236 struct work_struct work; 247 struct work_struct work; 237 }; 248 }; 238 249 239 /* Convert from hid unit expo to regular expon 250 /* Convert from hid unit expo to regular exponent */ 240 static inline int hid_sensor_convert_exponent( 251 static inline int hid_sensor_convert_exponent(int unit_expo) 241 { 252 { 242 if (unit_expo < 0x08) 253 if (unit_expo < 0x08) 243 return unit_expo; 254 return unit_expo; 244 else if (unit_expo <= 0x0f) 255 else if (unit_expo <= 0x0f) 245 return -(0x0f-unit_expo+1); 256 return -(0x0f-unit_expo+1); 246 else 257 else 247 return 0; 258 return 0; 248 } 259 } 249 260 250 int hid_sensor_parse_common_attributes(struct 261 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, 251 u32 us 262 u32 usage_id, 252 struct !! 263 struct hid_sensor_common *st); 253 const << 254 u32 se << 255 int hid_sensor_write_raw_hyst_value(struct hid 264 int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st, 256 int va 265 int val1, int val2); 257 int hid_sensor_write_raw_hyst_rel_value(struct << 258 int va << 259 int hid_sensor_read_raw_hyst_value(struct hid_ 266 int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, 260 int *v 267 int *val1, int *val2); 261 int hid_sensor_read_raw_hyst_rel_value(struct << 262 int *va << 263 int hid_sensor_write_samp_freq_value(struct hi 268 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, 264 int va 269 int val1, int val2); 265 int hid_sensor_read_samp_freq_value(struct hid 270 int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, 266 int *v 271 int *val1, int *val2); 267 272 268 int hid_sensor_get_usage_index(struct hid_sens 273 int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, 269 u32 report_id, 274 u32 report_id, int field_index, u32 usage_id); 270 275 271 int hid_sensor_format_scale(u32 usage_id, 276 int hid_sensor_format_scale(u32 usage_id, 272 struct hid_sensor_ 277 struct hid_sensor_hub_attribute_info *attr_info, 273 int *val0, int *va 278 int *val0, int *val1); 274 279 275 s32 hid_sensor_read_poll_value(struct hid_sens 280 s32 hid_sensor_read_poll_value(struct hid_sensor_common *st); 276 281 277 int64_t hid_sensor_convert_timestamp(struct hi 282 int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st, 278 int64_t r 283 int64_t raw_value); 279 bool hid_sensor_batch_mode_supported(struct hi 284 bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st); 280 int hid_sensor_set_report_latency(struct hid_s 285 int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency); 281 int hid_sensor_get_report_latency(struct hid_s 286 int hid_sensor_get_report_latency(struct hid_sensor_common *st); 282 287 283 #endif 288 #endif 284 289
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.