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