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
,
32 /* Convert a pen in-range reporting type to a string */
33 extern const char *uclogic_params_pen_inrange_to_str(
34 enum uclogic_params_pen_inrange inrange
);
37 * Tablet interface's pen input parameters.
39 * Must use declarative (descriptive) language, not imperative, to simplify
40 * understanding and maintain consistency.
42 * Noop (preserving functionality) when filled with zeroes.
44 struct uclogic_params_pen
{
46 * Pointer to report descriptor describing the inputs.
47 * Allocated with kmalloc.
51 * Size of the report descriptor.
52 * Only valid, if "desc_ptr" is not NULL.
54 unsigned int desc_size
;
55 /* Report ID, if reports should be tweaked, zero if not */
57 /* Type of in-range reporting, only valid if "id" is not zero */
58 enum uclogic_params_pen_inrange inrange
;
60 * True, if reports include fragmented high resolution coords, with
61 * high-order X and then Y bytes following the pressure field.
62 * Only valid if "id" is not zero.
64 bool fragmented_hires
;
68 * Parameters of frame control inputs of a tablet interface.
70 * Must use declarative (descriptive) language, not imperative, to simplify
71 * understanding and maintain consistency.
73 * Noop (preserving functionality) when filled with zeroes.
75 struct uclogic_params_frame
{
77 * Pointer to report descriptor describing the inputs.
78 * Allocated with kmalloc.
82 * Size of the report descriptor.
83 * Only valid, if "desc_ptr" is not NULL.
85 unsigned int desc_size
;
87 * Report ID, if reports should be tweaked, zero if not.
91 * Number of the least-significant bit of the 2-bit state of a rotary
92 * encoder, in the report. Cannot point to a 2-bit field crossing a
93 * byte boundary. Zero if not present. Only valid if "id" is not zero.
97 * Offset of the Wacom-style device ID byte in the report, to be set
98 * to pad device ID (0xf), for compatibility with Wacom drivers. Zero
99 * if no changes to the report should be made. Only valid if "id" is
102 unsigned int dev_id_byte
;
106 * Tablet interface report parameters.
108 * Must use declarative (descriptive) language, not imperative, to simplify
109 * understanding and maintain consistency.
111 * When filled with zeros represents a "noop" configuration - passes all
112 * reports unchanged and lets the generic HID driver handle everything.
114 * The resulting device report descriptor is assembled from all the report
115 * descriptor parts referenced by the structure. No order of assembly should
116 * be assumed. The structure represents original device report descriptor if
117 * all the parts are NULL.
119 struct uclogic_params
{
121 * True if the whole interface is invalid, false otherwise.
125 * Pointer to the common part of the replacement report descriptor,
126 * allocated with kmalloc. NULL if no common part is needed.
127 * Only valid, if "invalid" is false.
131 * Size of the common part of the replacement report descriptor.
132 * Only valid, if "desc_ptr" is not NULL.
134 unsigned int desc_size
;
136 * True, if pen usage in report descriptor is invalid, when present.
137 * Only valid, if "invalid" is false.
141 * Pen parameters and optional report descriptor part.
142 * Only valid if "pen_unused" is valid and false.
144 struct uclogic_params_pen pen
;
146 * Frame control parameters and optional report descriptor part.
147 * Only valid, if "invalid" is false.
149 struct uclogic_params_frame frame
;
151 * Bitmask matching frame controls "sub-report" flag in the second
152 * byte of the pen report, or zero if it's not expected.
153 * Only valid if both "pen" and "frame" are valid, and "frame.id" is
159 /* Initialize a tablet interface and discover its parameters */
160 extern int uclogic_params_init(struct uclogic_params
*params
,
161 struct hid_device
*hdev
);
163 /* Tablet interface parameters *printf format string */
164 #define UCLOGIC_PARAMS_FMT_STR \
167 ".desc_size = %u\n" \
168 ".pen_unused = %s\n" \
169 ".pen.desc_ptr = %p\n" \
170 ".pen.desc_size = %u\n" \
172 ".pen.inrange = %s\n" \
173 ".pen.fragmented_hires = %s\n" \
174 ".frame.desc_ptr = %p\n" \
175 ".frame.desc_size = %u\n" \
177 ".frame.re_lsb = %u\n" \
178 ".frame.dev_id_byte = %u\n" \
179 ".pen_frame_flag = 0x%02x\n"
181 /* Tablet interface parameters *printf format arguments */
182 #define UCLOGIC_PARAMS_FMT_ARGS(_params) \
183 ((_params)->invalid ? "true" : "false"), \
184 (_params)->desc_ptr, \
185 (_params)->desc_size, \
186 ((_params)->pen_unused ? "true" : "false"), \
187 (_params)->pen.desc_ptr, \
188 (_params)->pen.desc_size, \
190 uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \
191 ((_params)->pen.fragmented_hires ? "true" : "false"), \
192 (_params)->frame.desc_ptr, \
193 (_params)->frame.desc_size, \
194 (_params)->frame.id, \
195 (_params)->frame.re_lsb, \
196 (_params)->frame.dev_id_byte, \
197 (_params)->pen_frame_flag
199 /* Get a replacement report descriptor for a tablet's interface. */
200 extern int uclogic_params_get_desc(const struct uclogic_params
*params
,
202 unsigned int *psize
);
204 /* Free resources used by tablet interface's parameters */
205 extern void uclogic_params_cleanup(struct uclogic_params
*params
);
207 #endif /* _HID_UCLOGIC_PARAMS_H */