xref: /openbsd/sys/dev/usb/umidivar.h (revision 4b1a56af)
1 /*	$OpenBSD: umidivar.h,v 1.17 2022/01/09 05:43:01 jsg 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  * hierarchy
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 	unsigned 		intr;
72 	union {
73 		struct {
74 			void				(*intr)(void *);
75 		} out;
76 		struct {
77 			void				(*intr)(void *, int);
78 		} in;
79 	} u;
80 };
81 
82 #define UMIDI_MAX_EPJACKS	16
83 /* endpoint data */
84 struct umidi_endpoint {
85 	struct umidi_softc	*sc;
86 	/* */
87 	int			addr;
88 	struct usbd_pipe	*pipe;
89 	struct usbd_xfer	*xfer;
90 	unsigned char		*buffer;
91 	unsigned		packetsize;
92 	int			num_open;
93 	int			num_jacks;
94 	struct umidi_jack	*jacks[UMIDI_MAX_EPJACKS];
95 	unsigned		used;
96 	unsigned		busy;
97 	unsigned 		pending;
98 	SIMPLEQ_HEAD(, umidi_jack) intrq;
99 };
100 
101 /* software context */
102 struct umidi_softc {
103 	struct device		sc_dev;
104 	struct usbd_device	*sc_udev;
105 	struct usbd_interface	*sc_iface;
106 	struct umidi_quirk	*sc_quirk;
107 
108 	int			sc_out_num_jacks;
109 	struct umidi_jack	*sc_out_jacks;
110 	int			sc_in_num_jacks;
111 	struct umidi_jack	*sc_in_jacks;
112 	struct umidi_jack	*sc_jacks;
113 
114 	int			sc_num_mididevs;
115 	struct umidi_mididev	*sc_mididevs;
116 
117 	int			sc_out_num_endpoints;
118 	struct umidi_endpoint	*sc_out_ep;
119 	int			sc_in_num_endpoints;
120 	struct umidi_endpoint	*sc_in_ep;
121 	struct umidi_endpoint	*sc_endpoints;
122 };
123