1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * HID driver for UC-Logic devices not fully compliant with HID standard
4 * - tablet initialization and parameter retrieval
6 * Copyright (c) 2018 Nikolai Kondrashov
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
16 #ifndef _HID_UCLOGIC_PARAMS_H
17 #define _HID_UCLOGIC_PARAMS_H
19 #include <linux/usb.h>
20 #include <linux/hid.h>
22 /* Types of pen in-range reporting */
23 enum uclogic_params_pen_inrange {
24 /* Normal reports: zero - out of proximity, one - in proximity */
25 UCLOGIC_PARAMS_PEN_INRANGE_NORMAL = 0,
26 /* Inverted reports: zero - in proximity, one - out of proximity */
27 UCLOGIC_PARAMS_PEN_INRANGE_INVERTED,
29 UCLOGIC_PARAMS_PEN_INRANGE_NONE,
33 enum uclogic_params_frame_type {
34 /* Frame with buttons */
35 UCLOGIC_PARAMS_FRAME_BUTTONS = 0,
36 /* Frame with buttons and a dial */
37 UCLOGIC_PARAMS_FRAME_DIAL,
38 /* Frame with buttons and a mouse (shaped as a dial + touchpad) */
39 UCLOGIC_PARAMS_FRAME_MOUSE,
43 * Pen report's subreport data.
45 struct uclogic_params_pen_subreport {
47 * The value of the second byte of the pen report indicating this
48 * subreport. If zero, the subreport should be considered invalid and
54 * The ID to be assigned to the report, if the second byte of the pen
55 * report is equal to "value". Only valid if "value" is not zero.
61 * Tablet interface's pen input parameters.
63 * Must use declarative (descriptive) language, not imperative, to simplify
64 * understanding and maintain consistency.
66 * Noop (preserving functionality) when filled with zeroes.
68 struct uclogic_params_pen {
70 * True if pen usage is invalid for this interface and should be
71 * ignored, false otherwise.
75 * Pointer to report descriptor part describing the pen inputs.
76 * Allocated with kmalloc. NULL if the part is not specified.
80 * Size of the report descriptor.
81 * Only valid, if "desc_ptr" is not NULL.
83 unsigned int desc_size;
84 /* Report ID, if reports should be tweaked, zero if not */
86 /* The list of subreports, only valid if "id" is not zero */
87 struct uclogic_params_pen_subreport subreport_list[3];
88 /* Type of in-range reporting, only valid if "id" is not zero */
89 enum uclogic_params_pen_inrange inrange;
91 * True, if reports include fragmented high resolution coords, with
92 * high-order X and then Y bytes following the pressure field.
93 * Only valid if "id" is not zero.
95 bool fragmented_hires;
97 * True if the pen reports tilt in bytes at offset 10 (X) and 11 (Y),
98 * and the Y tilt direction is flipped.
99 * Only valid if "id" is not zero.
105 * Parameters of frame control inputs of a tablet interface.
107 * Must use declarative (descriptive) language, not imperative, to simplify
108 * understanding and maintain consistency.
110 * Noop (preserving functionality) when filled with zeroes.
112 struct uclogic_params_frame {
114 * Pointer to report descriptor part describing the frame inputs.
115 * Allocated with kmalloc. NULL if the part is not specified.
119 * Size of the report descriptor.
120 * Only valid, if "desc_ptr" is not NULL.
122 unsigned int desc_size;
124 * Report ID, if reports should be tweaked, zero if not.
128 * The suffix to add to the input device name, if not NULL.
132 * Number of the least-significant bit of the 2-bit state of a rotary
133 * encoder, in the report. Cannot point to a 2-bit field crossing a
134 * byte boundary. Zero if not present. Only valid if "id" is not zero.
138 * Offset of the Wacom-style device ID byte in the report, to be set
139 * to pad device ID (0xf), for compatibility with Wacom drivers. Zero
140 * if no changes to the report should be made. The ID byte will be set
141 * to zero whenever the byte pointed by "touch_byte" is zero, if
142 * the latter is valid. Only valid if "id" is not zero.
144 unsigned int dev_id_byte;
146 * Offset of the touch ring/strip state byte, in the report.
147 * Zero if not present. If dev_id_byte is also valid and non-zero,
148 * then the device ID byte will be cleared when the byte pointed to by
149 * this offset is zero. Only valid if "id" is not zero.
151 unsigned int touch_byte;
153 * The value to anchor the reversed touch ring/strip reports at.
154 * I.e. one, if the reports should be flipped without offset.
155 * Zero if no reversal should be done.
156 * Only valid if "touch_byte" is valid and not zero.
160 * Maximum value of the touch ring/strip report around which the value
161 * should be wrapped when flipping according to "touch_flip_at".
162 * The minimum valid value is considered to be one, with zero being
163 * out-of-proximity (finger lift) value.
164 * Only valid if "touch_flip_at" is valid and not zero.
168 * Offset of the bitmap dial byte, in the report. Zero if not present.
169 * Only valid if "id" is not zero. A bitmap dial sends reports with a
170 * dedicated bit per direction: 1 means clockwise rotation, 2 means
171 * counterclockwise, as opposed to the normal 1 and -1.
173 unsigned int bitmap_dial_byte;
177 * Tablet interface report parameters.
179 * Must use declarative (descriptive) language, not imperative, to simplify
180 * understanding and maintain consistency.
182 * When filled with zeros represents a "noop" configuration - passes all
183 * reports unchanged and lets the generic HID driver handle everything.
185 * The resulting device report descriptor is assembled from all the report
186 * descriptor parts referenced by the structure. No order of assembly should
187 * be assumed. The structure represents original device report descriptor if
188 * all the parts are NULL.
190 struct uclogic_params {
192 * True if the whole interface is invalid, false otherwise.
196 * Pointer to the common part of the replacement report descriptor,
197 * allocated with kmalloc. NULL if no common part is needed.
198 * Only valid, if "invalid" is false.
202 * Size of the common part of the replacement report descriptor.
203 * Only valid, if "desc_ptr" is valid and not NULL.
205 unsigned int desc_size;
207 * Pen parameters and optional report descriptor part.
208 * Only valid, if "invalid" is false.
210 struct uclogic_params_pen pen;
212 * The list of frame control parameters and optional report descriptor
213 * parts. Only valid, if "invalid" is false.
215 struct uclogic_params_frame frame_list[3];
218 /* Initialize a tablet interface and discover its parameters */
219 extern int uclogic_params_init(struct uclogic_params *params,
220 struct hid_device *hdev);
222 /* Get a replacement report descriptor for a tablet's interface. */
223 extern int uclogic_params_get_desc(const struct uclogic_params *params,
225 unsigned int *psize);
227 /* Free resources used by tablet interface's parameters */
228 extern void uclogic_params_cleanup(struct uclogic_params *params);
230 /* Dump tablet interface parameters with hid_dbg() */
231 extern void uclogic_params_hid_dbg(const struct hid_device *hdev,
232 const struct uclogic_params *params);
234 #endif /* _HID_UCLOGIC_PARAMS_H */