1 /* $NetBSD: aria.c,v 1.41 2019/06/08 08:02:38 isaki Exp $ */
2
3 /*-
4 * Copyright (c) 1995, 1996, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*-
33 * TODO:
34 * o Test the driver on cards other than a single
35 * Prometheus Aria 16.
36 * o Look into where aria_prometheus_kludge() belongs.
37 * o Add some DMA code. It accomplishes its goal by
38 * direct IO at the moment.
39 * I cannot effectively code it.
40 * o Rework the mixer interface.
41 * o Deal with the lvls better. We need to do better mapping
42 * between logarithmic scales and the one byte that
43 * we are passed.
44 * o Deal better with cards that have no mixer.
45 */
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: aria.c,v 1.41 2019/06/08 08:02:38 isaki Exp $");
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/errno.h>
53 #include <sys/ioctl.h>
54 #include <sys/syslog.h>
55 #include <sys/device.h>
56 #include <sys/proc.h>
57 #include <sys/buf.h>
58 #include <sys/fcntl.h>
59 #include <sys/cpu.h>
60 #include <sys/bus.h>
61 #include <sys/audioio.h>
62
63 #include <dev/audio/audio_if.h>
64
65 #include <dev/isa/isavar.h>
66 #include <dev/isa/ariareg.h>
67
68 #ifdef AUDIO_DEBUG
69 #define DPRINTF(x) printf x
70 int ariadebug = 0;
71 #else
72 #define DPRINTF(x)
73 #endif
74
75 struct aria_mixdev_info {
76 u_char num_channels;
77 u_char level[2];
78 u_char mute;
79 };
80
81 struct aria_mixmaster {
82 u_char num_channels;
83 u_char level[2];
84 u_char treble[2];
85 u_char bass[2];
86 };
87
88 struct aria_softc {
89 device_t sc_dev; /* base device */
90 kmutex_t sc_lock;
91 kmutex_t sc_intr_lock;
92 void *sc_ih; /* interrupt vectoring */
93 bus_space_tag_t sc_iot; /* Tag on 'da bus. */
94 bus_space_handle_t sc_ioh; /* Handle of iospace */
95 isa_chipset_tag_t sc_ic; /* ISA chipset info */
96
97 u_short sc_open; /* reference count of open calls */
98 u_short sc_play; /* non-paused play chans 2**chan */
99 u_short sc_record; /* non-paused record chans 2**chan */
100 /* XXX -- keep this? */
101 u_short sc_gain[2]; /* left/right gain (play) */
102
103 u_long sc_rate; /* Sample rate for input and output */
104 u_int sc_encoding; /* audio encoding -- mu-law/linear */
105 int sc_chans; /* # of channels */
106 int sc_precision; /* # bits per sample */
107
108 u_long sc_interrupts; /* number of interrupts taken */
109 void (*sc_rintr)(void*); /* record transfer completion intr handler */
110 void (*sc_pintr)(void*); /* play transfer completion intr handler */
111 void *sc_rarg; /* arg for sc_rintr() */
112 void *sc_parg; /* arg for sc_pintr() */
113
114 int sc_blocksize; /* literal dio block size */
115 void *sc_rdiobuffer; /* record: where the next samples should be */
116 void *sc_pdiobuffer; /* play: where the next samples are */
117
118 u_short sc_hardware; /* bit field of hardware present */
119 #define ARIA_TELEPHONE 0x0001 /* has telephone input */
120 #define ARIA_MIXER 0x0002 /* has SC18075 digital mixer */
121 #define ARIA_MODEL 0x0004 /* is SC18025 (=0) or SC18026 (=1) */
122
123 struct aria_mixdev_info aria_mix[6];
124 struct aria_mixmaster ariamix_master;
125 u_char aria_mix_source;
126
127 int sc_sendcmd_err;
128 };
129
130 int ariaprobe(device_t, cfdata_t, void *);
131 void ariaattach(device_t, device_t, void *);
132 void ariaclose(void *);
133 int ariaopen(void *, int);
134 int ariareset(bus_space_tag_t, bus_space_handle_t);
135 int aria_reset(struct aria_softc *);
136 int aria_getdev(void *, struct audio_device *);
137
138 void aria_do_kludge(bus_space_tag_t, bus_space_handle_t,
139 bus_space_handle_t,
140 u_short, u_short, u_short, u_short);
141 void aria_prometheus_kludge(struct isa_attach_args *, bus_space_handle_t);
142
143 int aria_query_format(void *, audio_format_query_t *);
144 int aria_round_blocksize(void *, int, int, const audio_params_t *);
145 int aria_speaker_ctl(void *, int);
146 int aria_commit_settings(void *);
147 int aria_set_format(void *, int,
148 const audio_params_t *, const audio_params_t *,
149 audio_filter_reg_t *, audio_filter_reg_t *);
150 int aria_get_props(void *);
151 void aria_get_locks(void *, kmutex_t **, kmutex_t **);
152
153 int aria_start_output(void *, void *, int, void (*)(void *), void*);
154 int aria_start_input(void *, void *, int, void (*)(void *), void*);
155
156 int aria_halt_input(void *);
157 int aria_halt_output(void *);
158
159 int aria_sendcmd(struct aria_softc *, u_short, int, int, int);
160
161 u_short aria_getdspmem(struct aria_softc *, u_short);
162 void aria_putdspmem(struct aria_softc *, u_short, u_short);
163
164 int aria_intr(void *);
165 short ariaversion(struct aria_softc *);
166
167 void aria_set_mixer(struct aria_softc *, int);
168
169 void aria_mix_write(struct aria_softc *, int, int);
170 int aria_mix_read(struct aria_softc *, int);
171
172 int aria_mixer_set_port(void *, mixer_ctrl_t *);
173 int aria_mixer_get_port(void *, mixer_ctrl_t *);
174 int aria_mixer_query_devinfo(void *, mixer_devinfo_t *);
175
176 CFATTACH_DECL_NEW(aria, sizeof(struct aria_softc),
177 ariaprobe, ariaattach, NULL, NULL);
178
179 /* XXX temporary test for 1.3 */
180 #ifndef AudioNaux
181 /* 1.3 */
182 struct cfdriver aria_cd = {
183 NULL, "aria", DV_DULL
184 };
185 #endif
186
187 struct audio_device aria_device = {
188 "Aria 16(se)",
189 "x",
190 "aria"
191 };
192
193 #define ARIA_FORMAT(enc, prec) \
194 { \
195 .mode = AUMODE_PLAY | AUMODE_RECORD, \
196 .encoding = (enc), \
197 .validbits = (prec), \
198 .precision = (prec), \
199 .channels = 2, \
200 .channel_mask = AUFMT_STEREO, \
201 .frequency_type = 6, \
202 .frequency = { 7875, 11025, 15750, 22050, 31500, 44100 }, \
203 }
204 /* XXX Some models seem to support mulaw/alaw. */
205 const struct audio_format aria_formats[] = {
206 ARIA_FORMAT(AUDIO_ENCODING_ULINEAR, 8),
207 ARIA_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 16),
208 };
209 #define ARIA_NFORMATS __arraycount(aria_formats)
210
211 /*
212 * Define our interface to the higher level audio driver.
213 */
214
215 const struct audio_hw_if aria_hw_if = {
216 .open = ariaopen,
217 .close = ariaclose,
218 .query_format = aria_query_format,
219 .set_format = aria_set_format,
220 .round_blocksize = aria_round_blocksize,
221 .commit_settings = aria_commit_settings,
222 .start_output = aria_start_output,
223 .start_input = aria_start_input,
224 .halt_output = aria_halt_output,
225 .halt_input = aria_halt_input,
226 .getdev = aria_getdev,
227 .set_port = aria_mixer_set_port,
228 .get_port = aria_mixer_get_port,
229 .query_devinfo = aria_mixer_query_devinfo,
230 .get_props = aria_get_props,
231 .get_locks = aria_get_locks,
232 };
233
234 /*
235 * Probe / attach routines.
236 */
237
238 /*
239 * Probe for the aria hardware.
240 */
241 int
ariaprobe(device_t parent,cfdata_t cf,void * aux)242 ariaprobe(device_t parent, cfdata_t cf, void *aux)
243 {
244 bus_space_handle_t ioh;
245 struct isa_attach_args *ia;
246
247 ia = aux;
248 if (ia->ia_nio < 1)
249 return 0;
250 if (ia->ia_nirq < 1)
251 return 0;
252
253 if (ISA_DIRECT_CONFIG(ia))
254 return 0;
255
256 if (!ARIA_BASE_VALID(ia->ia_io[0].ir_addr)) {
257 printf("aria: configured iobase %d invalid\n",
258 ia->ia_io[0].ir_addr);
259 return 0;
260 }
261
262 if (!ARIA_IRQ_VALID(ia->ia_irq[0].ir_irq)) {
263 printf("aria: configured irq %d invalid\n",
264 ia->ia_irq[0].ir_irq);
265 return 0;
266 }
267
268 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, ARIADSP_NPORT,
269 0, &ioh)) {
270 DPRINTF(("aria: aria probe failed\n"));
271 return 0;
272 }
273
274 if (cf->cf_flags & 1)
275 aria_prometheus_kludge(ia, ioh);
276
277 if (ariareset(ia->ia_iot, ioh) != 0) {
278 DPRINTF(("aria: aria probe failed\n"));
279 bus_space_unmap(ia->ia_iot, ioh, ARIADSP_NPORT);
280 return 0;
281 }
282
283 bus_space_unmap(ia->ia_iot, ioh, ARIADSP_NPORT);
284
285 ia->ia_nio = 1;
286 ia->ia_io[0].ir_size = ARIADSP_NPORT;
287
288 ia->ia_nirq = 1;
289
290 ia->ia_niomem = 0;
291 ia->ia_ndrq = 0;
292
293 DPRINTF(("aria: aria probe succeeded\n"));
294 return 1;
295 }
296
297 /*
298 * I didn't call this a kludge for
299 * nothing. This is cribbed from
300 * ariainit, the author of that
301 * disassembled some code to discover
302 * how to set up the initial values of
303 * the card. Without this, the card
304 * is dead. (It will not respond to _any_
305 * input at all.)
306 *
307 * ariainit can be found (ftp) at:
308 * ftp://ftp.wi.leidenuniv.nl/pub/audio/aria/programming/contrib/ariainit.zip
309 * currently.
310 */
311
312 void
aria_prometheus_kludge(struct isa_attach_args * ia,bus_space_handle_t ioh1)313 aria_prometheus_kludge(struct isa_attach_args *ia, bus_space_handle_t ioh1)
314 {
315 bus_space_tag_t iot;
316 bus_space_handle_t ioh;
317 u_short end;
318
319 DPRINTF(("aria: begin aria_prometheus_kludge\n"));
320
321 /* Begin Config Sequence */
322
323 iot = ia->ia_iot;
324 bus_space_map(iot, 0x200, 8, 0, &ioh);
325
326 bus_space_write_1(iot, ioh, 4, 0x4c);
327 bus_space_write_1(iot, ioh, 5, 0x42);
328 bus_space_write_1(iot, ioh, 6, 0x00);
329 bus_space_write_2(iot, ioh, 0, 0x0f);
330 bus_space_write_1(iot, ioh, 1, 0x00);
331 bus_space_write_2(iot, ioh, 0, 0x02);
332 bus_space_write_1(iot, ioh, 1, ia->ia_io[0].ir_addr>>2);
333
334 /*
335 * These next three lines set up the iobase
336 * and the irq; and disable the drq.
337 */
338 aria_do_kludge(iot, ioh, ioh1, 0x111,
339 ((ia->ia_io[0].ir_addr-0x280)>>2)+0xA0, 0xbf, 0xa0);
340 aria_do_kludge(iot, ioh, ioh1, 0x011,
341 ia->ia_irq[0].ir_irq-6, 0xf8, 0x00);
342 aria_do_kludge(iot, ioh, ioh1, 0x011, 0x00, 0xef, 0x00);
343
344 /* The rest of these lines just disable everything else */
345 aria_do_kludge(iot, ioh, ioh1, 0x113, 0x00, 0x88, 0x00);
346 aria_do_kludge(iot, ioh, ioh1, 0x013, 0x00, 0xf8, 0x00);
347 aria_do_kludge(iot, ioh, ioh1, 0x013, 0x00, 0xef, 0x00);
348 aria_do_kludge(iot, ioh, ioh1, 0x117, 0x00, 0x88, 0x00);
349 aria_do_kludge(iot, ioh, ioh1, 0x017, 0x00, 0xff, 0x00);
350
351 /* End Sequence */
352 bus_space_write_1(iot, ioh, 0, 0x0f);
353 end = bus_space_read_1(iot, ioh1, 0);
354 bus_space_write_2(iot, ioh, 0, 0x0f);
355 bus_space_write_1(iot, ioh, 1, end|0x80);
356 bus_space_read_1(iot, ioh, 0);
357
358 bus_space_unmap(iot, ioh, 8);
359 /*
360 * This delay is necessary for some reason,
361 * at least it would crash, and sometimes not
362 * probe properly if it did not exist.
363 */
364 delay(1000000);
365 }
366
367 void
aria_do_kludge(bus_space_tag_t iot,bus_space_handle_t ioh,bus_space_handle_t ioh1,u_short func,u_short bits,u_short and,u_short or)368 aria_do_kludge(
369 bus_space_tag_t iot,
370 bus_space_handle_t ioh,
371 bus_space_handle_t ioh1,
372 u_short func,
373 u_short bits,
374 u_short and,
375 u_short or)
376 {
377 u_int i;
378
379 if (func & 0x100) {
380 func &= ~0x100;
381 if (bits) {
382 bus_space_write_2(iot, ioh, 0, func-1);
383 bus_space_write_1(iot, ioh, 1, bits);
384 }
385 } else
386 or |= bits;
387
388 bus_space_write_1(iot, ioh, 0, func);
389 i = bus_space_read_1(iot, ioh1, 0);
390 bus_space_write_2(iot, ioh, 0, func);
391 bus_space_write_1(iot, ioh, 1, (i&and) | or);
392 }
393
394 /*
395 * Attach hardware to driver, attach hardware driver to audio
396 * pseudo-device driver.
397 */
398 void
ariaattach(device_t parent,device_t self,void * aux)399 ariaattach(device_t parent, device_t self, void *aux)
400 {
401 bus_space_handle_t ioh;
402 struct aria_softc *sc;
403 struct isa_attach_args *ia;
404 u_short i;
405
406 sc = device_private(self);
407 sc->sc_dev = self;
408 ia = aux;
409 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, ARIADSP_NPORT,
410 0, &ioh))
411 panic("%s: can map io port range", device_xname(self));
412
413 sc->sc_iot = ia->ia_iot;
414 sc->sc_ioh = ioh;
415 sc->sc_ic = ia->ia_ic;
416
417 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
418 mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_AUDIO);
419
420 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
421 IST_EDGE, IPL_AUDIO, aria_intr, sc);
422
423 DPRINTF(("isa_intr_establish() returns (%p)\n", sc->sc_ih));
424
425 i = aria_getdspmem(sc, ARIAA_HARDWARE_A);
426
427 sc->sc_hardware = 0;
428 sc->sc_hardware |= ((i>>13)&0x01)==1 ? ARIA_TELEPHONE:0;
429 sc->sc_hardware |= (((i>>5)&0x07))==0x04 ? ARIA_MIXER:0;
430 sc->sc_hardware |= (aria_getdspmem(sc, ARIAA_MODEL_A)>=1)?ARIA_MODEL:0;
431
432 sc->sc_open = 0;
433 sc->sc_play = 0;
434 sc->sc_record = 0;
435 sc->sc_rate = 7875;
436 sc->sc_chans = 1;
437 sc->sc_blocksize = 1024;
438 sc->sc_precision = 8;
439 sc->sc_rintr = 0;
440 sc->sc_rarg = 0;
441 sc->sc_pintr = 0;
442 sc->sc_parg = 0;
443 sc->sc_gain[0] = 127;
444 sc->sc_gain[1] = 127;
445
446 for (i=0; i<6; i++) {
447 if (i == ARIAMIX_TEL_LVL)
448 sc->aria_mix[i].num_channels = 1;
449 else
450 sc->aria_mix[i].num_channels = 2;
451 sc->aria_mix[i].level[0] = 127;
452 sc->aria_mix[i].level[1] = 127;
453 }
454
455 sc->ariamix_master.num_channels = 2;
456 sc->ariamix_master.level[0] = 222;
457 sc->ariamix_master.level[1] = 222;
458 sc->ariamix_master.bass[0] = 127;
459 sc->ariamix_master.bass[1] = 127;
460 sc->ariamix_master.treble[0] = 127;
461 sc->ariamix_master.treble[1] = 127;
462 sc->aria_mix_source = 0;
463
464 aria_commit_settings(sc);
465
466 printf(": dsp %s", (ARIA_MODEL&sc->sc_hardware)?"SC18026":"SC18025");
467 if (ARIA_TELEPHONE&sc->sc_hardware)
468 printf(", tel");
469 if (ARIA_MIXER&sc->sc_hardware)
470 printf(", SC18075 mixer");
471 printf("\n");
472
473 snprintf(aria_device.version, sizeof(aria_device.version), "%s",
474 ARIA_MODEL & sc->sc_hardware ? "SC18026" : "SC18025");
475
476 audio_attach_mi(&aria_hw_if, (void *)sc, sc->sc_dev);
477 }
478
479 /*
480 * Various routines to interface to higher level audio driver
481 */
482
483 int
ariaopen(void * addr,int flags)484 ariaopen(void *addr, int flags)
485 {
486 struct aria_softc *sc;
487
488 sc = addr;
489 DPRINTF(("ariaopen() called\n"));
490
491 if (!sc)
492 return ENXIO;
493
494 if (flags&FREAD)
495 sc->sc_open |= ARIAR_OPEN_RECORD;
496 if (flags&FWRITE)
497 sc->sc_open |= ARIAR_OPEN_PLAY;
498
499 return 0;
500 }
501
502 int
aria_getdev(void * addr,struct audio_device * retp)503 aria_getdev(void *addr, struct audio_device *retp)
504 {
505
506 *retp = aria_device;
507 return 0;
508 }
509
510 /*
511 * Various routines to interface to higher level audio driver
512 */
513
514 int
aria_query_format(void * addr,audio_format_query_t * afp)515 aria_query_format(void *addr, audio_format_query_t *afp)
516 {
517
518 return audio_query_format(aria_formats, ARIA_NFORMATS, afp);
519 }
520
521 /*
522 * Store blocksize in bytes.
523 */
524
525 int
aria_round_blocksize(void * addr,int blk,int mode,const audio_params_t * param)526 aria_round_blocksize(void *addr, int blk, int mode,
527 const audio_params_t *param)
528 {
529 int i;
530
531 #if 0 /* XXX -- this is being a tad bit of a problem... */
532 for (i = 64; i < 1024; i *= 2)
533 if (blk <= i)
534 break;
535 #else
536 i = 1024;
537 #endif
538 return i;
539 }
540
541 int
aria_get_props(void * addr)542 aria_get_props(void *addr)
543 {
544
545 /* XXX This driver doesn't seem to be written as full duplex. */
546 return AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE;
547 }
548
549 int
aria_set_format(void * addr,int setmode,const audio_params_t * p,const audio_params_t * r,audio_filter_reg_t * pfil,audio_filter_reg_t * rfil)550 aria_set_format(void *addr, int setmode,
551 const audio_params_t *p, const audio_params_t *r,
552 audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
553 {
554 struct aria_softc *sc;
555
556 sc = addr;
557
558 /* *p and *r are the identical because !AUDIO_PROP_INDEPENDENT. */
559 sc->sc_encoding = p->encoding;
560 sc->sc_precision = p->precision;
561 sc->sc_chans = p->channels;
562 sc->sc_rate = p->sample_rate;
563 return 0;
564 }
565
566 /*
567 * This is where all of the twiddling goes on.
568 */
569
570 int
aria_commit_settings(void * addr)571 aria_commit_settings(void *addr)
572 {
573 static u_char tones[16] =
574 { 7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15 };
575 struct aria_softc *sc;
576 bus_space_tag_t iot;
577 bus_space_handle_t ioh;
578 u_short format;
579 u_short left, right;
580 u_short samp;
581 u_char i;
582
583 DPRINTF(("aria_commit_settings\n"));
584
585 sc = addr;
586 iot = sc->sc_iot;
587 ioh = sc->sc_ioh;
588 switch (sc->sc_rate) {
589 case 7875: format = 0x00; samp = 0x60; break;
590 case 11025: format = 0x00; samp = 0x40; break;
591 case 15750: format = 0x10; samp = 0x60; break;
592 case 22050: format = 0x10; samp = 0x40; break;
593 case 31500: format = 0x10; samp = 0x20; break;
594 case 44100: format = 0x20; samp = 0x00; break;
595 default: format = 0x00; samp = 0x40; break;/* XXX can we get here? */
596 }
597
598 format |= (sc->sc_precision == 16) ? 0x02 : 0x00;
599 format |= (sc->sc_chans == 2) ? 1 : 0;
600 samp |= bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ~0x60;
601
602 aria_sendcmd(sc, ARIADSPC_FORMAT, format, -1, -1);
603 bus_space_write_2(iot, ioh, ARIADSP_CONTROL, samp);
604
605 if (sc->sc_hardware&ARIA_MIXER) {
606 for (i = 0; i < 6; i++)
607 aria_set_mixer(sc, i);
608
609 if (sc->sc_chans==2) {
610 aria_sendcmd(sc, ARIADSPC_CHAN_VOL, ARIAR_PLAY_CHAN,
611 ((sc->sc_gain[0]+sc->sc_gain[1])/2)<<7,
612 -1);
613 aria_sendcmd(sc, ARIADSPC_CHAN_PAN, ARIAR_PLAY_CHAN,
614 (sc->sc_gain[0]-sc->sc_gain[1])/4+0x40,
615 -1);
616 } else {
617 aria_sendcmd(sc, ARIADSPC_CHAN_VOL, ARIAR_PLAY_CHAN,
618 sc->sc_gain[0]<<7, -1);
619 aria_sendcmd(sc, ARIADSPC_CHAN_PAN, ARIAR_PLAY_CHAN,
620 0x40, -1);
621 }
622
623 aria_sendcmd(sc, ARIADSPC_MASMONMODE,
624 sc->ariamix_master.num_channels != 2, -1, -1);
625
626 aria_sendcmd(sc, ARIADSPC_MIXERVOL, 0x0004,
627 sc->ariamix_master.level[0] << 7,
628 sc->ariamix_master.level[1] << 7);
629
630 /* Convert treble/bass from byte to soundcard style */
631
632 left = (tones[(sc->ariamix_master.treble[0]>>4)&0x0f]<<8) |
633 tones[(sc->ariamix_master.bass[0]>>4)&0x0f];
634 right = (tones[(sc->ariamix_master.treble[1]>>4)&0x0f]<<8) |
635 tones[(sc->ariamix_master.bass[1]>>4)&0x0f];
636
637 aria_sendcmd(sc, ARIADSPC_TONE, left, right, -1);
638 }
639
640 aria_sendcmd(sc, ARIADSPC_BLOCKSIZE, sc->sc_blocksize/2, -1, -1);
641
642 /*
643 * If we think that the card is recording or playing, start it up again here.
644 * Some of the previous commands turn the channels off.
645 */
646
647 if (sc->sc_record&(1<<ARIAR_RECORD_CHAN))
648 aria_sendcmd(sc, ARIADSPC_START_REC, ARIAR_RECORD_CHAN, -1,-1);
649
650 if (sc->sc_play&(1<<ARIAR_PLAY_CHAN))
651 aria_sendcmd(sc, ARIADSPC_START_PLAY, ARIAR_PLAY_CHAN, -1, -1);
652
653 return 0;
654 }
655
656 void
aria_set_mixer(struct aria_softc * sc,int i)657 aria_set_mixer(struct aria_softc *sc, int i)
658 {
659 u_char source;
660
661 switch(i) {
662 case ARIAMIX_MIC_LVL: source = 0x0001; break;
663 case ARIAMIX_CD_LVL: source = 0x0002; break;
664 case ARIAMIX_LINE_IN_LVL: source = 0x0008; break;
665 case ARIAMIX_TEL_LVL: source = 0x0020; break;
666 case ARIAMIX_AUX_LVL: source = 0x0010; break;
667 case ARIAMIX_DAC_LVL: source = 0x0004; break;
668 default: source = 0x0000; break;
669 }
670
671 if (source != 0x0000 && source != 0x0004) {
672 if (sc->aria_mix[i].mute == 1)
673 aria_sendcmd(sc, ARIADSPC_INPMONMODE, source, 3, -1);
674 else
675 aria_sendcmd(sc, ARIADSPC_INPMONMODE, source,
676 sc->aria_mix[i].num_channels != 2, -1);
677
678 aria_sendcmd(sc, ARIADSPC_INPMONMODE, 0x8000|source,
679 sc->aria_mix[i].num_channels != 2, -1);
680 aria_sendcmd(sc, ARIADSPC_MIXERVOL, source,
681 sc->aria_mix[i].level[0] << 7,
682 sc->aria_mix[i].level[1] << 7);
683 }
684
685 if (sc->aria_mix_source == i) {
686 aria_sendcmd(sc, ARIADSPC_ADCSOURCE, source, -1, -1);
687
688 if (sc->sc_open & ARIAR_OPEN_RECORD)
689 aria_sendcmd(sc, ARIADSPC_ADCCONTROL, 1, -1, -1);
690 else
691 aria_sendcmd(sc, ARIADSPC_ADCCONTROL, 0, -1, -1);
692 }
693 }
694
695 void
ariaclose(void * addr)696 ariaclose(void *addr)
697 {
698 struct aria_softc *sc;
699
700 sc = addr;
701 DPRINTF(("aria_close sc=%p\n", sc));
702
703 sc->sc_open = 0;
704
705 if (aria_reset(sc) != 0) {
706 delay(500);
707 aria_reset(sc);
708 }
709 }
710
711 /*
712 * Reset the hardware.
713 */
714
ariareset(bus_space_tag_t iot,bus_space_handle_t ioh)715 int ariareset(bus_space_tag_t iot, bus_space_handle_t ioh)
716 {
717 struct aria_softc tmp, *sc;
718
719 sc = &tmp;
720 sc->sc_iot = iot;
721 sc->sc_ioh = ioh;
722 return aria_reset(sc);
723 }
724
725 int
aria_reset(struct aria_softc * sc)726 aria_reset(struct aria_softc *sc)
727 {
728 bus_space_tag_t iot;
729 bus_space_handle_t ioh;
730 int fail;
731 int i;
732
733 iot = sc->sc_iot;
734 ioh = sc->sc_ioh;
735 fail = 0;
736 bus_space_write_2(iot, ioh, ARIADSP_CONTROL,
737 ARIAR_ARIA_SYNTH | ARIAR_SR22K|ARIAR_DSPINTWR);
738 aria_putdspmem(sc, 0x6102, 0);
739
740 fail |= aria_sendcmd(sc, ARIADSPC_SYSINIT, 0x0000, 0x0000, 0x0000);
741
742 for (i=0; i < ARIAR_NPOLL; i++)
743 if (aria_getdspmem(sc, ARIAA_TASK_A) == 1)
744 break;
745
746 bus_space_write_2(iot, ioh, ARIADSP_CONTROL,
747 ARIAR_ARIA_SYNTH|ARIAR_SR22K | ARIAR_DSPINTWR |
748 ARIAR_PCINTWR);
749 fail |= aria_sendcmd(sc, ARIADSPC_MODE, ARIAV_MODE_NO_SYNTH,-1,-1);
750
751 return fail;
752 }
753
754 /*
755 * Lower-level routines
756 */
757
758 void
aria_putdspmem(struct aria_softc * sc,u_short loc,u_short val)759 aria_putdspmem(struct aria_softc *sc, u_short loc, u_short val)
760 {
761 bus_space_tag_t iot;
762 bus_space_handle_t ioh;
763
764 iot = sc->sc_iot;
765 ioh = sc->sc_ioh;
766 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, loc);
767 bus_space_write_2(iot, ioh, ARIADSP_DMADATA, val);
768 }
769
770 u_short
aria_getdspmem(struct aria_softc * sc,u_short loc)771 aria_getdspmem(struct aria_softc *sc, u_short loc)
772 {
773 bus_space_tag_t iot;
774 bus_space_handle_t ioh;
775
776 iot = sc->sc_iot;
777 ioh = sc->sc_ioh;
778 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, loc);
779 return bus_space_read_2(iot, ioh, ARIADSP_DMADATA);
780 }
781
782 /*
783 * aria_sendcmd()
784 * each full DSP command is unified into this
785 * function.
786 */
787
788 #define ARIASEND(data, flag) \
789 for (i = ARIAR_NPOLL; \
790 (bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ARIAR_BUSY) && i>0; \
791 i--) \
792 ; \
793 if (bus_space_read_2(iot, ioh, ARIADSP_STATUS) & ARIAR_BUSY) \
794 fail |= flag; \
795 bus_space_write_2(iot, ioh, ARIADSP_WRITE, (u_short)data)
796
797 int
aria_sendcmd(struct aria_softc * sc,u_short command,int arg1,int arg2,int arg3)798 aria_sendcmd(struct aria_softc *sc, u_short command,
799 int arg1, int arg2, int arg3)
800 {
801 bus_space_tag_t iot;
802 bus_space_handle_t ioh;
803 int i, fail;
804
805 iot = sc->sc_iot;
806 ioh = sc->sc_ioh;
807 fail = 0;
808 ARIASEND(command, 1);
809 if (arg1 != -1) {
810 ARIASEND(arg1, 2);
811 }
812 if (arg2 != -1) {
813 ARIASEND(arg2, 4);
814 }
815 if (arg3 != -1) {
816 ARIASEND(arg3, 8);
817 }
818 ARIASEND(ARIADSPC_TERM, 16);
819
820 if (fail) {
821 sc->sc_sendcmd_err++;
822 #ifdef AUDIO_DEBUG
823 DPRINTF(("aria_sendcmd: failure=(%d) cmd=(0x%x) fail=(0x%x)\n",
824 sc->sc_sendcmd_err, command, fail));
825 #endif
826 return -1;
827 }
828
829 return 0;
830 }
831 #undef ARIASEND
832
833 int
aria_halt_input(void * addr)834 aria_halt_input(void *addr)
835 {
836 struct aria_softc *sc;
837
838 sc = addr;
839 DPRINTF(("aria_halt_input\n"));
840
841 if (sc->sc_record & (1<<0)) {
842 aria_sendcmd(sc, ARIADSPC_STOP_REC, 0, -1, -1);
843 sc->sc_record &= ~(1<<0);
844 sc->sc_rdiobuffer = 0;
845 }
846
847 return 0;
848 }
849
850 int
aria_halt_output(void * addr)851 aria_halt_output(void *addr)
852 {
853 struct aria_softc *sc;
854
855 sc = addr;
856 DPRINTF(("aria_halt_output\n"));
857
858 if (sc->sc_play & (1<<1)) {
859 aria_sendcmd(sc, ARIADSPC_STOP_PLAY, 1, -1, -1);
860 sc->sc_play &= ~(1<<1);
861 sc->sc_pdiobuffer = 0;
862 }
863
864 return 0;
865 }
866
867 /*
868 * Here we just set up the buffers. If we receive
869 * an interrupt without these set, it is ignored.
870 */
871
872 int
aria_start_input(void * addr,void * p,int cc,void (* intr)(void *),void * arg)873 aria_start_input(void *addr, void *p, int cc, void (*intr)(void *), void *arg)
874 {
875 struct aria_softc *sc;
876
877 sc = addr;
878 DPRINTF(("aria_start_input %d @ %p\n", cc, p));
879
880 if (cc != sc->sc_blocksize) {
881 DPRINTF(("aria_start_input reqsize %d not sc_blocksize %d\n",
882 cc, sc->sc_blocksize));
883 return EINVAL;
884 }
885
886 sc->sc_rarg = arg;
887 sc->sc_rintr = intr;
888 sc->sc_rdiobuffer = p;
889
890 if (!(sc->sc_record&(1<<ARIAR_RECORD_CHAN))) {
891 aria_sendcmd(sc, ARIADSPC_START_REC, ARIAR_RECORD_CHAN, -1,-1);
892 sc->sc_record |= (1<<ARIAR_RECORD_CHAN);
893 }
894
895 return 0;
896 }
897
898 int
aria_start_output(void * addr,void * p,int cc,void (* intr)(void *),void * arg)899 aria_start_output(void *addr, void *p, int cc, void (*intr)(void *), void *arg)
900 {
901 struct aria_softc *sc;
902
903 sc = addr;
904 DPRINTF(("aria_start_output %d @ %p\n", cc, p));
905
906 if (cc != sc->sc_blocksize) {
907 DPRINTF(("aria_start_output reqsize %d not sc_blocksize %d\n",
908 cc, sc->sc_blocksize));
909 return EINVAL;
910 }
911
912 sc->sc_parg = arg;
913 sc->sc_pintr = intr;
914 sc->sc_pdiobuffer = p;
915
916 if (!(sc->sc_play&(1<<ARIAR_PLAY_CHAN))) {
917 aria_sendcmd(sc, ARIADSPC_START_PLAY, ARIAR_PLAY_CHAN, -1, -1);
918 sc->sc_play |= (1<<ARIAR_PLAY_CHAN);
919 }
920
921 return 0;
922 }
923
924 /*
925 * Process an interrupt. This should be a
926 * request (from the card) to write or read
927 * samples.
928 */
929 int
aria_intr(void * arg)930 aria_intr(void *arg)
931 {
932 struct aria_softc *sc;
933 bus_space_tag_t iot;
934 bus_space_handle_t ioh;
935 u_short *pdata;
936 u_short *rdata;
937 u_short address;
938
939 sc = arg;
940
941 mutex_spin_enter(&sc->sc_intr_lock);
942
943 iot = sc->sc_iot;
944 ioh = sc->sc_ioh;
945 pdata = sc->sc_pdiobuffer;
946 rdata = sc->sc_rdiobuffer;
947 #if 0 /* XXX -- BAD BAD BAD (That this is #define'd out */
948 DPRINTF(("Checking to see if this is our intr\n"));
949
950 if ((inw(iobase) & 1) != 0x1) {
951 mutex_spin_exit(&sc->sc_intr_lock);
952 return 0; /* not for us */
953 }
954 #endif
955
956 sc->sc_interrupts++;
957
958 DPRINTF(("aria_intr\n"));
959
960 if ((sc->sc_open & ARIAR_OPEN_PLAY) && (pdata!=NULL)) {
961 DPRINTF(("aria_intr play=(%p)\n", pdata));
962 address = 0x8000 - 2*(sc->sc_blocksize);
963 address+= aria_getdspmem(sc, ARIAA_PLAY_FIFO_A);
964 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, address);
965 bus_space_write_multi_2(iot, ioh, ARIADSP_DMADATA, pdata,
966 sc->sc_blocksize / 2);
967 if (sc->sc_pintr != NULL)
968 (*sc->sc_pintr)(sc->sc_parg);
969 }
970
971 if ((sc->sc_open & ARIAR_OPEN_RECORD) && (rdata!=NULL)) {
972 DPRINTF(("aria_intr record=(%p)\n", rdata));
973 address = 0x8000 - (sc->sc_blocksize);
974 address+= aria_getdspmem(sc, ARIAA_REC_FIFO_A);
975 bus_space_write_2(iot, ioh, ARIADSP_DMAADDRESS, address);
976 bus_space_read_multi_2(iot, ioh, ARIADSP_DMADATA, rdata,
977 sc->sc_blocksize / 2);
978 if (sc->sc_rintr != NULL)
979 (*sc->sc_rintr)(sc->sc_rarg);
980 }
981
982 aria_sendcmd(sc, ARIADSPC_TRANSCOMPLETE, -1, -1, -1);
983
984 mutex_spin_exit(&sc->sc_intr_lock);
985 return 1;
986 }
987
988 int
aria_mixer_set_port(void * addr,mixer_ctrl_t * cp)989 aria_mixer_set_port(void *addr, mixer_ctrl_t *cp)
990 {
991 struct aria_softc *sc;
992 int error;
993
994 DPRINTF(("aria_mixer_set_port\n"));
995 sc = addr;
996 error = EINVAL;
997
998 /* This could be done better, no mixer still has some controls. */
999 if (!(ARIA_MIXER & sc->sc_hardware))
1000 return ENXIO;
1001
1002 if (cp->type == AUDIO_MIXER_VALUE) {
1003 mixer_level_t *mv = &cp->un.value;
1004 switch (cp->dev) {
1005 case ARIAMIX_MIC_LVL:
1006 if (mv->num_channels == 1 || mv->num_channels == 2) {
1007 sc->aria_mix[ARIAMIX_MIC_LVL].num_channels =
1008 mv->num_channels;
1009 sc->aria_mix[ARIAMIX_MIC_LVL].level[0] =
1010 mv->level[0];
1011 sc->aria_mix[ARIAMIX_MIC_LVL].level[1] =
1012 mv->level[1];
1013 error = 0;
1014 }
1015 break;
1016
1017 case ARIAMIX_LINE_IN_LVL:
1018 if (mv->num_channels == 1 || mv->num_channels == 2) {
1019 sc->aria_mix[ARIAMIX_LINE_IN_LVL].num_channels=
1020 mv->num_channels;
1021 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[0] =
1022 mv->level[0];
1023 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[1] =
1024 mv->level[1];
1025 error = 0;
1026 }
1027 break;
1028
1029 case ARIAMIX_CD_LVL:
1030 if (mv->num_channels == 1 || mv->num_channels == 2) {
1031 sc->aria_mix[ARIAMIX_CD_LVL].num_channels =
1032 mv->num_channels;
1033 sc->aria_mix[ARIAMIX_CD_LVL].level[0] =
1034 mv->level[0];
1035 sc->aria_mix[ARIAMIX_CD_LVL].level[1] =
1036 mv->level[1];
1037 error = 0;
1038 }
1039 break;
1040
1041 case ARIAMIX_TEL_LVL:
1042 if (mv->num_channels == 1) {
1043 sc->aria_mix[ARIAMIX_TEL_LVL].num_channels =
1044 mv->num_channels;
1045 sc->aria_mix[ARIAMIX_TEL_LVL].level[0] =
1046 mv->level[0];
1047 error = 0;
1048 }
1049 break;
1050
1051 case ARIAMIX_DAC_LVL:
1052 if (mv->num_channels == 1 || mv->num_channels == 2) {
1053 sc->aria_mix[ARIAMIX_DAC_LVL].num_channels =
1054 mv->num_channels;
1055 sc->aria_mix[ARIAMIX_DAC_LVL].level[0] =
1056 mv->level[0];
1057 sc->aria_mix[ARIAMIX_DAC_LVL].level[1] =
1058 mv->level[1];
1059 error = 0;
1060 }
1061 break;
1062
1063 case ARIAMIX_AUX_LVL:
1064 if (mv->num_channels == 1 || mv->num_channels == 2) {
1065 sc->aria_mix[ARIAMIX_AUX_LVL].num_channels =
1066 mv->num_channels;
1067 sc->aria_mix[ARIAMIX_AUX_LVL].level[0] =
1068 mv->level[0];
1069 sc->aria_mix[ARIAMIX_AUX_LVL].level[1] =
1070 mv->level[1];
1071 error = 0;
1072 }
1073 break;
1074
1075 case ARIAMIX_MASTER_LVL:
1076 if (mv->num_channels == 1 || mv->num_channels == 2) {
1077 sc->ariamix_master.num_channels =
1078 mv->num_channels;
1079 sc->ariamix_master.level[0] = mv->level[0];
1080 sc->ariamix_master.level[1] = mv->level[1];
1081 error = 0;
1082 }
1083 break;
1084
1085 case ARIAMIX_MASTER_TREBLE:
1086 if (mv->num_channels == 2) {
1087 sc->ariamix_master.treble[0] =
1088 mv->level[0] == 0 ? 1 : mv->level[0];
1089 sc->ariamix_master.treble[1] =
1090 mv->level[1] == 0 ? 1 : mv->level[1];
1091 error = 0;
1092 }
1093 break;
1094 case ARIAMIX_MASTER_BASS:
1095 if (mv->num_channels == 2) {
1096 sc->ariamix_master.bass[0] =
1097 mv->level[0] == 0 ? 1 : mv->level[0];
1098 sc->ariamix_master.bass[1] =
1099 mv->level[1] == 0 ? 1 : mv->level[1];
1100 error = 0;
1101 }
1102 break;
1103 case ARIAMIX_OUT_LVL:
1104 if (mv->num_channels == 1 || mv->num_channels == 2) {
1105 sc->sc_gain[0] = mv->level[0];
1106 sc->sc_gain[1] = mv->level[1];
1107 error = 0;
1108 }
1109 break;
1110 default:
1111 break;
1112 }
1113 }
1114
1115 if (cp->type == AUDIO_MIXER_ENUM)
1116 switch(cp->dev) {
1117 case ARIAMIX_RECORD_SOURCE:
1118 if (cp->un.ord>=0 && cp->un.ord<=6) {
1119 sc->aria_mix_source = cp->un.ord;
1120 error = 0;
1121 }
1122 break;
1123
1124 case ARIAMIX_MIC_MUTE:
1125 if (cp->un.ord == 0 || cp->un.ord == 1) {
1126 sc->aria_mix[ARIAMIX_MIC_LVL].mute =cp->un.ord;
1127 error = 0;
1128 }
1129 break;
1130
1131 case ARIAMIX_LINE_IN_MUTE:
1132 if (cp->un.ord == 0 || cp->un.ord == 1) {
1133 sc->aria_mix[ARIAMIX_LINE_IN_LVL].mute =
1134 cp->un.ord;
1135 error = 0;
1136 }
1137 break;
1138
1139 case ARIAMIX_CD_MUTE:
1140 if (cp->un.ord == 0 || cp->un.ord == 1) {
1141 sc->aria_mix[ARIAMIX_CD_LVL].mute = cp->un.ord;
1142 error = 0;
1143 }
1144 break;
1145
1146 case ARIAMIX_DAC_MUTE:
1147 if (cp->un.ord == 0 || cp->un.ord == 1) {
1148 sc->aria_mix[ARIAMIX_DAC_LVL].mute =cp->un.ord;
1149 error = 0;
1150 }
1151 break;
1152
1153 case ARIAMIX_AUX_MUTE:
1154 if (cp->un.ord == 0 || cp->un.ord == 1) {
1155 sc->aria_mix[ARIAMIX_AUX_LVL].mute =cp->un.ord;
1156 error = 0;
1157 }
1158 break;
1159
1160 case ARIAMIX_TEL_MUTE:
1161 if (cp->un.ord == 0 || cp->un.ord == 1) {
1162 sc->aria_mix[ARIAMIX_TEL_LVL].mute =cp->un.ord;
1163 error = 0;
1164 }
1165 break;
1166
1167 default:
1168 /* NOTREACHED */
1169 return ENXIO;
1170 }
1171
1172 return error;
1173 }
1174
1175 int
aria_mixer_get_port(void * addr,mixer_ctrl_t * cp)1176 aria_mixer_get_port(void *addr, mixer_ctrl_t *cp)
1177 {
1178 struct aria_softc *sc;
1179 int error;
1180
1181 DPRINTF(("aria_mixer_get_port\n"));
1182 sc = addr;
1183 error = EINVAL;
1184
1185 /* This could be done better, no mixer still has some controls. */
1186 if (!(ARIA_MIXER&sc->sc_hardware))
1187 return ENXIO;
1188
1189 switch (cp->dev) {
1190 case ARIAMIX_MIC_LVL:
1191 if (cp->type == AUDIO_MIXER_VALUE) {
1192 cp->un.value.num_channels =
1193 sc->aria_mix[ARIAMIX_MIC_LVL].num_channels;
1194 cp->un.value.level[0] =
1195 sc->aria_mix[ARIAMIX_MIC_LVL].level[0];
1196 cp->un.value.level[1] =
1197 sc->aria_mix[ARIAMIX_MIC_LVL].level[1];
1198 error = 0;
1199 }
1200 break;
1201
1202 case ARIAMIX_LINE_IN_LVL:
1203 if (cp->type == AUDIO_MIXER_VALUE) {
1204 cp->un.value.num_channels =
1205 sc->aria_mix[ARIAMIX_LINE_IN_LVL].num_channels;
1206 cp->un.value.level[0] =
1207 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[0];
1208 cp->un.value.level[1] =
1209 sc->aria_mix[ARIAMIX_LINE_IN_LVL].level[1];
1210 error = 0;
1211 }
1212 break;
1213
1214 case ARIAMIX_CD_LVL:
1215 if (cp->type == AUDIO_MIXER_VALUE) {
1216 cp->un.value.num_channels =
1217 sc->aria_mix[ARIAMIX_CD_LVL].num_channels;
1218 cp->un.value.level[0] =
1219 sc->aria_mix[ARIAMIX_CD_LVL].level[0];
1220 cp->un.value.level[1] =
1221 sc->aria_mix[ARIAMIX_CD_LVL].level[1];
1222 error = 0;
1223 }
1224 break;
1225
1226 case ARIAMIX_TEL_LVL:
1227 if (cp->type == AUDIO_MIXER_VALUE) {
1228 cp->un.value.num_channels =
1229 sc->aria_mix[ARIAMIX_TEL_LVL].num_channels;
1230 cp->un.value.level[0] =
1231 sc->aria_mix[ARIAMIX_TEL_LVL].level[0];
1232 error = 0;
1233 }
1234 break;
1235 case ARIAMIX_DAC_LVL:
1236 if (cp->type == AUDIO_MIXER_VALUE) {
1237 cp->un.value.num_channels =
1238 sc->aria_mix[ARIAMIX_DAC_LVL].num_channels;
1239 cp->un.value.level[0] =
1240 sc->aria_mix[ARIAMIX_DAC_LVL].level[0];
1241 cp->un.value.level[1] =
1242 sc->aria_mix[ARIAMIX_DAC_LVL].level[1];
1243 error = 0;
1244 }
1245 break;
1246
1247 case ARIAMIX_AUX_LVL:
1248 if (cp->type == AUDIO_MIXER_VALUE) {
1249 cp->un.value.num_channels =
1250 sc->aria_mix[ARIAMIX_AUX_LVL].num_channels;
1251 cp->un.value.level[0] =
1252 sc->aria_mix[ARIAMIX_AUX_LVL].level[0];
1253 cp->un.value.level[1] =
1254 sc->aria_mix[ARIAMIX_AUX_LVL].level[1];
1255 error = 0;
1256 }
1257 break;
1258
1259 case ARIAMIX_MIC_MUTE:
1260 if (cp->type == AUDIO_MIXER_ENUM) {
1261 cp->un.ord = sc->aria_mix[ARIAMIX_MIC_LVL].mute;
1262 error = 0;
1263 }
1264 break;
1265
1266 case ARIAMIX_LINE_IN_MUTE:
1267 if (cp->type == AUDIO_MIXER_ENUM) {
1268 cp->un.ord = sc->aria_mix[ARIAMIX_LINE_IN_LVL].mute;
1269 error = 0;
1270 }
1271 break;
1272
1273 case ARIAMIX_CD_MUTE:
1274 if (cp->type == AUDIO_MIXER_ENUM) {
1275 cp->un.ord = sc->aria_mix[ARIAMIX_CD_LVL].mute;
1276 error = 0;
1277 }
1278 break;
1279
1280 case ARIAMIX_DAC_MUTE:
1281 if (cp->type == AUDIO_MIXER_ENUM) {
1282 cp->un.ord = sc->aria_mix[ARIAMIX_DAC_LVL].mute;
1283 error = 0;
1284 }
1285 break;
1286
1287 case ARIAMIX_AUX_MUTE:
1288 if (cp->type == AUDIO_MIXER_ENUM) {
1289 cp->un.ord = sc->aria_mix[ARIAMIX_AUX_LVL].mute;
1290 error = 0;
1291 }
1292 break;
1293
1294 case ARIAMIX_TEL_MUTE:
1295 if (cp->type == AUDIO_MIXER_ENUM) {
1296 cp->un.ord = sc->aria_mix[ARIAMIX_TEL_LVL].mute;
1297 error = 0;
1298 }
1299 break;
1300
1301 case ARIAMIX_MASTER_LVL:
1302 if (cp->type == AUDIO_MIXER_VALUE) {
1303 cp->un.value.num_channels =
1304 sc->ariamix_master.num_channels;
1305 cp->un.value.level[0] = sc->ariamix_master.level[0];
1306 cp->un.value.level[1] = sc->ariamix_master.level[1];
1307 error = 0;
1308 }
1309 break;
1310
1311 case ARIAMIX_MASTER_TREBLE:
1312 if (cp->type == AUDIO_MIXER_VALUE) {
1313 cp->un.value.num_channels = 2;
1314 cp->un.value.level[0] = sc->ariamix_master.treble[0];
1315 cp->un.value.level[1] = sc->ariamix_master.treble[1];
1316 error = 0;
1317 }
1318 break;
1319
1320 case ARIAMIX_MASTER_BASS:
1321 if (cp->type == AUDIO_MIXER_VALUE) {
1322 cp->un.value.num_channels = 2;
1323 cp->un.value.level[0] = sc->ariamix_master.bass[0];
1324 cp->un.value.level[1] = sc->ariamix_master.bass[1];
1325 error = 0;
1326 }
1327 break;
1328
1329 case ARIAMIX_OUT_LVL:
1330 if (cp->type == AUDIO_MIXER_VALUE) {
1331 cp->un.value.num_channels = sc->sc_chans;
1332 cp->un.value.level[0] = sc->sc_gain[0];
1333 cp->un.value.level[1] = sc->sc_gain[1];
1334 error = 0;
1335 }
1336 break;
1337 case ARIAMIX_RECORD_SOURCE:
1338 if (cp->type == AUDIO_MIXER_ENUM) {
1339 cp->un.ord = sc->aria_mix_source;
1340 error = 0;
1341 }
1342 break;
1343
1344 default:
1345 return ENXIO;
1346 /* NOT REACHED */
1347 }
1348
1349 return error;
1350 }
1351
1352 int
aria_mixer_query_devinfo(void * addr,mixer_devinfo_t * dip)1353 aria_mixer_query_devinfo(void *addr, mixer_devinfo_t *dip)
1354 {
1355 struct aria_softc *sc;
1356
1357 DPRINTF(("aria_mixer_query_devinfo\n"));
1358 sc = addr;
1359
1360 /* This could be done better, no mixer still has some controls. */
1361 if (!(ARIA_MIXER & sc->sc_hardware))
1362 return ENXIO;
1363
1364 dip->prev = dip->next = AUDIO_MIXER_LAST;
1365
1366 switch(dip->index) {
1367 case ARIAMIX_MIC_LVL:
1368 dip->type = AUDIO_MIXER_VALUE;
1369 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1370 dip->next = ARIAMIX_MIC_MUTE;
1371 strcpy(dip->label.name, AudioNmicrophone);
1372 dip->un.v.num_channels = 2;
1373 strcpy(dip->un.v.units.name, AudioNvolume);
1374 break;
1375
1376 case ARIAMIX_LINE_IN_LVL:
1377 dip->type = AUDIO_MIXER_VALUE;
1378 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1379 dip->next = ARIAMIX_LINE_IN_MUTE;
1380 strcpy(dip->label.name, AudioNline);
1381 dip->un.v.num_channels = 2;
1382 strcpy(dip->un.v.units.name, AudioNvolume);
1383 break;
1384
1385 case ARIAMIX_CD_LVL:
1386 dip->type = AUDIO_MIXER_VALUE;
1387 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1388 dip->next = ARIAMIX_CD_MUTE;
1389 strcpy(dip->label.name, AudioNcd);
1390 dip->un.v.num_channels = 2;
1391 strcpy(dip->un.v.units.name, AudioNvolume);
1392 break;
1393
1394 case ARIAMIX_TEL_LVL:
1395 dip->type = AUDIO_MIXER_VALUE;
1396 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1397 dip->next = ARIAMIX_TEL_MUTE;
1398 strcpy(dip->label.name, "telephone");
1399 dip->un.v.num_channels = 1;
1400 strcpy(dip->un.v.units.name, AudioNvolume);
1401 break;
1402
1403 case ARIAMIX_DAC_LVL:
1404 dip->type = AUDIO_MIXER_VALUE;
1405 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1406 dip->next = ARIAMIX_DAC_MUTE;
1407 strcpy(dip->label.name, AudioNdac);
1408 dip->un.v.num_channels = 1;
1409 strcpy(dip->un.v.units.name, AudioNvolume);
1410 break;
1411
1412 case ARIAMIX_AUX_LVL:
1413 dip->type = AUDIO_MIXER_VALUE;
1414 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1415 dip->next = ARIAMIX_AUX_MUTE;
1416 strcpy(dip->label.name, AudioNoutput);
1417 dip->un.v.num_channels = 1;
1418 strcpy(dip->un.v.units.name, AudioNvolume);
1419 break;
1420
1421 case ARIAMIX_MIC_MUTE:
1422 dip->prev = ARIAMIX_MIC_LVL;
1423 goto mute;
1424
1425 case ARIAMIX_LINE_IN_MUTE:
1426 dip->prev = ARIAMIX_LINE_IN_LVL;
1427 goto mute;
1428
1429 case ARIAMIX_CD_MUTE:
1430 dip->prev = ARIAMIX_CD_LVL;
1431 goto mute;
1432
1433 case ARIAMIX_DAC_MUTE:
1434 dip->prev = ARIAMIX_DAC_LVL;
1435 goto mute;
1436
1437 case ARIAMIX_AUX_MUTE:
1438 dip->prev = ARIAMIX_AUX_LVL;
1439 goto mute;
1440
1441 case ARIAMIX_TEL_MUTE:
1442 dip->prev = ARIAMIX_TEL_LVL;
1443 goto mute;
1444
1445 mute:
1446 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1447 dip->type = AUDIO_MIXER_ENUM;
1448 strcpy(dip->label.name, AudioNmute);
1449 dip->un.e.num_mem = 2;
1450 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1451 dip->un.e.member[0].ord = 0;
1452 strcpy(dip->un.e.member[1].label.name, AudioNon);
1453 dip->un.e.member[1].ord = 1;
1454 break;
1455
1456 case ARIAMIX_MASTER_LVL:
1457 dip->type = AUDIO_MIXER_VALUE;
1458 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1459 dip->next = AUDIO_MIXER_LAST;
1460 strcpy(dip->label.name, AudioNvolume);
1461 dip->un.v.num_channels = 2;
1462 strcpy(dip->un.v.units.name, AudioNvolume);
1463 break;
1464
1465 case ARIAMIX_MASTER_TREBLE:
1466 dip->type = AUDIO_MIXER_VALUE;
1467 dip->mixer_class = ARIAMIX_EQ_CLASS;
1468 strcpy(dip->label.name, AudioNtreble);
1469 dip->un.v.num_channels = 2;
1470 strcpy(dip->un.v.units.name, AudioNtreble);
1471 break;
1472
1473 case ARIAMIX_MASTER_BASS:
1474 dip->type = AUDIO_MIXER_VALUE;
1475 dip->mixer_class = ARIAMIX_EQ_CLASS;
1476 strcpy(dip->label.name, AudioNbass);
1477 dip->un.v.num_channels = 2;
1478 strcpy(dip->un.v.units.name, AudioNbass);
1479 break;
1480
1481 case ARIAMIX_OUT_LVL:
1482 dip->type = AUDIO_MIXER_VALUE;
1483 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1484 strcpy(dip->label.name, AudioNoutput);
1485 dip->un.v.num_channels = 2;
1486 strcpy(dip->un.v.units.name, AudioNvolume);
1487 break;
1488
1489 case ARIAMIX_RECORD_SOURCE:
1490 dip->mixer_class = ARIAMIX_RECORD_CLASS;
1491 dip->type = AUDIO_MIXER_ENUM;
1492 strcpy(dip->label.name, AudioNsource);
1493 dip->un.e.num_mem = 6;
1494 strcpy(dip->un.e.member[0].label.name, AudioNoutput);
1495 dip->un.e.member[0].ord = ARIAMIX_AUX_LVL;
1496 strcpy(dip->un.e.member[1].label.name, AudioNmicrophone);
1497 dip->un.e.member[1].ord = ARIAMIX_MIC_LVL;
1498 strcpy(dip->un.e.member[2].label.name, AudioNdac);
1499 dip->un.e.member[2].ord = ARIAMIX_DAC_LVL;
1500 strcpy(dip->un.e.member[3].label.name, AudioNline);
1501 dip->un.e.member[3].ord = ARIAMIX_LINE_IN_LVL;
1502 strcpy(dip->un.e.member[4].label.name, AudioNcd);
1503 dip->un.e.member[4].ord = ARIAMIX_CD_LVL;
1504 strcpy(dip->un.e.member[5].label.name, "telephone");
1505 dip->un.e.member[5].ord = ARIAMIX_TEL_LVL;
1506 break;
1507
1508 case ARIAMIX_INPUT_CLASS:
1509 dip->type = AUDIO_MIXER_CLASS;
1510 dip->mixer_class = ARIAMIX_INPUT_CLASS;
1511 strcpy(dip->label.name, AudioCinputs);
1512 break;
1513
1514 case ARIAMIX_OUTPUT_CLASS:
1515 dip->type = AUDIO_MIXER_CLASS;
1516 dip->mixer_class = ARIAMIX_OUTPUT_CLASS;
1517 strcpy(dip->label.name, AudioCoutputs);
1518 break;
1519
1520 case ARIAMIX_RECORD_CLASS:
1521 dip->type = AUDIO_MIXER_CLASS;
1522 dip->mixer_class = ARIAMIX_RECORD_CLASS;
1523 strcpy(dip->label.name, AudioCrecord);
1524 break;
1525
1526 case ARIAMIX_EQ_CLASS:
1527 dip->type = AUDIO_MIXER_CLASS;
1528 dip->mixer_class = ARIAMIX_EQ_CLASS;
1529 strcpy(dip->label.name, AudioCequalization);
1530 break;
1531
1532 default:
1533 return ENXIO;
1534 /*NOTREACHED*/
1535 }
1536 return 0;
1537 }
1538
1539 void
aria_get_locks(void * addr,kmutex_t ** intr,kmutex_t ** thread)1540 aria_get_locks(void *addr, kmutex_t **intr, kmutex_t **thread)
1541 {
1542 struct aria_softc *sc;
1543
1544 sc = addr;
1545 *intr = &sc->sc_intr_lock;
1546 *thread = &sc->sc_lock;
1547 }
1548