hid-uclogic-params.h 8.3 KB

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