2019-02-10 18:13:51 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
/*
|
|
|
|
* HID driver for UC-Logic devices not fully compliant with HID standard
|
|
|
|
* - tablet initialization and parameter retrieval
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Nikolai Kondrashov
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HID_UCLOGIC_PARAMS_H
|
|
|
|
#define _HID_UCLOGIC_PARAMS_H
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/hid.h>
|
2022-12-26 20:54:52 +08:00
|
|
|
#include <linux/list.h>
|
2019-02-10 18:13:51 +08:00
|
|
|
|
2022-12-26 20:54:49 +08:00
|
|
|
#define UCLOGIC_MOUSE_FRAME_QUIRK BIT(0)
|
2022-12-26 20:54:50 +08:00
|
|
|
#define UCLOGIC_BATTERY_QUIRK BIT(1)
|
2022-12-26 20:54:49 +08:00
|
|
|
|
2019-02-10 18:13:51 +08:00
|
|
|
/* Types of pen in-range reporting */
|
|
|
|
enum uclogic_params_pen_inrange {
|
|
|
|
/* Normal reports: zero - out of proximity, one - in proximity */
|
|
|
|
UCLOGIC_PARAMS_PEN_INRANGE_NORMAL = 0,
|
|
|
|
/* Inverted reports: zero - in proximity, one - out of proximity */
|
|
|
|
UCLOGIC_PARAMS_PEN_INRANGE_INVERTED,
|
2019-02-10 18:13:54 +08:00
|
|
|
/* No reports */
|
|
|
|
UCLOGIC_PARAMS_PEN_INRANGE_NONE,
|
2019-02-10 18:13:51 +08:00
|
|
|
};
|
|
|
|
|
2022-08-15 22:29:52 +08:00
|
|
|
/* Types of frames */
|
|
|
|
enum uclogic_params_frame_type {
|
|
|
|
/* Frame with buttons */
|
|
|
|
UCLOGIC_PARAMS_FRAME_BUTTONS = 0,
|
|
|
|
/* Frame with buttons and a dial */
|
|
|
|
UCLOGIC_PARAMS_FRAME_DIAL,
|
|
|
|
/* Frame with buttons and a mouse (shaped as a dial + touchpad) */
|
|
|
|
UCLOGIC_PARAMS_FRAME_MOUSE,
|
|
|
|
};
|
|
|
|
|
2022-02-19 18:01:50 +08:00
|
|
|
/*
|
|
|
|
* Pen report's subreport data.
|
|
|
|
*/
|
|
|
|
struct uclogic_params_pen_subreport {
|
|
|
|
/*
|
2022-02-19 18:01:51 +08:00
|
|
|
* The value of the second byte of the pen report indicating this
|
|
|
|
* subreport. If zero, the subreport should be considered invalid and
|
|
|
|
* not matched.
|
2022-02-19 18:01:50 +08:00
|
|
|
*/
|
2022-02-19 18:01:51 +08:00
|
|
|
__u8 value;
|
2022-02-19 18:01:50 +08:00
|
|
|
|
|
|
|
/*
|
2022-02-19 18:01:51 +08:00
|
|
|
* The ID to be assigned to the report, if the second byte of the pen
|
|
|
|
* report is equal to "value". Only valid if "value" is not zero.
|
2022-02-19 18:01:50 +08:00
|
|
|
*/
|
|
|
|
__u8 id;
|
|
|
|
};
|
|
|
|
|
2019-02-10 18:13:51 +08:00
|
|
|
/*
|
|
|
|
* Tablet interface's pen input parameters.
|
|
|
|
*
|
|
|
|
* Must use declarative (descriptive) language, not imperative, to simplify
|
|
|
|
* understanding and maintain consistency.
|
|
|
|
*
|
|
|
|
* Noop (preserving functionality) when filled with zeroes.
|
|
|
|
*/
|
|
|
|
struct uclogic_params_pen {
|
2022-04-22 01:50:51 +08:00
|
|
|
/*
|
|
|
|
* True if pen usage is invalid for this interface and should be
|
|
|
|
* ignored, false otherwise.
|
|
|
|
*/
|
|
|
|
bool usage_invalid;
|
2019-02-10 18:13:51 +08:00
|
|
|
/*
|
2022-04-22 01:50:49 +08:00
|
|
|
* Pointer to report descriptor part describing the pen inputs.
|
|
|
|
* Allocated with kmalloc. NULL if the part is not specified.
|
2019-02-10 18:13:51 +08:00
|
|
|
*/
|
|
|
|
__u8 *desc_ptr;
|
|
|
|
/*
|
|
|
|
* Size of the report descriptor.
|
|
|
|
* Only valid, if "desc_ptr" is not NULL.
|
|
|
|
*/
|
|
|
|
unsigned int desc_size;
|
|
|
|
/* Report ID, if reports should be tweaked, zero if not */
|
|
|
|
unsigned int id;
|
2022-03-03 15:47:33 +08:00
|
|
|
/* The list of subreports, only valid if "id" is not zero */
|
|
|
|
struct uclogic_params_pen_subreport subreport_list[3];
|
2019-02-10 18:13:51 +08:00
|
|
|
/* Type of in-range reporting, only valid if "id" is not zero */
|
|
|
|
enum uclogic_params_pen_inrange inrange;
|
2019-02-10 18:13:55 +08:00
|
|
|
/*
|
|
|
|
* True, if reports include fragmented high resolution coords, with
|
|
|
|
* high-order X and then Y bytes following the pressure field.
|
|
|
|
* Only valid if "id" is not zero.
|
|
|
|
*/
|
|
|
|
bool fragmented_hires;
|
2022-02-11 03:04:31 +08:00
|
|
|
/*
|
|
|
|
* True if the pen reports tilt in bytes at offset 10 (X) and 11 (Y),
|
|
|
|
* and the Y tilt direction is flipped.
|
|
|
|
* Only valid if "id" is not zero.
|
|
|
|
*/
|
|
|
|
bool tilt_y_flipped;
|
2019-02-10 18:13:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parameters of frame control inputs of a tablet interface.
|
|
|
|
*
|
|
|
|
* Must use declarative (descriptive) language, not imperative, to simplify
|
|
|
|
* understanding and maintain consistency.
|
|
|
|
*
|
|
|
|
* Noop (preserving functionality) when filled with zeroes.
|
|
|
|
*/
|
|
|
|
struct uclogic_params_frame {
|
|
|
|
/*
|
2022-04-22 01:50:49 +08:00
|
|
|
* Pointer to report descriptor part describing the frame inputs.
|
|
|
|
* Allocated with kmalloc. NULL if the part is not specified.
|
2019-02-10 18:13:51 +08:00
|
|
|
*/
|
|
|
|
__u8 *desc_ptr;
|
|
|
|
/*
|
|
|
|
* Size of the report descriptor.
|
|
|
|
* Only valid, if "desc_ptr" is not NULL.
|
|
|
|
*/
|
|
|
|
unsigned int desc_size;
|
|
|
|
/*
|
|
|
|
* Report ID, if reports should be tweaked, zero if not.
|
|
|
|
*/
|
|
|
|
unsigned int id;
|
2022-03-03 15:47:32 +08:00
|
|
|
/*
|
|
|
|
* The suffix to add to the input device name, if not NULL.
|
|
|
|
*/
|
|
|
|
const char *suffix;
|
2019-02-10 18:14:04 +08:00
|
|
|
/*
|
|
|
|
* Number of the least-significant bit of the 2-bit state of a rotary
|
|
|
|
* encoder, in the report. Cannot point to a 2-bit field crossing a
|
|
|
|
* byte boundary. Zero if not present. Only valid if "id" is not zero.
|
|
|
|
*/
|
|
|
|
unsigned int re_lsb;
|
2019-02-10 18:14:03 +08:00
|
|
|
/*
|
|
|
|
* Offset of the Wacom-style device ID byte in the report, to be set
|
|
|
|
* to pad device ID (0xf), for compatibility with Wacom drivers. Zero
|
2022-03-03 15:47:31 +08:00
|
|
|
* if no changes to the report should be made. The ID byte will be set
|
2022-05-09 00:01:42 +08:00
|
|
|
* to zero whenever the byte pointed by "touch_byte" is zero, if
|
2022-03-03 15:47:31 +08:00
|
|
|
* the latter is valid. Only valid if "id" is not zero.
|
2019-02-10 18:14:03 +08:00
|
|
|
*/
|
|
|
|
unsigned int dev_id_byte;
|
2022-03-03 15:47:31 +08:00
|
|
|
/*
|
2022-05-09 00:01:42 +08:00
|
|
|
* Offset of the touch ring/strip state byte, in the report.
|
2022-03-03 15:47:31 +08:00
|
|
|
* Zero if not present. If dev_id_byte is also valid and non-zero,
|
|
|
|
* then the device ID byte will be cleared when the byte pointed to by
|
|
|
|
* this offset is zero. Only valid if "id" is not zero.
|
|
|
|
*/
|
2022-05-09 00:01:42 +08:00
|
|
|
unsigned int touch_byte;
|
2022-03-03 15:47:31 +08:00
|
|
|
/*
|
2022-05-09 00:01:42 +08:00
|
|
|
* The value to anchor the reversed touch ring/strip reports at.
|
2022-03-03 15:47:31 +08:00
|
|
|
* I.e. one, if the reports should be flipped without offset.
|
|
|
|
* Zero if no reversal should be done.
|
2022-05-09 00:01:42 +08:00
|
|
|
* Only valid if "touch_byte" is valid and not zero.
|
|
|
|
*/
|
|
|
|
__s8 touch_flip_at;
|
|
|
|
/*
|
|
|
|
* Maximum value of the touch ring/strip report around which the value
|
|
|
|
* should be wrapped when flipping according to "touch_flip_at".
|
|
|
|
* The minimum valid value is considered to be one, with zero being
|
|
|
|
* out-of-proximity (finger lift) value.
|
|
|
|
* Only valid if "touch_flip_at" is valid and not zero.
|
2022-03-03 15:47:31 +08:00
|
|
|
*/
|
2022-05-09 00:01:42 +08:00
|
|
|
__s8 touch_max;
|
2022-04-14 19:09:35 +08:00
|
|
|
/*
|
|
|
|
* Offset of the bitmap dial byte, in the report. Zero if not present.
|
|
|
|
* Only valid if "id" is not zero. A bitmap dial sends reports with a
|
|
|
|
* dedicated bit per direction: 1 means clockwise rotation, 2 means
|
|
|
|
* counterclockwise, as opposed to the normal 1 and -1.
|
|
|
|
*/
|
|
|
|
unsigned int bitmap_dial_byte;
|
2019-02-10 18:13:51 +08:00
|
|
|
};
|
|
|
|
|
2022-12-26 20:54:52 +08:00
|
|
|
/*
|
|
|
|
* List of works to be performed when a certain raw event is received.
|
|
|
|
*/
|
|
|
|
struct uclogic_raw_event_hook {
|
|
|
|
struct hid_device *hdev;
|
|
|
|
__u8 *event;
|
|
|
|
size_t size;
|
|
|
|
struct work_struct work;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2019-02-10 18:13:51 +08:00
|
|
|
/*
|
|
|
|
* Tablet interface report parameters.
|
|
|
|
*
|
|
|
|
* Must use declarative (descriptive) language, not imperative, to simplify
|
|
|
|
* understanding and maintain consistency.
|
|
|
|
*
|
|
|
|
* When filled with zeros represents a "noop" configuration - passes all
|
|
|
|
* reports unchanged and lets the generic HID driver handle everything.
|
|
|
|
*
|
|
|
|
* The resulting device report descriptor is assembled from all the report
|
|
|
|
* descriptor parts referenced by the structure. No order of assembly should
|
|
|
|
* be assumed. The structure represents original device report descriptor if
|
|
|
|
* all the parts are NULL.
|
|
|
|
*/
|
|
|
|
struct uclogic_params {
|
|
|
|
/*
|
|
|
|
* True if the whole interface is invalid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool invalid;
|
|
|
|
/*
|
|
|
|
* Pointer to the common part of the replacement report descriptor,
|
|
|
|
* allocated with kmalloc. NULL if no common part is needed.
|
|
|
|
* Only valid, if "invalid" is false.
|
|
|
|
*/
|
|
|
|
__u8 *desc_ptr;
|
|
|
|
/*
|
|
|
|
* Size of the common part of the replacement report descriptor.
|
2022-04-22 01:50:48 +08:00
|
|
|
* Only valid, if "desc_ptr" is valid and not NULL.
|
2019-02-10 18:13:51 +08:00
|
|
|
*/
|
|
|
|
unsigned int desc_size;
|
|
|
|
/*
|
|
|
|
* Pen parameters and optional report descriptor part.
|
2022-02-19 18:01:49 +08:00
|
|
|
* Only valid, if "invalid" is false.
|
2019-02-10 18:13:51 +08:00
|
|
|
*/
|
|
|
|
struct uclogic_params_pen pen;
|
|
|
|
/*
|
2022-02-19 18:01:57 +08:00
|
|
|
* The list of frame control parameters and optional report descriptor
|
|
|
|
* parts. Only valid, if "invalid" is false.
|
2019-02-10 18:13:51 +08:00
|
|
|
*/
|
2022-03-03 15:47:33 +08:00
|
|
|
struct uclogic_params_frame frame_list[3];
|
2022-12-26 20:54:52 +08:00
|
|
|
/*
|
|
|
|
* List of event hooks.
|
|
|
|
*/
|
|
|
|
struct uclogic_raw_event_hook *event_hooks;
|
2019-02-10 18:13:51 +08:00
|
|
|
};
|
|
|
|
|
2022-12-26 20:54:49 +08:00
|
|
|
/* Driver data */
|
|
|
|
struct uclogic_drvdata {
|
|
|
|
/* Interface parameters */
|
|
|
|
struct uclogic_params params;
|
|
|
|
/* Pointer to the replacement report descriptor. NULL if none. */
|
|
|
|
__u8 *desc_ptr;
|
|
|
|
/*
|
|
|
|
* Size of the replacement report descriptor.
|
|
|
|
* Only valid if desc_ptr is not NULL
|
|
|
|
*/
|
|
|
|
unsigned int desc_size;
|
|
|
|
/* Pen input device */
|
|
|
|
struct input_dev *pen_input;
|
|
|
|
/* In-range timer */
|
|
|
|
struct timer_list inrange_timer;
|
|
|
|
/* Last rotary encoder state, or U8_MAX for none */
|
|
|
|
u8 re_state;
|
|
|
|
/* Device quirks */
|
|
|
|
unsigned long quirks;
|
|
|
|
};
|
|
|
|
|
2019-02-10 18:13:51 +08:00
|
|
|
/* Initialize a tablet interface and discover its parameters */
|
|
|
|
extern int uclogic_params_init(struct uclogic_params *params,
|
|
|
|
struct hid_device *hdev);
|
|
|
|
|
|
|
|
/* Get a replacement report descriptor for a tablet's interface. */
|
|
|
|
extern int uclogic_params_get_desc(const struct uclogic_params *params,
|
|
|
|
__u8 **pdesc,
|
|
|
|
unsigned int *psize);
|
|
|
|
|
|
|
|
/* Free resources used by tablet interface's parameters */
|
|
|
|
extern void uclogic_params_cleanup(struct uclogic_params *params);
|
|
|
|
|
2022-05-09 00:01:40 +08:00
|
|
|
/* Dump tablet interface parameters with hid_dbg() */
|
|
|
|
extern void uclogic_params_hid_dbg(const struct hid_device *hdev,
|
|
|
|
const struct uclogic_params *params);
|
|
|
|
|
2019-02-10 18:13:51 +08:00
|
|
|
#endif /* _HID_UCLOGIC_PARAMS_H */
|