2 * HID driver for Stantum multitouch panels
4 * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr>
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)
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
19 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
20 MODULE_DESCRIPTION("Stantum HID multitouch panels");
21 MODULE_LICENSE("GPL");
26 __s32 x, y, z, w, h; /* x, y, pressure, width, height */
27 __u16 id; /* touch id */
28 bool valid; /* valid finger data, or just placeholder? */
29 bool first; /* first finger in the HID packet? */
30 bool activity; /* at least one active finger so far? */
33 static int stantum_input_mapping(struct hid_device *hdev, struct hid_input *hi,
34 struct hid_field *field, struct hid_usage *usage,
35 unsigned long **bit, int *max)
37 switch (usage->hid & HID_USAGE_PAGE) {
42 hid_map_usage(hi, usage, bit, max,
43 EV_ABS, ABS_MT_POSITION_X);
44 /* touchscreen emulation */
45 input_set_abs_params(hi->input, ABS_X,
46 field->logical_minimum,
47 field->logical_maximum, 0, 0);
50 hid_map_usage(hi, usage, bit, max,
51 EV_ABS, ABS_MT_POSITION_Y);
52 /* touchscreen emulation */
53 input_set_abs_params(hi->input, ABS_Y,
54 field->logical_minimum,
55 field->logical_maximum, 0, 0);
60 case HID_UP_DIGITIZER:
63 case HID_DG_CONFIDENCE:
64 case HID_DG_INPUTMODE:
65 case HID_DG_DEVICEINDEX:
66 case HID_DG_CONTACTCOUNT:
67 case HID_DG_CONTACTMAX:
70 case HID_DG_TIPSWITCH:
71 /* touchscreen emulation */
72 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
76 hid_map_usage(hi, usage, bit, max,
77 EV_ABS, ABS_MT_TOUCH_MAJOR);
80 hid_map_usage(hi, usage, bit, max,
81 EV_ABS, ABS_MT_TOUCH_MINOR);
82 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
85 case HID_DG_TIPPRESSURE:
86 hid_map_usage(hi, usage, bit, max,
87 EV_ABS, ABS_MT_PRESSURE);
90 case HID_DG_CONTACTID:
91 hid_map_usage(hi, usage, bit, max,
92 EV_ABS, ABS_MT_TRACKING_ID);
99 /* no input-oriented meaning */
106 static int stantum_input_mapped(struct hid_device *hdev, struct hid_input *hi,
107 struct hid_field *field, struct hid_usage *usage,
108 unsigned long **bit, int *max)
110 if (usage->type == EV_KEY || usage->type == EV_ABS)
111 clear_bit(usage->code, *bit);
117 * this function is called when a whole finger has been parsed,
118 * so that it can decide what to send to the input layer.
120 static void stantum_filter_event(struct stantum_data *sd,
121 struct input_dev *input)
127 * touchscreen emulation: if the first finger is not valid and
128 * there previously was finger activity, this is a release
130 if (sd->first && sd->activity) {
131 input_event(input, EV_KEY, BTN_TOUCH, 0);
132 sd->activity = false;
137 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, sd->id);
138 input_event(input, EV_ABS, ABS_MT_POSITION_X, sd->x);
139 input_event(input, EV_ABS, ABS_MT_POSITION_Y, sd->y);
141 wide = (sd->w > sd->h);
142 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
143 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, wide ? sd->w : sd->h);
144 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, wide ? sd->h : sd->w);
146 input_event(input, EV_ABS, ABS_MT_PRESSURE, sd->z);
148 input_mt_sync(input);
151 /* touchscreen emulation */
154 input_event(input, EV_KEY, BTN_TOUCH, 1);
157 input_event(input, EV_ABS, ABS_X, sd->x);
158 input_event(input, EV_ABS, ABS_Y, sd->y);
164 static int stantum_event(struct hid_device *hid, struct hid_field *field,
165 struct hid_usage *usage, __s32 value)
167 struct stantum_data *sd = hid_get_drvdata(hid);
169 if (hid->claimed & HID_CLAIMED_INPUT) {
170 struct input_dev *input = field->hidinput->input;
172 switch (usage->hid) {
174 /* this is the last field in a finger */
175 stantum_filter_event(sd, input);
189 case HID_DG_TIPPRESSURE:
192 case HID_DG_CONTACTID:
195 case HID_DG_CONFIDENCE:
199 /* this comes only before the first finger */
204 /* ignore the others */
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);
216 static int stantum_probe(struct hid_device *hdev,
217 const struct hid_device_id *id)
220 struct stantum_data *sd;
222 sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL);
224 dev_err(&hdev->dev, "cannot allocate Stantum data\n");
229 sd->activity = false;
230 hid_set_drvdata(hdev, sd);
232 ret = hid_parse(hdev);
234 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
242 static void stantum_remove(struct hid_device *hdev)
245 kfree(hid_get_drvdata(hdev));
246 hid_set_drvdata(hdev, NULL);
249 static const struct hid_device_id stantum_devices[] = {
250 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
253 MODULE_DEVICE_TABLE(hid, stantum_devices);
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}
260 static struct hid_driver stantum_driver = {
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,
271 static int __init stantum_init(void)
273 return hid_register_driver(&stantum_driver);
276 static void __exit stantum_exit(void)
278 hid_unregister_driver(&stantum_driver);
281 module_init(stantum_init);
282 module_exit(stantum_exit);