xref: /titanic_41/usr/src/uts/common/sys/usb/clients/audio/usb_as/usb_as.h (revision 643918928169438203a594dfc3fc1b3e9afe5ba3)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_USB_AS_H
27 #define	_SYS_USB_AS_H
28 
29 
30 #include <sys/usb/usba/usbai_private.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* driver specific macros */
37 #define	USB_AS_HIWATER		(AM_MAX_QUEUED_MSGS_SIZE)
38 #define	USB_AS_LOWATER		(32*1024)
39 
40 
41 /* this structure is built from the descriptors */
42 typedef struct usb_as_alt_descr {
43 	uchar_t				alt_mode; /* USB_AUDIO_PLAY/RECORD */
44 	uchar_t				alt_valid;
45 	uchar_t				alt_format_len;
46 
47 	uchar_t				alt_n_sample_rates;
48 	uint_t				*alt_sample_rates;
49 	uint_t				alt_continuous_sr;
50 
51 	usb_if_descr_t			*alt_if;
52 	usb_audio_as_if_descr_t 	*alt_general;
53 	usb_audio_type1_format_descr_t	*alt_format;
54 	usb_ep_descr_t			*alt_ep;
55 	usb_audio_as_isoc_ep_descr_t	*alt_cs_ep;
56 } usb_as_alt_descr_t;
57 
58 
59 typedef struct usb_as_power {
60 	void		*aspm_state;	/* points back to usb_as_state */
61 	int		aspm_pm_busy;	/* device busy accounting */
62 	uint8_t		aspm_wakeup_enabled;
63 
64 	/* this is the bit mask of the power states that device has */
65 	uint8_t		aspm_pwr_states;
66 
67 	/* wakeup and power transistion capabilites of an interface */
68 	uint8_t		aspm_capabilities;
69 
70 	/* current power level the device is in */
71 	uint8_t		aspm_current_power;
72 } usb_as_power_t;
73 
74 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_state))
75 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_wakeup_enabled))
76 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_pwr_states))
77 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_capabilities))
78 _NOTE(SCHEME_PROTECTS_DATA("unshared", usb_ctrl_req))
79 
80 
81 /* usb_as soft state */
82 typedef struct usb_as_state {
83 	dev_info_t		*usb_as_dip;
84 	uint_t			usb_as_instance;
85 	usb_log_handle_t	usb_as_log_handle;
86 	uint_t			usb_as_dev_state;
87 	uint_t			usb_as_ifno;
88 	kmutex_t		usb_as_mutex;
89 	kcondvar_t		usb_as_pipe_cv;
90 
91 
92 	uint_t			usb_as_flag;		/* status */
93 
94 	/* mblk containing the current control command */
95 	mblk_t			*usb_as_def_mblk;
96 
97 	/* serialization */
98 	usb_serialization_t	usb_as_ser_acc;
99 
100 	/* registration data */
101 	usb_client_dev_data_t	*usb_as_dev_data;
102 
103 	/* info from descriptors per alternate */
104 	uint_t			usb_as_n_alternates;
105 	usb_as_alt_descr_t	*usb_as_alts;
106 	uint_t			usb_as_alternate;
107 
108 	/* pipe handle */
109 	usb_pipe_handle_t	usb_as_default_ph;
110 
111 	/* See below for flags */
112 	uchar_t			usb_as_xfer_cr;
113 
114 	/* Isoc pipe stuff */
115 	usb_pipe_handle_t	usb_as_isoc_ph;
116 	usb_pipe_policy_t	usb_as_isoc_pp;
117 	void *		usb_as_ahdl;
118 
119 	uint_t			usb_as_request_count;
120 	uint_t			usb_as_request_samples;
121 	uint_t			usb_as_curr_sr;
122 	usb_audio_formats_t	usb_as_curr_format;
123 
124 	uint_t			usb_as_pkt_count;
125 	ushort_t		usb_as_record_pkt_size;
126 
127 	uchar_t			usb_as_audio_state;
128 	uchar_t			usb_as_setup_cnt;
129 
130 	usb_as_power_t		*usb_as_pm; /* power capabilities */
131 
132 	/* registration data */
133 	usb_as_registration_t	usb_as_reg;
134 
135 	/* debug support */
136 	uint_t			usb_as_send_debug_count;
137 	uint_t			usb_as_rcv_debug_count;
138 	char			dstr[64];
139 } usb_as_state_t;
140 
141 /* warlock directives, stable data */
142 _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_state_t))
143 _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_power_t))
144 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dip))
145 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_pm))
146 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_instance))
147 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_default_ph))
148 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_isoc_ph))
149 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_log_handle))
150 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dev_data))
151 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_ser_acc))
152 
153 typedef struct usb_as_tq_arg {
154 	usb_as_state_t	*usb_as_tq_arg_statep;
155 	int		usb_as_tq_arg_cr;
156 } usb_as_tq_arg_t;
157 
158 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_as_tq_arg_t))
159 
160 
161 /* Default pipe states */
162 #define	USB_AS_DEF_AVAILABLE	0
163 #define	USB_AS_DEF_INUSE	1
164 #define	USB_AS_DEF_UNAVAILABLE	2
165 
166 
167 /*
168  * If a command has been initiated, the close callback should know
169  * how it finished. If there has been an error and ex cb initiaited
170  * the async pipe close, an M_ERROR should be sent up. If no error and
171  * default xfer cb had initiated close, M_CTL should be sent up. In
172  * some other cases, close callback may not send anything up.
173  */
174 #define	USB_AS_SEND_MERR	1
175 #define	USB_AS_SEND_MCTL	2
176 #define	USB_AS_SEND_NONE	3
177 
178 
179 /*
180  * States of playing/recording flag
181  */
182 #define	USB_AS_IDLE			0
183 #define	USB_AS_ACTIVE			1
184 #define	USB_AS_PLAY_PAUSED		2
185 #define	USB_AS_STOP_POLLING_STARTED	3
186 
187 /*
188  * Define constants needed for isoc transfer
189  */
190 #define	USB_AS_N_FRAMES			8
191 #define	USB_AS_MAX_REQUEST_COUNT	3
192 
193 /*
194  * usb_as turns the M_CTL request into a request control request on the
195  * default pipe.  usb_as needs the following information in the usb_as_req_t
196  * structure.  See the details below for specific values for each command.
197  */
198 typedef struct usb_as_req {
199 	uint16_t	usb_as_req_wValue;	/* wValue field of request */
200 	uint16_t	usb_as_req_wIndex;	/* wIndex field of request */
201 	uint16_t	usb_as_req_wLength;	/* wLength of request */
202 	mblk_t		*usb_as_req_data;	/* data for send case */
203 } usb_as_req_t;
204 
205 
206 /* status */
207 #define	USB_AS_OPEN		1
208 #define	USB_AS_DISMANTLING	2
209 
210 #define	USB_AS_BUFFER_SIZE		256	/* descriptor buffer size */
211 
212 /* minor node */
213 #define	USB_AS_CONSTRUCT_MINOR(inst)	(inst)
214 #define	USB_AS_MINOR_TO_INSTANCE(inst)	(inst)
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif	/* _SYS_USB_AS_H */
221