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) /*    -*- linux-c -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) GTCO digitizer USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) TO CHECK:  Is pressure done right on report 5?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) Copyright (C) 2006  GTCO CalComp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) modify it under the terms of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) as published by the Free Software Foundation; version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) Permission to use, copy, modify, distribute, and sell this software and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) documentation for any purpose is hereby granted without fee, provided that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) the above copyright notice appear in all copies and that both that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) copyright notice and this permission notice appear in supporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) documentation, and that the name of GTCO-CalComp not be used in advertising
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) or publicity pertaining to distribution of the software without specific,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) written prior permission. GTCO-CalComp makes no representations about the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) suitability of this software for any purpose.  It is provided "as is"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) without express or implied warranty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) GTCO-CALCOMP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) EVENT SHALL GTCO-CALCOMP BE LIABLE FOR ANY SPECIAL, INDIRECT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) TORTIOUS ACTIONS, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) PERFORMANCE OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) GTCO CalComp, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 7125 Riverwood Drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) Columbia, MD 21046
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) Jeremy Roberson jroberson@gtcocalcomp.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) Scott Hill shill@gtcocalcomp.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) /*#define DEBUG*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /* Version with a Major number of 2 is for kernel inclusion only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define  GTCO_VERSION   "2.00.0006"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) /*   MACROS  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define VENDOR_ID_GTCO	      0x078C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define PID_400               0x400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #define PID_401               0x401
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define PID_1000              0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define PID_1001              0x1001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define PID_1002              0x1002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) /* Max size of a single report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define REPORT_MAX_SIZE       10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define MAX_COLLECTION_LEVELS  10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) /* Bitmask whether pen is in range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define MASK_INRANGE 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define MASK_BUTTON  0x01F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define  PATHLENGTH     64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /* DATA STRUCTURES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) /* Device table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static const struct usb_device_id gtco_usbid_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	{ USB_DEVICE(VENDOR_ID_GTCO, PID_400) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	{ USB_DEVICE(VENDOR_ID_GTCO, PID_401) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	{ USB_DEVICE(VENDOR_ID_GTCO, PID_1000) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	{ USB_DEVICE(VENDOR_ID_GTCO, PID_1001) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	{ USB_DEVICE(VENDOR_ID_GTCO, PID_1002) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) MODULE_DEVICE_TABLE (usb, gtco_usbid_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) /* Structure to hold all of our device specific stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) struct gtco {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	struct input_dev  *inputdevice; /* input device struct pointer  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	struct usb_interface *intf;	/* the usb interface for this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct urb        *urbinfo;	 /* urb for incoming reports      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	dma_addr_t        buf_dma;  /* dma addr of the data buffer*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	unsigned char *   buffer;   /* databuffer for reports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	char  usbpath[PATHLENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	int   openCount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	/* Information pulled from Report Descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	u32  usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	u32  min_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	u32  max_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	u32  min_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	u32  max_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	s8   mintilt_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	s8   maxtilt_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	s8   mintilt_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	s8   maxtilt_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	u32  maxpressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	u32  minpressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) /*   Code for parsing the HID REPORT DESCRIPTOR          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) /* From HID1.11 spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) struct hid_descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct usb_descriptor_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	__le16   bcdHID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	u8       bCountryCode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	u8       bNumDescriptors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	u8       bDescriptorType;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	__le16   wDescriptorLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define HID_DESCRIPTOR_SIZE   9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define HID_DEVICE_TYPE       33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) #define REPORT_DEVICE_TYPE    34
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #define PREF_TAG(x)     ((x)>>4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define PREF_TYPE(x)    ((x>>2)&0x03)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define PREF_SIZE(x)    ((x)&0x03)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) #define TYPE_MAIN       0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #define TYPE_GLOBAL     1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #define TYPE_LOCAL      2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #define TYPE_RESERVED   3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #define TAG_MAIN_INPUT        0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) #define TAG_MAIN_OUTPUT       0x9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define TAG_MAIN_FEATURE      0xB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define TAG_MAIN_COL_START    0xA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) #define TAG_MAIN_COL_END      0xC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) #define TAG_GLOB_USAGE        0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #define TAG_GLOB_LOG_MIN      1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) #define TAG_GLOB_LOG_MAX      2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #define TAG_GLOB_PHYS_MIN     3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) #define TAG_GLOB_PHYS_MAX     4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) #define TAG_GLOB_UNIT_EXP     5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) #define TAG_GLOB_UNIT         6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) #define TAG_GLOB_REPORT_SZ    7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) #define TAG_GLOB_REPORT_ID    8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) #define TAG_GLOB_REPORT_CNT   9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) #define TAG_GLOB_PUSH         10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) #define TAG_GLOB_POP          11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) #define TAG_GLOB_MAX          12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) #define DIGITIZER_USAGE_TIP_PRESSURE   0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) #define DIGITIZER_USAGE_TILT_X         0x3D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #define DIGITIZER_USAGE_TILT_Y         0x3E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  *   This is an abbreviated parser for the HID Report Descriptor.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  *   know what devices we are talking to, so this is by no means meant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  *   to be generic.  We can make some safe assumptions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  *   - We know there are no LONG tags, all short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  *   - We know that we have no MAIN Feature and MAIN Output items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193)  *   - We know what the IRQ reports are supposed to look like.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  *   The main purpose of this is to use the HID report desc to figure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  *   out the mins and maxs of the fields in the IRQ reports.  The IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  *   reports for 400/401 change slightly if the max X is bigger than 64K.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) static void parse_hid_report_descriptor(struct gtco *device, char * report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 					int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	struct device *ddev = &device->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	int   x, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	/* Tag primitive vars */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	__u8   prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	__u8   size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	__u8   tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	__u8   type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	__u8   data   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	__u16  data16 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	__u32  data32 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	/* For parsing logic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	int   inputnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	__u32 usage = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	/* Global Values, indexed by TAG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	__u32 globalval[TAG_GLOB_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	__u32 oldval[TAG_GLOB_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	/* Debug stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	char  maintype = 'x';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	char  globtype[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	int   indent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	char  indentstr[MAX_COLLECTION_LEVELS + 1] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	dev_dbg(ddev, "======>>>>>>PARSE<<<<<<======\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	/* Walk  this report and pull out the info we need */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	while (i < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		prefix = report[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		/* Determine data size and save the data in the proper variable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		size = (1U << PREF_SIZE(prefix)) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		if (i + size > length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 			dev_err(ddev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 				"Not enough data (need %d, have %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 				i + size, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			data = report[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 			data16 = get_unaligned_le16(&report[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			data32 = get_unaligned_le32(&report[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		/* Skip size of data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		i += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		/* What we do depends on the tag type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		tag  = PREF_TAG(prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		type = PREF_TYPE(prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		case TYPE_MAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			strcpy(globtype, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			switch (tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			case TAG_MAIN_INPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 				 * The INPUT MAIN tag signifies this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 				 * information from a report.  We need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 				 * figure out what it is and store the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 				 * min/max values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 				maintype = 'I';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 				if (data == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 					strcpy(globtype, "Variable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 				else if (data == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 					strcpy(globtype, "Var|Const");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 				dev_dbg(ddev, "::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 					globalval[TAG_GLOB_REPORT_ID], inputnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 					globalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 					globalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 					globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				  We can assume that the first two input items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				  are always the X and Y coordinates.  After
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 				  that, we look for everything else by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 				  local usage value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 				switch (inputnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 				case 0:  /* X coord */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 					dev_dbg(ddev, "GER: X Usage: 0x%x\n", usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 					if (device->max_X == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 						device->max_X = globalval[TAG_GLOB_LOG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 						device->min_X = globalval[TAG_GLOB_LOG_MIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 				case 1:  /* Y coord */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 					dev_dbg(ddev, "GER: Y Usage: 0x%x\n", usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 					if (device->max_Y == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 						device->max_Y = globalval[TAG_GLOB_LOG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 						device->min_Y = globalval[TAG_GLOB_LOG_MIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 					/* Tilt X */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 					if (usage == DIGITIZER_USAGE_TILT_X) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 						if (device->maxtilt_X == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 							device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 							device->mintilt_X = globalval[TAG_GLOB_LOG_MIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 					/* Tilt Y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 					if (usage == DIGITIZER_USAGE_TILT_Y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 						if (device->maxtilt_Y == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 							device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 							device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 					/* Pressure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 					if (usage == DIGITIZER_USAGE_TIP_PRESSURE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 						if (device->maxpressure == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 							device->maxpressure = globalval[TAG_GLOB_LOG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 							device->minpressure = globalval[TAG_GLOB_LOG_MIN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 				inputnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			case TAG_MAIN_OUTPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				maintype = 'O';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			case TAG_MAIN_FEATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 				maintype = 'F';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			case TAG_MAIN_COL_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 				maintype = 'S';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 				if (indent == MAX_COLLECTION_LEVELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 					dev_err(ddev, "Collection level %d would exceed limit of %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 						indent + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 						MAX_COLLECTION_LEVELS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				if (data == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 					dev_dbg(ddev, "======>>>>>> Physical\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 					strcpy(globtype, "Physical");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 				} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 					dev_dbg(ddev, "======>>>>>>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 				/* Indent the debug output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 				indent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 				for (x = 0; x < indent; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 					indentstr[x] = '-';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				indentstr[x] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 				/* Save global tags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 				for (x = 0; x < TAG_GLOB_MAX; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 					oldval[x] = globalval[x];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			case TAG_MAIN_COL_END:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 				maintype = 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 				if (indent == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 					dev_err(ddev, "Collection level already at zero\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 				dev_dbg(ddev, "<<<<<<======\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				indent--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 				for (x = 0; x < indent; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 					indentstr[x] = '-';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 				indentstr[x] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				/* Copy global tags back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 				for (x = 0; x < TAG_GLOB_MAX; x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 					globalval[x] = oldval[x];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 			case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 				dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 					indentstr, tag, maintype, size, globtype, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 			case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 				dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 					indentstr, tag, maintype, size, globtype, data16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 				dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 					indentstr, tag, maintype, size, globtype, data32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		case TYPE_GLOBAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 			switch (tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			case TAG_GLOB_USAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 				 * First time we hit the global usage tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 				 * it should tell us the type of device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 				if (device->usage == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 					device->usage = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 				strcpy(globtype, "USAGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			case TAG_GLOB_LOG_MIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 				strcpy(globtype, "LOG_MIN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			case TAG_GLOB_LOG_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 				strcpy(globtype, "LOG_MAX");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			case TAG_GLOB_PHYS_MIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 				strcpy(globtype, "PHYS_MIN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			case TAG_GLOB_PHYS_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 				strcpy(globtype, "PHYS_MAX");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			case TAG_GLOB_UNIT_EXP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 				strcpy(globtype, "EXP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			case TAG_GLOB_UNIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				strcpy(globtype, "UNIT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			case TAG_GLOB_REPORT_SZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 				strcpy(globtype, "REPORT_SZ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			case TAG_GLOB_REPORT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				strcpy(globtype, "REPORT_ID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 				/* New report, restart numbering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 				inputnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			case TAG_GLOB_REPORT_CNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 				strcpy(globtype, "REPORT_CNT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			case TAG_GLOB_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				strcpy(globtype, "PUSH");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			case TAG_GLOB_POP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 				strcpy(globtype, "POP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			/* Check to make sure we have a good tag number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			   so we don't overflow array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			if (tag < TAG_GLOB_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 				switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 					dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 						indentstr, globtype, tag, size, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					globalval[tag] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 				case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 					dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 						indentstr, globtype, tag, size, data16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 					globalval[tag] = data16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 				case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 					dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 						indentstr, globtype, tag, size, data32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 					globalval[tag] = data32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 				dev_dbg(ddev, "%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 					indentstr, tag, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		case TYPE_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			switch (tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			case TAG_GLOB_USAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 				strcpy(globtype, "USAGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 				/* Always 1 byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 				usage = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			case TAG_GLOB_LOG_MIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 				strcpy(globtype, "MIN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			case TAG_GLOB_LOG_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 				strcpy(globtype, "MAX");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 				strcpy(globtype, "UNKNOWN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 				dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 					indentstr, tag, globtype, size, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 					indentstr, tag, globtype, size, data16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 				dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 					indentstr, tag, globtype, size, data32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) /*   INPUT DRIVER Routines                               */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  * Called when opening the input device.  This will submit the URB to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  * the usb system so we start getting reports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) static int gtco_input_open(struct input_dev *inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	struct gtco *device = input_get_drvdata(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	device->urbinfo->dev = interface_to_usbdev(device->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (usb_submit_urb(device->urbinfo, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * Called when closing the input device.  This will unlink the URB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) static void gtco_input_close(struct input_dev *inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	struct gtco *device = input_get_drvdata(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	usb_kill_urb(device->urbinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578)  *  Setup input device capabilities.  Tell the input system what this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579)  *  device is capable of generating.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581)  *  This information is based on what is read from the HID report and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)  *  placed in the struct gtco structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) static void gtco_setup_caps(struct input_dev *inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	struct gtco *device = input_get_drvdata(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	/* Which events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	inputdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		BIT_MASK(EV_MSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	/* Misc event menu block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	inputdev->mscbit[0] = BIT_MASK(MSC_SCAN) | BIT_MASK(MSC_SERIAL) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		BIT_MASK(MSC_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	/* Absolute values based on HID report info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			     0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	input_set_abs_params(inputdev, ABS_Y, device->min_Y, device->max_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			     0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	/* Proximity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	input_set_abs_params(inputdev, ABS_DISTANCE, 0, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	/* Tilt & pressure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	input_set_abs_params(inputdev, ABS_TILT_X, device->mintilt_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			     device->maxtilt_X, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	input_set_abs_params(inputdev, ABS_TILT_Y, device->mintilt_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 			     device->maxtilt_Y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			     device->maxpressure, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	/* Transducer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) /*   USB Routines  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  * URB callback routine.  Called when we get IRQ reports from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)  *  digitizer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  *  This bridges the USB and input device worlds.  It generates events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  *  on the input device based on the USB reports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static void gtco_urb_callback(struct urb *urbinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct gtco *device = urbinfo->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	struct input_dev  *inputdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	int               rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	u32               val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	char              le_buffer[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	inputdev = device->inputdevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	/* Was callback OK? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (urbinfo->status == -ECONNRESET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	    urbinfo->status == -ENOENT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	    urbinfo->status == -ESHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		/* Shutdown is occurring. Return and don't queue up any more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (urbinfo->status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		 * Some unknown error.  Hopefully temporary. Just go and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		 * requeue an URB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	 * Good URB, now process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	/* PID dependent when we interpret the report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (inputdev->id.product == PID_1000 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	    inputdev->id.product == PID_1001 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	    inputdev->id.product == PID_1002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		 * Switch on the report ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		 * Conveniently, the reports have more information, the higher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		 * the report number.  We can just fall through the case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		 * statements if we start with the highest number report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		switch (device->buffer[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			/* Pressure is 9 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			val = ((u16)(device->buffer[8]) << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			val |= (u16)(device->buffer[7] >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			input_report_abs(inputdev, ABS_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 					 device->buffer[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			/* Mask out the Y tilt value used for pressure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 			device->buffer[7] = (u8)((device->buffer[7]) & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			/* Tilt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			input_report_abs(inputdev, ABS_TILT_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 					 sign_extend32(device->buffer[6], 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 			input_report_abs(inputdev, ABS_TILT_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 					 sign_extend32(device->buffer[7], 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			/* Convert buttons, only 5 bits possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			val = (device->buffer[5]) & MASK_BUTTON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			/* We don't apply any meaning to the bitmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			   just report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			input_event(inputdev, EV_MSC, MSC_SERIAL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			/* All reports have X and Y coords in the same place */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			val = get_unaligned_le16(&device->buffer[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			input_report_abs(inputdev, ABS_X, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			val = get_unaligned_le16(&device->buffer[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			input_report_abs(inputdev, ABS_Y, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			/* Ditto for proximity bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			val = device->buffer[5] & MASK_INRANGE ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			input_report_abs(inputdev, ABS_DISTANCE, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 			/* Report 1 is an exception to how we handle buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 			/* Buttons are an index, not a bitmask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			if (device->buffer[0] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 				 * Convert buttons, 5 bit index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 				 * Report value of index set as one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 				 * the rest as 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 				val = device->buffer[5] & MASK_BUTTON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 				dev_dbg(&device->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 					"======>>>>>>REPORT 1: val 0x%X(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 					val, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 				 * We don't apply any meaning to the button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 				 * index, just report it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 				input_event(inputdev, EV_MSC, MSC_SERIAL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			/* Menu blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			input_event(inputdev, EV_MSC, MSC_SCAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				    device->buffer[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	/* Other pid class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (inputdev->id.product == PID_400 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	    inputdev->id.product == PID_401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		/* Report 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		if (device->buffer[0] == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			/* Menu blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		/*  Report 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		if (device->buffer[0] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			char buttonbyte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			/*  IF X max > 64K, we still a bit from the y report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			if (device->max_X > 0x10000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 				val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 				val |= (u32)(((u8)device->buffer[3] & 0x1) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 				input_report_abs(inputdev, ABS_X, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 				le_buffer[0]  = (u8)((u8)(device->buffer[3]) >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 				le_buffer[0] |= (u8)((device->buffer[3] & 0x1) << 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 				le_buffer[1]  = (u8)(device->buffer[4] >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 				le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 				val = get_unaligned_le16(le_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 				input_report_abs(inputdev, ABS_Y, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 				 * Shift the button byte right by one to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 				 * make it look like the standard report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 				buttonbyte = device->buffer[5] >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 				val = get_unaligned_le16(&device->buffer[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 				input_report_abs(inputdev, ABS_X, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 				val = get_unaligned_le16(&device->buffer[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 				input_report_abs(inputdev, ABS_Y, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 				buttonbyte = device->buffer[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			/* BUTTONS and PROXIMITY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			val = buttonbyte & MASK_INRANGE ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			input_report_abs(inputdev, ABS_DISTANCE, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			/* Convert buttons, only 4 bits possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			val = buttonbyte & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) #ifdef USE_BUTTONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 				input_report_key(inputdev, BTN_DIGI + i, val & (1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			/* We don't apply any meaning to the bitmask, just report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			input_event(inputdev, EV_MSC, MSC_SERIAL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			/* TRANSDUCER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			input_report_abs(inputdev, ABS_MISC, device->buffer[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	/* Everybody gets report ID's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	input_event(inputdev, EV_MSC, MSC_RAW,  device->buffer[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	/* Sync it up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	input_sync(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)  resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	rc = usb_submit_urb(urbinfo, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		dev_err(&device->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			"usb_submit_urb failed rc=0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  *  The probe routine.  This is called when the kernel find the matching USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  *   vendor/product.  We do the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *    - Allocate mem for a local structure to manage the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  *    - Request a HID Report Descriptor from the device and parse it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  *      find out the device parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  *    - Create an input device and assign it attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)  *   - Allocate an URB so the device can talk to us when the input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)  *      queue is open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) static int gtco_probe(struct usb_interface *usbinterface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		      const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	struct gtco             *gtco;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	struct input_dev        *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	struct hid_descriptor   *hid_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	char                    *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	int                     result = 0, retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	struct usb_endpoint_descriptor *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	struct usb_device	*udev = interface_to_usbdev(usbinterface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	/* Allocate memory for device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	if (!gtco || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		dev_err(&usbinterface->dev, "No more memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		goto err_free_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	/* Set pointer to the input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	gtco->inputdevice = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	/* Save interface information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	gtco->intf = usbinterface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	/* Allocate some data for incoming reports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	gtco->buffer = usb_alloc_coherent(udev, REPORT_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 					  GFP_KERNEL, &gtco->buf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	if (!gtco->buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		dev_err(&usbinterface->dev, "No more memory for us buffers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		goto err_free_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	/* Allocate URB for reports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	if (!gtco->urbinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		dev_err(&usbinterface->dev, "Failed to allocate URB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		goto err_free_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	/* Sanity check that a device has an endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	if (usbinterface->cur_altsetting->desc.bNumEndpoints < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		dev_err(&usbinterface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			"Invalid number of endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	endpoint = &usbinterface->cur_altsetting->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	/* Some debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	dev_dbg(&usbinterface->dev, "gtco # interfaces: %d\n", usbinterface->num_altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	dev_dbg(&usbinterface->dev, "num endpoints:     %d\n", usbinterface->cur_altsetting->desc.bNumEndpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	dev_dbg(&usbinterface->dev, "interface class:   %d\n", usbinterface->cur_altsetting->desc.bInterfaceClass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	dev_dbg(&usbinterface->dev, "endpoint: attribute:0x%x type:0x%x\n", endpoint->bmAttributes, endpoint->bDescriptorType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (usb_endpoint_xfer_int(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		dev_dbg(&usbinterface->dev, "endpoint: we have interrupt endpoint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	dev_dbg(&usbinterface->dev, "interface extra len:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		usbinterface->cur_altsetting->extralen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	 * Find the HID descriptor so we can find out the size of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	 * HID report descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (usb_get_extra_descriptor(usbinterface->cur_altsetting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 				     HID_DEVICE_TYPE, &hid_desc) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		dev_err(&usbinterface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			"Can't retrieve exta USB descriptor to get hid report descriptor length\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	dev_dbg(&usbinterface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		"Extra descriptor success: type:%d  len:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		hid_desc->bDescriptorType,  hid_desc->wDescriptorLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	report = kzalloc(le16_to_cpu(hid_desc->wDescriptorLength), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (!report) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		dev_err(&usbinterface->dev, "No more memory for report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	/* Couple of tries to get reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	for (retry = 0; retry < 3; retry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		result = usb_control_msg(udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 					 usb_rcvctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 					 USB_REQ_GET_DESCRIPTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 					 USB_RECIP_INTERFACE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 					 REPORT_DEVICE_TYPE << 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 					 0, /* interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 					 report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 					 le16_to_cpu(hid_desc->wDescriptorLength),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 					 5000); /* 5 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		dev_dbg(&usbinterface->dev, "usb_control_msg result: %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		if (result == le16_to_cpu(hid_desc->wDescriptorLength)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			parse_hid_report_descriptor(gtco, report, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	kfree(report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	/* If we didn't get the report, fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (result != le16_to_cpu(hid_desc->wDescriptorLength)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		dev_err(&usbinterface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			"Failed to get HID Report Descriptor of size: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			hid_desc->wDescriptorLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	/* Create a device file node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	usb_make_path(udev, gtco->usbpath, sizeof(gtco->usbpath));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	/* Set Input device functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	input_dev->open = gtco_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	input_dev->close = gtco_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	/* Set input device information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	input_dev->name = "GTCO_CalComp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	input_dev->phys = gtco->usbpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	input_set_drvdata(input_dev, gtco);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/* Now set up all the input device capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	gtco_setup_caps(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	/* Set input device required ID information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	usb_to_input_id(udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	input_dev->dev.parent = &usbinterface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	/* Setup the URB, it will be posted later on open of input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	usb_fill_int_urb(gtco->urbinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			 udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			 usb_rcvintpipe(udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 					endpoint->bEndpointAddress),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			 gtco->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			 REPORT_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			 gtco_urb_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			 gtco,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			 endpoint->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	gtco->urbinfo->transfer_dma = gtco->buf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	gtco->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	/* Save gtco pointer in USB interface gtco */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	usb_set_intfdata(usbinterface, gtco);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	/* All done, now register the input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		goto err_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)  err_free_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	usb_free_urb(gtco->urbinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998)  err_free_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	usb_free_coherent(udev, REPORT_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			  gtco->buffer, gtco->buf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)  err_free_devs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	kfree(gtco);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)  *  This function is a standard USB function called when the USB device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)  *  is disconnected.  We will get rid of the URV, de-register the input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)  *  device, and free up allocated memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static void gtco_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	/* Grab private device ptr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	struct gtco *gtco = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	struct usb_device *udev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	/* Now reverse all the registration stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	if (gtco) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		input_unregister_device(gtco->inputdevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		usb_kill_urb(gtco->urbinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		usb_free_urb(gtco->urbinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		usb_free_coherent(udev, REPORT_MAX_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 				  gtco->buffer, gtco->buf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		kfree(gtco);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	dev_info(&interface->dev, "gtco driver disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /*   STANDARD MODULE LOAD ROUTINES  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static struct usb_driver gtco_driverinfo_table = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	.name		= "gtco",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	.id_table	= gtco_usbid_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	.probe		= gtco_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	.disconnect	= gtco_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) module_usb_driver(gtco_driverinfo_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) MODULE_DESCRIPTION("GTCO digitizer USB driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) MODULE_LICENSE("GPL");