hid-uclogic-params.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * HID driver for UC-Logic devices not fully compliant with HID standard
  4. * - tablet initialization and parameter retrieval
  5. *
  6. * Copyright (c) 2018 Nikolai Kondrashov
  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. #ifndef _HID_UCLOGIC_PARAMS_H
  15. #define _HID_UCLOGIC_PARAMS_H
  16. #include <linux/usb.h>
  17. #include <linux/hid.h>
  18. #define UCLOGIC_MOUSE_FRAME_QUIRK BIT(0)
  19. #define UCLOGIC_BATTERY_QUIRK BIT(1)
  20. /* Types of pen in-range reporting */
  21. enum uclogic_params_pen_inrange {
  22. /* Normal reports: zero - out of proximity, one - in proximity */
  23. UCLOGIC_PARAMS_PEN_INRANGE_NORMAL = 0,
  24. /* Inverted reports: zero - in proximity, one - out of proximity */
  25. UCLOGIC_PARAMS_PEN_INRANGE_INVERTED,
  26. /* No reports */
  27. UCLOGIC_PARAMS_PEN_INRANGE_NONE,
  28. };
  29. /* Types of frames */
  30. enum uclogic_params_frame_type {
  31. /* Frame with buttons */
  32. UCLOGIC_PARAMS_FRAME_BUTTONS = 0,
  33. /* Frame with buttons and a dial */
  34. UCLOGIC_PARAMS_FRAME_DIAL,
  35. /* Frame with buttons and a mouse (shaped as a dial + touchpad) */
  36. UCLOGIC_PARAMS_FRAME_MOUSE,
  37. };
  38. /*
  39. * Pen report's subreport data.
  40. */
  41. struct uclogic_params_pen_subreport {
  42. /*
  43. * The value of the second byte of the pen report indicating this
  44. * subreport. If zero, the subreport should be considered invalid and
  45. * not matched.
  46. */
  47. __u8 value;
  48. /*
  49. * The ID to be assigned to the report, if the second byte of the pen
  50. * report is equal to "value". Only valid if "value" is not zero.
  51. */
  52. __u8 id;
  53. };
  54. /*
  55. * Tablet interface's pen input parameters.
  56. *
  57. * Must use declarative (descriptive) language, not imperative, to simplify
  58. * understanding and maintain consistency.
  59. *
  60. * Noop (preserving functionality) when filled with zeroes.
  61. */
  62. struct uclogic_params_pen {
  63. /*
  64. * True if pen usage is invalid for this interface and should be
  65. * ignored, false otherwise.
  66. */
  67. bool usage_invalid;
  68. /*
  69. * Pointer to report descriptor part describing the pen inputs.
  70. * Allocated with kmalloc. NULL if the part is not specified.
  71. */
  72. __u8 *desc_ptr;
  73. /*
  74. * Size of the report descriptor.
  75. * Only valid, if "desc_ptr" is not NULL.
  76. */
  77. unsigned int desc_size;
  78. /* Report ID, if reports should be tweaked, zero if not */
  79. unsigned int id;
  80. /* The list of subreports, only valid if "id" is not zero */
  81. struct uclogic_params_pen_subreport subreport_list[3];
  82. /* Type of in-range reporting, only valid if "id" is not zero */
  83. enum uclogic_params_pen_inrange inrange;
  84. /*
  85. * True, if reports include fragmented high resolution coords, with
  86. * high-order X and then Y bytes following the pressure field.
  87. * Only valid if "id" is not zero.
  88. */
  89. bool fragmented_hires;
  90. /*
  91. * True if the pen reports tilt in bytes at offset 10 (X) and 11 (Y),
  92. * and the Y tilt direction is flipped.
  93. * Only valid if "id" is not zero.
  94. */
  95. bool tilt_y_flipped;
  96. };
  97. /*
  98. * Parameters of frame control inputs of a tablet interface.
  99. *
  100. * Must use declarative (descriptive) language, not imperative, to simplify
  101. * understanding and maintain consistency.
  102. *
  103. * Noop (preserving functionality) when filled with zeroes.
  104. */
  105. struct uclogic_params_frame {
  106. /*
  107. * Pointer to report descriptor part describing the frame inputs.
  108. * Allocated with kmalloc. NULL if the part is not specified.
  109. */
  110. __u8 *desc_ptr;
  111. /*
  112. * Size of the report descriptor.
  113. * Only valid, if "desc_ptr" is not NULL.
  114. */
  115. unsigned int desc_size;
  116. /*
  117. * Report ID, if reports should be tweaked, zero if not.
  118. */
  119. unsigned int id;
  120. /*
  121. * The suffix to add to the input device name, if not NULL.
  122. */
  123. const char *suffix;
  124. /*
  125. * Number of the least-significant bit of the 2-bit state of a rotary
  126. * encoder, in the report. Cannot point to a 2-bit field crossing a
  127. * byte boundary. Zero if not present. Only valid if "id" is not zero.
  128. */
  129. unsigned int re_lsb;
  130. /*
  131. * Offset of the Wacom-style device ID byte in the report, to be set
  132. * to pad device ID (0xf), for compatibility with Wacom drivers. Zero
  133. * if no changes to the report should be made. The ID byte will be set
  134. * to zero whenever the byte pointed by "touch_byte" is zero, if
  135. * the latter is valid. Only valid if "id" is not zero.
  136. */
  137. unsigned int dev_id_byte;
  138. /*
  139. * Offset of the touch ring/strip state byte, in the report.
  140. * Zero if not present. If dev_id_byte is also valid and non-zero,
  141. * then the device ID byte will be cleared when the byte pointed to by
  142. * this offset is zero. Only valid if "id" is not zero.
  143. */
  144. unsigned int touch_byte;
  145. /*
  146. * The value to anchor the reversed touch ring/strip reports at.
  147. * I.e. one, if the reports should be flipped without offset.
  148. * Zero if no reversal should be done.
  149. * Only valid if "touch_byte" is valid and not zero.
  150. */
  151. __s8 touch_flip_at;
  152. /*
  153. * Maximum value of the touch ring/strip report around which the value
  154. * should be wrapped when flipping according to "touch_flip_at".
  155. * The minimum valid value is considered to be one, with zero being
  156. * out-of-proximity (finger lift) value.
  157. * Only valid if "touch_flip_at" is valid and not zero.
  158. */
  159. __s8 touch_max;
  160. /*
  161. * Offset of the bitmap dial byte, in the report. Zero if not present.
  162. * Only valid if "id" is not zero. A bitmap dial sends reports with a
  163. * dedicated bit per direction: 1 means clockwise rotation, 2 means
  164. * counterclockwise, as opposed to the normal 1 and -1.
  165. */
  166. unsigned int bitmap_dial_byte;
  167. };
  168. /*
  169. * Tablet interface report parameters.
  170. *
  171. * Must use declarative (descriptive) language, not imperative, to simplify
  172. * understanding and maintain consistency.
  173. *
  174. * When filled with zeros represents a "noop" configuration - passes all
  175. * reports unchanged and lets the generic HID driver handle everything.
  176. *
  177. * The resulting device report descriptor is assembled from all the report
  178. * descriptor parts referenced by the structure. No order of assembly should
  179. * be assumed. The structure represents original device report descriptor if
  180. * all the parts are NULL.
  181. */
  182. struct uclogic_params {
  183. /*
  184. * True if the whole interface is invalid, false otherwise.
  185. */
  186. bool invalid;
  187. /*
  188. * Pointer to the common part of the replacement report descriptor,
  189. * allocated with kmalloc. NULL if no common part is needed.
  190. * Only valid, if "invalid" is false.
  191. */
  192. __u8 *desc_ptr;
  193. /*
  194. * Size of the common part of the replacement report descriptor.
  195. * Only valid, if "desc_ptr" is valid and not NULL.
  196. */
  197. unsigned int desc_size;
  198. /*
  199. * Pen parameters and optional report descriptor part.
  200. * Only valid, if "invalid" is false.
  201. */
  202. struct uclogic_params_pen pen;
  203. /*
  204. * The list of frame control parameters and optional report descriptor
  205. * parts. Only valid, if "invalid" is false.
  206. */
  207. struct uclogic_params_frame frame_list[3];
  208. };
  209. /* Driver data */
  210. struct uclogic_drvdata {
  211. /* Interface parameters */
  212. struct uclogic_params params;
  213. /* Pointer to the replacement report descriptor. NULL if none. */
  214. __u8 *desc_ptr;
  215. /*
  216. * Size of the replacement report descriptor.
  217. * Only valid if desc_ptr is not NULL
  218. */
  219. unsigned int desc_size;
  220. /* Pen input device */
  221. struct input_dev *pen_input;
  222. /* In-range timer */
  223. struct timer_list inrange_timer;
  224. /* Last rotary encoder state, or U8_MAX for none */
  225. u8 re_state;
  226. /* Device quirks */
  227. unsigned long quirks;
  228. };
  229. /* Initialize a tablet interface and discover its parameters */
  230. extern int uclogic_params_init(struct uclogic_params *params,
  231. struct hid_device *hdev);
  232. /* Get a replacement report descriptor for a tablet's interface. */
  233. extern int uclogic_params_get_desc(const struct uclogic_params *params,
  234. __u8 **pdesc,
  235. unsigned int *psize);
  236. /* Free resources used by tablet interface's parameters */
  237. extern void uclogic_params_cleanup(struct uclogic_params *params);
  238. /* Dump tablet interface parameters with hid_dbg() */
  239. extern void uclogic_params_hid_dbg(const struct hid_device *hdev,
  240. const struct uclogic_params *params);
  241. #endif /* _HID_UCLOGIC_PARAMS_H */