xref: /openbsd-src/sys/dev/usb/umidi_quirks.c (revision 8500990981f885cbe5e6a4958549cacc238b5ae6)
1 /*	$OpenBSD: umidi_quirks.c,v 1.5 2003/05/19 00:36:52 nate Exp $	*/
2 /*	$NetBSD: umidi_quirks.c,v 1.4 2002/06/19 13:55:30 tshiozak Exp $	*/
3 
4 /*
5  * Copyright (c) 2001 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Takuya SHIOZAKI (tshiozak@netbsd.org).
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	  This product includes software developed by the NetBSD
22  *	  Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #include <sys/device.h>
45 #include <sys/ioctl.h>
46 #include <sys/conf.h>
47 #include <sys/file.h>
48 #include <sys/select.h>
49 #include <sys/proc.h>
50 #include <sys/vnode.h>
51 #include <sys/poll.h>
52 #include <sys/lock.h>
53 
54 #include <dev/usb/usb.h>
55 #include <dev/usb/usbdi.h>
56 #include <dev/usb/usbdi_util.h>
57 
58 #include <dev/usb/usbdevs.h>
59 #include <dev/usb/uaudioreg.h>
60 #include <dev/usb/umidireg.h>
61 #include <dev/usb/umidivar.h>
62 #include <dev/usb/umidi_quirks.h>
63 
64 /*
65  * quirk codes for UMIDI
66  */
67 
68 #ifdef UMIDIQUIRK_DEBUG
69 #define DPRINTF(x)	if (umidiquirkdebug) printf x
70 #define DPRINTFN(n,x)	if (umidiquirkdebug >= (n)) printf x
71 int	umidiquirkdebug = 1;
72 #else
73 #define DPRINTF(x)
74 #define DPRINTFN(n,x)
75 #endif
76 
77 
78 /*
79  * YAMAHA UX-256
80  *  --- this is a typical yamaha device, but has a broken descriptor :-<
81  */
82 
83 UMQ_FIXED_EP_DEF(YAMAHA, YAMAHA_UX256, ANYIFACE, 1, 1) = {
84 	/* out */
85 	{ 0, 16 },
86 	/* in */
87 	{ 1, 8 }
88 };
89 
90 UMQ_DEF(YAMAHA, YAMAHA_UX256, ANYIFACE) = {
91 	UMQ_FIXED_EP_REG(YAMAHA, YAMAHA_UX256, ANYIFACE),
92 #if 0
93 	UMQ_YAMAHA_REG(YAMAHA, ANYPRODUCT, ANYIFACE),
94 #endif
95 	UMQ_TERMINATOR
96 };
97 
98 
99 /*
100  * YAMAHA generic
101  */
102 UMQ_DEF(YAMAHA, ANYPRODUCT, ANYIFACE) = {
103 	UMQ_YAMAHA_REG(YAMAHA, ANYPRODUCT, ANYIFACE),
104 	UMQ_TERMINATOR
105 };
106 
107 
108 /*
109  * ROLAND UM-1
110  */
111 UMQ_FIXED_EP_DEF(ROLAND, ROLAND_UM1, 2, 1, 1) = {
112 	/* out */
113 	{ 0, 1 },
114 	/* in */
115 	{ 1, 1 }
116 };
117 
118 UMQ_DEF(ROLAND, ROLAND_UM1, 2) = {
119 	UMQ_FIXED_EP_REG(ROLAND, ROLAND_UM1, 2),
120 	UMQ_TERMINATOR
121 };
122 
123 /*
124  * ROLAND SC-8850
125  */
126 UMQ_FIXED_EP_DEF(ROLAND, ROLAND_SC8850, 2, 1, 1) = {
127 	/* out */
128 	{ 0, 6 },
129 	/* in */
130 	{ 1, 6 }
131 };
132 
133 UMQ_DEF(ROLAND, ROLAND_SC8850, 2) = {
134 	UMQ_FIXED_EP_REG(ROLAND, ROLAND_SC8850, 2),
135 	UMQ_TERMINATOR
136 };
137 
138 /*
139  * ROLAND SD-90
140  */
141 UMQ_FIXED_EP_DEF(ROLAND, ROLAND_SD90, 2, 1, 1) = {
142 	/* out */
143 	{ 0, 4 },
144 	/* in */
145 	{ 1, 4 }
146 };
147 
148 UMQ_DEF(ROLAND, ROLAND_SD90, 2) = {
149 	UMQ_FIXED_EP_REG(ROLAND, ROLAND_SD90, 2),
150 	UMQ_TERMINATOR
151 };
152 
153 
154 /*
155  * ROLAND UM-880 (native mode)
156  */
157 UMQ_FIXED_EP_DEF(ROLAND, ROLAND_UM880N, 0, 1, 1) = {
158 	/* out */
159 	{ 0, 9 },
160 	/* in */
161 	{ 1, 9 }
162 };
163 
164 UMQ_DEF(ROLAND, ROLAND_UM880N, 0) = {
165 	UMQ_FIXED_EP_REG(ROLAND, ROLAND_UM880N, 0),
166 	UMQ_TERMINATOR
167 };
168 
169 
170 
171 /*
172  * quirk list
173  */
174 struct umidi_quirk umidi_quirklist[] = {
175 	UMQ_REG(YAMAHA, YAMAHA_UX256, ANYIFACE),
176 	UMQ_REG(YAMAHA, ANYPRODUCT, ANYIFACE),
177 	UMQ_REG(ROLAND, ROLAND_UM1, 2),
178 	UMQ_REG(ROLAND, ROLAND_SC8850, 2),
179 	UMQ_REG(ROLAND, ROLAND_SD90, 2),
180 	UMQ_REG(ROLAND, ROLAND_UM880N, 0),
181 	UMQ_TERMINATOR
182 };
183 
184 
185 /*
186  * quirk utilities
187  */
188 
189 struct umidi_quirk *
190 umidi_search_quirk(int vendor, int product, int ifaceno)
191 {
192 	struct umidi_quirk *p;
193 	struct umq_data *q;
194 
195 	DPRINTF(("umidi_search_quirk: v=%d, p=%d, i=%d\n",
196 		 vendor, product, ifaceno));
197 
198 	for (p=&umidi_quirklist[0]; p->vendor; p++) {
199 		DPRINTFN(10, ("\tv=%d, p=%d, i=%d",
200 			      p->vendor, p->product, p->iface));
201 		if ((p->vendor==vendor || p->vendor==ANYVENDOR) &&
202 		    (p->product==product || p->product==ANYPRODUCT) &&
203 		    (p->iface==ifaceno || p->iface==ANYIFACE)) {
204 			DPRINTFN(10, (" found\n"));
205 			if (!p->type_mask)
206 				/* make quirk mask */
207 				for (q=p->quirks; q->type; q++)
208 					p->type_mask |= 1<<(q->type-1);
209 			return p;
210                 }
211 		DPRINTFN(10, ("\n"));
212 	}
213 
214 	return NULL;
215 }
216 
217 static char *quirk_name[] = {
218 	"NULL",
219 	"Fixed Endpoint",
220 	"Yamaha Specific",
221 };
222 
223 void
224 umidi_print_quirk(struct umidi_quirk *q)
225 {
226 	struct umq_data *qd;
227 	if (q) {
228 		printf("(");
229 		for (qd=q->quirks; qd->type; qd++)
230 			printf("%s%s", quirk_name[qd->type],
231 			       (qd+1)->type?", ":")\n");
232 	} else {
233 		printf("(genuine USB-MIDI)\n");
234 	}
235 }
236 
237 void *
238 umidi_get_quirk_data_from_type(struct umidi_quirk *q, u_int32_t type)
239 {
240 	struct umq_data *qd;
241 	if (q) {
242 		for (qd=q->quirks; qd->type; qd++)
243 			if (qd->type == type)
244 				return qd->data;
245 	}
246 	return NULL;
247 }
248