17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Common Development and Distribution License (the "License").
6d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2288447a05SGarrett D'Amore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_USB_AS_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_AS_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /* driver specific macros */
377c478bd9Sstevel@tonic-gate #define	USB_AS_HIWATER		(AM_MAX_QUEUED_MSGS_SIZE)
387c478bd9Sstevel@tonic-gate #define	USB_AS_LOWATER		(32*1024)
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /* this structure is built from the descriptors */
427c478bd9Sstevel@tonic-gate typedef struct usb_as_alt_descr {
437c478bd9Sstevel@tonic-gate 	uchar_t				alt_mode; /* USB_AUDIO_PLAY/RECORD */
447c478bd9Sstevel@tonic-gate 	uchar_t				alt_valid;
457c478bd9Sstevel@tonic-gate 	uchar_t				alt_format_len;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate 	uchar_t				alt_n_sample_rates;
487c478bd9Sstevel@tonic-gate 	uint_t				*alt_sample_rates;
497c478bd9Sstevel@tonic-gate 	uint_t				alt_continuous_sr;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	usb_if_descr_t			*alt_if;
527c478bd9Sstevel@tonic-gate 	usb_audio_as_if_descr_t 	*alt_general;
537c478bd9Sstevel@tonic-gate 	usb_audio_type1_format_descr_t	*alt_format;
547c478bd9Sstevel@tonic-gate 	usb_ep_descr_t			*alt_ep;
557c478bd9Sstevel@tonic-gate 	usb_audio_as_isoc_ep_descr_t	*alt_cs_ep;
567c478bd9Sstevel@tonic-gate } usb_as_alt_descr_t;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct usb_as_power {
607c478bd9Sstevel@tonic-gate 	void		*aspm_state;	/* points back to usb_as_state */
617c478bd9Sstevel@tonic-gate 	int		aspm_pm_busy;	/* device busy accounting */
627c478bd9Sstevel@tonic-gate 	uint8_t		aspm_wakeup_enabled;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
657c478bd9Sstevel@tonic-gate 	uint8_t		aspm_pwr_states;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/* wakeup and power transistion capabilites of an interface */
687c478bd9Sstevel@tonic-gate 	uint8_t		aspm_capabilities;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	/* current power level the device is in */
717c478bd9Sstevel@tonic-gate 	uint8_t		aspm_current_power;
727c478bd9Sstevel@tonic-gate } usb_as_power_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_state))
757c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_wakeup_enabled))
767c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_pwr_states))
777c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_capabilities))
787c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared", usb_ctrl_req))
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* usb_as soft state */
827c478bd9Sstevel@tonic-gate typedef struct usb_as_state {
837c478bd9Sstevel@tonic-gate 	dev_info_t		*usb_as_dip;
847c478bd9Sstevel@tonic-gate 	uint_t			usb_as_instance;
857c478bd9Sstevel@tonic-gate 	usb_log_handle_t	usb_as_log_handle;
867c478bd9Sstevel@tonic-gate 	uint_t			usb_as_dev_state;
877c478bd9Sstevel@tonic-gate 	uint_t			usb_as_ifno;
887c478bd9Sstevel@tonic-gate 	kmutex_t		usb_as_mutex;
89e272e4c8SBinzi Cao - Sun Microsystems - Beijing China 	kcondvar_t		usb_as_pipe_cv;
90e272e4c8SBinzi Cao - Sun Microsystems - Beijing China 
91e272e4c8SBinzi Cao - Sun Microsystems - Beijing China 
9288447a05SGarrett D'Amore 	uint_t			usb_as_flag;		/* status */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	/* mblk containing the current control command */
957c478bd9Sstevel@tonic-gate 	mblk_t			*usb_as_def_mblk;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	/* serialization */
987c478bd9Sstevel@tonic-gate 	usb_serialization_t	usb_as_ser_acc;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/* registration data */
1017c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*usb_as_dev_data;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	/* info from descriptors per alternate */
1047c478bd9Sstevel@tonic-gate 	uint_t			usb_as_n_alternates;
1057c478bd9Sstevel@tonic-gate 	usb_as_alt_descr_t	*usb_as_alts;
1067c478bd9Sstevel@tonic-gate 	uint_t			usb_as_alternate;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/* pipe handle */
1097c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	usb_as_default_ph;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	/* See below for flags */
1127c478bd9Sstevel@tonic-gate 	uchar_t			usb_as_xfer_cr;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	/* Isoc pipe stuff */
1157c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	usb_as_isoc_ph;
1167c478bd9Sstevel@tonic-gate 	usb_pipe_policy_t	usb_as_isoc_pp;
117e272e4c8SBinzi Cao - Sun Microsystems - Beijing China 	void *		usb_as_ahdl;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	uint_t			usb_as_request_count;
1207c478bd9Sstevel@tonic-gate 	uint_t			usb_as_request_samples;
121*64391892SAlbert Lee 	uint_t			usb_as_curr_sr;
1227c478bd9Sstevel@tonic-gate 	usb_audio_formats_t	usb_as_curr_format;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	uint_t			usb_as_pkt_count;
1257c478bd9Sstevel@tonic-gate 	ushort_t		usb_as_record_pkt_size;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	uchar_t			usb_as_audio_state;
1287c478bd9Sstevel@tonic-gate 	uchar_t			usb_as_setup_cnt;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	usb_as_power_t		*usb_as_pm; /* power capabilities */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	/* registration data */
1337c478bd9Sstevel@tonic-gate 	usb_as_registration_t	usb_as_reg;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/* debug support */
1367c478bd9Sstevel@tonic-gate 	uint_t			usb_as_send_debug_count;
1377c478bd9Sstevel@tonic-gate 	uint_t			usb_as_rcv_debug_count;
13888447a05SGarrett D'Amore 	char			dstr[64];
1397c478bd9Sstevel@tonic-gate } usb_as_state_t;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /* warlock directives, stable data */
1427c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_state_t))
1437c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_power_t))
1447c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dip))
1457c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_pm))
1467c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_instance))
1477c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_default_ph))
1487c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_isoc_ph))
1497c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_log_handle))
1507c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dev_data))
1517c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_ser_acc))
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate typedef struct usb_as_tq_arg {
1547c478bd9Sstevel@tonic-gate 	usb_as_state_t	*usb_as_tq_arg_statep;
1557c478bd9Sstevel@tonic-gate 	int		usb_as_tq_arg_cr;
1567c478bd9Sstevel@tonic-gate } usb_as_tq_arg_t;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_as_tq_arg_t))
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /* Default pipe states */
1627c478bd9Sstevel@tonic-gate #define	USB_AS_DEF_AVAILABLE	0
1637c478bd9Sstevel@tonic-gate #define	USB_AS_DEF_INUSE	1
1647c478bd9Sstevel@tonic-gate #define	USB_AS_DEF_UNAVAILABLE	2
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * If a command has been initiated, the close callback should know
1697c478bd9Sstevel@tonic-gate  * how it finished. If there has been an error and ex cb initiaited
1707c478bd9Sstevel@tonic-gate  * the async pipe close, an M_ERROR should be sent up. If no error and
1717c478bd9Sstevel@tonic-gate  * default xfer cb had initiated close, M_CTL should be sent up. In
1727c478bd9Sstevel@tonic-gate  * some other cases, close callback may not send anything up.
1737c478bd9Sstevel@tonic-gate  */
1747c478bd9Sstevel@tonic-gate #define	USB_AS_SEND_MERR	1
1757c478bd9Sstevel@tonic-gate #define	USB_AS_SEND_MCTL	2
1767c478bd9Sstevel@tonic-gate #define	USB_AS_SEND_NONE	3
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * States of playing/recording flag
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate #define	USB_AS_IDLE			0
1837c478bd9Sstevel@tonic-gate #define	USB_AS_ACTIVE			1
1847c478bd9Sstevel@tonic-gate #define	USB_AS_PLAY_PAUSED		2
1857c478bd9Sstevel@tonic-gate #define	USB_AS_STOP_POLLING_STARTED	3
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Define constants needed for isoc transfer
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate #define	USB_AS_N_FRAMES			8
1917c478bd9Sstevel@tonic-gate #define	USB_AS_MAX_REQUEST_COUNT	3
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * usb_as turns the M_CTL request into a request control request on the
1957c478bd9Sstevel@tonic-gate  * default pipe.  usb_as needs the following information in the usb_as_req_t
1967c478bd9Sstevel@tonic-gate  * structure.  See the details below for specific values for each command.
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate typedef struct usb_as_req {
1997c478bd9Sstevel@tonic-gate 	uint16_t	usb_as_req_wValue;	/* wValue field of request */
2007c478bd9Sstevel@tonic-gate 	uint16_t	usb_as_req_wIndex;	/* wIndex field of request */
2017c478bd9Sstevel@tonic-gate 	uint16_t	usb_as_req_wLength;	/* wLength of request */
2027c478bd9Sstevel@tonic-gate 	mblk_t		*usb_as_req_data;	/* data for send case */
2037c478bd9Sstevel@tonic-gate } usb_as_req_t;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 
20688447a05SGarrett D'Amore /* status */
20788447a05SGarrett D'Amore #define	USB_AS_OPEN		1
20888447a05SGarrett D'Amore #define	USB_AS_DISMANTLING	2
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #define	USB_AS_BUFFER_SIZE		256	/* descriptor buffer size */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* minor node */
2137c478bd9Sstevel@tonic-gate #define	USB_AS_CONSTRUCT_MINOR(inst)	(inst)
2147c478bd9Sstevel@tonic-gate #define	USB_AS_MINOR_TO_INSTANCE(inst)	(inst)
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate #endif
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_AS_H */
221