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>
18 #include <linux/slab.h>
20 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
21 MODULE_DESCRIPTION("Stantum HID multitouch panels");
22 MODULE_LICENSE("GPL");
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? */
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
)
38 switch (usage
->hid
& HID_USAGE_PAGE
) {
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);
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);
61 case HID_UP_DIGITIZER
:
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
:
71 case HID_DG_TIPSWITCH
:
72 /* touchscreen emulation */
73 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
77 hid_map_usage(hi
, usage
, bit
, max
,
78 EV_ABS
, ABS_MT_TOUCH_MAJOR
);
81 hid_map_usage(hi
, usage
, bit
, max
,
82 EV_ABS
, ABS_MT_TOUCH_MINOR
);
83 input_set_abs_params(hi
->input
, ABS_MT_ORIENTATION
,
86 case HID_DG_TIPPRESSURE
:
87 hid_map_usage(hi
, usage
, bit
, max
,
88 EV_ABS
, ABS_MT_PRESSURE
);
91 case HID_DG_CONTACTID
:
92 hid_map_usage(hi
, usage
, bit
, max
,
93 EV_ABS
, ABS_MT_TRACKING_ID
);
100 /* no input-oriented meaning */
107 static int stantum_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
108 struct hid_field
*field
, struct hid_usage
*usage
,
109 unsigned long **bit
, int *max
)
111 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
112 clear_bit(usage
->code
, *bit
);
118 * this function is called when a whole finger has been parsed,
119 * so that it can decide what to send to the input layer.
121 static void stantum_filter_event(struct stantum_data
*sd
,
122 struct input_dev
*input
)
128 * touchscreen emulation: if the first finger is not valid and
129 * there previously was finger activity, this is a release
131 if (sd
->first
&& sd
->activity
) {
132 input_event(input
, EV_KEY
, BTN_TOUCH
, 0);
133 sd
->activity
= false;
138 input_event(input
, EV_ABS
, ABS_MT_TRACKING_ID
, sd
->id
);
139 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, sd
->x
);
140 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, sd
->y
);
142 wide
= (sd
->w
> sd
->h
);
143 input_event(input
, EV_ABS
, ABS_MT_ORIENTATION
, wide
);
144 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MAJOR
, wide
? sd
->w
: sd
->h
);
145 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MINOR
, wide
? sd
->h
: sd
->w
);
147 input_event(input
, EV_ABS
, ABS_MT_PRESSURE
, sd
->z
);
149 input_mt_sync(input
);
152 /* touchscreen emulation */
155 input_event(input
, EV_KEY
, BTN_TOUCH
, 1);
158 input_event(input
, EV_ABS
, ABS_X
, sd
->x
);
159 input_event(input
, EV_ABS
, ABS_Y
, sd
->y
);
165 static int stantum_event(struct hid_device
*hid
, struct hid_field
*field
,
166 struct hid_usage
*usage
, __s32 value
)
168 struct stantum_data
*sd
= hid_get_drvdata(hid
);
170 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
171 struct input_dev
*input
= field
->hidinput
->input
;
173 switch (usage
->hid
) {
175 /* this is the last field in a finger */
176 stantum_filter_event(sd
, input
);
190 case HID_DG_TIPPRESSURE
:
193 case HID_DG_CONTACTID
:
196 case HID_DG_CONFIDENCE
:
200 /* this comes only before the first finger */
205 /* ignore the others */
210 /* we have handled the hidinput part, now remains hiddev */
211 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
212 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
217 static int stantum_probe(struct hid_device
*hdev
,
218 const struct hid_device_id
*id
)
221 struct stantum_data
*sd
;
223 sd
= kmalloc(sizeof(struct stantum_data
), GFP_KERNEL
);
225 dev_err(&hdev
->dev
, "cannot allocate Stantum data\n");
230 sd
->activity
= false;
231 hid_set_drvdata(hdev
, sd
);
233 ret
= hid_parse(hdev
);
235 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
243 static void stantum_remove(struct hid_device
*hdev
)
246 kfree(hid_get_drvdata(hdev
));
247 hid_set_drvdata(hdev
, NULL
);
250 static const struct hid_device_id stantum_devices
[] = {
251 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM
, USB_DEVICE_ID_MTP
) },
252 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM
, USB_DEVICE_ID_MTP_STM
) },
253 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX
, USB_DEVICE_ID_MTP_SITRONIX
) },
256 MODULE_DEVICE_TABLE(hid
, stantum_devices
);
258 static const struct hid_usage_id stantum_grabbed_usages
[] = {
259 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
260 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
263 static struct hid_driver stantum_driver
= {
265 .id_table
= stantum_devices
,
266 .probe
= stantum_probe
,
267 .remove
= stantum_remove
,
268 .input_mapping
= stantum_input_mapping
,
269 .input_mapped
= stantum_input_mapped
,
270 .usage_table
= stantum_grabbed_usages
,
271 .event
= stantum_event
,
274 static int __init
stantum_init(void)
276 return hid_register_driver(&stantum_driver
);
279 static void __exit
stantum_exit(void)
281 hid_unregister_driver(&stantum_driver
);
284 module_init(stantum_init
);
285 module_exit(stantum_exit
);