2 * HID driver for eGalax dual-touch panels
4 * Copyright (c) 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>
18 #include <linux/usb.h>
19 #include "usbhid/usbhid.h"
21 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
22 MODULE_DESCRIPTION("eGalax dual-touch panel");
23 MODULE_LICENSE("GPL");
30 bool first
; /* is this the first finger in the frame? */
31 bool valid
; /* valid finger data, or just placeholder? */
32 bool activity
; /* at least one active finger previously? */
33 __u16 lastx
, lasty
; /* latest valid (x, y) in the frame */
36 static int egalax_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
37 struct hid_field
*field
, struct hid_usage
*usage
,
38 unsigned long **bit
, int *max
)
40 switch (usage
->hid
& HID_USAGE_PAGE
) {
45 hid_map_usage(hi
, usage
, bit
, max
,
46 EV_ABS
, ABS_MT_POSITION_X
);
47 /* touchscreen emulation */
48 input_set_abs_params(hi
->input
, ABS_X
,
49 field
->logical_minimum
,
50 field
->logical_maximum
, 0, 0);
53 hid_map_usage(hi
, usage
, bit
, max
,
54 EV_ABS
, ABS_MT_POSITION_Y
);
55 /* touchscreen emulation */
56 input_set_abs_params(hi
->input
, ABS_Y
,
57 field
->logical_minimum
,
58 field
->logical_maximum
, 0, 0);
63 case HID_UP_DIGITIZER
:
65 case HID_DG_TIPSWITCH
:
66 /* touchscreen emulation */
67 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
70 case HID_DG_CONFIDENCE
:
71 case HID_DG_CONTACTCOUNT
:
72 case HID_DG_CONTACTMAX
:
74 case HID_DG_CONTACTID
:
75 hid_map_usage(hi
, usage
, bit
, max
,
76 EV_ABS
, ABS_MT_TRACKING_ID
);
78 case HID_DG_TIPPRESSURE
:
79 hid_map_usage(hi
, usage
, bit
, max
,
80 EV_ABS
, ABS_MT_PRESSURE
);
86 /* ignore others (from other reports we won't get anyway) */
90 static int egalax_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
91 struct hid_field
*field
, struct hid_usage
*usage
,
92 unsigned long **bit
, int *max
)
94 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
95 clear_bit(usage
->code
, *bit
);
101 * this function is called when a whole finger has been parsed,
102 * so that it can decide what to send to the input layer.
104 static void egalax_filter_event(struct egalax_data
*td
, struct input_dev
*input
)
106 td
->first
= !td
->first
; /* touchscreen emulation */
109 /* emit multitouch events */
110 input_event(input
, EV_ABS
, ABS_MT_TRACKING_ID
, td
->id
);
111 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, td
->x
);
112 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, td
->y
);
113 input_event(input
, EV_ABS
, ABS_MT_PRESSURE
, td
->z
);
115 input_mt_sync(input
);
118 * touchscreen emulation: store (x, y) as
119 * the last valid values in this frame
126 * touchscreen emulation: if this is the second finger and at least
127 * one in this frame is valid, the latest valid in the frame is
128 * the oldest on the panel, the one we want for single touch
130 if (!td
->first
&& td
->activity
) {
131 input_event(input
, EV_ABS
, ABS_X
, td
->lastx
);
132 input_event(input
, EV_ABS
, ABS_Y
, td
->lasty
);
137 * touchscreen emulation: if the first finger is invalid
138 * and there previously was finger activity, this is a release
140 if (td
->first
&& td
->activity
) {
141 input_event(input
, EV_KEY
, BTN_TOUCH
, 0);
142 td
->activity
= false;
148 /* touchscreen emulation: if no previous activity, emit touch event */
150 input_event(input
, EV_KEY
, BTN_TOUCH
, 1);
156 static int egalax_event(struct hid_device
*hid
, struct hid_field
*field
,
157 struct hid_usage
*usage
, __s32 value
)
159 struct egalax_data
*td
= hid_get_drvdata(hid
);
161 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
162 struct input_dev
*input
= field
->hidinput
->input
;
164 switch (usage
->hid
) {
166 case HID_DG_CONFIDENCE
:
167 /* avoid interference from generic hidinput handling */
169 case HID_DG_TIPSWITCH
:
172 case HID_DG_TIPPRESSURE
:
175 case HID_DG_CONTACTID
:
183 /* this is the last field in a finger */
184 egalax_filter_event(td
, input
);
186 case HID_DG_CONTACTCOUNT
:
187 /* touch emulation: this is the last field in a frame */
192 /* fallback to the generic hidinput handling */
197 /* we have handled the hidinput part, now remains hiddev */
198 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
199 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
204 static int egalax_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
207 struct egalax_data
*td
;
208 struct hid_report
*report
;
210 td
= kmalloc(sizeof(struct egalax_data
), GFP_KERNEL
);
212 dev_err(&hdev
->dev
, "cannot allocate eGalax data\n");
215 hid_set_drvdata(hdev
, td
);
217 ret
= hid_parse(hdev
);
221 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
225 report
= hdev
->report_enum
[HID_FEATURE_REPORT
].report_id_hash
[5];
227 report
->field
[0]->value
[0] = 2;
228 usbhid_submit_report(hdev
, report
, USB_DIR_OUT
);
238 static void egalax_remove(struct hid_device
*hdev
)
241 kfree(hid_get_drvdata(hdev
));
242 hid_set_drvdata(hdev
, NULL
);
245 static const struct hid_device_id egalax_devices
[] = {
246 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
247 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH
) },
250 MODULE_DEVICE_TABLE(hid
, egalax_devices
);
252 static const struct hid_usage_id egalax_grabbed_usages
[] = {
253 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
254 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
257 static struct hid_driver egalax_driver
= {
258 .name
= "egalax-touch",
259 .id_table
= egalax_devices
,
260 .probe
= egalax_probe
,
261 .remove
= egalax_remove
,
262 .input_mapping
= egalax_input_mapping
,
263 .input_mapped
= egalax_input_mapped
,
264 .usage_table
= egalax_grabbed_usages
,
265 .event
= egalax_event
,
268 static int __init
egalax_init(void)
270 return hid_register_driver(&egalax_driver
);
273 static void __exit
egalax_exit(void)
275 hid_unregister_driver(&egalax_driver
);
278 module_init(egalax_init
);
279 module_exit(egalax_exit
);