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