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