Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  HID driver for UC-Logic devices not fully compliant with HID standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  - tablet initialization and parameter retrieval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (c) 2018 Nikolai Kondrashov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * under the terms of the GNU General Public License as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Software Foundation; either version 2 of the License, or (at your option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #ifndef _HID_UCLOGIC_PARAMS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define _HID_UCLOGIC_PARAMS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* Types of pen in-range reporting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) enum uclogic_params_pen_inrange {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	/* Normal reports: zero - out of proximity, one - in proximity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	UCLOGIC_PARAMS_PEN_INRANGE_NORMAL = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	/* Inverted reports: zero - in proximity, one - out of proximity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	UCLOGIC_PARAMS_PEN_INRANGE_INVERTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/* No reports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	UCLOGIC_PARAMS_PEN_INRANGE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* Convert a pen in-range reporting type to a string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) extern const char *uclogic_params_pen_inrange_to_str(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			enum uclogic_params_pen_inrange inrange);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Tablet interface's pen input parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * Must use declarative (descriptive) language, not imperative, to simplify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * understanding and maintain consistency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * Noop (preserving functionality) when filled with zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) struct uclogic_params_pen {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	 * Pointer to report descriptor describing the inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 * Allocated with kmalloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	__u8 *desc_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * Size of the report descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 * Only valid, if "desc_ptr" is not NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned int desc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* Report ID, if reports should be tweaked, zero if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Type of in-range reporting, only valid if "id" is not zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	enum uclogic_params_pen_inrange inrange;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * True, if reports include fragmented high resolution coords, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * high-order X and then Y bytes following the pressure field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * Only valid if "id" is not zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	bool fragmented_hires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Parameters of frame control inputs of a tablet interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Must use declarative (descriptive) language, not imperative, to simplify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * understanding and maintain consistency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * Noop (preserving functionality) when filled with zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) struct uclogic_params_frame {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * Pointer to report descriptor describing the inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * Allocated with kmalloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	__u8 *desc_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * Size of the report descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * Only valid, if "desc_ptr" is not NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned int desc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * Report ID, if reports should be tweaked, zero if not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * Number of the least-significant bit of the 2-bit state of a rotary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * encoder, in the report. Cannot point to a 2-bit field crossing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * byte boundary. Zero if not present. Only valid if "id" is not zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned int re_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * Offset of the Wacom-style device ID byte in the report, to be set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 * to pad device ID (0xf), for compatibility with Wacom drivers. Zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 * if no changes to the report should be made. Only valid if "id" is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * not zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	unsigned int dev_id_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Tablet interface report parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * Must use declarative (descriptive) language, not imperative, to simplify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * understanding and maintain consistency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * When filled with zeros represents a "noop" configuration - passes all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * reports unchanged and lets the generic HID driver handle everything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * The resulting device report descriptor is assembled from all the report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * descriptor parts referenced by the structure. No order of assembly should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * be assumed. The structure represents original device report descriptor if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * all the parts are NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct uclogic_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * True if the whole interface is invalid, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	bool invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * Pointer to the common part of the replacement report descriptor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * allocated with kmalloc. NULL if no common part is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * Only valid, if "invalid" is false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	__u8 *desc_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * Size of the common part of the replacement report descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * Only valid, if "desc_ptr" is not NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	unsigned int desc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * True, if pen usage in report descriptor is invalid, when present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * Only valid, if "invalid" is false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	bool pen_unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * Pen parameters and optional report descriptor part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * Only valid if "pen_unused" is valid and false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct uclogic_params_pen pen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Frame control parameters and optional report descriptor part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * Only valid, if "invalid" is false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct uclogic_params_frame frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 * Bitmask matching frame controls "sub-report" flag in the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * byte of the pen report, or zero if it's not expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * Only valid if both "pen" and "frame" are valid, and "frame.id" is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * not zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	__u8 pen_frame_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Initialize a tablet interface and discover its parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) extern int uclogic_params_init(struct uclogic_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				struct hid_device *hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* Tablet interface parameters *printf format string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define UCLOGIC_PARAMS_FMT_STR \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		".invalid = %s\n"                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		".desc_ptr = %p\n"                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		".desc_size = %u\n"                 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		".pen_unused = %s\n"                \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		".pen.desc_ptr = %p\n"              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		".pen.desc_size = %u\n"             \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		".pen.id = %u\n"                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		".pen.inrange = %s\n"               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		".pen.fragmented_hires = %s\n"      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		".frame.desc_ptr = %p\n"            \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		".frame.desc_size = %u\n"           \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		".frame.id = %u\n"                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		".frame.re_lsb = %u\n"              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		".frame.dev_id_byte = %u\n"         \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		".pen_frame_flag = 0x%02x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Tablet interface parameters *printf format arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define UCLOGIC_PARAMS_FMT_ARGS(_params) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		((_params)->invalid ? "true" : "false"),                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		(_params)->desc_ptr,                                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		(_params)->desc_size,                                       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		((_params)->pen_unused ? "true" : "false"),                 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		(_params)->pen.desc_ptr,                                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		(_params)->pen.desc_size,                                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		(_params)->pen.id,                                          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		uclogic_params_pen_inrange_to_str((_params)->pen.inrange),  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		((_params)->pen.fragmented_hires ? "true" : "false"),       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		(_params)->frame.desc_ptr,                                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		(_params)->frame.desc_size,                                 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		(_params)->frame.id,                                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		(_params)->frame.re_lsb,                                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		(_params)->frame.dev_id_byte,                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		(_params)->pen_frame_flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Get a replacement report descriptor for a tablet's interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) extern int uclogic_params_get_desc(const struct uclogic_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 					__u8 **pdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 					unsigned int *psize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Free resources used by tablet interface's parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern void uclogic_params_cleanup(struct uclogic_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #endif /* _HID_UCLOGIC_PARAMS_H */