blob: 1060f70d647d09c341cf29a3b72c0dd906037fd8 [file] [log] [blame]
Nikolai Kondrashov96142192019-02-10 12:13:51 +02001/* 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 */
23enum 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,
Nikolai Kondrashov01309e22019-02-10 12:13:54 +020028 /* No reports */
29 UCLOGIC_PARAMS_PEN_INRANGE_NONE,
Nikolai Kondrashov96142192019-02-10 12:13:51 +020030};
31
32/* Convert a pen in-range reporting type to a string */
33extern const char *uclogic_params_pen_inrange_to_str(
34 enum uclogic_params_pen_inrange inrange);
35
36/*
37 * Tablet interface's pen input parameters.
38 *
39 * Must use declarative (descriptive) language, not imperative, to simplify
40 * understanding and maintain consistency.
41 *
42 * Noop (preserving functionality) when filled with zeroes.
43 */
44struct uclogic_params_pen {
45 /*
46 * Pointer to report descriptor describing the inputs.
47 * Allocated with kmalloc.
48 */
49 __u8 *desc_ptr;
50 /*
51 * Size of the report descriptor.
52 * Only valid, if "desc_ptr" is not NULL.
53 */
54 unsigned int desc_size;
55 /* Report ID, if reports should be tweaked, zero if not */
56 unsigned int id;
57 /* Type of in-range reporting, only valid if "id" is not zero */
58 enum uclogic_params_pen_inrange inrange;
Nikolai Kondrashov59f2e0f2019-02-10 12:13:55 +020059 /*
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.
63 */
64 bool fragmented_hires;
Nikolai Kondrashov96142192019-02-10 12:13:51 +020065};
66
67/*
68 * Parameters of frame control inputs of a tablet interface.
69 *
70 * Must use declarative (descriptive) language, not imperative, to simplify
71 * understanding and maintain consistency.
72 *
73 * Noop (preserving functionality) when filled with zeroes.
74 */
75struct uclogic_params_frame {
76 /*
77 * Pointer to report descriptor describing the inputs.
78 * Allocated with kmalloc.
79 */
80 __u8 *desc_ptr;
81 /*
82 * Size of the report descriptor.
83 * Only valid, if "desc_ptr" is not NULL.
84 */
85 unsigned int desc_size;
86 /*
87 * Report ID, if reports should be tweaked, zero if not.
88 */
89 unsigned int id;
90};
91
92/*
93 * Tablet interface report parameters.
94 *
95 * Must use declarative (descriptive) language, not imperative, to simplify
96 * understanding and maintain consistency.
97 *
98 * When filled with zeros represents a "noop" configuration - passes all
99 * reports unchanged and lets the generic HID driver handle everything.
100 *
101 * The resulting device report descriptor is assembled from all the report
102 * descriptor parts referenced by the structure. No order of assembly should
103 * be assumed. The structure represents original device report descriptor if
104 * all the parts are NULL.
105 */
106struct uclogic_params {
107 /*
108 * True if the whole interface is invalid, false otherwise.
109 */
110 bool invalid;
111 /*
112 * Pointer to the common part of the replacement report descriptor,
113 * allocated with kmalloc. NULL if no common part is needed.
114 * Only valid, if "invalid" is false.
115 */
116 __u8 *desc_ptr;
117 /*
118 * Size of the common part of the replacement report descriptor.
119 * Only valid, if "desc_ptr" is not NULL.
120 */
121 unsigned int desc_size;
122 /*
123 * True, if pen usage in report descriptor is invalid, when present.
124 * Only valid, if "invalid" is false.
125 */
126 bool pen_unused;
127 /*
128 * Pen parameters and optional report descriptor part.
129 * Only valid if "pen_unused" is valid and false.
130 */
131 struct uclogic_params_pen pen;
132 /*
133 * Frame control parameters and optional report descriptor part.
134 * Only valid, if "invalid" is false.
135 */
136 struct uclogic_params_frame frame;
137 /*
138 * Bitmask matching frame controls "sub-report" flag in the second
139 * byte of the pen report, or zero if it's not expected.
140 * Only valid if both "pen" and "frame" are valid, and "frame.id" is
141 * not zero.
142 */
143 __u8 pen_frame_flag;
144};
145
146/* Initialize a tablet interface and discover its parameters */
147extern int uclogic_params_init(struct uclogic_params *params,
148 struct hid_device *hdev);
149
150/* Tablet interface parameters *printf format string */
151#define UCLOGIC_PARAMS_FMT_STR \
152 ".invalid = %s\n" \
153 ".desc_ptr = %p\n" \
154 ".desc_size = %u\n" \
155 ".pen_unused = %s\n" \
156 ".pen.desc_ptr = %p\n" \
157 ".pen.desc_size = %u\n" \
158 ".pen.id = %u\n" \
159 ".pen.inrange = %s\n" \
Nikolai Kondrashov59f2e0f2019-02-10 12:13:55 +0200160 ".pen.fragmented_hires = %s\n" \
Nikolai Kondrashov96142192019-02-10 12:13:51 +0200161 ".frame.desc_ptr = %p\n" \
162 ".frame.desc_size = %u\n" \
163 ".frame.id = %u\n" \
164 ".pen_frame_flag = 0x%02x\n"
165
166/* Tablet interface parameters *printf format arguments */
167#define UCLOGIC_PARAMS_FMT_ARGS(_params) \
168 ((_params)->invalid ? "true" : "false"), \
169 (_params)->desc_ptr, \
170 (_params)->desc_size, \
171 ((_params)->pen_unused ? "true" : "false"), \
172 (_params)->pen.desc_ptr, \
173 (_params)->pen.desc_size, \
174 (_params)->pen.id, \
175 uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \
Nikolai Kondrashov59f2e0f2019-02-10 12:13:55 +0200176 ((_params)->pen.fragmented_hires ? "true" : "false"), \
Nikolai Kondrashov96142192019-02-10 12:13:51 +0200177 (_params)->frame.desc_ptr, \
178 (_params)->frame.desc_size, \
179 (_params)->frame.id, \
180 (_params)->pen_frame_flag
181
182/* Get a replacement report descriptor for a tablet's interface. */
183extern int uclogic_params_get_desc(const struct uclogic_params *params,
184 __u8 **pdesc,
185 unsigned int *psize);
186
187/* Free resources used by tablet interface's parameters */
188extern void uclogic_params_cleanup(struct uclogic_params *params);
189
190#endif /* _HID_UCLOGIC_PARAMS_H */