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
5*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Common Development and Distribution License (the "License").
6*d29f5a71Szhigang 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 /*
22*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Copyright 2008 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_USB_AH_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_USB_AH_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/stream.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define	USB_AH_RPT_NUMBER	3
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	USB_AH_INPUT_RPT	0
397c478bd9Sstevel@tonic-gate #define	USB_AH_OUTPUT_RPT	1
407c478bd9Sstevel@tonic-gate #define	USB_AH_FEATURE_RPT	2
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* definitions for various state machines */
437c478bd9Sstevel@tonic-gate #define	USB_AH_OPEN	0x00000001 /* audio hid is open for business */
447c478bd9Sstevel@tonic-gate #define	USB_AH_QWAIT	0x00000002 /* audio hid is waiting for a response */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate typedef struct usb_ah_button_descr {
487c478bd9Sstevel@tonic-gate 	uint_t		location;	/* which byte contains button info */
497c478bd9Sstevel@tonic-gate 	uint_t		offset;		/* offset of button info */
507c478bd9Sstevel@tonic-gate 	uint_t		no_of_bits;	/* size of button info */
517c478bd9Sstevel@tonic-gate 	uint_t		pressed;	/* if this button is pressed or not */
527c478bd9Sstevel@tonic-gate 	mblk_t		*mblk;		/* mblk for autorepeat feature */
537c478bd9Sstevel@tonic-gate 	void		*uahp;		/* Back ptr for timeout routine */
547c478bd9Sstevel@tonic-gate } usb_ah_button_descr_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * structure for each report type, INPUT, OUTPUT or FEATURE
587c478bd9Sstevel@tonic-gate  * Note report id 0 and only one collection is handled
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate typedef struct usb_ah_rpt {
627c478bd9Sstevel@tonic-gate 	hidparser_rpt_t		hid_rpt;
637c478bd9Sstevel@tonic-gate 	usb_ah_button_descr_t	button_descr[USAGE_MAX];
647c478bd9Sstevel@tonic-gate } usb_ah_rpt_t;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /* state structure for usb_ah */
677c478bd9Sstevel@tonic-gate typedef struct  usb_ah_state {
687c478bd9Sstevel@tonic-gate 	queue_t			*usb_ah_readq;		/* read queue */
697c478bd9Sstevel@tonic-gate 	queue_t			*usb_ah_writeq;		/* write queue */
707c478bd9Sstevel@tonic-gate 	kmutex_t		usb_ah_mutex;
717c478bd9Sstevel@tonic-gate 	int			usb_ah_flags;
727c478bd9Sstevel@tonic-gate 	uint_t			usb_ah_packet_size;	/* size usb packet */
737c478bd9Sstevel@tonic-gate 	int			usb_ah_uses_report_ids;	/* 1 if rep.ids used */
747c478bd9Sstevel@tonic-gate 	int			usb_ah_report_id;	/* report id used by */
757c478bd9Sstevel@tonic-gate 							/* the device */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	/* timeout id for re-trigger ctrl */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	timeout_id_t		usb_ah_tid;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/* Button descr. ptr to the currently pressed autorepeating button */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	usb_ah_button_descr_t	*usb_ah_cur_bd;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/* Pointer to the parser handle */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	hidparser_handle_t	usb_ah_report_descr;
887c478bd9Sstevel@tonic-gate 	usb_ah_rpt_t		usb_ah_report[USB_AH_RPT_NUMBER];
897c478bd9Sstevel@tonic-gate } usb_ah_state_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Only variable tid is protected by the mutex, all other r/w happens in
937c478bd9Sstevel@tonic-gate  * streams and callback context, thereby ensuring that they are protected
947c478bd9Sstevel@tonic-gate  * by the scheme
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usb_ah_state_t::usb_ah_mutex, usb_ah_state_t))
977c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_readq))
987c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_flags))
997c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_tid))
1007c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_state_t::usb_ah_writeq))
1017c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1027c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_packet_size))
1037c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1047c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_uses_report_ids))
1057c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1067c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_report_id))
1077c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1087c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_report_descr))
1097c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1107c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_cur_bd))
1117c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call",
1127c478bd9Sstevel@tonic-gate 			usb_ah_state_t::usb_ah_report))
1137c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_button_descr_t))
1147c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ah_rpt_t))
1157c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", hidparser_rpt_t))
1167c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", hidparser_usage_info_t))
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	USB_AH_TIMEOUT		50000	/* In usec */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate #endif
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_USB_AH_H */
125