pt_mtb.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * pt_mtb.c
  3. * Parade TrueTouch(TM) Standard Product Multi-Touch Protocol B Module.
  4. * For use with Parade touchscreen controllers.
  5. * Supported parts include:
  6. * TMA5XX
  7. * TMA448
  8. * TMA445A
  9. * TT21XXX
  10. * TT31XXX
  11. * TT4XXXX
  12. * TT7XXX
  13. * TC3XXX
  14. *
  15. * Copyright (C) 2015-2020 Parade Technologies
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * version 2, and only version 2, as published by the
  20. * Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * Contact Parade Technologies at www.paradetech.com <[email protected]>
  28. */
  29. #include "pt_regs.h"
  30. #include <linux/input/mt.h>
  31. #include <linux/version.h>
  32. /*******************************************************************************
  33. * FUNCTION: pt_final_sync
  34. *
  35. * SUMMARY: Function to create SYN_REPORT
  36. *
  37. * PARAMETERS:
  38. * *input - pointer to input device structure
  39. * max_slots - max support touch number
  40. * mt_sync_count - current valid touch number
  41. * ids - bit map value
  42. ******************************************************************************/
  43. static void pt_final_sync(struct input_dev *input, int max_slots,
  44. int mt_sync_count, unsigned long *ids)
  45. {
  46. int t;
  47. for (t = 0; t < max_slots; t++) {
  48. if (test_bit(t, ids))
  49. continue;
  50. input_mt_slot(input, t);
  51. input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
  52. }
  53. input_sync(input);
  54. }
  55. /*******************************************************************************
  56. * FUNCTION: pt_input_report
  57. *
  58. * SUMMARY: Function to report coordinate information of touch point
  59. * protocol
  60. *
  61. * PARAMETERS:
  62. * *input - pointer to input device structure
  63. * sig - track id to allow tracking of a touch
  64. * t - event id to indicate an event associated with touch instance
  65. * type - indicate the touch object
  66. ******************************************************************************/
  67. static void pt_input_report(struct input_dev *input, int sig,
  68. int t, int type)
  69. {
  70. input_mt_slot(input, t);
  71. if (type == PT_OBJ_STANDARD_FINGER || type == PT_OBJ_GLOVE)
  72. input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
  73. else if (type == PT_OBJ_STYLUS)
  74. input_mt_report_slot_state(input, MT_TOOL_PEN, true);
  75. }
  76. /*******************************************************************************
  77. * FUNCTION: pt_report_slot_liftoff
  78. *
  79. * SUMMARY: Function to report all touches are lifted
  80. * protocol
  81. *
  82. * PARAMETERS:
  83. * *md - pointer to input device structure
  84. * max_slots - indicate max number of touch id
  85. ******************************************************************************/
  86. static void pt_report_slot_liftoff(struct pt_mt_data *md,
  87. int max_slots)
  88. {
  89. int t;
  90. if (md->num_prv_rec == 0)
  91. return;
  92. for (t = 0; t < max_slots; t++) {
  93. input_mt_slot(md->input, t);
  94. input_mt_report_slot_state(md->input,
  95. MT_TOOL_FINGER, false);
  96. }
  97. }
  98. /*******************************************************************************
  99. * FUNCTION: pt_input_register_device
  100. *
  101. * SUMMARY: Function to register input device
  102. * protocol
  103. *
  104. * PARAMETERS:
  105. * *input - pointer to input device structure
  106. * max_slots - indicate max number of touch id
  107. ******************************************************************************/
  108. static int pt_input_register_device(struct input_dev *input, int max_slots)
  109. {
  110. #if (KERNEL_VERSION(3, 7, 0) <= LINUX_VERSION_CODE)
  111. input_mt_init_slots(input, max_slots, 0);
  112. #else
  113. input_mt_init_slots(input, max_slots);
  114. #endif
  115. return input_register_device(input);
  116. }
  117. /*******************************************************************************
  118. * FUNCTION: pt_init_function_ptrs
  119. *
  120. * SUMMARY: Function to init function pointer
  121. *
  122. * PARAMETERS:
  123. * *md - pointer to touch data structure
  124. ******************************************************************************/
  125. void pt_init_function_ptrs(struct pt_mt_data *md)
  126. {
  127. md->mt_function.report_slot_liftoff = pt_report_slot_liftoff;
  128. md->mt_function.final_sync = pt_final_sync;
  129. md->mt_function.input_sync = NULL;
  130. md->mt_function.input_report = pt_input_report;
  131. md->mt_function.input_register_device = pt_input_register_device;
  132. }