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