1 /* $NetBSD: auvitek_audio.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * Auvitek AU0828 USB controller - audio support 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: auvitek_audio.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 #include <sys/conf.h> 40 #include <sys/bus.h> 41 #include <sys/kmem.h> 42 43 #include <dev/usb/usb.h> 44 #include <dev/usb/usbdi.h> 45 #include <dev/usb/usbdivar.h> 46 #include <dev/usb/usbdi_util.h> 47 #include <dev/usb/usbdevs.h> 48 49 #include <dev/usb/auvitekreg.h> 50 #include <dev/usb/auvitekvar.h> 51 52 #include "locators.h" 53 54 static int auvitek_ifprint(void *, const char *); 55 56 int 57 auvitek_audio_attach(struct auvitek_softc *sc) 58 { 59 struct usbif_attach_arg uiaa; 60 usbd_device_handle udev = sc->sc_udev; 61 usb_device_descriptor_t *dd = &udev->ddesc; 62 usbd_interface_handle *ifaces; 63 int ilocs[USBIFIFCF_NLOCS], nifaces, i; 64 65 nifaces = udev->cdesc->bNumInterface; 66 ifaces = kmem_zalloc(nifaces * sizeof(*ifaces), KM_SLEEP); 67 if (ifaces == NULL) { 68 aprint_error_dev(sc->sc_dev, "audio attach: no memory\n"); 69 return ENOMEM; 70 } 71 for (i = 0; i < nifaces; i++) { 72 ifaces[i] = &udev->ifaces[i]; 73 } 74 75 uiaa.device = udev; 76 uiaa.port = sc->sc_uport; 77 uiaa.vendor = UGETW(dd->idVendor); 78 uiaa.product = UGETW(dd->idProduct); 79 uiaa.release = UGETW(dd->bcdDevice); 80 uiaa.configno = udev->cdesc->bConfigurationValue; 81 uiaa.ifaces = ifaces; 82 uiaa.nifaces = nifaces; 83 ilocs[USBIFIFCF_PORT] = uiaa.port; 84 ilocs[USBIFIFCF_VENDOR] = uiaa.vendor; 85 ilocs[USBIFIFCF_PRODUCT] = uiaa.product; 86 ilocs[USBIFIFCF_RELEASE] = uiaa.release; 87 ilocs[USBIFIFCF_CONFIGURATION] = uiaa.configno; 88 89 for (i = 0; i < nifaces; i++) { 90 if (!ifaces[i]) 91 continue; 92 uiaa.class = ifaces[i]->idesc->bInterfaceClass; 93 uiaa.subclass = ifaces[i]->idesc->bInterfaceSubClass; 94 if (uiaa.class != UICLASS_AUDIO) 95 continue; 96 if (uiaa.subclass != UISUBCLASS_AUDIOCONTROL) 97 continue; 98 uiaa.iface = ifaces[i]; 99 uiaa.proto = ifaces[i]->idesc->bInterfaceProtocol; 100 uiaa.ifaceno = ifaces[i]->idesc->bInterfaceNumber; 101 ilocs[USBIFIFCF_INTERFACE] = uiaa.ifaceno; 102 sc->sc_audiodev = config_found_sm_loc(sc->sc_dev, "usbifif", 103 ilocs, &uiaa, auvitek_ifprint, config_stdsubmatch); 104 if (sc->sc_audiodev) 105 break; 106 } 107 108 kmem_free(ifaces, nifaces * sizeof(*ifaces)); 109 110 return 0; 111 } 112 113 int 114 auvitek_audio_detach(struct auvitek_softc *sc, int flags) 115 { 116 if (sc->sc_audiodev != NULL) { 117 config_detach(sc->sc_audiodev, flags); 118 sc->sc_audiodev = NULL; 119 } 120 121 return 0; 122 } 123 124 void 125 auvitek_audio_childdet(struct auvitek_softc *sc, device_t child) 126 { 127 if (sc->sc_audiodev == child) 128 sc->sc_audiodev = NULL; 129 } 130 131 static int 132 auvitek_ifprint(void *opaque, const char *pnp) 133 { 134 struct usbif_attach_arg *uaa = opaque; 135 136 if (pnp) 137 return QUIET; 138 139 aprint_normal(" port %d", uaa->port); 140 aprint_normal(" configuration %d", uaa->configno); 141 aprint_normal(" interface %d", uaa->ifaceno); 142 143 return UNCONF; 144 } 145