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