Advertisement
Guest User

add_Quanta_touchscreen_hid_driver.patch

a guest
Mar 28th, 2012
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.32 KB | None | 0 0
  1. diff -rupN genesi-linux-legacy-39a8940//drivers/hid/hid-core.c genesi-linux-legacy-39a8940_mod//drivers/hid/hid-core.c
  2. --- genesi-linux-legacy-39a8940//drivers/hid/hid-core.c 2012-03-26 15:34:02.000000000 +0200
  3. +++ genesi-linux-legacy-39a8940_mod//drivers/hid/hid-core.c 2012-03-28 21:26:35.242150819 +0200
  4. @@ -1314,6 +1314,8 @@ static const struct hid_device_id hid_bl
  5.     { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
  6.     { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
  7.     { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  8. +        { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
  9. +        { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
  10.     { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  11.     { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  12.     { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
  13. diff -rupN genesi-linux-legacy-39a8940//drivers/hid/hid-ids.h genesi-linux-legacy-39a8940_mod//drivers/hid/hid-ids.h
  14. --- genesi-linux-legacy-39a8940//drivers/hid/hid-ids.h  2012-03-26 15:34:02.000000000 +0200
  15. +++ genesi-linux-legacy-39a8940_mod//drivers/hid/hid-ids.h  2012-03-28 21:13:25.062185586 +0200
  16. @@ -373,6 +373,10 @@
  17.  #define USB_VENDOR_ID_SAITEK       0x06a3
  18.  #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
  19.  
  20. +#define USB_VENDOR_ID_QUANTA            0x0408
  21. +#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH      0x3000
  22. +#define USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN   0x3001
  23. +
  24.  #define USB_VENDOR_ID_SAMSUNG      0x0419
  25.  #define USB_DEVICE_ID_SAMSUNG_IR_REMOTE    0x0001
  26.  
  27. diff -rupN genesi-linux-legacy-39a8940//drivers/hid/hid-quanta.c genesi-linux-legacy-39a8940_mod//drivers/hid/hid-quanta.c
  28. --- genesi-linux-legacy-39a8940//drivers/hid/hid-quanta.c   1970-01-01 01:00:00.000000000 +0100
  29. +++ genesi-linux-legacy-39a8940_mod//drivers/hid/hid-quanta.c   2012-03-28 21:23:26.566159121 +0200
  30. @@ -0,0 +1,260 @@
  31. + /*
  32. +  *  HID driver for Quanta Optical Touch dual-touch panels
  33. +  *
  34. +  *  Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
  35. +  *
  36. +  */
  37. +
  38. + /*
  39. +  * This program is free software; you can redistribute it and/or modify it
  40. +  * under the terms of the GNU General Public License as published by the Free
  41. +  * Software Foundation; either version 2 of the License, or (at your option)
  42. +  * any later version.
  43. +  */
  44. +
  45. + #include <linux/device.h>
  46. + #include <linux/hid.h>
  47. + #include <linux/module.h>
  48. + #include <linux/slab.h>
  49. +
  50. + MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
  51. + MODULE_DESCRIPTION("Quanta dual-touch panel");
  52. + MODULE_LICENSE("GPL");
  53. +
  54. + #include "hid-ids.h"
  55. +
  56. + struct quanta_data {
  57. +         __u16 x, y;
  58. +         __u8 id;
  59. +         bool valid;             /* valid finger data, or just placeholder? */
  60. +         bool first;             /* is this the first finger in this frame? */
  61. +         bool activity_now;      /* at least one active finger in this frame? */
  62. +         bool activity;          /* at least one active finger previously? */
  63. + };
  64. +
  65. + static int quanta_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  66. +                 struct hid_field *field, struct hid_usage *usage,
  67. +                 unsigned long **bit, int *max)
  68. + {
  69. +         switch (usage->hid & HID_USAGE_PAGE) {
  70. +
  71. +         case HID_UP_GENDESK:
  72. +                 switch (usage->hid) {
  73. +                 case HID_GD_X:
  74. +                         hid_map_usage(hi, usage, bit, max,
  75. +                                         EV_ABS, ABS_MT_POSITION_X);
  76. +                         /* touchscreen emulation */
  77. +                         input_set_abs_params(hi->input, ABS_X,
  78. +                                                 field->logical_minimum,
  79. +                                                 field->logical_maximum, 0, 0);
  80. +                         return 1;
  81. +                 case HID_GD_Y:
  82. +                         hid_map_usage(hi, usage, bit, max,
  83. +                                         EV_ABS, ABS_MT_POSITION_Y);
  84. +                         /* touchscreen emulation */
  85. +                         input_set_abs_params(hi->input, ABS_Y,
  86. +                                                 field->logical_minimum,
  87. +                                                 field->logical_maximum, 0, 0);
  88. +                         return 1;
  89. +                 }
  90. +                 return 0;
  91. +
  92. +         case HID_UP_DIGITIZER:
  93. +                 switch (usage->hid) {
  94. +                 case HID_DG_CONFIDENCE:
  95. +                 case HID_DG_TIPSWITCH:
  96. +                 case HID_DG_INPUTMODE:
  97. +                 case HID_DG_DEVICEINDEX:
  98. +                 case HID_DG_CONTACTCOUNT:
  99. +                 case HID_DG_CONTACTMAX:
  100. +                 case HID_DG_TIPPRESSURE:
  101. +                 case HID_DG_WIDTH:
  102. +                 case HID_DG_HEIGHT:
  103. +                         return -1;
  104. +                 case HID_DG_INRANGE:
  105. +                         /* touchscreen emulation */
  106. +                         hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
  107. +                         return 1;
  108. +                 case HID_DG_CONTACTID:
  109. +                         hid_map_usage(hi, usage, bit, max,
  110. +                                         EV_ABS, ABS_MT_TRACKING_ID);
  111. +                         return 1;
  112. +                 }
  113. +                 return 0;
  114. +
  115. +         case 0xff000000:
  116. +                 /* ignore vendor-specific features */
  117. +                 return -1;
  118. +         }
  119. +
  120. +         return 0;
  121. + }
  122. +
  123. + static int quanta_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  124. +                 struct hid_field *field, struct hid_usage *usage,
  125. +                 unsigned long **bit, int *max)
  126. + {
  127. +         if (usage->type == EV_KEY || usage->type == EV_ABS)
  128. +                 clear_bit(usage->code, *bit);
  129. +
  130. +         return 0;
  131. + }
  132. +
  133. + /*
  134. +  * this function is called when a whole finger has been parsed,
  135. +  * so that it can decide what to send to the input layer.
  136. +  */
  137. + static void quanta_filter_event(struct quanta_data *td, struct input_dev *input)
  138. + {
  139. +        
  140. +         td->first = !td->first; /* touchscreen emulation */
  141. +
  142. +         if (!td->valid) {
  143. +                 /*
  144. +                  * touchscreen emulation: if no finger in this frame is valid
  145. +                  * and there previously was finger activity, this is a release
  146. +                  */
  147. +                 if (!td->first && !td->activity_now && td->activity) {
  148. +                         input_event(input, EV_KEY, BTN_TOUCH, 0);
  149. +                         td->activity = false;
  150. +                 }
  151. +                 return;
  152. +         }
  153. +
  154. +         input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
  155. +         input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
  156. +         input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
  157. +
  158. +         input_mt_sync(input);
  159. +         td->valid = false;
  160. +
  161. +         /* touchscreen emulation: if first active finger in this frame... */
  162. +         if (!td->activity_now) {
  163. +                 /* if there was no previous activity, emit touch event */
  164. +                 if (!td->activity) {
  165. +                         input_event(input, EV_KEY, BTN_TOUCH, 1);
  166. +                         td->activity = true;
  167. +                 }
  168. +                 td->activity_now = true;
  169. +                 /* and in any case this is our preferred finger */
  170. +                 input_event(input, EV_ABS, ABS_X, td->x);
  171. +                 input_event(input, EV_ABS, ABS_Y, td->y);
  172. +         }
  173. + }
  174. +
  175. +
  176. + static int quanta_event(struct hid_device *hid, struct hid_field *field,
  177. +                                 struct hid_usage *usage, __s32 value)
  178. + {
  179. +         struct quanta_data *td = hid_get_drvdata(hid);
  180. +
  181. +         if (hid->claimed & HID_CLAIMED_INPUT) {
  182. +                 struct input_dev *input = field->hidinput->input;
  183. +
  184. +                 switch (usage->hid) {
  185. +                 case HID_DG_INRANGE:
  186. +                         td->valid = !!value;
  187. +                         break;
  188. +                 case HID_GD_X:
  189. +                         td->x = value;
  190. +                         break;
  191. +                 case HID_GD_Y:
  192. +                         td->y = value;
  193. +                         quanta_filter_event(td, input);
  194. +                         break;
  195. +                 case HID_DG_CONTACTID:
  196. +                         td->id = value;
  197. +                         break;
  198. +                 case HID_DG_CONTACTCOUNT:
  199. +                         /* touch emulation: this is the last field in a frame */
  200. +                         td->first = false;
  201. +                         td->activity_now = false;
  202. +                         break;
  203. +                 case HID_DG_CONFIDENCE:
  204. +                 case HID_DG_TIPSWITCH:
  205. +                         /* avoid interference from generic hidinput handling */
  206. +                         break;
  207. +
  208. +                 default:
  209. +                         /* fallback to the generic hidinput handling */
  210. +                         return 0;
  211. +                 }
  212. +         }
  213. +
  214. +         /* we have handled the hidinput part, now remains hiddev */
  215. +         if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
  216. +                 hid->hiddev_hid_event(hid, field, usage, value);
  217. +
  218. +         return 1;
  219. + }
  220. +
  221. + static int quanta_probe(struct hid_device *hdev, const struct hid_device_id *id)
  222. + {
  223. +         int ret;
  224. +         struct quanta_data *td;
  225. +
  226. +         td = kmalloc(sizeof(struct quanta_data), GFP_KERNEL);
  227. +         if (!td) {
  228. +                 dev_err(&hdev->dev, "cannot allocate Quanta Touch data\n");
  229. +                 return -ENOMEM;
  230. +         }
  231. +         td->valid = false;
  232. +         td->activity = false;
  233. +         td->activity_now = false;
  234. +         td->first = false;
  235. +         hid_set_drvdata(hdev, td);
  236. +
  237. +         ret = hid_parse(hdev);
  238. +         if (!ret)
  239. +                 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  240. +
  241. +         if (ret)
  242. +                 kfree(td);
  243. +
  244. +         return ret;
  245. + }
  246. +
  247. + static void quanta_remove(struct hid_device *hdev)
  248. + {
  249. +         hid_hw_stop(hdev);
  250. +         kfree(hid_get_drvdata(hdev));
  251. +         hid_set_drvdata(hdev, NULL);
  252. + }
  253. +
  254. + static const struct hid_device_id quanta_devices[] = {
  255. +         { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
  256. +                         USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
  257. +         { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
  258. +                         USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
  259. +         { }
  260. + };
  261. + MODULE_DEVICE_TABLE(hid, quanta_devices);
  262. +
  263. + static const struct hid_usage_id quanta_grabbed_usages[] = {
  264. +         { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  265. +         { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  266. + };
  267. +
  268. + static struct hid_driver quanta_driver = {
  269. +         .name = "quanta-touch",
  270. +         .id_table = quanta_devices,
  271. +         .probe = quanta_probe,
  272. +         .remove = quanta_remove,
  273. +         .input_mapping = quanta_input_mapping,
  274. +         .input_mapped = quanta_input_mapped,
  275. +         .usage_table = quanta_grabbed_usages,
  276. +         .event = quanta_event,
  277. + };
  278. +
  279. + static int __init quanta_init(void)
  280. + {
  281. +         return hid_register_driver(&quanta_driver);
  282. + }
  283. +
  284. + static void __exit quanta_exit(void)
  285. + {
  286. +         hid_unregister_driver(&quanta_driver);
  287. + }
  288. +
  289. + module_init(quanta_init);
  290. + module_exit(quanta_exit);
  291. diff -rupN genesi-linux-legacy-39a8940//drivers/hid/usbhid/hid-quirks.c genesi-linux-legacy-39a8940_mod//drivers/hid/usbhid/hid-quirks.c
  292. --- genesi-linux-legacy-39a8940//drivers/hid/usbhid/hid-quirks.c    2012-03-26 15:34:02.000000000 +0200
  293. +++ genesi-linux-legacy-39a8940_mod//drivers/hid/usbhid/hid-quirks.c    2012-03-28 21:28:52.410144785 +0200
  294. @@ -55,6 +55,7 @@ static const struct hid_blacklist {
  295.     { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_PRO_PEDALS, HID_QUIRK_NOGET },
  296.     { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
  297.     { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
  298. +   { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NOGET },
  299.     { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
  300.     { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
  301.     { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement