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_AC_H
28 #define	_SYS_USB_AC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <sys/sunldi.h>
38 #include <sys/usb/usba/usbai_private.h>
39 
40 /* driver specific macros */
41 #define	USB_AC_HIWATER		(AM_MAX_QUEUED_MSGS_SIZE)
42 #define	USB_AC_LOWATER		(32*1024)
43 
44 
45 /* structure for each unit described by descriptors */
46 typedef struct usb_ac_unit_list {
47 	uint_t		acu_type;
48 	void		*acu_descriptor;
49 	size_t		acu_descr_length;
50 } usb_ac_unit_list_t;
51 
52 #define	USB_AC_ID_NONE			0
53 
54 #define	USB_AC_FIND_ONE			0
55 #define	USB_AC_FIND_ALL			1
56 #define	USB_AC_MAX_DEPTH		8
57 
58 /*
59  * plumbing data; info per plumbed module
60  */
61 typedef struct usb_ac_plumbed {
62 	dev_info_t	*acp_dip;	/* devinfo pointer */
63 	uint_t		acp_ifno;	/* interface number */
64 	int		acp_linkid;	/* link ID for plumbing */
65 	int		acp_driver;	/* Plumbed driver, see value below */
66 	queue_t		*acp_lrq;	/* lower read queue */
67 	queue_t		*acp_lwq;	/* lower write queue */
68 	void		*acp_data;	/* ptr to streams or hid data */
69 } usb_ac_plumbed_t;
70 
71 
72 /*
73  * request structure to usb_as: info per MCTL request;
74  * only one active at a time.
75  */
76 typedef struct usb_ac_to_as_req {
77 	int		acr_wait_flag;	/* an mblk sent wait on this flag */
78 	kcondvar_t	acr_cv;		/* an mblk sent; wait on this cv */
79 	mblk_t		*acr_reply_mp;	/* response to current request */
80 	usb_audio_formats_t acr_curr_format; /* format data from mixer */
81 	int		acr_curr_dir;
82 } usb_ac_to_as_req_t;
83 
84 
85 /* registration and plumbing info per streaming interface */
86 typedef struct usb_ac_streams_info {
87 					/* ptr to entry in plumbed list */
88 	usb_ac_plumbed_t *acs_plumbed;
89 					/* valid registration data rcvd */
90 	uint_t		acs_rcvd_reg_data;
91 					/* pointer to registration data */
92 	usb_as_registration_t *acs_streams_reg;
93 
94 	/* request structure to usb_as; one active at a time */
95 	usb_ac_to_as_req_t acs_ac_to_as_req;
96 
97 	/* Multiple command management */
98 	int		acs_setup_teardown_count;
99 
100 	usb_audio_formats_t acs_cur_fmt; /* format data from mixer */
101 } usb_ac_streams_info_t;
102 
103 
104 /* power state */
105 typedef struct usb_ac_power {
106 	void		*acpm_state;	/* points back to usb_ac_state */
107 	int		acpm_pm_busy;	/* device busy accounting */
108 	uint8_t		acpm_wakeup_enabled;
109 
110 	/* this is the bit mask of the power states that device has */
111 	uint8_t		acpm_pwr_states;
112 
113 	/* wakeup and power transistion capabilites of an interface */
114 	uint8_t		acpm_capabilities;
115 
116 	/* current power level the device is in */
117 	uint8_t		acpm_current_power;
118 } usb_ac_power_t;
119 
120 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_power_t::acpm_state))
121 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_power_t::acpm_wakeup_enabled))
122 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_power_t::acpm_pwr_states))
123 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_power_t::acpm_capabilities))
124 
125 /* limits */
126 #define	USB_AC_MAX_PLUMBED		3	/* play, record, hid */
127 #define	USB_AC_MAX_AS_PLUMBED		2	/* play, record */
128 
129 /* usb_ac soft state */
130 typedef struct usb_ac_state {
131 	dev_info_t		*usb_ac_dip;
132 	uint_t			usb_ac_instance;
133 	usb_log_handle_t	usb_ac_log_handle;
134 
135 	uint_t			usb_ac_dev_state;
136 	uint_t			usb_ac_ifno;
137 	kmutex_t		usb_ac_mutex;
138 
139 	usb_client_dev_data_t	*usb_ac_dev_data; /* registration data */
140 
141 	/* audio framework */
142 	audiohdl_t		usb_ac_audiohdl;
143 	am_ad_info_t		usb_ac_am_ad_info;
144 	audio_info_t		usb_ac_am_ad_defaults;
145 
146 	/* descriptors */
147 	usb_if_descr_t		usb_ac_if_descr;
148 
149 	/* unit number array, indexed by unit ID */
150 	uint_t			usb_ac_max_unit;
151 	usb_ac_unit_list_t	*usb_ac_units;
152 
153 	/* adjacency matrix for reflecting connections */
154 	uchar_t			**usb_ac_connections;
155 	size_t			usb_ac_connections_len;
156 	uchar_t			*usb_ac_connections_a;
157 	size_t			usb_ac_connections_a_len;
158 	uchar_t			*usb_ac_unit_type;
159 	uchar_t			*usb_ac_traverse_path;
160 	uchar_t			usb_ac_traverse_path_index;
161 
162 	/* port types, eg LINE IN, Micr, Speakers */
163 	uint_t			usb_ac_input_ports;
164 	uint_t			usb_ac_output_ports;
165 
166 	/* pipe handle */
167 	usb_pipe_handle_t	usb_ac_default_ph;
168 
169 	/* streams management */
170 	queue_t			*usb_ac_rq;		/* read q ptr */
171 	queue_t			*usb_ac_wq;		/* write q ptr */
172 	dev_t			usb_ac_dev;	/* dev_t of plumbing open */
173 
174 	/* serial access */
175 	usb_serialization_t	usb_ac_ser_acc;
176 
177 	/* power management */
178 	usb_ac_power_t		*usb_ac_pm; /* power capabilities */
179 
180 	/* mixer registration data */
181 	uint_t			usb_ac_mixer_mode_enable;
182 	uint_t			usb_ac_registered_with_mixer;
183 
184 	/* plumbing management */
185 	int			usb_ac_mux_minor;
186 	uint_t			usb_ac_plumbing_state;
187 	ldi_handle_t		usb_ac_mux_lh;
188 	ushort_t		usb_ac_busy_count;
189 	usb_ac_plumbed_t	usb_ac_plumbed[USB_AC_MAX_PLUMBED];
190 
191 	/* Current plumbed module index to usb_ac_plumbed structure */
192 	int			usb_ac_current_plumbed_index;
193 
194 	/* per streams interface info */
195 	usb_ac_streams_info_t	usb_ac_streams[USB_AC_MAX_AS_PLUMBED];
196 
197 	/*
198 	 * preserve streams registration because the mixer does not
199 	 * copy registration data
200 	 */
201 	usb_as_registration_t	usb_ac_streams_reg[USB_AC_MAX_AS_PLUMBED];
202 } usb_ac_state_t;
203 
204 typedef struct usb_ac_state_space {
205 	void			*sp;	/* soft state for the instance */
206 				/* ptr to usb_ac_restore_audio_state */
207 	int			(*restore_func)
208 					(usb_ac_state_t *, int);
209 				/* ptr to usb_ac_get_featureID */
210 	uint_t			(* get_featureID_func)
211 					(usb_ac_state_t *, uchar_t,
212 					uint_t, uint_t);
213 				/* ptr to the usb_ac entry points */
214 	am_ad_entry_t		*ac_entryp;
215 				/* ptr to pm_busy/idle calls */
216 	void			(*pm_busy_component)
217 					(usb_ac_state_t *);
218 	void			(*pm_idle_component)
219 					(usb_ac_state_t *);
220 } usb_ac_state_space_t;
221 
222 /* warlock directives, stable data */
223 _NOTE(MUTEX_PROTECTS_DATA(usb_ac_state_t::usb_ac_mutex, usb_ac_state_t))
224 _NOTE(MUTEX_PROTECTS_DATA(usb_ac_state_t::usb_ac_mutex, usb_ac_power_t))
225 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_dip))
226 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_ser_acc))
227 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_pm))
228 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_instance))
229 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_default_ph))
230 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_log_handle))
231 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_if_descr))
232 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_audiohdl))
233 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_dev_data))
234 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_ac_state_t::usb_ac_ifno))
235 
236 /* usb_ac driver only care about two states:  plumbed or unplumbed */
237 #define	USB_AC_STATE_UNPLUMBED		0
238 #define	USB_AC_STATE_PLUMBED		1
239 #define	USB_AC_STATE_PLUMBED_RESTORING	2
240 
241 /* Default pipe states */
242 #define	USB_AC_DEF_CLOSED		0
243 #define	USB_AC_DEF_OPENED		1
244 
245 #define	USB_AC_BUFFER_SIZE		256	/* descriptor buffer size */
246 
247 
248 /*
249  * delay before restoring state
250  */
251 #define	USB_AC_RESTORE_DELAY		drv_usectohz(1000000)
252 
253 /* value for acp_driver */
254 #define	USB_AS_PLUMBED	1
255 #define	USB_AH_PLUMBED	2
256 #define	UNKNOWN_PLUMBED	3
257 
258 /* other useful macros */
259 #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif	/* _SYS_USB_AC_H */
266