xref: /openbsd-src/sys/dev/usb/umidivar.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: umidivar.h,v 1.12 2008/06/26 05:42:19 ray Exp $ */
2 /*	$NetBSD: umidivar.h,v 1.5 2002/09/12 21:00:42 augustss Exp $	*/
3 /*
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Takuya SHIOZAKI (tshiozak@netbsd.org).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #define UMIDI_PACKET_SIZE 4
33 struct umidi_packet {
34 	unsigned	status;
35 	unsigned	index;
36 	unsigned char	buf[UMIDI_PACKET_SIZE];		/* common/voice packet */
37 };
38 
39 /*
40  * hierarchie
41  *
42  * <-- parent	       child -->
43  *
44  * umidi(sc) -> endpoint -> jack   <- (dynamically assignable) - mididev
45  *	   ^	 |    ^	    |
46  *	   +-----+    +-----+
47  */
48 
49 /* midi device */
50 struct umidi_mididev {
51 	struct umidi_softc	*sc;
52 	struct device		*mdev;
53 	/* */
54 	struct umidi_jack	*in_jack;
55 	struct umidi_jack	*out_jack;
56 	/* */
57 	int			opened;
58 	int			flags;
59 };
60 
61 /* Jack Information */
62 struct umidi_jack {
63 	struct umidi_endpoint	*endpoint;
64 	/* */
65 	int			cable_number;
66 	struct umidi_packet	packet;
67 	void			*arg;
68 	int			binded;
69 	int			opened;
70 	SIMPLEQ_ENTRY(umidi_jack) intrq_entry;
71 #ifdef DIAGNOSTIC
72 	unsigned 		wait;
73 #endif
74 	union {
75 		struct {
76 			void				(*intr)(void *);
77 		} out;
78 		struct {
79 			void				(*intr)(void *, int);
80 		} in;
81 	} u;
82 };
83 
84 #define UMIDI_MAX_EPJACKS	16
85 /* endpoint data */
86 struct umidi_endpoint {
87 	struct umidi_softc	*sc;
88 	/* */
89 	int			addr;
90 	usbd_pipe_handle	pipe;
91 	usbd_xfer_handle	xfer;
92 	unsigned char		*buffer;
93 	unsigned		packetsize;
94 	int			num_open;
95 	int			num_jacks;
96 	struct umidi_jack	*jacks[UMIDI_MAX_EPJACKS];
97 	unsigned		used;
98 	unsigned		busy;
99 	unsigned 		pending;
100 	SIMPLEQ_HEAD(, umidi_jack) intrq;
101 };
102 
103 /* software context */
104 struct umidi_softc {
105 	struct device		sc_dev;
106 	usbd_device_handle	sc_udev;
107 	usbd_interface_handle	sc_iface;
108 	struct umidi_quirk	*sc_quirk;
109 
110 	int			sc_dying;
111 
112 	int			sc_out_num_jacks;
113 	struct umidi_jack	*sc_out_jacks;
114 	int			sc_in_num_jacks;
115 	struct umidi_jack	*sc_in_jacks;
116 	struct umidi_jack	*sc_jacks;
117 
118 	int			sc_num_mididevs;
119 	struct umidi_mididev	*sc_mididevs;
120 
121 	int			sc_out_num_endpoints;
122 	struct umidi_endpoint	*sc_out_ep;
123 	int			sc_in_num_endpoints;
124 	struct umidi_endpoint	*sc_in_ep;
125 	struct umidi_endpoint	*sc_endpoints;
126 };
127