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