diff options
author | Stephane Chatty <chatty@lii-enac.fr> | 2010-01-04 06:04:08 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2010-01-04 06:04:08 -0500 |
commit | d3fb5454a8474d5d22c8f8fe4d043b05732d91d5 (patch) | |
tree | 469fb34026a744b21a9eb4d72af3700ac5510d36 | |
parent | 4b186f72033611c2b526c7341534e71ee4afd222 (diff) |
HID: add support for Stantum multitouch panel
Added support for the Stantum multitouch panel.
Signed-off-by: Stephane Chatty <chatty@enac.fr>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/Kconfig | 6 | ||||
-rw-r--r-- | drivers/hid/Makefile | 1 | ||||
-rw-r--r-- | drivers/hid/hid-core.c | 1 | ||||
-rw-r--r-- | drivers/hid/hid-ids.h | 3 | ||||
-rw-r--r-- | drivers/hid/hid-stantum.c | 283 |
5 files changed, 294 insertions, 0 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 0c8ce3a68d27..84272c690310 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -247,6 +247,12 @@ config HID_SONY | |||
247 | ---help--- | 247 | ---help--- |
248 | Support for Sony PS3 controller. | 248 | Support for Sony PS3 controller. |
249 | 249 | ||
250 | config HID_STANTUM | ||
251 | tristate "Stantum" if EMBEDDED | ||
252 | depends on USB_HID | ||
253 | ---help--- | ||
254 | Support for Stantum multitouch panel. | ||
255 | |||
250 | config HID_SUNPLUS | 256 | config HID_SUNPLUS |
251 | tristate "Sunplus" if EMBEDDED | 257 | tristate "Sunplus" if EMBEDDED |
252 | depends on USB_HID | 258 | depends on USB_HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 1bdfb97910f1..f8dc5bac79bd 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o | |||
40 | obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o | 40 | obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o |
41 | obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o | 41 | obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o |
42 | obj-$(CONFIG_HID_SONY) += hid-sony.o | 42 | obj-$(CONFIG_HID_SONY) += hid-sony.o |
43 | obj-$(CONFIG_HID_STANTUM) += hid-stantum.o | ||
43 | obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o | 44 | obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o |
44 | obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o | 45 | obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o |
45 | obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o | 46 | obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o |
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 70c25a056205..6462c923805f 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -1339,6 +1339,7 @@ static const struct hid_device_id hid_blacklist[] = { | |||
1339 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, | 1339 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, |
1340 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, | 1340 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, |
1341 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, | 1341 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, |
1342 | { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) }, | ||
1342 | { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, | 1343 | { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, |
1343 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, | 1344 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, |
1344 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, | 1345 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 3d55f983dbaf..07e056b0e188 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
@@ -393,6 +393,9 @@ | |||
393 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034 | 393 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034 |
394 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046 | 394 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046 |
395 | 395 | ||
396 | #define USB_VENDOR_ID_STANTUM 0x1f87 | ||
397 | #define USB_DEVICE_ID_MTP 0x0002 | ||
398 | |||
396 | #define USB_VENDOR_ID_SUN 0x0430 | 399 | #define USB_VENDOR_ID_SUN 0x0430 |
397 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | 400 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab |
398 | 401 | ||
diff --git a/drivers/hid/hid-stantum.c b/drivers/hid/hid-stantum.c new file mode 100644 index 000000000000..add965dab932 --- /dev/null +++ b/drivers/hid/hid-stantum.c | |||
@@ -0,0 +1,283 @@ | |||
1 | /* | ||
2 | * HID driver for Stantum multitouch panels | ||
3 | * | ||
4 | * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr> | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the Free | ||
11 | * Software Foundation; either version 2 of the License, or (at your option) | ||
12 | * any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/device.h> | ||
16 | #include <linux/hid.h> | ||
17 | #include <linux/module.h> | ||
18 | |||
19 | MODULE_VERSION("0.6"); | ||
20 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); | ||
21 | MODULE_DESCRIPTION("Stantum HID multitouch panels"); | ||
22 | MODULE_LICENSE("GPL"); | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | struct stantum_data { | ||
27 | __s32 x, y, z, w, h; /* x, y, pressure, width, height */ | ||
28 | __u16 id; /* touch id */ | ||
29 | bool valid; /* valid finger data, or just placeholder? */ | ||
30 | bool first; /* first finger in the HID packet? */ | ||
31 | bool activity; /* at least one active finger so far? */ | ||
32 | }; | ||
33 | |||
34 | static int stantum_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
35 | struct hid_field *field, struct hid_usage *usage, | ||
36 | unsigned long **bit, int *max) | ||
37 | { | ||
38 | switch (usage->hid & HID_USAGE_PAGE) { | ||
39 | |||
40 | case HID_UP_GENDESK: | ||
41 | switch (usage->hid) { | ||
42 | case HID_GD_X: | ||
43 | hid_map_usage(hi, usage, bit, max, | ||
44 | EV_ABS, ABS_MT_POSITION_X); | ||
45 | /* touchscreen emulation */ | ||
46 | input_set_abs_params(hi->input, ABS_X, | ||
47 | field->logical_minimum, | ||
48 | field->logical_maximum, 0, 0); | ||
49 | return 1; | ||
50 | case HID_GD_Y: | ||
51 | hid_map_usage(hi, usage, bit, max, | ||
52 | EV_ABS, ABS_MT_POSITION_Y); | ||
53 | /* touchscreen emulation */ | ||
54 | input_set_abs_params(hi->input, ABS_Y, | ||
55 | field->logical_minimum, | ||
56 | field->logical_maximum, 0, 0); | ||
57 | return 1; | ||
58 | } | ||
59 | return 0; | ||
60 | |||
61 | case HID_UP_DIGITIZER: | ||
62 | switch (usage->hid) { | ||
63 | case HID_DG_INRANGE: | ||
64 | case HID_DG_CONFIDENCE: | ||
65 | case HID_DG_INPUTMODE: | ||
66 | case HID_DG_DEVICEINDEX: | ||
67 | case HID_DG_CONTACTCOUNT: | ||
68 | case HID_DG_CONTACTMAX: | ||
69 | case HID_DG_TIPPRESSURE: | ||
70 | return -1; | ||
71 | |||
72 | case HID_DG_TIPSWITCH: | ||
73 | /* touchscreen emulation */ | ||
74 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | ||
75 | return 1; | ||
76 | |||
77 | case HID_DG_WIDTH: | ||
78 | hid_map_usage(hi, usage, bit, max, | ||
79 | EV_ABS, ABS_MT_TOUCH_MAJOR); | ||
80 | return 1; | ||
81 | case HID_DG_HEIGHT: | ||
82 | hid_map_usage(hi, usage, bit, max, | ||
83 | EV_ABS, ABS_MT_TOUCH_MINOR); | ||
84 | input_set_abs_params(hi->input, ABS_MT_ORIENTATION, | ||
85 | 1, 1, 0, 0); | ||
86 | return 1; | ||
87 | case HID_DG_CONTACTID: | ||
88 | hid_map_usage(hi, usage, bit, max, | ||
89 | EV_ABS, ABS_MT_TRACKING_ID); | ||
90 | return 1; | ||
91 | |||
92 | } | ||
93 | return 0; | ||
94 | |||
95 | case 0xff000000: | ||
96 | /* no input-oriented meaning */ | ||
97 | return -1; | ||
98 | } | ||
99 | |||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | static int stantum_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
104 | struct hid_field *field, struct hid_usage *usage, | ||
105 | unsigned long **bit, int *max) | ||
106 | { | ||
107 | if (usage->type == EV_KEY || usage->type == EV_ABS) | ||
108 | clear_bit(usage->code, *bit); | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * this function is called when a whole finger has been parsed, | ||
115 | * so that it can decide what to send to the input layer. | ||
116 | */ | ||
117 | static void stantum_filter_event(struct stantum_data *sd, | ||
118 | struct input_dev *input) | ||
119 | { | ||
120 | bool wide; | ||
121 | |||
122 | if (!sd->valid) { | ||
123 | /* | ||
124 | * touchscreen emulation: if the first finger is not valid and | ||
125 | * there previously was finger activity, this is a release | ||
126 | */ | ||
127 | if (sd->first && sd->activity) { | ||
128 | input_event(input, EV_KEY, BTN_TOUCH, 0); | ||
129 | sd->activity = false; | ||
130 | } | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | input_event(input, EV_ABS, ABS_MT_TRACKING_ID, sd->id); | ||
135 | input_event(input, EV_ABS, ABS_MT_POSITION_X, sd->x); | ||
136 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, sd->y); | ||
137 | |||
138 | wide = (sd->w > sd->h); | ||
139 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); | ||
140 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, wide ? sd->w : sd->h); | ||
141 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, wide ? sd->h : sd->w); | ||
142 | |||
143 | #if 0 | ||
144 | /* MT_PRESSURE does not exist yet */ | ||
145 | input_event(input, EV_ABS, ABS_MT_PRESSURE, sd->z); | ||
146 | #endif | ||
147 | |||
148 | input_mt_sync(input); | ||
149 | sd->valid = false; | ||
150 | sd->first = false; | ||
151 | |||
152 | /* touchscreen emulation */ | ||
153 | if (sd->first) { | ||
154 | if (!sd->activity) { | ||
155 | input_event(input, EV_KEY, BTN_TOUCH, 1); | ||
156 | sd->activity = true; | ||
157 | } | ||
158 | input_event(input, EV_ABS, ABS_X, sd->x); | ||
159 | input_event(input, EV_ABS, ABS_Y, sd->y); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | |||
164 | static int stantum_event(struct hid_device *hid, struct hid_field *field, | ||
165 | struct hid_usage *usage, __s32 value) | ||
166 | { | ||
167 | struct stantum_data *sd = hid_get_drvdata(hid); | ||
168 | |||
169 | if (hid->claimed & HID_CLAIMED_INPUT) { | ||
170 | struct input_dev *input = field->hidinput->input; | ||
171 | |||
172 | switch (usage->hid) { | ||
173 | case HID_DG_INRANGE: | ||
174 | /* this is the last field in a finger */ | ||
175 | stantum_filter_event(sd, input); | ||
176 | break; | ||
177 | case HID_DG_WIDTH: | ||
178 | sd->w = value; | ||
179 | break; | ||
180 | case HID_DG_HEIGHT: | ||
181 | sd->h = value; | ||
182 | break; | ||
183 | case HID_GD_X: | ||
184 | sd->x = value; | ||
185 | break; | ||
186 | case HID_GD_Y: | ||
187 | sd->y = value; | ||
188 | break; | ||
189 | case HID_DG_TIPPRESSURE: | ||
190 | sd->z = value; | ||
191 | break; | ||
192 | case HID_DG_CONTACTID: | ||
193 | sd->id = value; | ||
194 | break; | ||
195 | case HID_DG_CONFIDENCE: | ||
196 | sd->valid = !!value; | ||
197 | break; | ||
198 | case 0xff000002: | ||
199 | /* this comes only before the first finger */ | ||
200 | sd->first = true; | ||
201 | break; | ||
202 | |||
203 | default: | ||
204 | /* ignore the others */ | ||
205 | return 1; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | /* we have handled the hidinput part, now remains hiddev */ | ||
210 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) | ||
211 | hid->hiddev_hid_event(hid, field, usage, value); | ||
212 | |||
213 | return 1; | ||
214 | } | ||
215 | |||
216 | static int stantum_probe(struct hid_device *hdev, | ||
217 | const struct hid_device_id *id) | ||
218 | { | ||
219 | int ret; | ||
220 | struct stantum_data *sd; | ||
221 | |||
222 | sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL); | ||
223 | if (!sd) { | ||
224 | dev_err(&hdev->dev, "cannot allocate Stantum data\n"); | ||
225 | return -ENOMEM; | ||
226 | } | ||
227 | sd->valid = false; | ||
228 | sd->first = false; | ||
229 | sd->activity = false; | ||
230 | hid_set_drvdata(hdev, sd); | ||
231 | |||
232 | ret = hid_parse(hdev); | ||
233 | if (!ret) | ||
234 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
235 | |||
236 | if (ret) | ||
237 | kfree(sd); | ||
238 | |||
239 | return ret; | ||
240 | } | ||
241 | |||
242 | static void stantum_remove(struct hid_device *hdev) | ||
243 | { | ||
244 | hid_hw_stop(hdev); | ||
245 | kfree(hid_get_drvdata(hdev)); | ||
246 | hid_set_drvdata(hdev, NULL); | ||
247 | } | ||
248 | |||
249 | static const struct hid_device_id stantum_devices[] = { | ||
250 | { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) }, | ||
251 | { } | ||
252 | }; | ||
253 | MODULE_DEVICE_TABLE(hid, stantum_devices); | ||
254 | |||
255 | static const struct hid_usage_id stantum_grabbed_usages[] = { | ||
256 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, | ||
257 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} | ||
258 | }; | ||
259 | |||
260 | static struct hid_driver stantum_driver = { | ||
261 | .name = "stantum", | ||
262 | .id_table = stantum_devices, | ||
263 | .probe = stantum_probe, | ||
264 | .remove = stantum_remove, | ||
265 | .input_mapping = stantum_input_mapping, | ||
266 | .input_mapped = stantum_input_mapped, | ||
267 | .usage_table = stantum_grabbed_usages, | ||
268 | .event = stantum_event, | ||
269 | }; | ||
270 | |||
271 | static int __init stantum_init(void) | ||
272 | { | ||
273 | return hid_register_driver(&stantum_driver); | ||
274 | } | ||
275 | |||
276 | static void __exit stantum_exit(void) | ||
277 | { | ||
278 | hid_unregister_driver(&stantum_driver); | ||
279 | } | ||
280 | |||
281 | module_init(stantum_init); | ||
282 | module_exit(stantum_exit); | ||
283 | |||