Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
16struct 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
24struct hid_haptic_effect_node {
25 struct list_head node;
26 struct file *file;
27};
28
29struct 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)
58void hid_haptic_feature_mapping(struct hid_device *hdev,
59 struct hid_haptic_device *haptic,
60 struct hid_field *field, struct hid_usage
61 *usage);
62bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
63 struct hid_input *hi, struct hid_field *field);
64int 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);
69int hid_haptic_input_configured(struct hid_device *hdev,
70 struct hid_haptic_device *haptic,
71 struct hid_input *hi);
72int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_ptr);
73void hid_haptic_handle_press_release(struct hid_haptic_device *haptic);
74void hid_haptic_pressure_reset(struct hid_haptic_device *haptic);
75void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
76 __s32 pressure);
77#else
78static inline
79void 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{}
84static inline
85bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
86 struct hid_input *hi, struct hid_field *field)
87{
88 return false;
89}
90static inline
91int 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}
99static inline
100int hid_haptic_input_configured(struct hid_device *hdev,
101 struct hid_haptic_device *haptic,
102 struct hid_input *hi)
103{
104 return 0;
105}
106static inline
107void hid_haptic_reset(struct hid_device *hdev, struct hid_haptic_device *haptic)
108{}
109static inline
110int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_ptr)
111{
112 return 0;
113}
114static inline
115void hid_haptic_handle_press_release(struct hid_haptic_device *haptic) {}
116static inline
117bool hid_haptic_handle_input(struct hid_haptic_device *haptic)
118{
119 return false;
120}
121static inline
122void hid_haptic_pressure_reset(struct hid_haptic_device *haptic) {}
123static inline
124void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
125 __s32 pressure)
126{}
127#endif