diff options
Diffstat (limited to 'usr/src/dkms_source_tree/hid-egalax.c')
| -rw-r--r-- | usr/src/dkms_source_tree/hid-egalax.c | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/usr/src/dkms_source_tree/hid-egalax.c b/usr/src/dkms_source_tree/hid-egalax.c new file mode 100644 index 0000000..61e6a80 --- /dev/null +++ b/usr/src/dkms_source_tree/hid-egalax.c | |||
| @@ -0,0 +1,292 @@ | |||
| 1 | /* | ||
| 2 | * HID driver for eGalax dual-touch panels | ||
| 3 | * | ||
| 4 | * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr> | ||
| 5 | * | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* | ||
| 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) | ||
| 12 | * any later version. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/device.h> | ||
| 16 | #include <linux/hid.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/usb.h> | ||
| 19 | #include <linux/slab.h> | ||
| 20 | |||
| 21 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); | ||
| 22 | MODULE_DESCRIPTION("eGalax dual-touch panel"); | ||
| 23 | MODULE_LICENSE("GPL"); | ||
| 24 | |||
| 25 | #include "hid-ids.h" | ||
| 26 | |||
| 27 | void usbhid_submit_report | ||
| 28 | (struct hid_device *hid, struct hid_report *report, unsigned char dir); | ||
| 29 | |||
| 30 | struct egalax_data { | ||
| 31 | __u16 x, y, z; | ||
| 32 | __u8 id; | ||
| 33 | bool first; /* is this the first finger in the frame? */ | ||
| 34 | bool valid; /* valid finger data, or just placeholder? */ | ||
| 35 | bool activity; /* at least one active finger previously? */ | ||
| 36 | __u16 lastx, lasty; /* latest valid (x, y) in the frame */ | ||
| 37 | }; | ||
| 38 | |||
| 39 | static int egalax_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
| 40 | struct hid_field *field, struct hid_usage *usage, | ||
| 41 | unsigned long **bit, int *max) | ||
| 42 | { | ||
| 43 | switch (usage->hid & HID_USAGE_PAGE) { | ||
| 44 | |||
| 45 | case HID_UP_GENDESK: | ||
| 46 | switch (usage->hid) { | ||
| 47 | case HID_GD_X: | ||
| 48 | hid_map_usage(hi, usage, bit, max, | ||
| 49 | EV_ABS, ABS_MT_POSITION_X); | ||
| 50 | /* touchscreen emulation */ | ||
| 51 | input_set_abs_params(hi->input, ABS_X, | ||
| 52 | field->logical_minimum, | ||
| 53 | field->logical_maximum, 0, 0); | ||
| 54 | return 1; | ||
| 55 | case HID_GD_Y: | ||
| 56 | hid_map_usage(hi, usage, bit, max, | ||
| 57 | EV_ABS, ABS_MT_POSITION_Y); | ||
| 58 | /* touchscreen emulation */ | ||
| 59 | input_set_abs_params(hi->input, ABS_Y, | ||
| 60 | field->logical_minimum, | ||
| 61 | field->logical_maximum, 0, 0); | ||
| 62 | return 1; | ||
| 63 | } | ||
| 64 | return 0; | ||
| 65 | |||
| 66 | case HID_UP_DIGITIZER: | ||
| 67 | switch (usage->hid) { | ||
| 68 | case HID_DG_TIPSWITCH: | ||
| 69 | /* touchscreen emulation */ | ||
| 70 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | ||
| 71 | return 1; | ||
| 72 | case HID_DG_INRANGE: | ||
| 73 | case HID_DG_CONFIDENCE: | ||
| 74 | case HID_DG_CONTACTCOUNT: | ||
| 75 | case HID_DG_CONTACTMAX: | ||
| 76 | return -1; | ||
| 77 | case HID_DG_CONTACTID: | ||
| 78 | hid_map_usage(hi, usage, bit, max, | ||
| 79 | EV_ABS, ABS_MT_TRACKING_ID); | ||
| 80 | return 1; | ||
| 81 | case HID_DG_TIPPRESSURE: | ||
| 82 | hid_map_usage(hi, usage, bit, max, | ||
| 83 | EV_ABS, ABS_MT_PRESSURE); | ||
| 84 | return 1; | ||
| 85 | } | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | /* ignore others (from other reports we won't get anyway) */ | ||
| 90 | return -1; | ||
| 91 | } | ||
| 92 | |||
| 93 | static int egalax_input_mapped(struct hid_device *hdev, struct hid_input *hi, | ||
| 94 | struct hid_field *field, struct hid_usage *usage, | ||
| 95 | unsigned long **bit, int *max) | ||
| 96 | { | ||
| 97 | if (usage->type == EV_KEY || usage->type == EV_ABS) | ||
| 98 | clear_bit(usage->code, *bit); | ||
| 99 | |||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * this function is called when a whole finger has been parsed, | ||
| 105 | * so that it can decide what to send to the input layer. | ||
| 106 | */ | ||
| 107 | static void egalax_filter_event(struct egalax_data *td, struct input_dev *input) | ||
| 108 | { | ||
| 109 | td->first = !td->first; /* touchscreen emulation */ | ||
| 110 | |||
| 111 | if (td->valid) { | ||
| 112 | /* emit multitouch events */ | ||
| 113 | input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id); | ||
| 114 | input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x); | ||
| 115 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y); | ||
| 116 | input_event(input, EV_ABS, ABS_MT_PRESSURE, td->z); | ||
| 117 | |||
| 118 | input_mt_sync(input); | ||
| 119 | |||
| 120 | /* | ||
| 121 | * touchscreen emulation: store (x, y) as | ||
| 122 | * the last valid values in this frame | ||
| 123 | */ | ||
| 124 | td->lastx = td->x; | ||
| 125 | td->lasty = td->y; | ||
| 126 | } | ||
| 127 | |||
| 128 | /* | ||
| 129 | * touchscreen emulation: if this is the second finger and at least | ||
| 130 | * one in this frame is valid, the latest valid in the frame is | ||
| 131 | * the oldest on the panel, the one we want for single touch | ||
| 132 | */ | ||
| 133 | if (!td->first && td->activity) { | ||
| 134 | input_event(input, EV_ABS, ABS_X, td->lastx); | ||
| 135 | input_event(input, EV_ABS, ABS_Y, td->lasty); | ||
| 136 | } | ||
| 137 | |||
| 138 | if (!td->valid) { | ||
| 139 | /* | ||
| 140 | * touchscreen emulation: if the first finger is invalid | ||
| 141 | * and there previously was finger activity, this is a release | ||
| 142 | */ | ||
| 143 | if (td->first && td->activity) { | ||
| 144 | input_event(input, EV_KEY, BTN_TOUCH, 0); | ||
| 145 | td->activity = false; | ||
| 146 | } | ||
| 147 | return; | ||
| 148 | } | ||
| 149 | |||
| 150 | |||
| 151 | /* touchscreen emulation: if no previous activity, emit touch event */ | ||
| 152 | if (!td->activity) { | ||
| 153 | input_event(input, EV_KEY, BTN_TOUCH, 1); | ||
| 154 | td->activity = true; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | |||
| 159 | static int egalax_event(struct hid_device *hid, struct hid_field *field, | ||
| 160 | struct hid_usage *usage, __s32 value) | ||
| 161 | { | ||
| 162 | struct egalax_data *td = hid_get_drvdata(hid); | ||
| 163 | |||
| 164 | /* Note, eGalax has two product lines: the first is resistive and | ||
| 165 | * uses a standard parallel multitouch protocol (product ID == | ||
| 166 | * 48xx). The second is capacitive and uses an unusual "serial" | ||
| 167 | * protocol with a different message for each multitouch finger | ||
| 168 | * (product ID == 72xx). We do not yet generate a correct event | ||
| 169 | * sequence for the capacitive/serial protocol. | ||
| 170 | */ | ||
| 171 | if (hid->claimed & HID_CLAIMED_INPUT) { | ||
| 172 | struct input_dev *input = field->hidinput->input; | ||
| 173 | |||
| 174 | switch (usage->hid) { | ||
| 175 | case HID_DG_INRANGE: | ||
| 176 | case HID_DG_CONFIDENCE: | ||
| 177 | /* avoid interference from generic hidinput handling */ | ||
| 178 | break; | ||
| 179 | case HID_DG_TIPSWITCH: | ||
| 180 | td->valid = value; | ||
| 181 | break; | ||
| 182 | case HID_DG_TIPPRESSURE: | ||
| 183 | td->z = value; | ||
| 184 | break; | ||
| 185 | case HID_DG_CONTACTID: | ||
| 186 | td->id = value; | ||
| 187 | break; | ||
| 188 | case HID_GD_X: | ||
| 189 | td->x = value; | ||
| 190 | break; | ||
| 191 | case HID_GD_Y: | ||
| 192 | td->y = value; | ||
| 193 | /* this is the last field in a finger */ | ||
| 194 | egalax_filter_event(td, input); | ||
| 195 | break; | ||
| 196 | case HID_DG_CONTACTCOUNT: | ||
| 197 | /* touch emulation: this is the last field in a frame */ | ||
| 198 | td->first = false; | ||
| 199 | break; | ||
| 200 | |||
| 201 | default: | ||
| 202 | /* fallback to the generic hidinput handling */ | ||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | /* we have handled the hidinput part, now remains hiddev */ | ||
| 208 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) | ||
| 209 | hid->hiddev_hid_event(hid, field, usage, value); | ||
| 210 | |||
| 211 | return 1; | ||
| 212 | } | ||
| 213 | |||
| 214 | static int egalax_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
| 215 | { | ||
| 216 | int ret; | ||
| 217 | struct egalax_data *td; | ||
| 218 | struct hid_report *report; | ||
| 219 | |||
| 220 | td = kmalloc(sizeof(struct egalax_data), GFP_KERNEL); | ||
| 221 | if (!td) { | ||
| 222 | dev_err(&hdev->dev, "cannot allocate eGalax data\n"); | ||
| 223 | return -ENOMEM; | ||
| 224 | } | ||
| 225 | hid_set_drvdata(hdev, td); | ||
| 226 | |||
| 227 | ret = hid_parse(hdev); | ||
| 228 | if (ret) | ||
| 229 | goto end; | ||
| 230 | |||
| 231 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
| 232 | if (ret) | ||
| 233 | goto end; | ||
| 234 | |||
| 235 | report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[5]; | ||
| 236 | if (report) { | ||
| 237 | report->field[0]->value[0] = 2; | ||
| 238 | usbhid_submit_report(hdev, report, USB_DIR_OUT); | ||
| 239 | } | ||
| 240 | |||
| 241 | end: | ||
| 242 | if (ret) | ||
| 243 | kfree(td); | ||
| 244 | |||
| 245 | return ret; | ||
| 246 | } | ||
| 247 | |||
| 248 | static void egalax_remove(struct hid_device *hdev) | ||
| 249 | { | ||
| 250 | hid_hw_stop(hdev); | ||
| 251 | kfree(hid_get_drvdata(hdev)); | ||
| 252 | hid_set_drvdata(hdev, NULL); | ||
| 253 | } | ||
| 254 | |||
| 255 | static const struct hid_device_id egalax_devices[] = { | ||
| 256 | { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | ||
| 257 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, | ||
| 258 | { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | ||
| 259 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, | ||
| 260 | { } | ||
| 261 | }; | ||
| 262 | MODULE_DEVICE_TABLE(hid, egalax_devices); | ||
| 263 | |||
| 264 | static const struct hid_usage_id egalax_grabbed_usages[] = { | ||
| 265 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, | ||
| 266 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} | ||
| 267 | }; | ||
| 268 | |||
| 269 | static struct hid_driver egalax_driver = { | ||
| 270 | .name = "egalax-touch", | ||
| 271 | .id_table = egalax_devices, | ||
| 272 | .probe = egalax_probe, | ||
| 273 | .remove = egalax_remove, | ||
| 274 | .input_mapping = egalax_input_mapping, | ||
| 275 | .input_mapped = egalax_input_mapped, | ||
| 276 | .usage_table = egalax_grabbed_usages, | ||
| 277 | .event = egalax_event, | ||
| 278 | }; | ||
| 279 | |||
| 280 | static int __init egalax_init(void) | ||
| 281 | { | ||
| 282 | return hid_register_driver(&egalax_driver); | ||
| 283 | } | ||
| 284 | |||
| 285 | static void __exit egalax_exit(void) | ||
| 286 | { | ||
| 287 | hid_unregister_driver(&egalax_driver); | ||
| 288 | } | ||
| 289 | |||
| 290 | module_init(egalax_init); | ||
| 291 | module_exit(egalax_exit); | ||
| 292 | |||
