xref: /OK3568_Linux_fs/external/xserver/hw/dmx/input/usb-other.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2002 Red Hat Inc., Durham, North Carolina.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * All Rights Reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining
7*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
8*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun  * without limitation on the rights to use, copy, modify, merge,
10*4882a593Smuzhiyun  * publish, distribute, sublicense, and/or sell copies of the Software,
11*4882a593Smuzhiyun  * and to permit persons to whom the Software is furnished to do so,
12*4882a593Smuzhiyun  * subject to the following conditions:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial
16*4882a593Smuzhiyun  * portions of the Software.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21*4882a593Smuzhiyun  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25*4882a593Smuzhiyun  * SOFTWARE.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * Authors:
30*4882a593Smuzhiyun  *   Rickard E. (Rik) Faith <faith@redhat.com>
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /** \file
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * This code implements a low-level device driver for a non-keyboard,
37*4882a593Smuzhiyun  * non-mouse USB device (e.g., a joystick or gamepad). */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #ifdef HAVE_DMX_CONFIG_H
40*4882a593Smuzhiyun #include <dmx-config.h>
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #include "usb-private.h"
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /*****************************************************************************/
46*4882a593Smuzhiyun /* Define some macros to make it easier to move this file to another
47*4882a593Smuzhiyun  * part of the Xserver tree.  All calls to the dmx* layer are #defined
48*4882a593Smuzhiyun  * here for the .c file.  The .h file will also have to be edited. */
49*4882a593Smuzhiyun #include "dmxinputinit.h"
50*4882a593Smuzhiyun #include "usb-other.h"
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define GETPRIV       myPrivate *priv                            \
53*4882a593Smuzhiyun                       = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #define LOG0(f)       dmxLog(dmxDebug,f)
56*4882a593Smuzhiyun #define LOG1(f,a)     dmxLog(dmxDebug,f,a)
57*4882a593Smuzhiyun #define LOG2(f,a,b)   dmxLog(dmxDebug,f,a,b)
58*4882a593Smuzhiyun #define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c)
59*4882a593Smuzhiyun #define FATAL0(f)     dmxLog(dmxFatal,f)
60*4882a593Smuzhiyun #define FATAL1(f,a)   dmxLog(dmxFatal,f,a)
61*4882a593Smuzhiyun #define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b)
62*4882a593Smuzhiyun #define MOTIONPROC    dmxMotionProcPtr
63*4882a593Smuzhiyun #define ENQUEUEPROC   dmxEnqueueProcPtr
64*4882a593Smuzhiyun #define CHECKPROC     dmxCheckSpecialProcPtr
65*4882a593Smuzhiyun #define BLOCK         DMXBlockType
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /* End of interface definitions. */
68*4882a593Smuzhiyun /*****************************************************************************/
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /** Read the USB device using #usbRead. */
71*4882a593Smuzhiyun void
othUSBRead(DevicePtr pDev,MOTIONPROC motion,ENQUEUEPROC enqueue,CHECKPROC checkspecial,BLOCK block)72*4882a593Smuzhiyun othUSBRead(DevicePtr pDev,
73*4882a593Smuzhiyun            MOTIONPROC motion,
74*4882a593Smuzhiyun            ENQUEUEPROC enqueue, CHECKPROC checkspecial, BLOCK block)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun     usbRead(pDev, motion, enqueue, 0xffff, block);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /** Initialize \a pDev using #usbInit. */
80*4882a593Smuzhiyun void
othUSBInit(DevicePtr pDev)81*4882a593Smuzhiyun othUSBInit(DevicePtr pDev)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun     usbInit(pDev, usbOther);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /** Turn \a pDev on (i.e., take input from \a pDev). */
87*4882a593Smuzhiyun int
othUSBOn(DevicePtr pDev)88*4882a593Smuzhiyun othUSBOn(DevicePtr pDev)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun     GETPRIV;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun     if (priv->fd < 0)
93*4882a593Smuzhiyun         othUSBInit(pDev);
94*4882a593Smuzhiyun     return priv->fd;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /** Fill the \a info structure with information needed to initialize \a
98*4882a593Smuzhiyun  * pDev. */
99*4882a593Smuzhiyun void
othUSBGetInfo(DevicePtr pDev,DMXLocalInitInfoPtr info)100*4882a593Smuzhiyun othUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun     GETPRIV;
103*4882a593Smuzhiyun     int i, j;
104*4882a593Smuzhiyun     static KeySym keyboard_mapping = NoSymbol;
105*4882a593Smuzhiyun     int absolute[5];
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #define test_bit(bit) (priv->mask[(bit)/8] & (1 << ((bit)%8)))
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun     /* Some USB mice devices return key
110*4882a593Smuzhiyun      * events from their pair'd
111*4882a593Smuzhiyun      * keyboard...  */
112*4882a593Smuzhiyun     info->keyClass = 1;
113*4882a593Smuzhiyun     info->keySyms.minKeyCode = 8;
114*4882a593Smuzhiyun     info->keySyms.maxKeyCode = 8;
115*4882a593Smuzhiyun     info->keySyms.mapWidth = 1;
116*4882a593Smuzhiyun     info->keySyms.map = &keyboard_mapping;
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun     for (i = 0; i < EV_MAX; i++) {
119*4882a593Smuzhiyun         if (test_bit(i)) {
120*4882a593Smuzhiyun             switch (i) {
121*4882a593Smuzhiyun             case EV_KEY:
122*4882a593Smuzhiyun                 /* See above */
123*4882a593Smuzhiyun                 break;
124*4882a593Smuzhiyun             case EV_REL:
125*4882a593Smuzhiyun                 info->valuatorClass = 1;
126*4882a593Smuzhiyun                 if (info->numRelAxes + info->numAbsAxes > DMX_MAX_AXES - 1) {
127*4882a593Smuzhiyun                     info->numRelAxes = DMX_MAX_AXES - info->numAbsAxes - 1;
128*4882a593Smuzhiyun                     dmxLog(dmxWarning, "Can only use %d relative axes\n",
129*4882a593Smuzhiyun                            info->numRelAxes);
130*4882a593Smuzhiyun                 }
131*4882a593Smuzhiyun                 else
132*4882a593Smuzhiyun                     info->numRelAxes = priv->numRel;
133*4882a593Smuzhiyun                 info->minval[0] = 0;
134*4882a593Smuzhiyun                 info->maxval[0] = 0;
135*4882a593Smuzhiyun                 info->res[0] = 1;
136*4882a593Smuzhiyun                 info->minres[0] = 0;
137*4882a593Smuzhiyun                 info->maxres[0] = 1;
138*4882a593Smuzhiyun                 break;
139*4882a593Smuzhiyun             case EV_ABS:
140*4882a593Smuzhiyun                 info->valuatorClass = 1;
141*4882a593Smuzhiyun                 if (info->numRelAxes + info->numAbsAxes > DMX_MAX_AXES - 1) {
142*4882a593Smuzhiyun                     info->numAbsAxes = DMX_MAX_AXES - info->numRelAxes - 1;
143*4882a593Smuzhiyun                     dmxLog(dmxWarning, "Can only use %d absolute axes\n",
144*4882a593Smuzhiyun                            info->numAbsAxes);
145*4882a593Smuzhiyun                 }
146*4882a593Smuzhiyun                 else
147*4882a593Smuzhiyun                     info->numAbsAxes = priv->numAbs;
148*4882a593Smuzhiyun                 for (j = 0; j < info->numAbsAxes; j++) {
149*4882a593Smuzhiyun                     ioctl(priv->fd, EVIOCGABS(j), absolute);
150*4882a593Smuzhiyun                     info->minval[1 + j] = absolute[1];
151*4882a593Smuzhiyun                     info->maxval[1 + j] = absolute[2];
152*4882a593Smuzhiyun                     info->res[1 + j] = absolute[3];
153*4882a593Smuzhiyun                     info->minres[1 + j] = absolute[3];
154*4882a593Smuzhiyun                     info->maxres[1 + j] = absolute[3];
155*4882a593Smuzhiyun                 }
156*4882a593Smuzhiyun                 break;
157*4882a593Smuzhiyun             case EV_LED:
158*4882a593Smuzhiyun                 info->ledFeedbackClass = 0;     /* Not supported at this time */
159*4882a593Smuzhiyun                 break;
160*4882a593Smuzhiyun             case EV_SND:
161*4882a593Smuzhiyun                 info->belFeedbackClass = 0;     /* Not supported at this time */
162*4882a593Smuzhiyun                 break;
163*4882a593Smuzhiyun             }
164*4882a593Smuzhiyun         }
165*4882a593Smuzhiyun     }
166*4882a593Smuzhiyun }
167