2 * HID driver for Quanta Optical Touch dual-touch panels
4 * Copyright (c) 2009-2010 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("Quanta dual-touch panel");
21 MODULE_LICENSE("GPL");
28 bool valid
; /* valid finger data, or just placeholder? */
29 bool first
; /* is this the first finger in this frame? */
30 bool activity_now
; /* at least one active finger in this frame? */
31 bool activity
; /* at least one active finger previously? */
34 static int quanta_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
:
63 case HID_DG_CONFIDENCE
:
64 case HID_DG_TIPSWITCH
:
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
:
74 /* touchscreen emulation */
75 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
77 case HID_DG_CONTACTID
:
78 hid_map_usage(hi
, usage
, bit
, max
,
79 EV_ABS
, ABS_MT_TRACKING_ID
);
85 /* ignore vendor-specific features */
92 static int quanta_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
93 struct hid_field
*field
, struct hid_usage
*usage
,
94 unsigned long **bit
, int *max
)
96 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
97 clear_bit(usage
->code
, *bit
);
103 * this function is called when a whole finger has been parsed,
104 * so that it can decide what to send to the input layer.
106 static void quanta_filter_event(struct quanta_data
*td
, struct input_dev
*input
)
109 td
->first
= !td
->first
; /* touchscreen emulation */
113 * touchscreen emulation: if no finger in this frame is valid
114 * and there previously was finger activity, this is a release
116 if (!td
->first
&& !td
->activity_now
&& td
->activity
) {
117 input_event(input
, EV_KEY
, BTN_TOUCH
, 0);
118 td
->activity
= false;
123 input_event(input
, EV_ABS
, ABS_MT_TRACKING_ID
, td
->id
);
124 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, td
->x
);
125 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, td
->y
);
127 input_mt_sync(input
);
130 /* touchscreen emulation: if first active finger in this frame... */
131 if (!td
->activity_now
) {
132 /* if there was no previous activity, emit touch event */
134 input_event(input
, EV_KEY
, BTN_TOUCH
, 1);
137 td
->activity_now
= true;
138 /* and in any case this is our preferred finger */
139 input_event(input
, EV_ABS
, ABS_X
, td
->x
);
140 input_event(input
, EV_ABS
, ABS_Y
, td
->y
);
145 static int quanta_event(struct hid_device
*hid
, struct hid_field
*field
,
146 struct hid_usage
*usage
, __s32 value
)
148 struct quanta_data
*td
= hid_get_drvdata(hid
);
150 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
151 struct input_dev
*input
= field
->hidinput
->input
;
153 switch (usage
->hid
) {
162 quanta_filter_event(td
, input
);
164 case HID_DG_CONTACTID
:
167 case HID_DG_CONTACTCOUNT
:
168 /* touch emulation: this is the last field in a frame */
170 td
->activity_now
= false;
172 case HID_DG_CONFIDENCE
:
173 case HID_DG_TIPSWITCH
:
174 /* avoid interference from generic hidinput handling */
178 /* fallback to the generic hidinput handling */
183 /* we have handled the hidinput part, now remains hiddev */
184 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
185 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
190 static int quanta_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
193 struct quanta_data
*td
;
195 td
= kmalloc(sizeof(struct quanta_data
), GFP_KERNEL
);
197 dev_err(&hdev
->dev
, "cannot allocate Quanta Touch data\n");
201 td
->activity
= false;
202 td
->activity_now
= false;
204 hid_set_drvdata(hdev
, td
);
206 ret
= hid_parse(hdev
);
208 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
216 static void quanta_remove(struct hid_device
*hdev
)
219 kfree(hid_get_drvdata(hdev
));
220 hid_set_drvdata(hdev
, NULL
);
223 static const struct hid_device_id quanta_devices
[] = {
224 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
225 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH
) },
226 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
227 USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN
) },
230 MODULE_DEVICE_TABLE(hid
, quanta_devices
);
232 static const struct hid_usage_id quanta_grabbed_usages
[] = {
233 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
234 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
237 static struct hid_driver quanta_driver
= {
238 .name
= "quanta-touch",
239 .id_table
= quanta_devices
,
240 .probe
= quanta_probe
,
241 .remove
= quanta_remove
,
242 .input_mapping
= quanta_input_mapping
,
243 .input_mapped
= quanta_input_mapped
,
244 .usage_table
= quanta_grabbed_usages
,
245 .event
= quanta_event
,
248 static int __init
quanta_init(void)
250 return hid_register_driver(&quanta_driver
);
253 static void __exit
quanta_exit(void)
255 hid_unregister_driver(&quanta_driver
);
258 module_init(quanta_init
);
259 module_exit(quanta_exit
);