18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  HID driver for ViewSonic devices not fully compliant with HID standard
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2017 Nikolai Kondrashov
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it
108c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License as published by the Free
118c2ecf20Sopenharmony_ci * Software Foundation; either version 2 of the License, or (at your option)
128c2ecf20Sopenharmony_ci * any later version.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/device.h>
168c2ecf20Sopenharmony_ci#include <linux/hid.h>
178c2ecf20Sopenharmony_ci#include <linux/module.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "hid-ids.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Size of the original descriptor of PD1011 signature pad */
228c2ecf20Sopenharmony_ci#define PD1011_RDESC_ORIG_SIZE	408
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* Fixed report descriptor of PD1011 signature pad */
258c2ecf20Sopenharmony_cistatic __u8 pd1011_rdesc_fixed[] = {
268c2ecf20Sopenharmony_ci	0x05, 0x0D,             /*  Usage Page (Digitizer),             */
278c2ecf20Sopenharmony_ci	0x09, 0x02,             /*  Usage (Pen),                        */
288c2ecf20Sopenharmony_ci	0xA1, 0x01,             /*  Collection (Application),           */
298c2ecf20Sopenharmony_ci	0x85, 0x02,             /*      Report ID (2),                  */
308c2ecf20Sopenharmony_ci	0x09, 0x20,             /*      Usage (Stylus),                 */
318c2ecf20Sopenharmony_ci	0xA0,                   /*      Collection (Physical),          */
328c2ecf20Sopenharmony_ci	0x75, 0x10,             /*          Report Size (16),           */
338c2ecf20Sopenharmony_ci	0x95, 0x01,             /*          Report Count (1),           */
348c2ecf20Sopenharmony_ci	0xA4,                   /*          Push,                       */
358c2ecf20Sopenharmony_ci	0x05, 0x01,             /*          Usage Page (Desktop),       */
368c2ecf20Sopenharmony_ci	0x65, 0x13,             /*          Unit (Inch),                */
378c2ecf20Sopenharmony_ci	0x55, 0xFD,             /*          Unit Exponent (-3),         */
388c2ecf20Sopenharmony_ci	0x34,                   /*          Physical Minimum (0),       */
398c2ecf20Sopenharmony_ci	0x09, 0x30,             /*          Usage (X),                  */
408c2ecf20Sopenharmony_ci	0x46, 0x5D, 0x21,       /*          Physical Maximum (8541),    */
418c2ecf20Sopenharmony_ci	0x27, 0x80, 0xA9,
428c2ecf20Sopenharmony_ci		0x00, 0x00,     /*          Logical Maximum (43392),    */
438c2ecf20Sopenharmony_ci	0x81, 0x02,             /*          Input (Variable),           */
448c2ecf20Sopenharmony_ci	0x09, 0x31,             /*          Usage (Y),                  */
458c2ecf20Sopenharmony_ci	0x46, 0xDA, 0x14,       /*          Physical Maximum (5338),    */
468c2ecf20Sopenharmony_ci	0x26, 0xF0, 0x69,       /*          Logical Maximum (27120),    */
478c2ecf20Sopenharmony_ci	0x81, 0x02,             /*          Input (Variable),           */
488c2ecf20Sopenharmony_ci	0xB4,                   /*          Pop,                        */
498c2ecf20Sopenharmony_ci	0x14,                   /*          Logical Minimum (0),        */
508c2ecf20Sopenharmony_ci	0x25, 0x01,             /*          Logical Maximum (1),        */
518c2ecf20Sopenharmony_ci	0x75, 0x01,             /*          Report Size (1),            */
528c2ecf20Sopenharmony_ci	0x95, 0x01,             /*          Report Count (1),           */
538c2ecf20Sopenharmony_ci	0x81, 0x03,             /*          Input (Constant, Variable), */
548c2ecf20Sopenharmony_ci	0x09, 0x32,             /*          Usage (In Range),           */
558c2ecf20Sopenharmony_ci	0x09, 0x42,             /*          Usage (Tip Switch),         */
568c2ecf20Sopenharmony_ci	0x95, 0x02,             /*          Report Count (2),           */
578c2ecf20Sopenharmony_ci	0x81, 0x02,             /*          Input (Variable),           */
588c2ecf20Sopenharmony_ci	0x95, 0x05,             /*          Report Count (5),           */
598c2ecf20Sopenharmony_ci	0x81, 0x03,             /*          Input (Constant, Variable), */
608c2ecf20Sopenharmony_ci	0x75, 0x10,             /*          Report Size (16),           */
618c2ecf20Sopenharmony_ci	0x95, 0x01,             /*          Report Count (1),           */
628c2ecf20Sopenharmony_ci	0x09, 0x30,             /*          Usage (Tip Pressure),       */
638c2ecf20Sopenharmony_ci	0x15, 0x05,             /*          Logical Minimum (5),        */
648c2ecf20Sopenharmony_ci	0x26, 0xFF, 0x07,       /*          Logical Maximum (2047),     */
658c2ecf20Sopenharmony_ci	0x81, 0x02,             /*          Input (Variable),           */
668c2ecf20Sopenharmony_ci	0x75, 0x10,             /*          Report Size (16),           */
678c2ecf20Sopenharmony_ci	0x95, 0x01,             /*          Report Count (1),           */
688c2ecf20Sopenharmony_ci	0x81, 0x03,             /*          Input (Constant, Variable), */
698c2ecf20Sopenharmony_ci	0xC0,                   /*      End Collection,                 */
708c2ecf20Sopenharmony_ci	0xC0                    /*  End Collection                      */
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic __u8 *viewsonic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
748c2ecf20Sopenharmony_ci				    unsigned int *rsize)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	switch (hdev->product) {
778c2ecf20Sopenharmony_ci	case USB_DEVICE_ID_VIEWSONIC_PD1011:
788c2ecf20Sopenharmony_ci	case USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011:
798c2ecf20Sopenharmony_ci		if (*rsize == PD1011_RDESC_ORIG_SIZE) {
808c2ecf20Sopenharmony_ci			rdesc = pd1011_rdesc_fixed;
818c2ecf20Sopenharmony_ci			*rsize = sizeof(pd1011_rdesc_fixed);
828c2ecf20Sopenharmony_ci		}
838c2ecf20Sopenharmony_ci		break;
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	return rdesc;
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic const struct hid_device_id viewsonic_devices[] = {
908c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_VIEWSONIC,
918c2ecf20Sopenharmony_ci				USB_DEVICE_ID_VIEWSONIC_PD1011) },
928c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_SIGNOTEC,
938c2ecf20Sopenharmony_ci				USB_DEVICE_ID_SIGNOTEC_VIEWSONIC_PD1011) },
948c2ecf20Sopenharmony_ci	{ }
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, viewsonic_devices);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic struct hid_driver viewsonic_driver = {
998c2ecf20Sopenharmony_ci	.name = "viewsonic",
1008c2ecf20Sopenharmony_ci	.id_table = viewsonic_devices,
1018c2ecf20Sopenharmony_ci	.report_fixup = viewsonic_report_fixup,
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_cimodule_hid_driver(viewsonic_driver);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
106