xref: /illumos-gate/usr/src/uts/common/sys/usb/clients/usbms/usbms.h (revision 622200ad88c6c6382403a01985a94e22484baac6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_USB_USBMS_H
28 #define	_SYS_USB_USBMS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 
38 struct usbmouseinfo {
39 	int	mi_x;		/* current X coordinate */
40 	int	mi_y;		/* current Y coordinate */
41 	int	mi_z;		/* current wheel */
42 	int	mi_buttons;	/* current button status */
43 	struct timeval32 mi_time; /* timestamp */
44 };
45 
46 struct usbmousebuf {
47 	ushort_t mb_size;	/* size (in usbmouseinfo units) of buf */
48 	ushort_t mb_off;	/* current offset in buffer */
49 	struct usbmouseinfo *mb_info; /* current usbmouseinfo */
50 };
51 
52 typedef struct usbms_input {
53 	uint_t		xpos;	/* X position in the sample info */
54 	uint_t		xlen;	/* length of X coordinate */
55 	uint_t		xattr;	/* attribute of X coordinate */
56 	uint_t		ypos;	/* Y position in the sample info */
57 	uint_t		ylen;	/* length of Y coordinate */
58 	uint_t		yattr;	/* attribute of Y coordinate */
59 	uint_t		zpos;	/* wheel data position in the sample info */
60 	uint_t		zlen;	/* length of wheel data */
61 	uint_t		zattr;	/* attribute of wheel data */
62 	uint_t		bpos;	/* button data position in the sample info */
63 	uint_t		tlen;	/* length of the sample info */
64 } usbms_idf;
65 
66 typedef struct usbms_state {
67 	queue_t			*usbms_rq_ptr;   /* pointer to read queue */
68 	queue_t			*usbms_wq_ptr;   /* pointer to write queue */
69 
70 	/* Flag for mouse open/qwait status */
71 
72 	int			usbms_flags;
73 
74 	/*
75 	 * Is an ioctl fails because an mblk wasn't
76 	 * available, the mlbk is saved here.
77 	 */
78 
79 	mblk_t			*usbms_iocpending;
80 
81 	/* mouse software structure from msreg.h */
82 
83 	struct ms_softc		usbms_softc;
84 
85 	/* Previous button byte */
86 
87 	char			usbms_oldbutt;
88 
89 
90 	/* Report descriptor handle received from hid */
91 
92 	hidparser_handle_t	usbms_report_descr_handle;
93 
94 	/*
95 	 * Max pixel delta of jitter controlled. As this number increases
96 	 * the jumpiness of the msd increases, i.e., the coarser the motion
97 	 * for mediumm speeds.
98 	 * jitter_thresh is the maximum number of jitters suppressed. Thus,
99 	 * hz/jitter_thresh is the maximum interval of jitters suppressed. As
100 	 * jitter_thresh increases, a wider range of jitter is suppressed.
101 	 * However, the more inertia the mouse seems to have, i.e., the slower
102 	 * the mouse is to react.
103 	 */
104 
105 	int			usbms_jitter_thresh;
106 
107 	/* Timeout used when mstimeout in effect */
108 
109 	clock_t			usbms_jittertimeout;
110 
111 	/*
112 	 * Measure how many (speed_count) msd deltas exceed threshold
113 	 * (speedlimit). If speedlaw then throw away deltas over speedlimit.
114 	 * This is to keep really bad mice that jump around from getting
115 	 * too far.
116 	 */
117 
118 	/* Threshold above which deltas are thrown out */
119 
120 	int		usbms_speedlimit;
121 
122 	int		usbms_speedlaw;	/* Whether to throw away deltas */
123 
124 	/*  No. of deltas exceeding spd. limit */
125 
126 	int		usbms_speed_count;
127 
128 	int		usbms_iocid;	/* ID of "ioctl" being waited for */
129 	short		usbms_state;	/* button state at last sample */
130 	short		usbms_jitter;	/* state counter for input routine */
131 	timeout_id_t	usbms_timeout_id;	/* id returned by timeout() */
132 	bufcall_id_t	usbms_reioctl_id;	/* id returned by bufcall() */
133 	bufcall_id_t	usbms_resched_id;	/* id returned by bufcall() */
134 	int32_t		usbms_num_buttons;	/* No. of buttons */
135 	int32_t		usbms_num_wheels;	/* No. of wheels */
136 	uchar_t		usbms_protoerr;		/* Error set proto */
137 	ushort_t	usbms_wheel_state_bf;	/* Wheel state bit field */
138 	ushort_t	usbms_wheel_orient_bf;	/* Wheel orientation	*/
139 	int32_t		usbms_rptid;		/* Report id of mouse app */
140 	int32_t		usbms_logical_Xmax;	/* X logical maximum */
141 	int32_t		usbms_logical_Ymax;	/* Y logical maximum */
142 
143 	/* Screen resolution for absolute mouse */
144 
145 	Ms_screen_resolution	usbms_resolution;
146 
147 	usbms_idf	usbms_idf;
148 	struct		usbmousebuf *usbms_buf;
149 } usbms_state_t;
150 
151 
152 #define	USBMS_OPEN    0x00000001 /* mouse is open for business */
153 #define	USBMS_QWAIT   0x00000002 /* mouse is waiting for a response */
154 
155 /* Macro to find absolute value */
156 
157 #define	USB_ABS(x)		((x) < 0 ? -(x) : (x))
158 
159 /*
160  * Macro to restrict the value of x to lie between 127 & -127 :
161  * if x > 127 return 127
162  * else if x < -127 return -127
163  * else return x
164  */
165 
166 #define	USB_BYTECLIP(x)	(char)((x) > 127 ? 127 : ((x) < -127 ? -127 : (x)))
167 
168 /*
169  * Default and MAX (supported) number of buttons
170  */
171 
172 #define	USB_MS_DEFAULT_BUTTON_NO	3
173 #define	USB_MS_MAX_BUTTON_NO		8
174 
175 
176 /*
177  * Input routine states. See usbms_input().
178  */
179 #define	USBMS_WAIT_BUTN		0	/* Button byte */
180 #define	USBMS_WAIT_X		1	/* Delta X byte */
181 #define	USBMS_WAIT_Y    	2	/* Delta Y byte */
182 #define	USBMS_WAIT_WHEEL	3	/* Wheel Byte	*/
183 
184 /*
185  * default resolution, 1024x768.
186  */
187 #define	USBMS_DEFAULT_RES_HEIGHT	768
188 #define	USBMS_DEFAULT_RES_WIDTH		1024
189 /*
190  * USB buttons:
191  *		How the device sends it:
192  *		0x01 - Left   button position
193  *		0x02 - Right  button position
194  *		0x04 - Middle button position
195  */
196 
197 
198 #define	USBMS_BUT(i)	1 << (i - 1)
199 
200 /*
201  * These defines are for converting USB button information to the
202  * format that Type 5 mouse sends upstream, which is what the xserver
203  * expects.
204  */
205 
206 #define	USB_NO_BUT_PRESSED	0xFF
207 #define	USB_LEFT_BUT_PRESSED	0xFB
208 #define	USB_RIGHT_BUT_PRESSED	0xFE
209 #define	USB_MIDDLE_BUT_PRESSED	0xFD
210 
211 #define	USB_BUT_PRESSED(i)	~(1 << (i - 1))
212 
213 /*
214  * State structure used for transparent ioctls
215  */
216 
217 typedef struct usbms_iocstate {
218 		int ioc_state;
219 		caddr_t u_addr;
220 } usbms_iocstate_t;
221 
222 /*
223  * Transparent ioctl states
224  */
225 
226 #define	USBMS_GETSTRUCT 1
227 #define	USBMS_GETRESULT	2
228 
229 /*
230  * Private data are initialized to these values
231  */
232 #define	USBMS_JITTER_THRESH	0	/* Max no. of jitters suppressed */
233 #define	USBMS_SPEEDLIMIT	48	/* Threshold for msd deltas */
234 #define	USBMS_SPEEDLAW		0	/* Whether to throw away deltas */
235 #define	USBMS_SPEED_COUNT	0	/* No. of deltas exceeding spd. limit */
236 #define	USBMS_BUF_BYTES		4096	/* Mouse buffer size */
237 #define	USBMS_USAGE_PAGE_BUTTON	0x9	/* Usage Page data value : Button */
238 
239 #define	JITTERRATE		12	/* No of jitters before timeout */
240 
241 /* Jitter Timeout while initialization */
242 #define	JITTER_TIMEOUT		(hz/JITTERRATE)
243 
244 /*
245  * Masks for debug printing
246  */
247 #define	PRINT_MASK_ATTA		0x00000001
248 #define	PRINT_MASK_OPEN 	0x00000002
249 #define	PRINT_MASK_CLOSE	0x00000004
250 #define	PRINT_MASK_SERV		0x00000008
251 #define	PRINT_MASK_IOCTL	0x00000010
252 #define	PRINT_MASK_INPUT_INCR	0x00000020
253 #define	PRINT_MASK_ALL		0xFFFFFFFF
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif	/* _SYS_USB_USBMS_H */
260