2 * HID driver for the multitouch panel on the ASUS EeePC T91MT
4 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010 Teemu Tuominen <teemu.tuominen@cybercom.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
16 #include <linux/device.h>
17 #include <linux/hid.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/usb.h>
21 #include "usbhid/usbhid.h"
23 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
24 MODULE_DESCRIPTION("MosArt dual-touch panel");
25 MODULE_LICENSE("GPL");
32 bool valid; /* valid finger data, or just placeholder? */
33 bool first; /* is this the first finger in this frame? */
34 bool activity_now; /* at least one active finger in this frame? */
35 bool activity; /* at least one active finger previously? */
38 static int mosart_input_mapping(struct hid_device *hdev, struct hid_input *hi,
39 struct hid_field *field, struct hid_usage *usage,
40 unsigned long **bit, int *max)
42 switch (usage->hid & HID_USAGE_PAGE) {
47 hid_map_usage(hi, usage, bit, max,
48 EV_ABS, ABS_MT_POSITION_X);
49 /* touchscreen emulation */
50 input_set_abs_params(hi->input, ABS_X,
51 field->logical_minimum,
52 field->logical_maximum, 0, 0);
55 hid_map_usage(hi, usage, bit, max,
56 EV_ABS, ABS_MT_POSITION_Y);
57 /* touchscreen emulation */
58 input_set_abs_params(hi->input, ABS_Y,
59 field->logical_minimum,
60 field->logical_maximum, 0, 0);
65 case HID_UP_DIGITIZER:
67 case HID_DG_CONFIDENCE:
68 case HID_DG_TIPSWITCH:
69 case HID_DG_INPUTMODE:
70 case HID_DG_DEVICEINDEX:
71 case HID_DG_CONTACTCOUNT:
72 case HID_DG_CONTACTMAX:
73 case HID_DG_TIPPRESSURE:
78 /* touchscreen emulation */
79 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
82 case HID_DG_CONTACTID:
83 hid_map_usage(hi, usage, bit, max,
84 EV_ABS, ABS_MT_TRACKING_ID);
91 /* ignore HID features */
102 static int mosart_input_mapped(struct hid_device *hdev, struct hid_input *hi,
103 struct hid_field *field, struct hid_usage *usage,
104 unsigned long **bit, int *max)
106 if (usage->type == EV_KEY || usage->type == EV_ABS)
107 clear_bit(usage->code, *bit);
113 * this function is called when a whole finger has been parsed,
114 * so that it can decide what to send to the input layer.
116 static void mosart_filter_event(struct mosart_data *td, struct input_dev *input)
118 td->first = !td->first; /* touchscreen emulation */
122 * touchscreen emulation: if no finger in this frame is valid
123 * and there previously was finger activity, this is a release
125 if (!td->first && !td->activity_now && td->activity) {
126 input_event(input, EV_KEY, BTN_TOUCH, 0);
127 td->activity = false;
132 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
133 input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
134 input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
136 input_mt_sync(input);
139 /* touchscreen emulation: if first active finger in this frame... */
140 if (!td->activity_now) {
141 /* if there was no previous activity, emit touch event */
143 input_event(input, EV_KEY, BTN_TOUCH, 1);
146 td->activity_now = true;
147 /* and in any case this is our preferred finger */
148 input_event(input, EV_ABS, ABS_X, td->x);
149 input_event(input, EV_ABS, ABS_Y, td->y);
154 static int mosart_event(struct hid_device *hid, struct hid_field *field,
155 struct hid_usage *usage, __s32 value)
157 struct mosart_data *td = hid_get_drvdata(hid);
159 if (hid->claimed & HID_CLAIMED_INPUT) {
160 struct input_dev *input = field->hidinput->input;
161 switch (usage->hid) {
170 mosart_filter_event(td, input);
172 case HID_DG_CONTACTID:
175 case HID_DG_CONTACTCOUNT:
176 /* touch emulation: this is the last field in a frame */
178 td->activity_now = false;
180 case HID_DG_CONFIDENCE:
181 case HID_DG_TIPSWITCH:
182 /* avoid interference from generic hidinput handling */
186 /* fallback to the generic hidinput handling */
191 /* we have handled the hidinput part, now remains hiddev */
192 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
193 hid->hiddev_hid_event(hid, field, usage, value);
198 static int mosart_probe(struct hid_device *hdev, const struct hid_device_id *id)
201 struct mosart_data *td;
204 td = kmalloc(sizeof(struct mosart_data), GFP_KERNEL);
206 hid_err(hdev, "cannot allocate MosArt data\n");
210 td->activity = false;
211 td->activity_now = false;
213 hid_set_drvdata(hdev, td);
215 /* currently, it's better to have one evdev device only */
217 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
220 ret = hid_parse(hdev);
222 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
225 struct hid_report_enum *re = hdev->report_enum
226 + HID_FEATURE_REPORT;
227 struct hid_report *r = re->report_id_hash[7];
229 r->field[0]->value[0] = 0x02;
230 usbhid_submit_report(hdev, r, USB_DIR_OUT);
238 static int mosart_reset_resume(struct hid_device *hdev)
240 struct hid_report_enum *re = hdev->report_enum
241 + HID_FEATURE_REPORT;
242 struct hid_report *r = re->report_id_hash[7];
244 r->field[0]->value[0] = 0x02;
245 usbhid_submit_report(hdev, r, USB_DIR_OUT);
250 static void mosart_remove(struct hid_device *hdev)
253 kfree(hid_get_drvdata(hdev));
254 hid_set_drvdata(hdev, NULL);
257 static const struct hid_device_id mosart_devices[] = {
258 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
259 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
260 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
263 MODULE_DEVICE_TABLE(hid, mosart_devices);
265 static const struct hid_usage_id mosart_grabbed_usages[] = {
266 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
267 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
270 static struct hid_driver mosart_driver = {
272 .id_table = mosart_devices,
273 .probe = mosart_probe,
274 .remove = mosart_remove,
275 .input_mapping = mosart_input_mapping,
276 .input_mapped = mosart_input_mapped,
277 .usage_table = mosart_grabbed_usages,
278 .event = mosart_event,
280 .reset_resume = mosart_reset_resume,
284 static int __init mosart_init(void)
286 return hid_register_driver(&mosart_driver);
289 static void __exit mosart_exit(void)
291 hid_unregister_driver(&mosart_driver);
294 module_init(mosart_init);
295 module_exit(mosart_exit);