aica.c revision 1.22 1 /* $NetBSD: aica.c,v 1.22 2011/11/23 23:07:29 jmcneill Exp $ */
2
3 /*
4 * Copyright (c) 2003 SHIMIZU Ryo <ryo (at) misakimix.org>
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 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.22 2011/11/23 23:07:29 jmcneill Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/kernel.h>
38 #include <sys/proc.h>
39 #include <sys/audioio.h>
40 #include <sys/bus.h>
41
42 #include <dev/audio_if.h>
43 #include <dev/mulaw.h>
44 #include <dev/auconv.h>
45
46 #include <machine/sysasicvar.h>
47
48 #include <dreamcast/dev/g2/g2busvar.h>
49 #include <dreamcast/dev/g2/aicavar.h>
50 #include <dreamcast/dev/microcode/aica_armcode.h>
51
52 #define AICA_REG_ADDR 0x00700000
53 #define AICA_RAM_START 0x00800000
54 #define AICA_RAM_SIZE 0x00200000
55 #define AICA_NCHAN 64
56 #define AICA_TIMEOUT 0x1800
57
58 struct aica_softc {
59 device_t sc_dev; /* base device */
60 kmutex_t sc_lock;
61 kmutex_t sc_intr_lock;
62 bus_space_tag_t sc_memt;
63 bus_space_handle_t sc_aica_regh;
64 bus_space_handle_t sc_aica_memh;
65
66 /* audio property */
67 int sc_open;
68 int sc_encodings;
69 int sc_precision;
70 int sc_channels;
71 int sc_rate;
72 void (*sc_intr)(void *);
73 void *sc_intr_arg;
74
75 int sc_output_master;
76 int sc_output_gain[2];
77 #define AICA_VOLUME_LEFT 0
78 #define AICA_VOLUME_RIGHT 1
79
80 /* work for output */
81 void *sc_buffer;
82 void *sc_buffer_start;
83 void *sc_buffer_end;
84 int sc_blksize;
85 int sc_nextfill;
86 };
87
88 const struct {
89 const char *name;
90 int encoding;
91 int precision;
92 } aica_encodings[] = {
93 {AudioEadpcm, AUDIO_ENCODING_ADPCM, 4},
94 {AudioEslinear, AUDIO_ENCODING_SLINEAR, 8},
95 {AudioEulinear, AUDIO_ENCODING_ULINEAR, 8},
96 {AudioEmulaw, AUDIO_ENCODING_ULAW, 8},
97 {AudioEalaw, AUDIO_ENCODING_ALAW, 8},
98 {AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE, 16},
99 {AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE, 16},
100 {AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE, 16},
101 {AudioEulinear_le, AUDIO_ENCODING_ULINEAR_LE, 16},
102 };
103
104 #define AICA_NFORMATS 5
105 static const struct audio_format aica_formats[AICA_NFORMATS] = {
106 {NULL, AUMODE_PLAY, AUDIO_ENCODING_ADPCM, 4, 4,
107 1, AUFMT_MONAURAL, 0, {1, 65536}},
108 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
109 1, AUFMT_MONAURAL, 0, {1, 65536}},
110 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
111 2, AUFMT_STEREO, 0, {1, 65536}},
112 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 8, 8,
113 1, AUFMT_MONAURAL, 0, {1, 65536}},
114 {NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 8, 8,
115 2, AUFMT_STEREO, 0, {1, 65536}},
116 };
117
118 int aica_match(device_t, cfdata_t, void *);
119 void aica_attach(device_t, device_t, void *);
120 int aica_print(void *, const char *);
121
122 CFATTACH_DECL_NEW(aica, sizeof(struct aica_softc), aica_match, aica_attach,
123 NULL, NULL);
124
125 const struct audio_device aica_device = {
126 "Dreamcast Sound",
127 "",
128 "aica"
129 };
130
131 inline static void aica_g2fifo_wait(void);
132 void aica_enable(struct aica_softc *);
133 void aica_disable(struct aica_softc *);
134 void aica_memwrite(struct aica_softc *, bus_size_t, uint32_t *, int);
135 void aica_ch2p16write(struct aica_softc *, bus_size_t, uint16_t *, int);
136 void aica_ch2p8write(struct aica_softc *, bus_size_t, uint8_t *, int);
137 void aica_command(struct aica_softc *, uint32_t);
138 void aica_sendparam(struct aica_softc *, uint32_t, int, int);
139 void aica_play(struct aica_softc *, int, int, int, int);
140 void aica_fillbuffer(struct aica_softc *);
141
142 /* intr */
143 int aica_intr(void *);
144
145 /* for audio */
146 int aica_open(void *, int);
147 void aica_close(void *);
148 int aica_query_encoding(void *, struct audio_encoding *);
149 int aica_set_params(void *, int, int, audio_params_t *,
150 audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
151 int aica_round_blocksize(void *, int, int, const audio_params_t *);
152 size_t aica_round_buffersize(void *, int, size_t);
153 int aica_trigger_output(void *, void *, void *, int, void (*)(void *), void *,
154 const audio_params_t *);
155 int aica_trigger_input(void *, void *, void *, int, void (*)(void *), void *,
156 const audio_params_t *);
157 int aica_halt_output(void *);
158 int aica_halt_input(void *);
159 int aica_getdev(void *, struct audio_device *);
160 int aica_set_port(void *, mixer_ctrl_t *);
161 int aica_get_port(void *, mixer_ctrl_t *);
162 int aica_query_devinfo(void *, mixer_devinfo_t *);
163 void aica_encode(int, int, int, int, u_char *, u_short **);
164 int aica_get_props(void *);
165 void aica_get_locks(void *, kmutex_t **, kmutex_t **);
166
167 const struct audio_hw_if aica_hw_if = {
168 aica_open,
169 aica_close,
170 NULL, /* aica_drain */
171 aica_query_encoding,
172 aica_set_params,
173 aica_round_blocksize,
174 NULL, /* aica_commit_setting */
175 NULL, /* aica_init_output */
176 NULL, /* aica_init_input */
177 NULL, /* aica_start_output */
178 NULL, /* aica_start_input */
179 aica_halt_output,
180 aica_halt_input,
181 NULL, /* aica_speaker_ctl */
182 aica_getdev,
183 NULL, /* aica_setfd */
184 aica_set_port,
185 aica_get_port,
186 aica_query_devinfo,
187 NULL, /* aica_allocm */
188 NULL, /* aica_freem */
189
190 aica_round_buffersize, /* aica_round_buffersize */
191
192 NULL, /* aica_mappage */
193 aica_get_props,
194 aica_trigger_output,
195 aica_trigger_input,
196 NULL, /* aica_dev_ioctl */
197 aica_get_locks,
198 };
199
200 int
201 aica_match(device_t parent, cfdata_t cf, void *aux)
202 {
203 static int aica_matched = 0;
204
205 if (aica_matched)
206 return 0;
207
208 aica_matched = 1;
209 return 1;
210 }
211
212 void
213 aica_attach(device_t parent, device_t self, void *aux)
214 {
215 struct aica_softc *sc;
216 struct g2bus_attach_args *ga;
217 int i;
218
219 sc = device_private(self);
220 ga = aux;
221 sc->sc_dev = self;
222 sc->sc_memt = ga->ga_memt;
223
224 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
225 mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
226
227 if (bus_space_map(sc->sc_memt, AICA_REG_ADDR, 0x3000, 0,
228 &sc->sc_aica_regh) != 0) {
229 aprint_error(": can't map AICA register space\n");
230 return;
231 }
232
233 if (bus_space_map(sc->sc_memt, AICA_RAM_START, AICA_RAM_SIZE, 0,
234 &sc->sc_aica_memh) != 0) {
235 aprint_error(": can't map AICA memory space\n");
236 return;
237 }
238
239 aprint_normal(": ARM7 Sound Processing Unit\n");
240
241 aica_disable(sc);
242
243 for (i = 0; i < AICA_NCHAN; i++)
244 bus_space_write_4(sc->sc_memt,sc->sc_aica_regh, i << 7,
245 ((bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, i << 7)
246 & ~0x4000) | 0x8000));
247
248 /* load microcode, and clear memory */
249 bus_space_set_region_4(sc->sc_memt, sc->sc_aica_memh,
250 0, 0, AICA_RAM_SIZE / 4);
251
252 aica_memwrite(sc, 0, aica_armcode, sizeof(aica_armcode));
253
254 aica_enable(sc);
255
256 aprint_normal_dev(self, "interrupting at %s\n",
257 sysasic_intr_string(SYSASIC_IRL9));
258 sysasic_intr_establish(SYSASIC_EVENT_AICA, IPL_BIO, SYSASIC_IRL9,
259 aica_intr, sc);
260
261 audio_attach_mi(&aica_hw_if, sc, self);
262
263 /* init parameters */
264 sc->sc_output_master = 255;
265 sc->sc_output_gain[AICA_VOLUME_LEFT] = 255;
266 sc->sc_output_gain[AICA_VOLUME_RIGHT] = 255;
267 }
268
269 void
270 aica_enable(struct aica_softc *sc)
271 {
272
273 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28a8, 24);
274 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00,
275 bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) & ~1);
276 }
277
278 void
279 aica_disable(struct aica_softc *sc)
280 {
281
282 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00,
283 bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) | 1);
284 }
285
286 inline static void
287 aica_g2fifo_wait(void)
288 {
289 int i;
290
291 i = AICA_TIMEOUT;
292 while (--i > 0)
293 if ((*(volatile uint32_t *)0xa05f688c) & 0x11)
294 break;
295 }
296
297 void
298 aica_memwrite(struct aica_softc *sc, bus_size_t offset, uint32_t *src, int len)
299 {
300 int n;
301
302 KASSERT((offset & 3) == 0);
303 n = (len + 3) / 4; /* uint32_t * n (aligned) */
304
305 aica_g2fifo_wait();
306 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
307 offset, src, n);
308 }
309
310 void
311 aica_ch2p16write(struct aica_softc *sc, bus_size_t offset, uint16_t *src,
312 int len)
313 {
314 union {
315 uint32_t w[8];
316 uint16_t s[16];
317 } buf;
318 uint16_t *p;
319 int i;
320
321 KASSERT((offset & 3) == 0);
322
323 while (len >= 32) {
324 p = buf.s;
325 *p++ = *src++; src++;
326 *p++ = *src++; src++;
327 *p++ = *src++; src++;
328 *p++ = *src++; src++;
329 *p++ = *src++; src++;
330 *p++ = *src++; src++;
331 *p++ = *src++; src++;
332 *p++ = *src++; src++;
333 *p++ = *src++; src++;
334 *p++ = *src++; src++;
335 *p++ = *src++; src++;
336 *p++ = *src++; src++;
337 *p++ = *src++; src++;
338 *p++ = *src++; src++;
339 *p++ = *src++; src++;
340 *p++ = *src++; src++;
341
342 aica_g2fifo_wait();
343 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
344 offset, buf.w , 32 / 4);
345
346 offset += sizeof(uint16_t) * 16;
347 len -= 32;
348 }
349
350 if (len / 2 > 0) {
351 p = buf.s;
352 for (i = 0; i < len / 2; i++) {
353 *p++ = *src++; src++;
354 }
355
356 aica_g2fifo_wait();
357 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
358 offset, buf.w, len / 4);
359 }
360 }
361
362 void
363 aica_ch2p8write(struct aica_softc *sc, bus_size_t offset, uint8_t *src,
364 int len)
365 {
366 uint32_t buf[8];
367 uint8_t *p;
368 int i;
369
370 KASSERT((offset & 3) == 0);
371 while (len >= 32) {
372 p = (uint8_t *)buf;
373
374 *p++ = *src++; src++;
375 *p++ = *src++; src++;
376 *p++ = *src++; src++;
377 *p++ = *src++; src++;
378 *p++ = *src++; src++;
379 *p++ = *src++; src++;
380 *p++ = *src++; src++;
381 *p++ = *src++; src++;
382 *p++ = *src++; src++;
383 *p++ = *src++; src++;
384 *p++ = *src++; src++;
385 *p++ = *src++; src++;
386 *p++ = *src++; src++;
387 *p++ = *src++; src++;
388 *p++ = *src++; src++;
389 *p++ = *src++; src++;
390 *p++ = *src++; src++;
391 *p++ = *src++; src++;
392 *p++ = *src++; src++;
393 *p++ = *src++; src++;
394 *p++ = *src++; src++;
395 *p++ = *src++; src++;
396 *p++ = *src++; src++;
397 *p++ = *src++; src++;
398 *p++ = *src++; src++;
399 *p++ = *src++; src++;
400 *p++ = *src++; src++;
401 *p++ = *src++; src++;
402 *p++ = *src++; src++;
403 *p++ = *src++; src++;
404 *p++ = *src++; src++;
405 *p++ = *src++; src++;
406
407 aica_g2fifo_wait();
408 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
409 offset, buf, 32 / 4);
410
411 offset += 32;
412 len -= 32;
413 }
414
415 if (len) {
416 p = (uint8_t *)buf;
417 for (i = 0; i < len; i++)
418 *p++ = *src++; src++;
419
420 aica_g2fifo_wait();
421 bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
422 offset, buf, len / 4);
423 }
424 }
425
426 int
427 aica_open(void *addr, int flags)
428 {
429 struct aica_softc *sc;
430
431 sc = addr;
432 if (sc->sc_open)
433 return EBUSY;
434
435 sc->sc_intr = NULL;
436 sc->sc_open = 1;
437
438 return 0;
439 }
440
441 void
442 aica_close(void *addr)
443 {
444 struct aica_softc *sc;
445
446 sc = addr;
447 sc->sc_open = 0;
448 sc->sc_intr = NULL;
449 }
450
451 int
452 aica_query_encoding(void *addr, struct audio_encoding *fp)
453 {
454 if (fp->index >= sizeof(aica_encodings) / sizeof(aica_encodings[0]))
455 return EINVAL;
456
457 strcpy(fp->name, aica_encodings[fp->index].name);
458 fp->encoding = aica_encodings[fp->index].encoding;
459 fp->precision = aica_encodings[fp->index].precision;
460 fp->flags = 0;
461
462 return 0;
463 }
464
465 int
466 aica_set_params(void *addr, int setmode, int usemode,
467 audio_params_t *play, audio_params_t *rec,
468 stream_filter_list_t *pfil, stream_filter_list_t *rfil)
469 {
470 struct aica_softc *sc;
471 const audio_params_t *hw;
472 int i;
473
474 i = auconv_set_converter(aica_formats, AICA_NFORMATS,
475 AUMODE_PLAY, play, false, pfil);
476 if (i < 0)
477 return EINVAL;
478 hw = pfil->req_size > 0 ? &pfil->filters[0].param : play;
479 sc = addr;
480 sc->sc_precision = hw->precision;
481 sc->sc_channels = hw->channels;
482 sc->sc_rate = hw->sample_rate;
483 sc->sc_encodings = hw->encoding;
484 return 0;
485 }
486
487 int
488 aica_round_blocksize(void *addr, int blk, int mode, const audio_params_t *param)
489 {
490 #if 0 /* XXX this has not worked since kent-audio1 merge? */
491 struct aica_softc *sc;
492
493 sc = addr;
494 switch (sc->sc_precision) {
495 case 4:
496 if (sc->sc_channels == 1)
497 return AICA_DMABUF_SIZE / 4;
498 else
499 return AICA_DMABUF_SIZE / 2;
500 break;
501 case 8:
502 if (sc->sc_channels == 1)
503 return AICA_DMABUF_SIZE / 2;
504 else
505 return AICA_DMABUF_SIZE;
506 break;
507 case 16:
508 if (sc->sc_channels == 1)
509 return AICA_DMABUF_SIZE;
510 else
511 return AICA_DMABUF_SIZE * 2;
512 break;
513 default:
514 break;
515 }
516
517 #endif
518 return AICA_DMABUF_SIZE / 4;
519 }
520
521 size_t
522 aica_round_buffersize(void *addr, int dir, size_t bufsize)
523 {
524
525 if (dir == AUMODE_PLAY)
526 return 65536;
527
528 return 512; /* XXX: AUMINBUF */
529 }
530
531 void
532 aica_command(struct aica_softc *sc, uint32_t command)
533 {
534
535 bus_space_write_4(sc->sc_memt, sc->sc_aica_memh,
536 AICA_ARM_CMD_COMMAND, command);
537 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, AICA_ARM_CMD_SERIAL,
538 bus_space_read_4(sc->sc_memt, sc->sc_aica_memh,
539 AICA_ARM_CMD_SERIAL) + 1);
540 }
541
542 void
543 aica_sendparam(struct aica_softc *sc, uint32_t command,
544 int32_t lparam, int32_t rparam)
545 {
546
547 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
548 AICA_ARM_CMD_LPARAM, lparam);
549 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
550 AICA_ARM_CMD_RPARAM, rparam);
551
552 aica_command(sc, command);
553 }
554
555 void
556 aica_play(struct aica_softc *sc, int blksize, int channel, int rate, int prec)
557 {
558
559 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
560 AICA_ARM_CMD_BLOCKSIZE, blksize);
561 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
562 AICA_ARM_CMD_CHANNEL, channel);
563 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
564 AICA_ARM_CMD_RATE, rate);
565 bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
566 AICA_ARM_CMD_PRECISION, prec);
567
568 aica_command(sc, AICA_COMMAND_PLAY);
569 }
570
571 void
572 aica_fillbuffer(struct aica_softc *sc)
573 {
574
575 if (sc->sc_channels == 2) {
576 if (sc->sc_precision == 16) {
577 aica_ch2p16write(sc,
578 AICA_DMABUF_LEFT + sc->sc_nextfill,
579 (uint16_t *)sc->sc_buffer + 0, sc->sc_blksize / 2);
580 aica_ch2p16write(sc,
581 AICA_DMABUF_RIGHT + sc->sc_nextfill,
582 (uint16_t *)sc->sc_buffer + 1, sc->sc_blksize / 2);
583 } else if (sc->sc_precision == 8) {
584 aica_ch2p8write(sc, AICA_DMABUF_LEFT + sc->sc_nextfill,
585 (uint8_t *)sc->sc_buffer + 0, sc->sc_blksize / 2);
586 aica_ch2p8write(sc, AICA_DMABUF_RIGHT + sc->sc_nextfill,
587 (uint8_t *)sc->sc_buffer + 1, sc->sc_blksize / 2);
588 }
589 } else {
590 aica_memwrite(sc, AICA_DMABUF_MONO + sc->sc_nextfill,
591 sc->sc_buffer, sc->sc_blksize);
592 }
593
594 sc->sc_buffer = (int8_t *)sc->sc_buffer + sc->sc_blksize;
595 if (sc->sc_buffer >= sc->sc_buffer_end)
596 sc->sc_buffer = sc->sc_buffer_start;
597
598 sc->sc_nextfill ^= sc->sc_blksize / sc->sc_channels;
599 }
600
601 int
602 aica_intr(void *arg)
603 {
604 struct aica_softc *sc;
605
606 sc = arg;
607
608 mutex_spin_enter(&sc->sc_intr_lock);
609
610 aica_fillbuffer(sc);
611
612 /* call audio interrupt handler (audio_pint()) */
613 if (sc->sc_open && sc->sc_intr != NULL) {
614 (*(sc->sc_intr))(sc->sc_intr_arg);
615 }
616
617 /* clear SPU interrupt */
618 bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28bc, 0x20);
619
620 mutex_spin_exit(&sc->sc_intr_lock);
621
622 return 1;
623 }
624
625 int
626 aica_trigger_output(void *addr, void *start, void *end, int blksize,
627 void (*intr)(void *), void *arg, const audio_params_t *param)
628 {
629 struct aica_softc *sc;
630
631 sc = addr;
632 aica_command(sc, AICA_COMMAND_INIT);
633 tsleep(aica_trigger_output, PWAIT, "aicawait", hz / 20);
634
635 sc->sc_buffer_start = sc->sc_buffer = start;
636 sc->sc_buffer_end = end;
637 sc->sc_blksize = blksize;
638 sc->sc_nextfill = 0;
639
640 sc->sc_intr = intr;
641 sc->sc_intr_arg = arg;
642
643 /* fill buffers in advance */
644 aica_intr(sc);
645 aica_intr(sc);
646
647 /* ...and start playing */
648 aica_play(sc, blksize / sc->sc_channels, sc->sc_channels, sc->sc_rate,
649 sc->sc_precision);
650
651 return 0;
652 }
653
654 int
655 aica_trigger_input(void *addr, void *start, void *end, int blksize,
656 void (*intr)(void *), void *arg, const audio_params_t *param)
657 {
658
659 return ENODEV;
660 }
661
662 int
663 aica_halt_output(void *addr)
664 {
665 struct aica_softc *sc;
666
667 sc = addr;
668 aica_command(sc, AICA_COMMAND_STOP);
669 return 0;
670 }
671
672 int
673 aica_halt_input(void *addr)
674 {
675
676 return ENODEV;
677 }
678
679 int
680 aica_getdev(void *addr, struct audio_device *ret)
681 {
682
683 *ret = aica_device;
684 return 0;
685 }
686
687 int
688 aica_set_port(void *addr, mixer_ctrl_t *mc)
689 {
690 struct aica_softc *sc;
691
692 sc = addr;
693 switch (mc->dev) {
694 case AICA_MASTER_VOL:
695 sc->sc_output_master =
696 mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] & 0xff;
697 aica_sendparam(sc, AICA_COMMAND_MVOL,
698 sc->sc_output_master, sc->sc_output_master);
699 break;
700 case AICA_OUTPUT_GAIN:
701 sc->sc_output_gain[AICA_VOLUME_LEFT] =
702 mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] & 0xff;
703 sc->sc_output_gain[AICA_VOLUME_RIGHT] =
704 mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & 0xff;
705 aica_sendparam(sc, AICA_COMMAND_VOL,
706 sc->sc_output_gain[AICA_VOLUME_LEFT],
707 sc->sc_output_gain[AICA_VOLUME_RIGHT]);
708 break;
709 default:
710 return EINVAL;
711 }
712
713 return 0;
714 }
715
716 int
717 aica_get_port(void *addr, mixer_ctrl_t *mc)
718 {
719 struct aica_softc *sc;
720
721 sc = addr;
722 switch (mc->dev) {
723 case AICA_MASTER_VOL:
724 if (mc->un.value.num_channels != 1)
725 return EINVAL;
726 mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
727 L16TO256(L256TO16(sc->sc_output_master));
728 break;
729 case AICA_OUTPUT_GAIN:
730 mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
731 sc->sc_output_gain[AICA_VOLUME_LEFT];
732 mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
733 sc->sc_output_gain[AICA_VOLUME_RIGHT];
734 break;
735 default:
736 return EINVAL;
737 }
738 return 0;
739 }
740
741 int
742 aica_query_devinfo(void *addr, mixer_devinfo_t *md)
743 {
744
745 switch (md->index) {
746 case AICA_MASTER_VOL:
747 md->type = AUDIO_MIXER_VALUE;
748 md->mixer_class = AICA_OUTPUT_CLASS;
749 md->prev = md->next = AUDIO_MIXER_LAST;
750 strcpy(md->label.name, AudioNmaster);
751 md->un.v.num_channels = 1;
752 strcpy(md->un.v.units.name, AudioNvolume);
753 return 0;
754 case AICA_OUTPUT_GAIN:
755 md->type = AUDIO_MIXER_VALUE;
756 md->mixer_class = AICA_OUTPUT_CLASS;
757 md->prev = md->next = AUDIO_MIXER_LAST;
758 strcpy(md->label.name, AudioNoutput);
759 md->un.v.num_channels = 2;
760 strcpy(md->label.name, AudioNvolume);
761 return 0;
762 case AICA_OUTPUT_CLASS:
763 md->type = AUDIO_MIXER_CLASS;
764 md->mixer_class = AICA_OUTPUT_CLASS;
765 md->next = md->prev = AUDIO_MIXER_LAST;
766 strcpy(md->label.name, AudioCoutputs);
767 return 0;
768 }
769
770 return ENXIO;
771 }
772
773 int
774 aica_get_props(void *addr)
775 {
776
777 return 0;
778 }
779
780 void
781 aica_get_locks(void *addr, kmutex_t **intr, kmutex_t **thread)
782 {
783 struct aica_softc *sc;
784
785 sc = addr;
786 *intr = &sc->sc_intr_lock;
787 *thread = &sc->sc_lock;
788 }
789