1 /* $NetBSD: umidi_quirks.c,v 1.1 2001/01/30 23:26:48 tshiozak 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 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 125 /* 126 * quirk list 127 */ 128 struct umidi_quirk umidi_quirklist[] = { 129 UMQ_REG(YAMAHA, YAMAHA_UX256, ANYIFACE), 130 UMQ_REG(YAMAHA, ANYPRODUCT, ANYIFACE), 131 UMQ_REG(ROLAND, ROLAND_UM1, 2), 132 UMQ_TERMINATOR 133 }; 134 135 136 /* 137 * quirk utilities 138 */ 139 140 struct umidi_quirk * 141 umidi_search_quirk(int vendor, int product, int ifaceno) 142 { 143 struct umidi_quirk *p; 144 struct umq_data *q; 145 146 DPRINTF(("umidi_search_quirk: v=%d, p=%d, i=%d\n", 147 vendor, product, ifaceno)); 148 149 for (p=&umidi_quirklist[0]; p->vendor; p++) { 150 DPRINTFN(10, ("\tv=%d, p=%d, i=%d", 151 p->vendor, p->product, p->iface)); 152 if ((p->vendor==vendor || p->vendor==ANYVENDOR) && 153 (p->product==product || p->product==ANYPRODUCT) && 154 (p->iface==ifaceno || p->iface==ANYIFACE)) { 155 DPRINTFN(10, (" found\n")); 156 if (!p->type_mask) 157 /* make quirk mask */ 158 for (q=p->quirks; q->type; q++) 159 p->type_mask |= 1<<(q->type-1); 160 return p; 161 } 162 DPRINTFN(10, ("\n")); 163 } 164 165 return NULL; 166 } 167 168 static char *quirk_name[] = { 169 "NULL", 170 "Fixed Endpoint", 171 "Yamaha Specific", 172 }; 173 174 void 175 umidi_print_quirk(struct umidi_quirk *q) 176 { 177 struct umq_data *qd; 178 if (q) { 179 printf("("); 180 for (qd=q->quirks; qd->type; qd++) 181 printf("%s%s", quirk_name[qd->type], 182 (qd+1)->type?", ":")\n"); 183 } else { 184 printf("(genuine USB-MIDI)\n"); 185 } 186 } 187 188 void * 189 umidi_get_quirk_data_from_type(struct umidi_quirk *q, u_int32_t type) 190 { 191 struct umq_data *qd; 192 if (q) { 193 for (qd=q->quirks; qd->type; qd++) 194 if (qd->type == type) 195 return qd->data; 196 } 197 return NULL; 198 } 199