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