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