|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | +/* |
| 3 | + * HID Haptic support for Linux |
| 4 | + * |
| 5 | + * Copyright (c) 2021 Angela Czubak <acz@semihalf.com> |
| 6 | + */ |
| 7 | + |
| 8 | +#include <linux/hid.h> |
| 9 | + |
| 10 | +#define HID_HAPTIC_ORDINAL_WAVEFORMNONE 1 |
| 11 | +#define HID_HAPTIC_ORDINAL_WAVEFORMSTOP 2 |
| 12 | + |
| 13 | +#define HID_HAPTIC_MODE_DEVICE 0 |
| 14 | +#define HID_HAPTIC_MODE_HOST 1 |
| 15 | + |
| 16 | +struct hid_haptic_effect { |
| 17 | + u8 *report_buf; |
| 18 | + struct input_dev *input_dev; |
| 19 | + struct work_struct work; |
| 20 | + struct list_head control; |
| 21 | + struct mutex control_mutex; |
| 22 | +}; |
| 23 | + |
| 24 | +struct hid_haptic_effect_node { |
| 25 | + struct list_head node; |
| 26 | + struct file *file; |
| 27 | +}; |
| 28 | + |
| 29 | +struct hid_haptic_device { |
| 30 | + struct input_dev *input_dev; |
| 31 | + struct hid_device *hdev; |
| 32 | + struct hid_report *auto_trigger_report; |
| 33 | + struct mutex auto_trigger_mutex; |
| 34 | + struct workqueue_struct *wq; |
| 35 | + struct hid_report *manual_trigger_report; |
| 36 | + struct mutex manual_trigger_mutex; |
| 37 | + size_t manual_trigger_report_len; |
| 38 | + int pressed_state; |
| 39 | + s32 pressure_sum; |
| 40 | + s32 force_logical_minimum; |
| 41 | + s32 force_physical_minimum; |
| 42 | + s32 force_resolution; |
| 43 | + u32 mode; |
| 44 | + u32 default_auto_trigger; |
| 45 | + u32 vendor_page; |
| 46 | + u32 vendor_id; |
| 47 | + u32 max_waveform_id; |
| 48 | + u32 max_duration_id; |
| 49 | + u16 *hid_usage_map; |
| 50 | + u32 *duration_map; |
| 51 | + u16 press_ordinal; |
| 52 | + u16 release_ordinal; |
| 53 | + struct hid_haptic_effect *effect; |
| 54 | + struct hid_haptic_effect stop_effect; |
| 55 | +}; |
| 56 | + |
| 57 | +#if IS_ENABLED(CONFIG_HID_HAPTIC) |
| 58 | +void hid_haptic_feature_mapping(struct hid_device *hdev, |
| 59 | + struct hid_haptic_device *haptic, |
| 60 | + struct hid_field *field, struct hid_usage |
| 61 | + *usage); |
| 62 | +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, |
| 63 | + struct hid_input *hi, struct hid_field *field); |
| 64 | +int hid_haptic_input_mapping(struct hid_device *hdev, |
| 65 | + struct hid_haptic_device *haptic, |
| 66 | + struct hid_input *hi, |
| 67 | + struct hid_field *field, struct hid_usage *usage, |
| 68 | + unsigned long **bit, int *max); |
| 69 | +int hid_haptic_input_configured(struct hid_device *hdev, |
| 70 | + struct hid_haptic_device *haptic, |
| 71 | + struct hid_input *hi); |
| 72 | +#else |
| 73 | +static inline |
| 74 | +void hid_haptic_feature_mapping(struct hid_device *hdev, |
| 75 | + struct hid_haptic_device *haptic, |
| 76 | + struct hid_field *field, struct hid_usage |
| 77 | + *usage) |
| 78 | +{} |
| 79 | +static inline |
| 80 | +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, |
| 81 | + struct hid_input *hi, struct hid_field *field) |
| 82 | +{ |
| 83 | + return false; |
| 84 | +} |
| 85 | +static inline |
| 86 | +int hid_haptic_input_mapping(struct hid_device *hdev, |
| 87 | + struct hid_haptic_device *haptic, |
| 88 | + struct hid_input *hi, |
| 89 | + struct hid_field *field, struct hid_usage *usage, |
| 90 | + unsigned long **bit, int *max) |
| 91 | +{ |
| 92 | + return 0; |
| 93 | +} |
| 94 | +static inline |
| 95 | +int hid_haptic_input_configured(struct hid_device *hdev, |
| 96 | + struct hid_haptic_device *haptic, |
| 97 | + struct hid_input *hi) |
| 98 | +{ |
| 99 | + return 0; |
| 100 | +} |
| 101 | +#endif |
0 commit comments