pad.c revision 1.2.4.4 1 1.2.4.4 jmcneill /* $NetBSD: pad.c,v 1.2.4.4 2007/12/08 16:21:21 jmcneill Exp $ */
2 1.2.4.2 joerg
3 1.2.4.2 joerg /*-
4 1.2.4.2 joerg * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.2.4.2 joerg * All rights reserved.
6 1.2.4.2 joerg *
7 1.2.4.2 joerg * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 joerg * modification, are permitted provided that the following conditions
9 1.2.4.2 joerg * are met:
10 1.2.4.2 joerg * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 joerg * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 joerg * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 joerg * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 joerg * documentation and/or other materials provided with the distribution.
15 1.2.4.2 joerg * 3. All advertising materials mentioning features or use of this software
16 1.2.4.2 joerg * must display the following acknowledgement:
17 1.2.4.2 joerg * This product includes software developed by Jared D. McNeill.
18 1.2.4.2 joerg * 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.2.4.2 joerg * contributors may be used to endorse or promote products derived
20 1.2.4.2 joerg * from this software without specific prior written permission.
21 1.2.4.2 joerg *
22 1.2.4.2 joerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.2.4.2 joerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.2.4.2 joerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.2.4.2 joerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.2.4.2 joerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.2.4.2 joerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.2.4.2 joerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.2.4.2 joerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.2.4.2 joerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.2.4.2 joerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.2.4.2 joerg * POSSIBILITY OF SUCH DAMAGE.
33 1.2.4.2 joerg */
34 1.2.4.2 joerg
35 1.2.4.2 joerg #include <sys/cdefs.h>
36 1.2.4.4 jmcneill __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.2.4.4 2007/12/08 16:21:21 jmcneill Exp $");
37 1.2.4.2 joerg
38 1.2.4.2 joerg #include <sys/types.h>
39 1.2.4.2 joerg #include <sys/param.h>
40 1.2.4.2 joerg #include <sys/conf.h>
41 1.2.4.2 joerg #include <sys/buf.h>
42 1.2.4.2 joerg #include <sys/kmem.h>
43 1.2.4.2 joerg #include <sys/kernel.h>
44 1.2.4.2 joerg #include <sys/device.h>
45 1.2.4.2 joerg #include <sys/proc.h>
46 1.2.4.2 joerg #include <sys/condvar.h>
47 1.2.4.2 joerg #include <sys/select.h>
48 1.2.4.2 joerg #include <sys/audioio.h>
49 1.2.4.2 joerg
50 1.2.4.2 joerg #include <dev/audio_if.h>
51 1.2.4.2 joerg #include <dev/audiovar.h>
52 1.2.4.2 joerg #include <dev/auconv.h>
53 1.2.4.2 joerg
54 1.2.4.2 joerg #include <dev/pad/padvar.h>
55 1.2.4.2 joerg #include <dev/pad/padvol.h>
56 1.2.4.2 joerg
57 1.2.4.2 joerg #define PADUNIT(x) minor(x)
58 1.2.4.2 joerg
59 1.2.4.2 joerg extern struct cfdriver pad_cd;
60 1.2.4.2 joerg
61 1.2.4.2 joerg static struct audio_device pad_device = {
62 1.2.4.2 joerg "Pseudo Audio",
63 1.2.4.2 joerg "1.0",
64 1.2.4.2 joerg "pad",
65 1.2.4.2 joerg };
66 1.2.4.2 joerg
67 1.2.4.2 joerg typedef struct pad_block {
68 1.2.4.2 joerg uint8_t *pb_ptr;
69 1.2.4.2 joerg int pb_len;
70 1.2.4.2 joerg } pad_block_t;
71 1.2.4.2 joerg
72 1.2.4.2 joerg enum {
73 1.2.4.2 joerg PAD_OUTPUT_CLASS,
74 1.2.4.2 joerg PAD_INPUT_CLASS,
75 1.2.4.2 joerg PAD_OUTPUT_MASTER_VOLUME,
76 1.2.4.2 joerg PAD_INPUT_DAC_VOLUME,
77 1.2.4.2 joerg PAD_ENUM_LAST,
78 1.2.4.2 joerg };
79 1.2.4.2 joerg
80 1.2.4.2 joerg static int pad_match(struct device *, struct cfdata *, void *);
81 1.2.4.2 joerg static void pad_attach(struct device *, struct device *, void *);
82 1.2.4.2 joerg
83 1.2.4.2 joerg static int pad_query_encoding(void *, struct audio_encoding *);
84 1.2.4.2 joerg static int pad_set_params(void *, int, int,
85 1.2.4.2 joerg audio_params_t *, audio_params_t *,
86 1.2.4.2 joerg stream_filter_list_t *, stream_filter_list_t *);
87 1.2.4.2 joerg static int pad_start_output(void *, void *, int,
88 1.2.4.2 joerg void (*)(void *), void *);
89 1.2.4.2 joerg static int pad_start_input(void *, void *, int,
90 1.2.4.2 joerg void (*)(void *), void *);
91 1.2.4.2 joerg static int pad_halt_output(void *);
92 1.2.4.2 joerg static int pad_halt_input(void *);
93 1.2.4.2 joerg static int pad_getdev(void *, struct audio_device *);
94 1.2.4.2 joerg static int pad_set_port(void *, mixer_ctrl_t *);
95 1.2.4.2 joerg static int pad_get_port(void *, mixer_ctrl_t *);
96 1.2.4.2 joerg static int pad_query_devinfo(void *, mixer_devinfo_t *);
97 1.2.4.2 joerg static int pad_get_props(void *);
98 1.2.4.2 joerg static int pad_round_blocksize(void *, int, int, const audio_params_t *);
99 1.2.4.2 joerg
100 1.2.4.2 joerg static const struct audio_hw_if pad_hw_if = {
101 1.2.4.2 joerg .query_encoding = pad_query_encoding,
102 1.2.4.2 joerg .set_params = pad_set_params,
103 1.2.4.2 joerg .start_output = pad_start_output,
104 1.2.4.2 joerg .start_input = pad_start_input,
105 1.2.4.2 joerg .halt_output = pad_halt_output,
106 1.2.4.2 joerg .halt_input = pad_halt_input,
107 1.2.4.2 joerg .getdev = pad_getdev,
108 1.2.4.2 joerg .set_port = pad_set_port,
109 1.2.4.2 joerg .get_port = pad_get_port,
110 1.2.4.2 joerg .query_devinfo = pad_query_devinfo,
111 1.2.4.2 joerg .get_props = pad_get_props,
112 1.2.4.2 joerg .round_blocksize = pad_round_blocksize,
113 1.2.4.2 joerg };
114 1.2.4.2 joerg
115 1.2.4.2 joerg #define PAD_NFORMATS 1
116 1.2.4.2 joerg static const struct audio_format pad_formats[PAD_NFORMATS] = {
117 1.2.4.2 joerg { NULL, AUMODE_PLAY|AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
118 1.2.4.2 joerg 2, AUFMT_STEREO, 1, { 44100 } },
119 1.2.4.2 joerg };
120 1.2.4.2 joerg
121 1.2.4.2 joerg extern void padattach(int);
122 1.2.4.2 joerg
123 1.2.4.2 joerg static pad_softc_t * pad_find_softc(dev_t);
124 1.2.4.2 joerg static int pad_add_block(pad_softc_t *, uint8_t *, int);
125 1.2.4.2 joerg static int pad_get_block(pad_softc_t *, pad_block_t *, int);
126 1.2.4.2 joerg
127 1.2.4.2 joerg dev_type_open(pad_open);
128 1.2.4.2 joerg dev_type_close(pad_close);
129 1.2.4.2 joerg dev_type_read(pad_read);
130 1.2.4.2 joerg
131 1.2.4.2 joerg const struct cdevsw pad_cdevsw = {
132 1.2.4.2 joerg .d_open = pad_open,
133 1.2.4.2 joerg .d_close = pad_close,
134 1.2.4.2 joerg .d_read = pad_read,
135 1.2.4.2 joerg .d_write = nowrite,
136 1.2.4.2 joerg .d_ioctl = noioctl,
137 1.2.4.2 joerg .d_stop = nostop,
138 1.2.4.2 joerg .d_tty = notty,
139 1.2.4.2 joerg .d_poll = nopoll,
140 1.2.4.2 joerg .d_mmap = nommap,
141 1.2.4.2 joerg .d_kqfilter = nokqfilter,
142 1.2.4.2 joerg .d_flag = D_OTHER,
143 1.2.4.2 joerg };
144 1.2.4.2 joerg
145 1.2.4.2 joerg CFATTACH_DECL(pad, sizeof(pad_softc_t), pad_match, pad_attach, NULL, NULL);
146 1.2.4.2 joerg
147 1.2.4.2 joerg void
148 1.2.4.2 joerg padattach(int n)
149 1.2.4.2 joerg {
150 1.2.4.2 joerg int i, err;
151 1.2.4.2 joerg struct cfdata *cf;
152 1.2.4.2 joerg
153 1.2.4.2 joerg #ifdef DEBUG
154 1.2.4.2 joerg printf("pad: requested %d units\n", n);
155 1.2.4.2 joerg #endif
156 1.2.4.2 joerg
157 1.2.4.2 joerg err = config_cfattach_attach(pad_cd.cd_name, &pad_ca);
158 1.2.4.2 joerg if (err) {
159 1.2.4.2 joerg aprint_error("%s: couldn't register cfattach: %d\n",
160 1.2.4.2 joerg pad_cd.cd_name, err);
161 1.2.4.2 joerg config_cfdriver_detach(&pad_cd);
162 1.2.4.2 joerg return;
163 1.2.4.2 joerg }
164 1.2.4.2 joerg
165 1.2.4.2 joerg for (i = 0; i < n; i++) {
166 1.2.4.2 joerg cf = kmem_alloc(sizeof(struct cfdata), KM_NOSLEEP);
167 1.2.4.2 joerg if (cf == NULL) {
168 1.2.4.2 joerg aprint_error("%s: couldn't allocate cfdata\n",
169 1.2.4.2 joerg pad_cd.cd_name);
170 1.2.4.2 joerg continue;
171 1.2.4.2 joerg }
172 1.2.4.2 joerg cf->cf_name = pad_cd.cd_name;
173 1.2.4.2 joerg cf->cf_atname = pad_cd.cd_name;
174 1.2.4.2 joerg cf->cf_unit = i;
175 1.2.4.2 joerg cf->cf_fstate = FSTATE_STAR;
176 1.2.4.2 joerg
177 1.2.4.2 joerg (void)config_attach_pseudo(cf);
178 1.2.4.2 joerg }
179 1.2.4.2 joerg
180 1.2.4.2 joerg return;
181 1.2.4.2 joerg }
182 1.2.4.2 joerg
183 1.2.4.2 joerg static pad_softc_t *
184 1.2.4.2 joerg pad_find_softc(dev_t dev)
185 1.2.4.2 joerg {
186 1.2.4.2 joerg int unit;
187 1.2.4.2 joerg
188 1.2.4.2 joerg unit = PADUNIT(dev);
189 1.2.4.2 joerg if (unit >= pad_cd.cd_ndevs)
190 1.2.4.2 joerg return NULL;
191 1.2.4.2 joerg
192 1.2.4.2 joerg return pad_cd.cd_devs[unit];
193 1.2.4.2 joerg }
194 1.2.4.2 joerg
195 1.2.4.2 joerg static int
196 1.2.4.2 joerg pad_add_block(pad_softc_t *sc, uint8_t *blk, int blksize)
197 1.2.4.2 joerg {
198 1.2.4.2 joerg int l;
199 1.2.4.2 joerg
200 1.2.4.2 joerg if (sc->sc_buflen + blksize > PAD_BUFSIZE)
201 1.2.4.2 joerg return ENOBUFS;
202 1.2.4.2 joerg
203 1.2.4.2 joerg if (sc->sc_wpos + blksize <= PAD_BUFSIZE)
204 1.2.4.2 joerg memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, blksize);
205 1.2.4.2 joerg else {
206 1.2.4.2 joerg l = PAD_BUFSIZE - sc->sc_wpos;
207 1.2.4.2 joerg memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, l);
208 1.2.4.2 joerg memcpy(sc->sc_audiobuf, blk + l, blksize - l);
209 1.2.4.2 joerg }
210 1.2.4.2 joerg
211 1.2.4.2 joerg sc->sc_wpos += blksize;
212 1.2.4.2 joerg if (sc->sc_wpos > PAD_BUFSIZE)
213 1.2.4.2 joerg sc->sc_wpos -= PAD_BUFSIZE;
214 1.2.4.2 joerg
215 1.2.4.2 joerg sc->sc_buflen += blksize;
216 1.2.4.2 joerg
217 1.2.4.2 joerg return 0;
218 1.2.4.2 joerg }
219 1.2.4.2 joerg
220 1.2.4.2 joerg static int
221 1.2.4.2 joerg pad_get_block(pad_softc_t *sc, pad_block_t *pb, int blksize)
222 1.2.4.2 joerg {
223 1.2.4.2 joerg int l;
224 1.2.4.2 joerg
225 1.2.4.2 joerg KASSERT(pb != NULL);
226 1.2.4.2 joerg
227 1.2.4.2 joerg if (sc->sc_buflen < blksize)
228 1.2.4.2 joerg return ERESTART;
229 1.2.4.2 joerg
230 1.2.4.2 joerg pb->pb_ptr = (sc->sc_audiobuf + sc->sc_rpos);
231 1.2.4.2 joerg if (sc->sc_rpos + blksize < PAD_BUFSIZE) {
232 1.2.4.2 joerg pb->pb_len = blksize;
233 1.2.4.2 joerg sc->sc_rpos += blksize;
234 1.2.4.2 joerg } else {
235 1.2.4.2 joerg l = PAD_BUFSIZE - sc->sc_rpos;
236 1.2.4.2 joerg pb->pb_len = l;
237 1.2.4.2 joerg sc->sc_rpos = 0;
238 1.2.4.2 joerg }
239 1.2.4.2 joerg sc->sc_buflen -= pb->pb_len;
240 1.2.4.2 joerg
241 1.2.4.2 joerg return 0;
242 1.2.4.2 joerg }
243 1.2.4.2 joerg
244 1.2.4.2 joerg static int
245 1.2.4.2 joerg pad_match(struct device *parent, struct cfdata *data, void *opaque)
246 1.2.4.2 joerg {
247 1.2.4.2 joerg return 1;
248 1.2.4.2 joerg }
249 1.2.4.2 joerg
250 1.2.4.2 joerg static void
251 1.2.4.2 joerg pad_attach(struct device *parent, struct device *self, void *opaque)
252 1.2.4.2 joerg {
253 1.2.4.2 joerg pad_softc_t *sc;
254 1.2.4.2 joerg
255 1.2.4.2 joerg sc = (pad_softc_t *)self;
256 1.2.4.2 joerg
257 1.2.4.2 joerg aprint_normal_dev(self, "outputs: 44100Hz, 16-bit, stereo\n");
258 1.2.4.2 joerg
259 1.2.4.2 joerg sc->sc_open = 0;
260 1.2.4.2 joerg if (auconv_create_encodings(pad_formats, PAD_NFORMATS,
261 1.2.4.2 joerg &sc->sc_encodings) != 0) {
262 1.2.4.2 joerg aprint_error_dev(self, "couldn't create encodings\n");
263 1.2.4.2 joerg return;
264 1.2.4.2 joerg }
265 1.2.4.2 joerg
266 1.2.4.2 joerg cv_init(&sc->sc_condvar, device_xname(self));
267 1.2.4.2 joerg mutex_init(&sc->sc_mutex, MUTEX_DRIVER, IPL_AUDIO);
268 1.2.4.2 joerg
269 1.2.4.2 joerg sc->sc_swvol = 255;
270 1.2.4.2 joerg sc->sc_buflen = 0;
271 1.2.4.2 joerg sc->sc_rpos = sc->sc_wpos = 0;
272 1.2.4.2 joerg sc->sc_audiodev = (void *)audio_attach_mi(&pad_hw_if, sc, &sc->sc_dev);
273 1.2.4.2 joerg
274 1.2.4.4 jmcneill if (!pmf_device_register(self, NULL, NULL))
275 1.2.4.3 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
276 1.2.4.3 jmcneill
277 1.2.4.2 joerg return;
278 1.2.4.2 joerg }
279 1.2.4.2 joerg
280 1.2.4.2 joerg int
281 1.2.4.2 joerg pad_open(dev_t dev, int flags, int fmt, struct lwp *l)
282 1.2.4.2 joerg {
283 1.2.4.2 joerg pad_softc_t *sc;
284 1.2.4.2 joerg
285 1.2.4.2 joerg sc = pad_find_softc(dev);
286 1.2.4.2 joerg if (sc == NULL)
287 1.2.4.2 joerg return ENODEV;
288 1.2.4.2 joerg
289 1.2.4.2 joerg if (sc->sc_open++) {
290 1.2.4.2 joerg sc->sc_open--;
291 1.2.4.2 joerg return EBUSY;
292 1.2.4.2 joerg }
293 1.2.4.2 joerg
294 1.2.4.2 joerg return 0;
295 1.2.4.2 joerg }
296 1.2.4.2 joerg
297 1.2.4.2 joerg int
298 1.2.4.2 joerg pad_close(dev_t dev, int flags, int fmt, struct lwp *l)
299 1.2.4.2 joerg {
300 1.2.4.2 joerg pad_softc_t *sc;
301 1.2.4.2 joerg
302 1.2.4.2 joerg sc = pad_find_softc(dev);
303 1.2.4.2 joerg if (sc == NULL)
304 1.2.4.2 joerg return ENODEV;
305 1.2.4.2 joerg
306 1.2.4.2 joerg KASSERT(sc->sc_open > 0);
307 1.2.4.2 joerg sc->sc_open--;
308 1.2.4.2 joerg
309 1.2.4.2 joerg return 0;
310 1.2.4.2 joerg }
311 1.2.4.2 joerg
312 1.2.4.2 joerg int
313 1.2.4.2 joerg pad_read(dev_t dev, struct uio *uio, int flags)
314 1.2.4.2 joerg {
315 1.2.4.2 joerg pad_softc_t *sc;
316 1.2.4.2 joerg pad_block_t pb;
317 1.2.4.2 joerg void (*intr)(void *);
318 1.2.4.2 joerg void *intrarg;
319 1.2.4.2 joerg int err;
320 1.2.4.2 joerg
321 1.2.4.2 joerg sc = pad_find_softc(dev);
322 1.2.4.2 joerg if (sc == NULL)
323 1.2.4.2 joerg return ENODEV;
324 1.2.4.2 joerg
325 1.2.4.2 joerg err = 0;
326 1.2.4.2 joerg
327 1.2.4.2 joerg intr = sc->sc_intr;
328 1.2.4.2 joerg intrarg = sc->sc_intrarg;
329 1.2.4.2 joerg
330 1.2.4.2 joerg while (uio->uio_resid > 0 && !err) {
331 1.2.4.2 joerg err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE));
332 1.2.4.2 joerg if (!err)
333 1.2.4.2 joerg err = uiomove(pb.pb_ptr, pb.pb_len, uio);
334 1.2.4.2 joerg else {
335 1.2.4.2 joerg if (intr) {
336 1.2.4.2 joerg (*intr)(intrarg);
337 1.2.4.2 joerg intr = sc->sc_intr;
338 1.2.4.2 joerg intrarg = sc->sc_intrarg;
339 1.2.4.2 joerg err = 0;
340 1.2.4.2 joerg continue;
341 1.2.4.2 joerg }
342 1.2.4.2 joerg
343 1.2.4.2 joerg mutex_enter(&sc->sc_mutex);
344 1.2.4.2 joerg err = cv_timedwait_sig(&sc->sc_condvar, &sc->sc_mutex,
345 1.2.4.2 joerg hz/100);
346 1.2.4.2 joerg if (err != 0 && err != EWOULDBLOCK) {
347 1.2.4.2 joerg mutex_exit(&sc->sc_mutex);
348 1.2.4.2 joerg aprint_error_dev(&sc->sc_dev,
349 1.2.4.2 joerg "cv_timedwait_sig returned %d\n", err);
350 1.2.4.2 joerg return EINTR;
351 1.2.4.2 joerg }
352 1.2.4.2 joerg intr = sc->sc_intr;
353 1.2.4.2 joerg intrarg = sc->sc_intrarg;
354 1.2.4.2 joerg mutex_exit(&sc->sc_mutex);
355 1.2.4.2 joerg err = 0;
356 1.2.4.2 joerg }
357 1.2.4.2 joerg }
358 1.2.4.2 joerg
359 1.2.4.2 joerg if (intr)
360 1.2.4.2 joerg (*intr)(intrarg);
361 1.2.4.2 joerg
362 1.2.4.2 joerg return err;
363 1.2.4.2 joerg }
364 1.2.4.2 joerg
365 1.2.4.2 joerg static int
366 1.2.4.2 joerg pad_query_encoding(void *opaque, struct audio_encoding *ae)
367 1.2.4.2 joerg {
368 1.2.4.2 joerg pad_softc_t *sc;
369 1.2.4.2 joerg
370 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
371 1.2.4.2 joerg
372 1.2.4.2 joerg return auconv_query_encoding(sc->sc_encodings, ae);
373 1.2.4.2 joerg }
374 1.2.4.2 joerg
375 1.2.4.2 joerg static int
376 1.2.4.2 joerg pad_set_params(void *opaque, int setmode, int usemode,
377 1.2.4.2 joerg audio_params_t *play, audio_params_t *rec,
378 1.2.4.2 joerg stream_filter_list_t *pfil, stream_filter_list_t *rfil)
379 1.2.4.2 joerg {
380 1.2.4.2 joerg pad_softc_t *sc;
381 1.2.4.2 joerg
382 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
383 1.2.4.2 joerg
384 1.2.4.2 joerg if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_PLAY,
385 1.2.4.2 joerg play, true, pfil) < 0)
386 1.2.4.2 joerg return EINVAL;
387 1.2.4.2 joerg if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_RECORD,
388 1.2.4.2 joerg rec, true, rfil) < 0)
389 1.2.4.2 joerg return EINVAL;
390 1.2.4.2 joerg
391 1.2.4.2 joerg if (pfil->req_size > 0)
392 1.2.4.2 joerg play = &pfil->filters[0].param;
393 1.2.4.2 joerg switch (play->encoding) {
394 1.2.4.2 joerg case AUDIO_ENCODING_SLINEAR_LE:
395 1.2.4.2 joerg if (play->precision == 16 && play->validbits == 16)
396 1.2.4.2 joerg pfil->prepend(pfil, pad_vol_slinear16_le, play);
397 1.2.4.2 joerg break;
398 1.2.4.2 joerg case AUDIO_ENCODING_SLINEAR_BE:
399 1.2.4.2 joerg if (play->precision == 16 && play->validbits == 16)
400 1.2.4.2 joerg pfil->prepend(pfil, pad_vol_slinear16_be, play);
401 1.2.4.2 joerg break;
402 1.2.4.2 joerg default:
403 1.2.4.2 joerg break;
404 1.2.4.2 joerg }
405 1.2.4.2 joerg
406 1.2.4.2 joerg return 0;
407 1.2.4.2 joerg }
408 1.2.4.2 joerg
409 1.2.4.2 joerg static int
410 1.2.4.2 joerg pad_start_output(void *opaque, void *block, int blksize,
411 1.2.4.2 joerg void (*intr)(void *), void *intrarg)
412 1.2.4.2 joerg {
413 1.2.4.2 joerg pad_softc_t *sc;
414 1.2.4.2 joerg int err;
415 1.2.4.2 joerg
416 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
417 1.2.4.2 joerg
418 1.2.4.2 joerg mutex_enter(&sc->sc_mutex);
419 1.2.4.2 joerg
420 1.2.4.2 joerg sc->sc_intr = intr;
421 1.2.4.2 joerg sc->sc_intrarg = intrarg;
422 1.2.4.2 joerg sc->sc_blksize = blksize;
423 1.2.4.2 joerg
424 1.2.4.2 joerg err = pad_add_block(sc, block, blksize);
425 1.2.4.2 joerg
426 1.2.4.2 joerg cv_signal(&sc->sc_condvar);
427 1.2.4.2 joerg
428 1.2.4.2 joerg mutex_exit(&sc->sc_mutex);
429 1.2.4.2 joerg
430 1.2.4.2 joerg return err;
431 1.2.4.2 joerg }
432 1.2.4.2 joerg
433 1.2.4.2 joerg static int
434 1.2.4.2 joerg pad_start_input(void *opaque, void *block, int blksize,
435 1.2.4.2 joerg void (*intr)(void *), void *intrarg)
436 1.2.4.2 joerg {
437 1.2.4.2 joerg return EINVAL;
438 1.2.4.2 joerg }
439 1.2.4.2 joerg
440 1.2.4.2 joerg static int
441 1.2.4.2 joerg pad_halt_output(void *opaque)
442 1.2.4.2 joerg {
443 1.2.4.2 joerg pad_softc_t *sc;
444 1.2.4.2 joerg
445 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
446 1.2.4.2 joerg sc->sc_intr = NULL;
447 1.2.4.2 joerg sc->sc_intrarg = NULL;
448 1.2.4.2 joerg sc->sc_buflen = 0;
449 1.2.4.2 joerg sc->sc_rpos = sc->sc_wpos = 0;
450 1.2.4.2 joerg
451 1.2.4.2 joerg return 0;
452 1.2.4.2 joerg }
453 1.2.4.2 joerg
454 1.2.4.2 joerg static int
455 1.2.4.2 joerg pad_halt_input(void *opaque)
456 1.2.4.2 joerg {
457 1.2.4.2 joerg return 0;
458 1.2.4.2 joerg }
459 1.2.4.2 joerg
460 1.2.4.2 joerg static int
461 1.2.4.2 joerg pad_getdev(void *opaque, struct audio_device *ret)
462 1.2.4.2 joerg {
463 1.2.4.2 joerg
464 1.2.4.2 joerg *ret = pad_device;
465 1.2.4.2 joerg
466 1.2.4.2 joerg return 0;
467 1.2.4.2 joerg }
468 1.2.4.2 joerg
469 1.2.4.2 joerg static int
470 1.2.4.2 joerg pad_set_port(void *opaque, mixer_ctrl_t *mc)
471 1.2.4.2 joerg {
472 1.2.4.2 joerg pad_softc_t *sc;
473 1.2.4.2 joerg
474 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
475 1.2.4.2 joerg
476 1.2.4.2 joerg switch (mc->dev) {
477 1.2.4.2 joerg case PAD_OUTPUT_MASTER_VOLUME:
478 1.2.4.2 joerg case PAD_INPUT_DAC_VOLUME:
479 1.2.4.2 joerg sc->sc_swvol = mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
480 1.2.4.2 joerg return 0;
481 1.2.4.2 joerg }
482 1.2.4.2 joerg
483 1.2.4.2 joerg return ENXIO;
484 1.2.4.2 joerg }
485 1.2.4.2 joerg
486 1.2.4.2 joerg static int
487 1.2.4.2 joerg pad_get_port(void *opaque, mixer_ctrl_t *mc)
488 1.2.4.2 joerg {
489 1.2.4.2 joerg pad_softc_t *sc;
490 1.2.4.2 joerg
491 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
492 1.2.4.2 joerg
493 1.2.4.2 joerg switch (mc->dev) {
494 1.2.4.2 joerg case PAD_OUTPUT_MASTER_VOLUME:
495 1.2.4.2 joerg case PAD_INPUT_DAC_VOLUME:
496 1.2.4.2 joerg mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_swvol;
497 1.2.4.2 joerg return 0;
498 1.2.4.2 joerg }
499 1.2.4.2 joerg
500 1.2.4.2 joerg return ENXIO;
501 1.2.4.2 joerg }
502 1.2.4.2 joerg
503 1.2.4.2 joerg static int
504 1.2.4.2 joerg pad_query_devinfo(void *opaque, mixer_devinfo_t *di)
505 1.2.4.2 joerg {
506 1.2.4.2 joerg pad_softc_t *sc;
507 1.2.4.2 joerg
508 1.2.4.2 joerg sc = (pad_softc_t *)opaque;
509 1.2.4.2 joerg
510 1.2.4.2 joerg switch (di->index) {
511 1.2.4.2 joerg case PAD_OUTPUT_CLASS:
512 1.2.4.2 joerg di->mixer_class = PAD_OUTPUT_CLASS;
513 1.2.4.2 joerg strcpy(di->label.name, AudioCoutputs);
514 1.2.4.2 joerg di->type = AUDIO_MIXER_CLASS;
515 1.2.4.2 joerg di->next = di->prev = AUDIO_MIXER_LAST;
516 1.2.4.2 joerg return 0;
517 1.2.4.2 joerg case PAD_INPUT_CLASS:
518 1.2.4.2 joerg di->mixer_class = PAD_INPUT_CLASS;
519 1.2.4.2 joerg strcpy(di->label.name, AudioCinputs);
520 1.2.4.2 joerg di->type = AUDIO_MIXER_CLASS;
521 1.2.4.2 joerg di->next = di->prev = AUDIO_MIXER_LAST;
522 1.2.4.2 joerg return 0;
523 1.2.4.2 joerg case PAD_OUTPUT_MASTER_VOLUME:
524 1.2.4.2 joerg di->mixer_class = PAD_OUTPUT_CLASS;
525 1.2.4.2 joerg strcpy(di->label.name, AudioNmaster);
526 1.2.4.2 joerg di->type = AUDIO_MIXER_VALUE;
527 1.2.4.2 joerg di->next = di->prev = AUDIO_MIXER_LAST;
528 1.2.4.2 joerg di->un.v.num_channels = 1;
529 1.2.4.2 joerg strcpy(di->un.v.units.name, AudioNvolume);
530 1.2.4.2 joerg return 0;
531 1.2.4.2 joerg case PAD_INPUT_DAC_VOLUME:
532 1.2.4.2 joerg di->mixer_class = PAD_INPUT_CLASS;
533 1.2.4.2 joerg strcpy(di->label.name, AudioNdac);
534 1.2.4.2 joerg di->type = AUDIO_MIXER_VALUE;
535 1.2.4.2 joerg di->next = di->prev = AUDIO_MIXER_LAST;
536 1.2.4.2 joerg di->un.v.num_channels = 1;
537 1.2.4.2 joerg strcpy(di->un.v.units.name, AudioNvolume);
538 1.2.4.2 joerg return 0;
539 1.2.4.2 joerg }
540 1.2.4.2 joerg
541 1.2.4.2 joerg return ENXIO;
542 1.2.4.2 joerg }
543 1.2.4.2 joerg
544 1.2.4.2 joerg static int
545 1.2.4.2 joerg pad_get_props(void *opaque)
546 1.2.4.2 joerg {
547 1.2.4.2 joerg return 0;
548 1.2.4.2 joerg }
549 1.2.4.2 joerg
550 1.2.4.2 joerg static int
551 1.2.4.2 joerg pad_round_blocksize(void *opaque, int blksize, int mode,
552 1.2.4.2 joerg const audio_params_t *p)
553 1.2.4.2 joerg {
554 1.2.4.2 joerg return PAD_BLKSIZE;
555 1.2.4.2 joerg }
556