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 int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic, 73 struct input_dev *dev); 74 void hid_haptic_handle_press_release(struct hid_haptic_device *haptic); 75 void hid_haptic_pressure_reset(struct hid_haptic_device *haptic); 76 void hid_haptic_pressure_increase(struct hid_haptic_device *haptic, 77 __s32 pressure); 78 #else 79 static inline 80 void hid_haptic_feature_mapping(struct hid_device *hdev, 81 struct hid_haptic_device *haptic, 82 struct hid_field *field, struct hid_usage 83 *usage) 84 {} 85 static inline 86 bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, 87 struct hid_input *hi, struct hid_field *field) 88 { 89 return false; 90 } 91 static inline 92 int hid_haptic_input_mapping(struct hid_device *hdev, 93 struct hid_haptic_device *haptic, 94 struct hid_input *hi, 95 struct hid_field *field, struct hid_usage *usage, 96 unsigned long **bit, int *max) 97 { 98 return 0; 99 } 100 static inline 101 int hid_haptic_input_configured(struct hid_device *hdev, 102 struct hid_haptic_device *haptic, 103 struct hid_input *hi) 104 { 105 return 0; 106 } 107 static inline 108 void hid_haptic_reset(struct hid_device *hdev, struct hid_haptic_device *haptic) 109 {} 110 static inline 111 int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic, 112 struct input_dev *dev) 113 { 114 return 0; 115 } 116 static inline 117 void hid_haptic_handle_press_release(struct hid_haptic_device *haptic) {} 118 static inline 119 bool hid_haptic_handle_input(struct hid_haptic_device *haptic) 120 { 121 return false; 122 } 123 static inline 124 void hid_haptic_pressure_reset(struct hid_haptic_device *haptic) {} 125 static inline 126 void hid_haptic_pressure_increase(struct hid_haptic_device *haptic, 127 __s32 pressure) 128 {} 129 #endif 130