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