si_mdt_inputdev.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*
  2. SiI8348 Linux Driver
  3. Copyright (C) 2013 Silicon Image, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation version 2.
  7. This program is distributed AS-IS WITHOUT ANY WARRANTY of any
  8. kind, whether express or implied; INCLUDING without the implied warranty
  9. of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE or NON-INFRINGEMENT. See
  10. the GNU General Public License for more details at http://www.gnu.org/licenses/gpl-2.0.html.
  11. */
  12. /**
  13. @file si_mdt_inputdev.c
  14. */
  15. #include "sii_hal.h"
  16. #ifdef MEDIA_DATA_TUNNEL_SUPPORT
  17. #include <linux/input.h>
  18. #include <linux/cdev.h>
  19. #include <linux/hrtimer.h>
  20. #include "si_fw_macros.h"
  21. #include "si_mhl_defs.h"
  22. #include "si_infoframe.h"
  23. #include "si_edid.h"
  24. #include "si_mhl2_edid_3d_api.h"
  25. #include "si_mhl_tx_hw_drv_api.h"
  26. #include "si_mdt_inputdev.h"
  27. #include "mhl_linux_tx.h"
  28. #include "platform.h"
  29. #ifdef KERNEL_2_6_38_AND_LATER
  30. #include <linux/input/mt.h>
  31. #endif
  32. #include <linux/kernel.h>
  33. /* keycode map from usbkbd.c */
  34. uint8_t usb_kbd_keycode[256] = {
  35. 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
  36. 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
  37. 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
  38. 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
  39. 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
  40. 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
  41. 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
  42. 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
  43. 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
  44. 122,123, 90, 91, 85, 0, 0, 0, 0, 0,150,155, 0, 0, 0, 0,
  45. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  46. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  47. 200,201,207,208,213,215,216,217,226,139,172, 0, 0, 0, 0, 0,
  48. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  49. 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
  50. 150,158,159,128,136,177,178,176,142,152,173,140
  51. };
  52. // Local, helper functions
  53. static bool is_mdt_dev_active(struct mhl_dev_context *dev_context, enum mdt_dev_types_e dev_type) {
  54. if (dev_context->mdt_devs.is_dev_registered[dev_type]==INPUT_ACTIVE)
  55. return true;
  56. else
  57. return false;
  58. }
  59. static bool is_mdt_dev_waiting(struct mhl_dev_context *dev_context, enum mdt_dev_types_e dev_type) {
  60. if (dev_context->mdt_devs.is_dev_registered[dev_type]==INPUT_WAITING_FOR_REGISTRATION)
  61. return true;
  62. else
  63. return false;
  64. }
  65. static void destroy_mouse(struct mhl_dev_context *dev_context)
  66. {
  67. if (dev_context->mdt_devs.dev_mouse == NULL)
  68. return;
  69. MHL_TX_DBG_INFO(dev_context, "Unregistering mouse: %p\n",dev_context->mdt_devs.dev_mouse);
  70. input_unregister_device(dev_context->mdt_devs.dev_mouse);
  71. MHL_TX_DBG_INFO(dev_context, "Freeing mouse: %p\n",dev_context->mdt_devs.dev_mouse);
  72. input_free_device(dev_context->mdt_devs.dev_mouse);
  73. dev_context->mdt_devs.dev_mouse = NULL;
  74. }
  75. static void destroy_keyboard(struct mhl_dev_context *dev_context)
  76. {
  77. if (dev_context->mdt_devs.dev_keyboard == NULL)
  78. return;
  79. MHL_TX_DBG_INFO(dev_context, "Unregistering keyboard: %p\n",dev_context->mdt_devs.dev_keyboard);
  80. input_unregister_device(dev_context->mdt_devs.dev_keyboard);
  81. MHL_TX_DBG_INFO(dev_context, "Freeing keyboard: %p\n",dev_context->mdt_devs.dev_keyboard);
  82. input_free_device(dev_context->mdt_devs.dev_keyboard);
  83. dev_context->mdt_devs.dev_keyboard = NULL;
  84. }
  85. static void destroy_touchscreen(struct mhl_dev_context *dev_context)
  86. {
  87. if (dev_context->mdt_devs.dev_touchscreen == NULL)
  88. return;
  89. MHL_TX_DBG_INFO(dev_context, "Unregistering mouse: %p\n",dev_context->mdt_devs.dev_touchscreen);
  90. input_unregister_device(dev_context->mdt_devs.dev_touchscreen);
  91. MHL_TX_DBG_INFO(dev_context, "Freeing mouse: %p\n",dev_context->mdt_devs.dev_touchscreen);
  92. input_free_device(dev_context->mdt_devs.dev_touchscreen);
  93. dev_context->mdt_devs.dev_touchscreen = NULL;
  94. memset(dev_context->mdt_devs.prior_touch_events, 0,
  95. MAX_TOUCH_CONTACTS * sizeof(dev_context->mdt_devs.prior_touch_events[0]));
  96. }
  97. int init_mdt_keyboard(struct mhl_dev_context *dev_context)
  98. {
  99. int i;
  100. uint8_t error;
  101. struct input_dev *dev_keyboard;
  102. dev_keyboard = input_allocate_device();
  103. if (!dev_keyboard) {
  104. MHL_TX_DBG_ERR(dev_context, "Not enough memory\n");
  105. return -ENOMEM;
  106. }
  107. MHL_TX_DBG_INFO(dev_context, "Allocated keyboard: %p\n",dev_keyboard);
  108. set_bit(EV_KEY, dev_keyboard->evbit);
  109. set_bit(EV_REP, dev_keyboard->evbit);
  110. dev_keyboard->phys = "mdt_kbd/input0";
  111. dev_keyboard->name = "MDTkeyboard";
  112. dev_keyboard->keycode = usb_kbd_keycode;
  113. dev_keyboard->keycodesize= sizeof(unsigned char);
  114. dev_keyboard->keycodemax = ARRAY_SIZE(usb_kbd_keycode);
  115. for (i = 1; i < 256; i++)
  116. set_bit(usb_kbd_keycode[i], dev_keyboard->keybit);
  117. dev_keyboard->id.bustype = BUS_VIRTUAL;
  118. dev_keyboard->id.vendor = 0x1095;
  119. dev_keyboard->id.product = MHL_PRODUCT_NUM;
  120. /* Use version to distinguish between devices */
  121. dev_keyboard->id.version = 0xA;
  122. error = input_register_device(dev_keyboard);
  123. if (error) {
  124. MHL_TX_DBG_ERR(dev_context, "Failed to register device\n");
  125. input_free_device(dev_keyboard);
  126. return error;
  127. }
  128. MHL_TX_DBG_INFO(dev_context, "Registered keyboard: %p\n",dev_keyboard);
  129. dev_context->mdt_devs.dev_keyboard = dev_keyboard;
  130. return 0;
  131. }
  132. int init_mdt_mouse(struct mhl_dev_context *dev_context)
  133. {
  134. uint8_t error;
  135. struct input_dev *dev_mouse;
  136. dev_mouse = input_allocate_device();
  137. if (!dev_mouse) {
  138. MHL_TX_DBG_ERR(dev_context, "Not enough memory\n");
  139. return -ENOMEM;
  140. }
  141. MHL_TX_DBG_INFO(dev_context, "Allocated mouse: %p\n",dev_mouse);
  142. set_bit(EV_REL, dev_mouse->evbit);
  143. set_bit(EV_KEY, dev_mouse->evbit);
  144. set_bit(BTN_LEFT, dev_mouse->keybit);
  145. set_bit(BTN_RIGHT, dev_mouse->keybit);
  146. set_bit(BTN_MIDDLE, dev_mouse->keybit);
  147. set_bit(BTN_SIDE, dev_mouse->keybit);
  148. set_bit(BTN_EXTRA, dev_mouse->keybit);
  149. set_bit(REL_X, dev_mouse->relbit);
  150. set_bit(REL_Y, dev_mouse->relbit);
  151. set_bit(REL_WHEEL, dev_mouse->relbit);
  152. #if (RIGHT_MOUSE_BUTTON_IS_ESC == 1)
  153. set_bit(KEY_ESC, dev_mouse->keybit);
  154. dev_context->mdt_devs.prior_right_button = 0;
  155. #endif
  156. dev_mouse->phys = "mdt_mouse/input0";
  157. dev_mouse->name = "MDTmouse";
  158. dev_mouse->id.bustype = BUS_VIRTUAL;
  159. dev_mouse->id.vendor = 0x1095;
  160. dev_mouse->id.product = MHL_PRODUCT_NUM;
  161. /* Use version to distinguish between devices */
  162. dev_mouse->id.version = 0xB;
  163. error = input_register_device(dev_mouse);
  164. if (error) {
  165. MHL_TX_DBG_ERR(dev_context, "Failed to register device\n");
  166. input_free_device(dev_mouse);
  167. return error;
  168. }
  169. MHL_TX_DBG_INFO(dev_context, "Registered mouse: %p\n",dev_mouse);
  170. dev_context->mdt_devs.dev_mouse = dev_mouse;
  171. return 0;
  172. }
  173. int init_mdt_touchscreen(struct mhl_dev_context *dev_context)
  174. {
  175. uint8_t error;
  176. struct input_dev *dev_touchscreen;
  177. dev_touchscreen = input_allocate_device();
  178. if (!dev_touchscreen) {
  179. MHL_TX_DBG_ERR(dev_context, "Not enough memory\n");
  180. return -ENOMEM;
  181. }
  182. MHL_TX_DBG_INFO(dev_context, "Allocated touch screen: %p\n",dev_touchscreen);
  183. #if !defined(SINGLE_TOUCH) && defined(KERNEL_2_6_38_AND_LATER)
  184. input_mt_init_slots (dev_touchscreen, MAX_TOUCH_CONTACTS);
  185. #endif
  186. dev_touchscreen->phys = "mdt_touch/input0";
  187. dev_touchscreen->name = "MDTtouchscreen";
  188. dev_touchscreen->id.bustype = BUS_VIRTUAL;
  189. dev_touchscreen->id.vendor = 0x1095;
  190. dev_touchscreen->id.product = MHL_PRODUCT_NUM;
  191. /* use version to distinguish between devices */
  192. dev_touchscreen->id.version = 0xC;
  193. #if defined(SINGLE_TOUCH)
  194. __set_bit(EV_ABS, dev_touchscreen->evbit);
  195. __set_bit(ABS_X, dev_touchscreen->absbit);
  196. __set_bit(ABS_Y, dev_touchscreen->absbit);
  197. __set_bit(EV_KEY, dev_touchscreen->evbit);
  198. #if (CORNER_BUTTON == 1)
  199. __set_bit(KEY_ESC, dev_touchscreen->keybit);
  200. #endif
  201. __set_bit(BTN_TOUCH, dev_touchscreen->keybit);
  202. #ifdef KERNEL_2_6_38_AND_LATER
  203. __set_bit(INPUT_PROP_DIRECT, dev_touchscreen->propbit);
  204. #endif
  205. input_set_abs_params( dev_touchscreen, ABS_X, 0, dev_context->mdt_devs.x_max, 0, 0);
  206. input_set_abs_params( dev_touchscreen, ABS_Y, 0, dev_context->mdt_devs.y_max, 0, 0);
  207. #else
  208. __set_bit(EV_ABS, dev_touchscreen->evbit);
  209. __set_bit(EV_KEY, dev_touchscreen->evbit);
  210. #ifdef KERNEL_2_6_38_AND_LATER
  211. __set_bit(EV_SYN, dev_touchscreen->evbit);
  212. __set_bit(MT_TOOL_FINGER, dev_touchscreen->keybit);
  213. __set_bit(INPUT_PROP_DIRECT,dev_touchscreen->propbit);
  214. input_mt_init_slots (dev_touchscreen, MAX_TOUCH_CONTACTS);
  215. #else
  216. __set_bit(BTN_TOUCH, dev_touchscreen->keybit);
  217. input_set_abs_params( dev_touchscreen, ABS_MT_WIDTH_MAJOR, 0, 3, 0, 0);
  218. input_set_abs_params( dev_touchscreen, ABS_MT_TRACKING_ID, 0, 3, 0, 0);
  219. #endif
  220. #if (CORNER_BUTTON == 1)
  221. __set_bit(KEY_ESC, dev_touchscreen->keybit);
  222. #endif
  223. input_set_abs_params( dev_touchscreen, ABS_MT_TOUCH_MAJOR, 0, 30, 0, 0);
  224. input_set_abs_params( dev_touchscreen, ABS_MT_PRESSURE, 0, 255, 0, 0);
  225. input_set_abs_params( dev_touchscreen, ABS_MT_POSITION_X, 0, dev_context->mdt_devs.x_max, 0, 0);
  226. input_set_abs_params( dev_touchscreen, ABS_MT_POSITION_Y, 0, dev_context->mdt_devs.y_max, 0, 0);
  227. #endif
  228. #if (JB_421 == 1) && (ICS_BAR == 1)
  229. #if (Y_BUTTON_RECENTAPPS_TOP != 0)
  230. __set_bit(KEY_MENU, dev_touchscreen->keybit);
  231. #endif
  232. #if (Y_BUTTON_HOME_TOP != 0)
  233. __set_bit(KEY_HOMEPAGE, dev_touchscreen->keybit);
  234. #endif
  235. #if (Y_BUTTON_BACK_TOP != 0)
  236. __set_bit(KEY_BACK, dev_touchscreen->keybit);
  237. #endif
  238. #endif
  239. error = input_register_device(dev_touchscreen);
  240. if (error) {
  241. MHL_TX_DBG_ERR(dev_context, "Failed to register device\n");
  242. input_free_device(dev_touchscreen);
  243. return error;
  244. }
  245. MHL_TX_DBG_INFO(dev_context, "Registered touchscreen: %p\n",dev_touchscreen);
  246. dev_context->mdt_devs.dev_touchscreen = dev_touchscreen;
  247. /* initialize history; in parcitular initialize state elements with MDT_TOUCH_INACTIVE */
  248. memset(dev_context->mdt_devs.prior_touch_events, 0, MAX_TOUCH_CONTACTS * sizeof(dev_context->mdt_devs.prior_touch_events[0]));
  249. return 0;
  250. }
  251. static int destroy_device(struct mhl_dev_context *dev_context, enum mdt_dev_types_e mdt_device_type)
  252. {
  253. if ((mdt_device_type >= MDT_TYPE_COUNT) ||
  254. (is_mdt_dev_active(dev_context, mdt_device_type) == 0)) {
  255. MHL_TX_DBG_INFO(dev_context, "FAILURE. Invalid disconnect request. mdt_device_type=0x%x\n", mdt_device_type);
  256. return REGISTRATION_ERROR;
  257. }
  258. switch (mdt_device_type) {
  259. case MDT_TYPE_MOUSE:
  260. destroy_mouse(dev_context);
  261. break;
  262. case MDT_TYPE_KEYBOARD:
  263. destroy_keyboard(dev_context);
  264. break;
  265. case MDT_TYPE_TOUCHSCREEN:
  266. destroy_touchscreen(dev_context);
  267. break;
  268. #if 0
  269. case MDT_TYPE_GAME:
  270. if (!cancel_delayed_work( &(dev_context->mdt_devs.repeat_for_gamepad) ))
  271. flush_workqueue(dev_context->mdt_devs.mdt_joystick_wq);
  272. /* deregister only if not shared */
  273. if (is_mdt_dev_active(dev_context, MDT_TYPE_MOUSE) == 0)
  274. destroy_mouse(dev_context);
  275. if (is_mdt_dev_active(dev_context, MDT_TYPE_KEYBOARD) == 0)
  276. destroy_keyboard(dev_context);
  277. break;
  278. #endif
  279. case MDT_TYPE_COUNT:
  280. /*
  281. * This case is out of range.
  282. * Code is included to avoid compiler warning.
  283. */
  284. break;
  285. }
  286. dev_context->mdt_devs.is_dev_registered[mdt_device_type] = INPUT_WAITING_FOR_REGISTRATION;
  287. MHL_TX_DBG_INFO(dev_context, "SUCCESS. Disconnect event handled for %d device type.\n", mdt_device_type);
  288. return REGISTRATION_SUCCESS;
  289. }
  290. // The recursive piece of the registeration function.
  291. static int registration_helper(struct mhl_dev_context *dev_context, enum mdt_dev_types_e mdt_device_type)
  292. {
  293. switch (mdt_device_type) {
  294. case MDT_TYPE_KEYBOARD:
  295. if (dev_context->mdt_devs.dev_keyboard != 0)
  296. return REGISTRATION_SUCCESS;
  297. return init_mdt_keyboard(dev_context);
  298. break;
  299. case MDT_TYPE_MOUSE:
  300. if (dev_context->mdt_devs.dev_mouse != 0 )
  301. return REGISTRATION_SUCCESS;
  302. if (init_mdt_mouse(dev_context) != REGISTRATION_SUCCESS)
  303. return REGISTRATION_ERROR;
  304. /* Do not support both a pointer and touch. */
  305. destroy_device(dev_context, MDT_TYPE_TOUCHSCREEN);
  306. break;
  307. case MDT_TYPE_TOUCHSCREEN:
  308. if (dev_context->mdt_devs.dev_touchscreen != 0)
  309. return REGISTRATION_SUCCESS;
  310. if (init_mdt_touchscreen(dev_context) != REGISTRATION_SUCCESS)
  311. return REGISTRATION_ERROR;
  312. /* Do not support both a pointer and touch. */
  313. destroy_device(dev_context, MDT_TYPE_MOUSE);
  314. break;
  315. #if 0
  316. case MDT_TYPE_GAME:
  317. if (registration_helper(MDT_TYPE_KEYBOARD) == REGISTRATION_ERROR)
  318. return REGISTRATION_ERROR;
  319. if (registration_helper(MDT_TYPE_MOUSE) == REGISTRATION_ERROR)
  320. return REGISTRATION_ERROR;
  321. break;
  322. #endif
  323. case MDT_TYPE_COUNT:
  324. /*
  325. * This case is out of range.
  326. * Code is included to avoid compiler warning.
  327. */
  328. break;
  329. }
  330. return REGISTRATION_SUCCESS;
  331. }
  332. static int register_device(struct mhl_dev_context *dev_context, enum mdt_dev_types_e mdt_device_type)
  333. {
  334. uint8_t error = 0;
  335. if ((mdt_device_type >= MDT_TYPE_COUNT) ||
  336. (is_mdt_dev_waiting(dev_context, mdt_device_type) == false))
  337. return REGISTRATION_ERROR;
  338. /* Call recursive part of the function.
  339. Don't update is_dev_registered there. */
  340. error = registration_helper(dev_context, mdt_device_type);
  341. if (error != REGISTRATION_SUCCESS) {
  342. dev_context->mdt_devs.is_dev_registered[mdt_device_type] = INPUT_DISABLED;
  343. MHL_TX_DBG_INFO(dev_context, "SUCCESS. Device type %d registered.\n", mdt_device_type);
  344. } else {
  345. dev_context->mdt_devs.is_dev_registered[mdt_device_type] = INPUT_ACTIVE;
  346. MHL_TX_DBG_INFO(dev_context, "FAILURE. Device type %d registration failed.\n", mdt_device_type);
  347. }
  348. return error;
  349. }
  350. void generate_event_keyboard(struct mhl_dev_context *dev_context,
  351. struct mdt_packet *keyboard_packet)
  352. {
  353. struct input_dev *dev_keyboard = dev_context->mdt_devs.dev_keyboard;
  354. uint8_t *keycodes_new = dev_context->mdt_devs.keycodes_new;
  355. uint8_t *keycodes_old = dev_context->mdt_devs.keycodes_old;
  356. int i;
  357. //register_device(dev_context, MDT_TYPE_KEYBOARD);
  358. memcpy(keycodes_new, &keyboard_packet->header, HID_INPUT_REPORT);
  359. MHL_TX_DBG_INFO(dev_context, "Key (scancode %02X) asserted.\n",
  360. keycodes_new[1]);
  361. if (dev_keyboard == 0) {
  362. MHL_TX_DBG_INFO(dev_context, "MDT_ERR_NOKEY\n");
  363. return;
  364. }
  365. /* following code was copied from usbkbd.c */
  366. /* generate events for CRL, SHIFT, and ALT keys */
  367. for (i = 0; i < 3; i++)
  368. input_report_key(dev_keyboard,
  369. usb_kbd_keycode[i + 224],
  370. (keycodes_new[0] >> i) & 1);
  371. /*
  372. * Generate key press/release events for the
  373. * remaining bytes in the input packet
  374. */
  375. for (i = 1; i < 7; i++) {
  376. /* If keycode in pervious HID payload doesn't appear
  377. * in NEW HID payload, generate de-assertion event
  378. */
  379. if ((keycodes_old[i] > 3) &&
  380. ((uint8_t *)memscan(keycodes_new + 1, keycodes_old[i], 6) ==
  381. ((uint8_t *)(keycodes_new) + 7))) {
  382. if (usb_kbd_keycode[keycodes_old[i]]) {
  383. input_report_key(dev_keyboard, usb_kbd_keycode[keycodes_old[i]], 0);
  384. } else {
  385. MHL_TX_DBG_INFO(dev_context, "Unknown key (scancode %#x) "
  386. "released.\n", keycodes_old[i]);
  387. }
  388. }
  389. /* If keycode in NEW HID paylaod doesn't appear in previous
  390. * HID payload, generate assertion event
  391. */
  392. if (keycodes_new[i] > 3 &&
  393. memscan(keycodes_old + 1, keycodes_new[i], 6) == keycodes_old + 7) {
  394. if (usb_kbd_keycode[keycodes_new[i]]) {
  395. input_report_key(dev_keyboard, usb_kbd_keycode[keycodes_new[i]], 1);
  396. } else {
  397. MHL_TX_DBG_INFO(dev_context, "Unknown key (scancode %#x) "
  398. "pressed.\n", keycodes_new[i]);
  399. }
  400. }
  401. }
  402. input_sync(dev_keyboard);
  403. /* NEW HID payload is now OLD */
  404. memcpy(keycodes_old, keycodes_new, HID_INPUT_REPORT);
  405. }
  406. static void mdt_toggle_keycode(struct input_dev *hid_device
  407. ,unsigned char keycode)
  408. {
  409. if (NULL == hid_device)
  410. return;
  411. input_report_key(hid_device, keycode, KEY_PRESSED);
  412. input_sync(hid_device);
  413. input_report_key(hid_device, keycode, KEY_RELEASED);
  414. input_sync(hid_device);
  415. }
  416. void mdt_toggle_keyboard_keycode(struct mhl_dev_context *dev_context
  417. ,unsigned char keycode)
  418. {
  419. mdt_toggle_keycode(dev_context->mdt_devs.dev_keyboard, keycode);
  420. }
  421. void generate_event_mouse(struct mhl_dev_context *dev_context,
  422. struct mdt_packet *mousePacket)
  423. {
  424. struct input_dev *dev_mouse = dev_context->mdt_devs.dev_mouse;
  425. //register_device(dev_context, MDT_TYPE_MOUSE);
  426. MHL_TX_DBG_INFO(dev_context, "mouse buttons (0x%02x)\n",
  427. mousePacket->header & MDT_HDR_MOUSE_BUTTON_MASK);
  428. if (dev_mouse == 0) {
  429. MHL_TX_DBG_ERR(dev_context, "MDT_ERR_NOMOUSE\n");
  430. return;
  431. }
  432. /* Translate and report mouse button changes */
  433. input_report_key(dev_mouse, BTN_LEFT,
  434. mousePacket->header & MDT_HDR_MOUSE_BUTTON_1);
  435. #if (RIGHT_MOUSE_BUTTON_IS_ESC == 1)
  436. if (mousePacket->header & MDT_HDR_MOUSE_BUTTON_2) {
  437. if (!dev_context->mdt_devs.prior_right_button) {
  438. dev_context->mdt_devs.prior_right_button = 1;
  439. mdt_toggle_keycode(dev_mouse, KEY_ESC);
  440. }
  441. } else
  442. dev_context->mdt_devs.prior_right_button = 0;
  443. #else
  444. input_report_key(dev_mouse, BTN_RIGHT,
  445. mousePacket->header & MDT_HDR_MOUSE_BUTTON_2);
  446. #endif
  447. input_report_key(dev_mouse, BTN_MIDDLE,
  448. mousePacket->header & MDT_HDR_MOUSE_BUTTON_3);
  449. input_report_rel(dev_mouse, REL_X,
  450. mousePacket->event.mouse.x_displacement);
  451. input_report_rel(dev_mouse, REL_Y,
  452. mousePacket->event.mouse.y_displacement);
  453. input_report_rel(dev_mouse, REL_WHEEL,
  454. mousePacket->event.mouse.z_displacement);
  455. input_sync(dev_mouse);
  456. }
  457. static uint8_t process_touch_packet(struct mhl_dev_context *dev_context,
  458. struct mdt_packet *touchPacket)
  459. {
  460. struct mdt_touch_history_t *prior_event;
  461. int abs_x, abs_y;
  462. uint8_t isTouched = (touchPacket->header & 0x01);
  463. uint8_t contactID = ((touchPacket->header & 0x06) >> 1);
  464. prior_event = (struct mdt_touch_history_t *)&(dev_context->mdt_devs.prior_touch_events[contactID]);
  465. abs_x = touchPacket->event.touch_pad.x_abs_coordinate[MDT_TOUCH_X_LOW] |
  466. (touchPacket->event.touch_pad.x_abs_coordinate[MDT_TOUCH_X_HIGH] << 8);
  467. abs_y = touchPacket->event.touch_pad.y_abs_coordinate[MDT_TOUCH_Y_LOW] |
  468. (touchPacket->event.touch_pad.y_abs_coordinate[MDT_TOUCH_Y_HIGH] << 8);
  469. #if (CORNER_BUTTON == 1)
  470. /* Handle LOWER RIGHT corner like a EXIT button (ESC key) */
  471. if (( abs_x > X_CORNER_RIGHT_LOWER ) && ( abs_y > Y_CORNER_RIGHT_LOWER )) {
  472. if (isTouched != dev_context->mdt_devs.prior_touch_button)
  473. {
  474. dev_context->mdt_devs.prior_touch_button = isTouched;
  475. if (isTouched)
  476. mdt_toggle_keycode(dev_context->mdt_devs.dev_touchscreen, KEY_ESC);
  477. }
  478. return 0xFF;
  479. }
  480. #elif (ICS_BAR == 1)
  481. /* JB421 doesn't allow this driver to trigger buttons on the bar.
  482. implement custom buttons to workaround the problem. */
  483. if ((isTouched != dev_context->mdt_devs.prior_touch_button)
  484. && ( abs_x >= X_BUTTON_BAR_START)) {
  485. if (( abs_y > Y_BUTTON_RECENTAPPS_TOP) && ( abs_y < Y_BUTTON_RECENTAPPS_BOTTOM))
  486. mdt_toggle_keycode(dev_context->mdt_devs.dev_touchscreen, KEY_MENU);
  487. else if (( abs_y > Y_BUTTON_HOME_TOP) && ( abs_y < Y_BUTTON_HOME_BOTTOM))
  488. mdt_toggle_keycode(dev_context->mdt_devs.dev_touchscreen, KEY_HOMEPAGE);
  489. else if (( abs_y > Y_BUTTON_BACK_TOP) && ( abs_y < Y_BUTTON_BACK_BOTTOM))
  490. mdt_toggle_keycode(dev_context->mdt_devs.dev_touchscreen, KEY_BACK);
  491. return 0xFF;
  492. }
  493. #endif
  494. /* support dynamic configuration through ATTRIBUTES */
  495. if (dev_context->mdt_devs.swap_xy != 0) {
  496. prior_event->abs_x = abs_y;
  497. prior_event->abs_y = abs_x;
  498. } else {
  499. prior_event->abs_x = abs_x;
  500. prior_event->abs_y = abs_y;
  501. }
  502. if ((dev_context->mdt_devs.x_raw != 0) &&
  503. (dev_context->mdt_devs.x_screen != 0) && (prior_event->abs_x != 0)) {
  504. prior_event->abs_x *= dev_context->mdt_devs.x_screen;
  505. prior_event->abs_x /= dev_context->mdt_devs.x_raw;
  506. }
  507. if ((dev_context->mdt_devs.y_raw != 0) &&
  508. (dev_context->mdt_devs.y_screen != 0) && (prior_event->abs_y != 0)) {
  509. prior_event->abs_y *= dev_context->mdt_devs.y_screen;
  510. prior_event->abs_y /= dev_context->mdt_devs.y_raw;
  511. }
  512. if ((dev_context->mdt_devs.swap_leftright) &&
  513. (dev_context->mdt_devs.x_max >= prior_event->abs_x))
  514. prior_event->abs_x = (dev_context->mdt_devs.x_max - prior_event->abs_x);
  515. if ((dev_context->mdt_devs.swap_updown) &&
  516. (dev_context->mdt_devs.y_max >= prior_event->abs_y))
  517. prior_event->abs_y = (dev_context->mdt_devs.y_max - prior_event->abs_y);
  518. prior_event->abs_x += dev_context->mdt_devs.x_shift;
  519. prior_event->abs_y += dev_context->mdt_devs.y_shift;
  520. if (isTouched == 0) {
  521. if (prior_event->isTouched == 0)
  522. /* Multiple release events; declare contact inactive & ignore */
  523. prior_event->state = MDT_TOUCH_INACTIVE;
  524. } else {
  525. prior_event->state = MDT_TOUCH_ACTIVE;
  526. }
  527. prior_event->isTouched = isTouched;
  528. return contactID;
  529. }
  530. #if defined(SINGLE_TOUCH)
  531. static void submit_touchscreen_events_as_single_touch(struct mhl_dev_context *dev_context)
  532. {
  533. struct input_dev *dev_ts = dev_context->mdt_devs.dev_touchscreen;
  534. struct mdt_touch_history_t *prior_event;
  535. prior_event = &(dev_context->mdt_devs.prior_touch_events[0]);
  536. input_report_key(dev_ts, BTN_TOUCH, prior_event->isTouched);
  537. input_report_abs(dev_ts, ABS_X, prior_event->abs_x);
  538. input_report_abs(dev_ts, ABS_Y, prior_event->abs_y);
  539. }
  540. #elif defined(KERNEL_2_6_38_AND_LATER)
  541. static void submit_touchscreen_events_with_proto_B(struct mhl_dev_context *dev_context,
  542. uint8_t contactID)
  543. {
  544. struct input_dev *dev_ts = dev_context->mdt_devs.dev_touchscreen;
  545. struct mdt_touch_history_t *prior_event;
  546. uint8_t i;
  547. uint8_t counter = 0;
  548. for (i=0; i< MAX_TOUCH_CONTACTS; i++) {
  549. prior_event = &(dev_context->mdt_devs.prior_touch_events[i]);
  550. if (prior_event->state == MDT_TOUCH_INACTIVE)
  551. continue;
  552. input_mt_slot(dev_ts, i);
  553. input_mt_report_slot_state(dev_ts, MT_TOOL_FINGER, prior_event->isTouched);
  554. /* Event already handled; don't handle it again. */
  555. if (prior_event->isTouched == 0) {
  556. prior_event->state = MDT_TOUCH_INACTIVE;
  557. } else {
  558. counter++;
  559. input_report_abs(dev_ts, ABS_MT_TOUCH_MAJOR,15);
  560. input_report_abs(dev_ts, ABS_MT_PRESSURE, 50);
  561. input_report_abs(dev_ts, ABS_MT_POSITION_X, prior_event->abs_x);
  562. input_report_abs(dev_ts, ABS_MT_POSITION_Y, prior_event->abs_y);
  563. }
  564. /* BTN_TOUCH breaks support brokend as of JB42 */
  565. #if !defined(JB_421)
  566. if (counter == 1)
  567. input_report_key(dev_ts, BTN_TOUCH, 1);
  568. else
  569. input_report_key(dev_ts, BTN_TOUCH, 0);
  570. #endif
  571. }
  572. #else
  573. static void submit_touchscreen_events_with_proto_A(struct mhl_dev_context *dev_context,
  574. uint8_t contactID)
  575. {
  576. struct input_dev *dev_ts = dev_context->mdt_devs.dev_touchscreen;
  577. struct mdt_touch_history_t *prior_event;
  578. uint8_t i;
  579. uint8_t count = 0;
  580. for (i=0; i< MAX_TOUCH_CONTACTS; i++) {
  581. prior_event = &(dev_context->mdt_devs.prior_touch_events[i]);
  582. if (prior_event->state == MDT_TOUCH_INACTIVE)
  583. continue;
  584. count++;
  585. if (prior_event->isTouched == 0) //Event handled; don't handle it again.
  586. prior_event->state = MDT_TOUCH_INACTIVE;
  587. input_report_key(dev_ts, BTN_TOUCH, prior_event->isTouched);
  588. input_report_abs(dev_ts, ABS_MT_TOUCH_MAJOR, prior_event->isTouched);
  589. input_report_abs(dev_ts, ABS_MT_TRACKING_ID, i);
  590. input_report_abs(dev_ts, ABS_MT_WIDTH_MAJOR, 1);
  591. input_report_abs(dev_ts, ABS_MT_POSITION_X, prior_event->abs_x);
  592. input_report_abs(dev_ts,ABS_MT_POSITION_Y, prior_event->abs_y);
  593. input_mt_sync(dev_ts);
  594. }
  595. if (count == 0)
  596. input_mt_sync(dev_ts);
  597. }
  598. #endif
  599. static void generate_event_touchscreen(struct mhl_dev_context *dev_context,
  600. struct mdt_packet *touchPacket)
  601. {
  602. struct input_dev *dev_ts = dev_context->mdt_devs.dev_touchscreen;
  603. uint8_t contactID;
  604. //register_device(dev_context, MDT_TYPE_TOUCHSCREEN);
  605. if (dev_ts == 0 ) {
  606. MHL_TX_DBG_ERR(dev_context, "MDT_ERR_NOTOUCHSCREEN\n");
  607. return;
  608. }
  609. /* process touch packet into prior_touch_events */
  610. contactID = process_touch_packet(dev_context, touchPacket);
  611. if (contactID == 0xFF)
  612. return;
  613. #if defined(SINGLE_TOUCH)
  614. submit_touchscreen_events_as_single_touch(dev_context);
  615. #elif defined(KERNEL_2_6_38_AND_LATER)
  616. submit_touchscreen_events_with_proto_B(dev_context, contactID);
  617. #else
  618. submit_touchscreen_events_with_proto_A(dev_context, contactID);
  619. #endif
  620. /* generate touchscreen assertion */
  621. input_sync(dev_ts);
  622. }
  623. static bool process_hotplug_packet(struct mhl_dev_context *dev_context, struct mdt_packet *hotplug_packet)
  624. {
  625. /* 'M' previoulsy found to be in the header byte */
  626. if ((hotplug_packet->event.hotplug.sub_header_d != D_CHAR) &&
  627. (hotplug_packet->event.hotplug.sub_header_t != T_CHAR) &&
  628. (hotplug_packet->event.hotplug.mdt_version != MDT_VERSION))
  629. return false;
  630. /* in the future, support response with ACK or NACK */
  631. MHL_TX_DBG_INFO(dev_context, "HP packet. Device type: %02x. Event: %02x.\n",
  632. hotplug_packet->event.hotplug.device_type, hotplug_packet->event.hotplug.event_code );
  633. switch (hotplug_packet->event.hotplug.event_code) {
  634. case NOTICE_DEV_PLUG:
  635. register_device(dev_context, hotplug_packet->event.hotplug.device_type);
  636. break;
  637. case NOTICE_DEV_UNPLUG:
  638. destroy_device(dev_context, hotplug_packet->event.hotplug.device_type);
  639. break;
  640. default:
  641. return false;
  642. }
  643. return true;
  644. }
  645. bool si_mhl_tx_mdt_process_packet(struct mhl_dev_context *dev_context,void *packet)
  646. {
  647. struct mdt_packet *mdt_event_packet=(struct mdt_packet *)packet;
  648. if (!(MDT_HDR_IS_HID & mdt_event_packet->header)) {
  649. if (M_CHAR == mdt_event_packet->header)
  650. return process_hotplug_packet(dev_context, mdt_event_packet);
  651. MHL_TX_DBG_INFO(dev_context, "Ignoring non-HID packet\n");
  652. return false;
  653. }
  654. if (MDT_HDR_IS_KEYBOARD & mdt_event_packet->header) {
  655. generate_event_keyboard(dev_context, mdt_event_packet);
  656. } else if (!(MDT_HDR_IS_KEYBOARD & mdt_event_packet->header) &&
  657. (!(MDT_HDR_IS_NOT_MOUSE & mdt_event_packet->header))) {
  658. generate_event_mouse(dev_context, mdt_event_packet);
  659. } else if (!(MDT_HDR_IS_KEYBOARD & mdt_event_packet->header) &&
  660. (MDT_HDR_IS_NOT_MOUSE & mdt_event_packet->header)) {
  661. generate_event_touchscreen(dev_context, mdt_event_packet);
  662. } else if (!(MDT_HDR_IS_KEYBOARD & mdt_event_packet->header) &&
  663. (MDT_HDR_IS_NOT_MOUSE & mdt_event_packet->header) &&
  664. (MDT_HDR_IS_NOT_LAST & mdt_event_packet->header)) {
  665. MHL_TX_DBG_INFO(dev_context, "Unsupported gaming controller "\
  666. "event received\n");
  667. } else {
  668. MHL_TX_DBG_INFO(dev_context, "Event is either not an HID event or "\
  669. "is an an unknown HID event type\n");
  670. return false;
  671. }
  672. /* Consume the write burst event as an MDT event */
  673. return true;
  674. }
  675. /*
  676. int mdt_init(struct mhl_dev_context *dev_context)
  677. {
  678. int status;
  679. MHL_TX_DBG_INFO(dev_context, "mdt_init!!!!!!!!!!!!!!.\n");
  680. status = init_mdt_keyboard(dev_context);
  681. if (status < 0){
  682. MHL_TX_DBG_INFO(dev_context, "Keyboard registration failure.\n");
  683. goto exit;
  684. }
  685. status = init_mdt_mouse(dev_context);
  686. if (status < 0){
  687. MHL_TX_DBG_INFO(dev_context, "Mouse registration failure.\n");
  688. MHL_TX_DBG_INFO(dev_context, "Unregistering keyboard: %p\n",dev_context->mdt_devs.dev_keyboard);
  689. input_unregister_device(dev_context->mdt_devs.dev_keyboard);
  690. }
  691. exit:
  692. return status;
  693. }
  694. */
  695. void mdt_destroy(struct mhl_dev_context *dev_context)
  696. {
  697. MHL_TX_DBG_INFO(dev_context, "mdt_destroy!!!!!!!!!!!!!!.\n");
  698. destroy_device(dev_context, MDT_TYPE_KEYBOARD);
  699. destroy_device(dev_context, MDT_TYPE_MOUSE);
  700. destroy_device(dev_context, MDT_TYPE_TOUCHSCREEN);
  701. }
  702. #endif