Home | History | Annotate | Line # | Download | only in usb
      1  1.6  riastrad /* $NetBSD: auvitek_audio.c,v 1.6 2022/03/13 12:49:36 riastradh 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.6  riastrad __KERNEL_RCSID(0, "$NetBSD: auvitek_audio.c,v 1.6 2022/03/13 12:49:36 riastradh 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.2     skrll 	struct usbd_device *udev = sc->sc_udev;
     61  1.2     skrll 	usb_device_descriptor_t *dd = &udev->ud_ddesc;
     62  1.2     skrll 	struct usbd_interface **ifaces;
     63  1.1  jmcneill 	int ilocs[USBIFIFCF_NLOCS], nifaces, i;
     64  1.1  jmcneill 
     65  1.2     skrll 	nifaces = udev->ud_cdesc->bNumInterface;
     66  1.1  jmcneill 	ifaces = kmem_zalloc(nifaces * sizeof(*ifaces), KM_SLEEP);
     67  1.1  jmcneill 	for (i = 0; i < nifaces; i++) {
     68  1.2     skrll 		ifaces[i] = &udev->ud_ifaces[i];
     69  1.1  jmcneill 	}
     70  1.1  jmcneill 
     71  1.2     skrll 	uiaa.uiaa_device = udev;
     72  1.2     skrll 	uiaa.uiaa_port = sc->sc_uport;
     73  1.2     skrll 	uiaa.uiaa_vendor = UGETW(dd->idVendor);
     74  1.2     skrll 	uiaa.uiaa_product = UGETW(dd->idProduct);
     75  1.2     skrll 	uiaa.uiaa_release = UGETW(dd->bcdDevice);
     76  1.2     skrll 	uiaa.uiaa_configno = udev->ud_cdesc->bConfigurationValue;
     77  1.2     skrll 	uiaa.uiaa_ifaces = ifaces;
     78  1.2     skrll 	uiaa.uiaa_nifaces = nifaces;
     79  1.2     skrll 	ilocs[USBIFIFCF_PORT] = uiaa.uiaa_port;
     80  1.2     skrll 	ilocs[USBIFIFCF_VENDOR] = uiaa.uiaa_vendor;
     81  1.2     skrll 	ilocs[USBIFIFCF_PRODUCT] = uiaa.uiaa_product;
     82  1.2     skrll 	ilocs[USBIFIFCF_RELEASE] = uiaa.uiaa_release;
     83  1.2     skrll 	ilocs[USBIFIFCF_CONFIGURATION] = uiaa.uiaa_configno;
     84  1.1  jmcneill 
     85  1.1  jmcneill 	for (i = 0; i < nifaces; i++) {
     86  1.1  jmcneill 		if (!ifaces[i])
     87  1.1  jmcneill 			continue;
     88  1.2     skrll 		uiaa.uiaa_class = ifaces[i]->ui_idesc->bInterfaceClass;
     89  1.2     skrll 		uiaa.uiaa_subclass = ifaces[i]->ui_idesc->bInterfaceSubClass;
     90  1.2     skrll 		if (uiaa.uiaa_class != UICLASS_AUDIO)
     91  1.1  jmcneill 			continue;
     92  1.2     skrll 		if (uiaa.uiaa_subclass != UISUBCLASS_AUDIOCONTROL)
     93  1.1  jmcneill 			continue;
     94  1.2     skrll 		uiaa.uiaa_iface = ifaces[i];
     95  1.2     skrll 		uiaa.uiaa_proto = ifaces[i]->ui_idesc->bInterfaceProtocol;
     96  1.2     skrll 		uiaa.uiaa_ifaceno = ifaces[i]->ui_idesc->bInterfaceNumber;
     97  1.2     skrll 		ilocs[USBIFIFCF_INTERFACE] = uiaa.uiaa_ifaceno;
     98  1.4   thorpej 		sc->sc_audiodev =
     99  1.4   thorpej 		    config_found(sc->sc_dev, &uiaa, auvitek_ifprint,
    100  1.5   thorpej 				 CFARGS(.submatch = config_stdsubmatch,
    101  1.5   thorpej 					.iattr = "usbifif",
    102  1.5   thorpej 					.locators = ilocs));
    103  1.1  jmcneill 		if (sc->sc_audiodev)
    104  1.1  jmcneill 			break;
    105  1.1  jmcneill 	}
    106  1.1  jmcneill 
    107  1.1  jmcneill 	kmem_free(ifaces, nifaces * sizeof(*ifaces));
    108  1.1  jmcneill 
    109  1.1  jmcneill 	return 0;
    110  1.1  jmcneill }
    111  1.1  jmcneill 
    112  1.1  jmcneill int
    113  1.1  jmcneill auvitek_audio_detach(struct auvitek_softc *sc, int flags)
    114  1.1  jmcneill {
    115  1.1  jmcneill 
    116  1.1  jmcneill 	return 0;
    117  1.1  jmcneill }
    118  1.1  jmcneill 
    119  1.1  jmcneill void
    120  1.1  jmcneill auvitek_audio_childdet(struct auvitek_softc *sc, device_t child)
    121  1.1  jmcneill {
    122  1.1  jmcneill 	if (sc->sc_audiodev == child)
    123  1.1  jmcneill 		sc->sc_audiodev = NULL;
    124  1.1  jmcneill }
    125  1.1  jmcneill 
    126  1.1  jmcneill static int
    127  1.1  jmcneill auvitek_ifprint(void *opaque, const char *pnp)
    128  1.1  jmcneill {
    129  1.2     skrll 	struct usbif_attach_arg *uiaa = opaque;
    130  1.1  jmcneill 
    131  1.1  jmcneill 	if (pnp)
    132  1.1  jmcneill 		return QUIET;
    133  1.1  jmcneill 
    134  1.2     skrll 	aprint_normal(" port %d", uiaa->uiaa_port);
    135  1.2     skrll 	aprint_normal(" configuration %d", uiaa->uiaa_configno);
    136  1.2     skrll 	aprint_normal(" interface %d", uiaa->uiaa_ifaceno);
    137  1.1  jmcneill 
    138  1.1  jmcneill 	return UNCONF;
    139  1.1  jmcneill }
    140