auvitek_audio.c revision 1.2 1 1.2 skrll /* $NetBSD: auvitek_audio.c,v 1.2 2016/04/23 10:15:31 skrll 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.2 skrll __KERNEL_RCSID(0, "$NetBSD: auvitek_audio.c,v 1.2 2016/04/23 10:15:31 skrll 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 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.2 skrll ifaces[i] = &udev->ud_ifaces[i];
73 1.1 jmcneill }
74 1.1 jmcneill
75 1.2 skrll uiaa.uiaa_device = udev;
76 1.2 skrll uiaa.uiaa_port = sc->sc_uport;
77 1.2 skrll uiaa.uiaa_vendor = UGETW(dd->idVendor);
78 1.2 skrll uiaa.uiaa_product = UGETW(dd->idProduct);
79 1.2 skrll uiaa.uiaa_release = UGETW(dd->bcdDevice);
80 1.2 skrll uiaa.uiaa_configno = udev->ud_cdesc->bConfigurationValue;
81 1.2 skrll uiaa.uiaa_ifaces = ifaces;
82 1.2 skrll uiaa.uiaa_nifaces = nifaces;
83 1.2 skrll ilocs[USBIFIFCF_PORT] = uiaa.uiaa_port;
84 1.2 skrll ilocs[USBIFIFCF_VENDOR] = uiaa.uiaa_vendor;
85 1.2 skrll ilocs[USBIFIFCF_PRODUCT] = uiaa.uiaa_product;
86 1.2 skrll ilocs[USBIFIFCF_RELEASE] = uiaa.uiaa_release;
87 1.2 skrll ilocs[USBIFIFCF_CONFIGURATION] = uiaa.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.2 skrll uiaa.uiaa_class = ifaces[i]->ui_idesc->bInterfaceClass;
93 1.2 skrll uiaa.uiaa_subclass = ifaces[i]->ui_idesc->bInterfaceSubClass;
94 1.2 skrll if (uiaa.uiaa_class != UICLASS_AUDIO)
95 1.1 jmcneill continue;
96 1.2 skrll if (uiaa.uiaa_subclass != UISUBCLASS_AUDIOCONTROL)
97 1.1 jmcneill continue;
98 1.2 skrll uiaa.uiaa_iface = ifaces[i];
99 1.2 skrll uiaa.uiaa_proto = ifaces[i]->ui_idesc->bInterfaceProtocol;
100 1.2 skrll uiaa.uiaa_ifaceno = ifaces[i]->ui_idesc->bInterfaceNumber;
101 1.2 skrll ilocs[USBIFIFCF_INTERFACE] = uiaa.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.2 skrll struct usbif_attach_arg *uiaa = opaque;
135 1.1 jmcneill
136 1.1 jmcneill if (pnp)
137 1.1 jmcneill return QUIET;
138 1.1 jmcneill
139 1.2 skrll aprint_normal(" port %d", uiaa->uiaa_port);
140 1.2 skrll aprint_normal(" configuration %d", uiaa->uiaa_configno);
141 1.2 skrll aprint_normal(" interface %d", uiaa->uiaa_ifaceno);
142 1.1 jmcneill
143 1.1 jmcneill return UNCONF;
144 1.1 jmcneill }
145