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