0001
0002
0003
0004
0005
0006 #ifndef _HID_SENSORS_HUB_H
0007 #define _HID_SENSORS_HUB_H
0008
0009 #include <linux/hid.h>
0010 #include <linux/hid-sensor-ids.h>
0011 #include <linux/iio/iio.h>
0012 #include <linux/iio/trigger.h>
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 struct hid_sensor_hub_attribute_info {
0027 u32 usage_id;
0028 u32 attrib_id;
0029 s32 report_id;
0030 s32 index;
0031 s32 units;
0032 s32 unit_expo;
0033 s32 size;
0034 s32 logical_minimum;
0035 s32 logical_maximum;
0036 };
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 struct sensor_hub_pending {
0048 bool status;
0049 struct completion ready;
0050 u32 usage_id;
0051 u32 attr_usage_id;
0052 int raw_size;
0053 u8 *raw_data;
0054 };
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 struct hid_sensor_hub_device {
0068 struct hid_device *hdev;
0069 u32 vendor_id;
0070 u32 product_id;
0071 u32 usage;
0072 int start_collection_index;
0073 int end_collection_index;
0074 struct mutex *mutex_ptr;
0075 struct sensor_hub_pending pending;
0076 };
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 struct hid_sensor_hub_callbacks {
0088 struct platform_device *pdev;
0089 int (*suspend)(struct hid_sensor_hub_device *hsdev, void *priv);
0090 int (*resume)(struct hid_sensor_hub_device *hsdev, void *priv);
0091 int (*capture_sample)(struct hid_sensor_hub_device *hsdev,
0092 u32 usage_id, size_t raw_len, char *raw_data,
0093 void *priv);
0094 int (*send_event)(struct hid_sensor_hub_device *hsdev, u32 usage_id,
0095 void *priv);
0096 };
0097
0098
0099
0100
0101
0102
0103
0104 int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev);
0105
0106
0107
0108
0109
0110
0111
0112 void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev);
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
0127 u32 usage_id,
0128 struct hid_sensor_hub_callbacks *usage_callback);
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
0139 u32 usage_id);
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
0156 u8 type,
0157 u32 usage_id, u32 attr_usage_id,
0158 struct hid_sensor_hub_attribute_info *info);
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 enum sensor_hub_read_flags {
0174 SENSOR_HUB_SYNC,
0175 SENSOR_HUB_ASYNC,
0176 };
0177
0178 int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
0179 u32 usage_id,
0180 u32 attr_usage_id, u32 report_id,
0181 enum sensor_hub_read_flags flag,
0182 bool is_signed
0183 );
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
0197 u32 field_index, int buffer_size, void *buffer);
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
0213 u32 field_index, int buffer_size, void *buffer);
0214
0215
0216
0217
0218 struct hid_sensor_common {
0219 struct hid_sensor_hub_device *hsdev;
0220 struct platform_device *pdev;
0221 unsigned usage_id;
0222 atomic_t data_ready;
0223 atomic_t user_requested_state;
0224 atomic_t runtime_pm_enable;
0225 int poll_interval;
0226 int raw_hystersis;
0227 int latency_ms;
0228 struct iio_trigger *trigger;
0229 int timestamp_ns_scale;
0230 struct hid_sensor_hub_attribute_info poll;
0231 struct hid_sensor_hub_attribute_info report_state;
0232 struct hid_sensor_hub_attribute_info power_state;
0233 struct hid_sensor_hub_attribute_info sensitivity;
0234 struct hid_sensor_hub_attribute_info sensitivity_rel;
0235 struct hid_sensor_hub_attribute_info report_latency;
0236 struct work_struct work;
0237 };
0238
0239
0240 static inline int hid_sensor_convert_exponent(int unit_expo)
0241 {
0242 if (unit_expo < 0x08)
0243 return unit_expo;
0244 else if (unit_expo <= 0x0f)
0245 return -(0x0f-unit_expo+1);
0246 else
0247 return 0;
0248 }
0249
0250 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
0251 u32 usage_id,
0252 struct hid_sensor_common *st,
0253 const u32 *sensitivity_addresses,
0254 u32 sensitivity_addresses_len);
0255 int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
0256 int val1, int val2);
0257 int hid_sensor_write_raw_hyst_rel_value(struct hid_sensor_common *st, int val1,
0258 int val2);
0259 int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
0260 int *val1, int *val2);
0261 int hid_sensor_read_raw_hyst_rel_value(struct hid_sensor_common *st,
0262 int *val1, int *val2);
0263 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
0264 int val1, int val2);
0265 int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
0266 int *val1, int *val2);
0267
0268 int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
0269 u32 report_id, int field_index, u32 usage_id);
0270
0271 int hid_sensor_format_scale(u32 usage_id,
0272 struct hid_sensor_hub_attribute_info *attr_info,
0273 int *val0, int *val1);
0274
0275 s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
0276
0277 int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st,
0278 int64_t raw_value);
0279 bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st);
0280 int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency);
0281 int hid_sensor_get_report_latency(struct hid_sensor_common *st);
0282
0283 #endif