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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_USB_USB_AH_H
28 #define	_SYS_USB_USB_AH_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/stream.h>
37 
38 #define	USB_AH_RPT_NUMBER	3
39 
40 #define	USB_AH_INPUT_RPT	0
41 #define	USB_AH_OUTPUT_RPT	1
42 #define	USB_AH_FEATURE_RPT	2
43 
44 /* definitions for various state machines */
45 #define	USB_AH_OPEN	0x00000001 /* audio hid is open for business */
46 #define	USB_AH_QWAIT	0x00000002 /* audio hid is waiting for a response */
47 
48 
49 typedef struct usb_ah_button_descr {
50 	uint_t		location;	/* which byte contains button info */
51 	uint_t		offset;		/* offset of button info */
52 	uint_t		no_of_bits;	/* size of button info */
53 	uint_t		pressed;	/* if this button is pressed or not */
54 	mblk_t		*mblk;		/* mblk for autorepeat feature */
55 	void		*uahp;		/* Back ptr for timeout routine */
56 } usb_ah_button_descr_t;
57 
58 /*
59  * structure for each report type, INPUT, OUTPUT or FEATURE
60  * Note report id 0 and only one collection is handled
61  */
62 
63 typedef struct usb_ah_rpt {
64 	hidparser_rpt_t		hid_rpt;
65 	usb_ah_button_descr_t	button_descr[USAGE_MAX];
66 } usb_ah_rpt_t;
67 
68 /* state structure for usb_ah */
69 typedef struct  usb_ah_state {
70 	queue_t			*usb_ah_readq;		/* read queue */
71 	queue_t			*usb_ah_writeq;		/* write queue */
72 	kmutex_t		usb_ah_mutex;
73 	int			usb_ah_flags;
74 	uint_t			usb_ah_packet_size;	/* size usb packet */
75 	int			usb_ah_uses_report_ids;	/* 1 if rep.ids used */
76 	int			usb_ah_report_id;	/* report id used by */
77 							/* the device */
78 
79 	/* timeout id for re-trigger ctrl */
80 
81 	timeout_id_t		usb_ah_tid;
82 
83 	/* Button descr. ptr to the currently pressed autorepeating button */
84 
85 	usb_ah_button_descr_t	*usb_ah_cur_bd;
86 
87 	/* Pointer to the parser handle */
88 
89 	hidparser_handle_t	usb_ah_report_descr;
90 	usb_ah_rpt_t		usb_ah_report[USB_AH_RPT_NUMBER];
91 } usb_ah_state_t;
92 
93 /*
94  * Only variable tid is protected by the mutex, all other r/w happens in
95  * streams and callback context, thereby ensuring that they are protected
96  * by the scheme
97  */
98 _NOTE(MUTEX_PROTECTS_DATA(usb_ah_state_t::usb_ah_mutex, usb_ah_state_t))
99 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_readq))
100 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_flags))
101 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_tid))
102 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_writeq))
103 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
104 			usb_ah_state_t::usb_ah_packet_size))
105 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
106 			usb_ah_state_t::usb_ah_uses_report_ids))
107 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
108 			usb_ah_state_t::usb_ah_report_id))
109 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
110 			usb_ah_state_t::usb_ah_report_descr))
111 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
112 			usb_ah_state_t::usb_ah_cur_bd))
113 _NOTE(SCHEME_PROTECTS_DATA("unique per call",
114 			usb_ah_state_t::usb_ah_report))
115 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_button_descr_t))
116 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_rpt_t))
117 _NOTE(SCHEME_PROTECTS_DATA("unique per call", hidparser_rpt_t))
118 _NOTE(SCHEME_PROTECTS_DATA("unique per call", hidparser_usage_info_t))
119 
120 #define	USB_AH_TIMEOUT		50000	/* In usec */
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif	/* _SYS_USB_USB_AH_H */
127