Annotation of sys/arch/sparc/dev/amd7930.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: amd7930.c,v 1.30 2005/08/14 10:58:33 miod Exp $ */
2: /* $NetBSD: amd7930.c,v 1.37 1998/03/30 14:23:40 pk Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Rolf Grossmann
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
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. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by Rolf Grossmann.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: #include <sys/param.h>
35: #include <sys/systm.h>
36: #include <sys/errno.h>
37: #include <sys/ioctl.h>
38: #include <sys/device.h>
39: #include <sys/proc.h>
40:
41: #include <machine/autoconf.h>
42: #include <machine/cpu.h>
43:
44: #include <sys/audioio.h>
45: #include <dev/audio_if.h>
46:
47: #include <dev/ic/am7930reg.h>
48: #include <sparc/dev/amd7930var.h>
49:
50: #define AUDIO_ROM_NAME "audio"
51:
52: #ifdef AUDIO_DEBUG
53: int amd7930debug = 0;
54: #define DPRINTF(x) if (amd7930debug) printf x
55: #else
56: #define DPRINTF(x)
57: #endif
58:
59: /*
60: * Define AUDIO_C_HANDLER to force using non-fast trap routines.
61: */
62: /* #define AUDIO_C_HANDLER */
63:
64: /*
65: * Software state, per AMD79C30 audio chip.
66: */
67: struct amd7930_softc {
68: struct device sc_dev; /* base device */
69: struct intrhand sc_swih; /* software interrupt vector */
70:
71: int sc_open; /* single use device */
72: int sc_locked; /* true when transferring data */
73: struct mapreg sc_map; /* current contents of map registers */
74:
75: u_char sc_rlevel; /* record level */
76: u_char sc_plevel; /* play level */
77: u_char sc_mlevel; /* monitor level */
78: u_char sc_out_port; /* output port */
79:
80: /* interfacing with the interrupt handlers */
81: void (*sc_rintr)(void *); /* input completion intr handler */
82: void *sc_rarg; /* arg for sc_rintr() */
83: void (*sc_pintr)(void *); /* output completion intr handler */
84: void *sc_parg; /* arg for sc_pintr() */
85:
86: /* sc_au is special in that the hardware interrupt handler uses it */
87: struct auio sc_au; /* recv and xmit buffers, etc */
88: #define sc_hwih sc_au.au_ih /* hardware interrupt vector */
89: };
90:
91: /* interrupt interfaces */
92: #if defined(SUN4M)
93: #define AUDIO_SET_SWINTR do { \
94: if (CPU_ISSUN4M) \
95: raise(0, 4); \
96: else \
97: ienab_bis(IE_L4); \
98: } while(0);
99: #else
100: #define AUDIO_SET_SWINTR ienab_bis(IE_L4)
101: #endif /* defined(SUN4M) */
102:
103: #ifndef AUDIO_C_HANDLER
104: struct auio *auiop;
105: #endif /* AUDIO_C_HANDLER */
106: int amd7930hwintr(void *);
107: int amd7930swintr(void *);
108:
109: /* forward declarations */
110: void audio_setmap(volatile struct amd7930 *, struct mapreg *);
111: static void init_amd(volatile struct amd7930 *);
112: int amd7930_shareintr(void *);
113:
114: /* autoconfiguration driver */
115: void amd7930attach(struct device *, struct device *, void *);
116: int amd7930match(struct device *, void *, void *);
117:
118: struct cfattach audioamd_ca = {
119: sizeof(struct amd7930_softc), amd7930match, amd7930attach
120: };
121:
122: struct cfdriver audioamd_cd = {
123: NULL, "audioamd", DV_DULL
124: };
125:
126: struct audio_device amd7930_device = {
127: "amd7930",
128: "x",
129: "audioamd"
130: };
131:
132: /* Write 16 bits of data from variable v to the data port of the audio chip */
133: #define WAMD16(amd, v) ((amd)->dr = (v), (amd)->dr = (v) >> 8)
134:
135: /* The following tables stolen from former (4.4Lite's) sys/sparc/bsd_audio.c */
136:
137: /*
138: * gx, gr & stg gains. this table must contain 256 elements with
139: * the 0th being "infinity" (the magic value 9008). The remaining
140: * elements match sun's gain curve (but with higher resolution):
141: * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
142: */
143: static const u_short gx_coeff[256] = {
144: 0x9008, 0x8e7c, 0x8e51, 0x8e45, 0x8d42, 0x8d3b, 0x8c36, 0x8c33,
145: 0x8b32, 0x8b2a, 0x8b2b, 0x8b2c, 0x8b25, 0x8b23, 0x8b22, 0x8b22,
146: 0x9122, 0x8b1a, 0x8aa3, 0x8aa3, 0x8b1c, 0x8aa6, 0x912d, 0x912b,
147: 0x8aab, 0x8b12, 0x8aaa, 0x8ab2, 0x9132, 0x8ab4, 0x913c, 0x8abb,
148: 0x9142, 0x9144, 0x9151, 0x8ad5, 0x8aeb, 0x8a79, 0x8a5a, 0x8a4a,
149: 0x8b03, 0x91c2, 0x91bb, 0x8a3f, 0x8a33, 0x91b2, 0x9212, 0x9213,
150: 0x8a2c, 0x921d, 0x8a23, 0x921a, 0x9222, 0x9223, 0x922d, 0x9231,
151: 0x9234, 0x9242, 0x925b, 0x92dd, 0x92c1, 0x92b3, 0x92ab, 0x92a4,
152: 0x92a2, 0x932b, 0x9341, 0x93d3, 0x93b2, 0x93a2, 0x943c, 0x94b2,
153: 0x953a, 0x9653, 0x9782, 0x9e21, 0x9d23, 0x9cd2, 0x9c23, 0x9baa,
154: 0x9bde, 0x9b33, 0x9b22, 0x9b1d, 0x9ab2, 0xa142, 0xa1e5, 0x9a3b,
155: 0xa213, 0xa1a2, 0xa231, 0xa2eb, 0xa313, 0xa334, 0xa421, 0xa54b,
156: 0xada4, 0xac23, 0xab3b, 0xaaab, 0xaa5c, 0xb1a3, 0xb2ca, 0xb3bd,
157: 0xbe24, 0xbb2b, 0xba33, 0xc32b, 0xcb5a, 0xd2a2, 0xe31d, 0x0808,
158: 0x72ba, 0x62c2, 0x5c32, 0x52db, 0x513e, 0x4cce, 0x43b2, 0x4243,
159: 0x41b4, 0x3b12, 0x3bc3, 0x3df2, 0x34bd, 0x3334, 0x32c2, 0x3224,
160: 0x31aa, 0x2a7b, 0x2aaa, 0x2b23, 0x2bba, 0x2c42, 0x2e23, 0x25bb,
161: 0x242b, 0x240f, 0x231a, 0x22bb, 0x2241, 0x2223, 0x221f, 0x1a33,
162: 0x1a4a, 0x1acd, 0x2132, 0x1b1b, 0x1b2c, 0x1b62, 0x1c12, 0x1c32,
163: 0x1d1b, 0x1e71, 0x16b1, 0x1522, 0x1434, 0x1412, 0x1352, 0x1323,
164: 0x1315, 0x12bc, 0x127a, 0x1235, 0x1226, 0x11a2, 0x1216, 0x0a2a,
165: 0x11bc, 0x11d1, 0x1163, 0x0ac2, 0x0ab2, 0x0aab, 0x0b1b, 0x0b23,
166: 0x0b33, 0x0c0f, 0x0bb3, 0x0c1b, 0x0c3e, 0x0cb1, 0x0d4c, 0x0ec1,
167: 0x079a, 0x0614, 0x0521, 0x047c, 0x0422, 0x03b1, 0x03e3, 0x0333,
168: 0x0322, 0x031c, 0x02aa, 0x02ba, 0x02f2, 0x0242, 0x0232, 0x0227,
169: 0x0222, 0x021b, 0x01ad, 0x0212, 0x01b2, 0x01bb, 0x01cb, 0x01f6,
170: 0x0152, 0x013a, 0x0133, 0x0131, 0x012c, 0x0123, 0x0122, 0x00a2,
171: 0x011b, 0x011e, 0x0114, 0x00b1, 0x00aa, 0x00b3, 0x00bd, 0x00ba,
172: 0x00c5, 0x00d3, 0x00f3, 0x0062, 0x0051, 0x0042, 0x003b, 0x0033,
173: 0x0032, 0x002a, 0x002c, 0x0025, 0x0023, 0x0022, 0x001a, 0x0021,
174: 0x001b, 0x001b, 0x001d, 0x0015, 0x0013, 0x0013, 0x0012, 0x0012,
175: 0x000a, 0x000a, 0x0011, 0x0011, 0x000b, 0x000b, 0x000c, 0x000e,
176: };
177:
178: /*
179: * second stage play gain.
180: */
181: static const u_short ger_coeff[] = {
182: 0x431f, /* 5. dB */
183: 0x331f, /* 5.5 dB */
184: 0x40dd, /* 6. dB */
185: 0x11dd, /* 6.5 dB */
186: 0x440f, /* 7. dB */
187: 0x411f, /* 7.5 dB */
188: 0x311f, /* 8. dB */
189: 0x5520, /* 8.5 dB */
190: 0x10dd, /* 9. dB */
191: 0x4211, /* 9.5 dB */
192: 0x410f, /* 10. dB */
193: 0x111f, /* 10.5 dB */
194: 0x600b, /* 11. dB */
195: 0x00dd, /* 11.5 dB */
196: 0x4210, /* 12. dB */
197: 0x110f, /* 13. dB */
198: 0x7200, /* 14. dB */
199: 0x2110, /* 15. dB */
200: 0x2200, /* 15.9 dB */
201: 0x000b, /* 16.9 dB */
202: 0x000f /* 18. dB */
203: #define NGER (sizeof(ger_coeff) / sizeof(ger_coeff[0]))
204: };
205:
206: /*
207: * Define our interface to the higher level audio driver.
208: */
209: int amd7930_open(void *, int);
210: void amd7930_close(void *);
211: int amd7930_query_encoding(void *, struct audio_encoding *);
212: int amd7930_set_params(void *, int, int, struct audio_params *, struct audio_params *);
213: int amd7930_round_blocksize(void *, int);
214: int amd7930_commit_settings(void *);
215: int amd7930_start_output(void *, void *, int, void (*)(void *), void *);
216: int amd7930_start_input(void *, void *, int, void (*)(void *), void *);
217: int amd7930_halt_output(void *);
218: int amd7930_halt_input(void *);
219: int amd7930_getdev(void *, struct audio_device *);
220: int amd7930_set_port(void *, mixer_ctrl_t *);
221: int amd7930_get_port(void *, mixer_ctrl_t *);
222: int amd7930_query_devinfo(void *, mixer_devinfo_t *);
223: int amd7930_get_props(void *);
224:
225: struct audio_hw_if sa_hw_if = {
226: amd7930_open,
227: amd7930_close,
228: NULL,
229: amd7930_query_encoding,
230: amd7930_set_params,
231: amd7930_round_blocksize,
232: amd7930_commit_settings,
233: NULL,
234: NULL,
235: amd7930_start_output,
236: amd7930_start_input,
237: amd7930_halt_output,
238: amd7930_halt_input,
239: NULL,
240: amd7930_getdev,
241: NULL,
242: amd7930_set_port,
243: amd7930_get_port,
244: amd7930_query_devinfo,
245: NULL,
246: NULL,
247: NULL,
248: NULL,
249: amd7930_get_props,
250: NULL,
251: NULL
252: };
253:
254: /* autoconfig routines */
255:
256: int
257: amd7930match(parent, vcf, aux)
258: struct device *parent;
259: void *vcf, *aux;
260: {
261: register struct confargs *ca = aux;
262: register struct romaux *ra = &ca->ca_ra;
263:
264: if (CPU_ISSUN4)
265: return (0);
266: return (strcmp(AUDIO_ROM_NAME, ra->ra_name) == 0);
267: }
268:
269: /*
270: * Audio chip found.
271: */
272: void
273: amd7930attach(parent, self, args)
274: struct device *parent, *self;
275: void *args;
276: {
277: register struct amd7930_softc *sc = (struct amd7930_softc *)self;
278: register struct confargs *ca = args;
279: register struct romaux *ra = &ca->ca_ra;
280: register volatile struct amd7930 *amd;
281: register int pri;
282:
283: if (ra->ra_nintr != 1) {
284: printf(": expected 1 interrupt, got %d\n", ra->ra_nintr);
285: return;
286: }
287: pri = ra->ra_intr[0].int_pri;
288: printf(" pri %d, softpri %d\n", pri, IPL_AUSOFT);
289: amd = (volatile struct amd7930 *)(ra->ra_vaddr ?
290: ra->ra_vaddr : mapiodev(ra->ra_reg, 0, sizeof (*amd)));
291:
292: sc->sc_map.mr_mmr1 = AMD_MMR1_GX | AMD_MMR1_GER |
293: AMD_MMR1_GR | AMD_MMR1_STG;
294: sc->sc_au.au_amd = amd;
295: /* set boot defaults */
296: sc->sc_rlevel = 128;
297: sc->sc_plevel = 128;
298: sc->sc_mlevel = 0;
299: sc->sc_out_port = SUNAUDIO_SPEAKER;
300:
301: init_amd(amd);
302:
303: /*
304: * Register interrupt handlers. We'll prefer a fast trap (unless
305: * AUDIO_C_HANDLER is defined), with a sharing callback so that we
306: * can revert into a regular trap vector if necessary.
307: */
308: #ifndef AUDIO_C_HANDLER
309: sc->sc_hwih.ih_vec = pri;
310: if (intr_fasttrap(pri, amd7930_trap, amd7930_shareintr, sc) == 0) {
311: auiop = &sc->sc_au;
312: evcount_attach(&sc->sc_hwih.ih_count, sc->sc_dev.dv_xname,
313: &sc->sc_hwih.ih_vec, &evcount_intr);
314: } else {
315: #ifdef AUDIO_DEBUG
316: printf("%s: unable to register fast trap handler\n",
317: self->dv_xname);
318: #endif
319: #else
320: {
321: #endif
322: sc->sc_hwih.ih_fun = amd7930hwintr;
323: sc->sc_hwih.ih_arg = &sc->sc_au;
324: intr_establish(pri, &sc->sc_hwih, IPL_AUHARD,
325: sc->sc_dev.dv_xname);
326: }
327: sc->sc_swih.ih_fun = amd7930swintr;
328: sc->sc_swih.ih_arg = sc;
329: intr_establish(IPL_AUSOFT, &sc->sc_swih, IPL_AUSOFT,
330: sc->sc_dev.dv_xname);
331:
332: audio_attach_mi(&sa_hw_if, sc, &sc->sc_dev);
333: amd7930_commit_settings(sc);
334: }
335:
336: static void
337: init_amd(amd)
338: register volatile struct amd7930 *amd;
339: {
340: /* disable interrupts */
341: amd->cr = AMDR_INIT;
342: amd->dr = AMD_INIT_PMS_ACTIVE | AMD_INIT_INT_DISABLE;
343:
344: /*
345: * Initialize the mux unit. We use MCR3 to route audio (MAP)
346: * through channel Bb. MCR1 and MCR2 are unused.
347: * Setting the INT enable bit in MCR4 will generate an interrupt
348: * on each converted audio sample.
349: */
350: amd->cr = AMDR_MUX_1_4;
351: amd->dr = 0;
352: amd->dr = 0;
353: amd->dr = (AMD_MCRCHAN_BB << 4) | AMD_MCRCHAN_BA;
354: amd->dr = AMD_MCR4_INT_ENABLE;
355: }
356:
357: int
358: amd7930_open(addr, flags)
359: void *addr;
360: int flags;
361: {
362: struct amd7930_softc *sc = addr;
363:
364: DPRINTF(("sa_open: unit %p\n", sc));
365:
366: if (sc->sc_open)
367: return (EBUSY);
368: sc->sc_open = 1;
369: sc->sc_locked = 0;
370: sc->sc_rintr = 0;
371: sc->sc_rarg = 0;
372: sc->sc_pintr = 0;
373: sc->sc_parg = 0;
374:
375: sc->sc_au.au_rdata = 0;
376: sc->sc_au.au_pdata = 0;
377:
378: DPRINTF(("saopen: ok -> sc=0x%x\n",sc));
379:
380: return (0);
381: }
382:
383: void
384: amd7930_close(addr)
385: void *addr;
386: {
387: register struct amd7930_softc *sc = addr;
388:
389: DPRINTF(("sa_close: sc=0x%x\n", sc));
390: /*
391: * halt i/o, clear open flag, and done.
392: */
393: amd7930_halt_input(sc);
394: amd7930_halt_output(sc);
395: sc->sc_open = 0;
396:
397: DPRINTF(("sa_close: closed.\n"));
398: }
399:
400: int
401: amd7930_set_params(addr, setmode, usemode, p, r)
402: void *addr;
403: int setmode, usemode;
404: struct audio_params *p, *r;
405: {
406: if (p->sample_rate < 7500 || p->sample_rate > 8500 ||
407: p->encoding != AUDIO_ENCODING_ULAW ||
408: p->precision != 8 ||
409: p->channels != 1)
410: return (EINVAL);
411: p->sample_rate = 8000; /* no other rates supported by amd chip */
412:
413: return (0);
414: }
415:
416: int
417: amd7930_query_encoding(addr, fp)
418: void *addr;
419: struct audio_encoding *fp;
420: {
421: switch (fp->index) {
422: case 0:
423: strlcpy(fp->name, AudioEmulaw, sizeof fp->name);
424: fp->encoding = AUDIO_ENCODING_ULAW;
425: fp->precision = 8;
426: fp->flags = 0;
427: break;
428: default:
429: return (EINVAL);
430: /*NOTREACHED*/
431: }
432: return (0);
433: }
434:
435: int
436: amd7930_round_blocksize(addr, blk)
437: void *addr;
438: int blk;
439: {
440: return (blk);
441: }
442:
443: int
444: amd7930_commit_settings(addr)
445: void *addr;
446: {
447: register struct amd7930_softc *sc = addr;
448: register struct mapreg *map;
449: register volatile struct amd7930 *amd;
450: register int s, level;
451:
452: DPRINTF(("sa_commit.\n"));
453:
454: map = &sc->sc_map;
455: amd = sc->sc_au.au_amd;
456:
457: map->mr_gx = gx_coeff[sc->sc_rlevel];
458: map->mr_stgr = gx_coeff[sc->sc_mlevel];
459:
460: level = (sc->sc_plevel * (256 + NGER)) >> 8;
461: if (level >= 256) {
462: map->mr_ger = ger_coeff[level - 256];
463: map->mr_gr = gx_coeff[255];
464: } else {
465: map->mr_ger = ger_coeff[0];
466: map->mr_gr = gx_coeff[level];
467: }
468:
469: if (sc->sc_out_port == SUNAUDIO_SPEAKER)
470: map->mr_mmr2 |= AMD_MMR2_LS;
471: else
472: map->mr_mmr2 &= ~AMD_MMR2_LS;
473:
474: s = splaudio();
475:
476: amd->cr = AMDR_MAP_MMR1;
477: amd->dr = map->mr_mmr1;
478: amd->cr = AMDR_MAP_GX;
479: WAMD16(amd, map->mr_gx);
480: amd->cr = AMDR_MAP_STG;
481: WAMD16(amd, map->mr_stgr);
482: amd->cr = AMDR_MAP_GR;
483: WAMD16(amd, map->mr_gr);
484: amd->cr = AMDR_MAP_GER;
485: WAMD16(amd, map->mr_ger);
486: amd->cr = AMDR_MAP_MMR2;
487: amd->dr = map->mr_mmr2;
488:
489: splx(s);
490: return (0);
491: }
492:
493: int
494: amd7930_start_output(addr, p, cc, intr, arg)
495: void *addr;
496: void *p;
497: int cc;
498: void (*intr)(void *);
499: void *arg;
500: {
501: register struct amd7930_softc *sc = addr;
502:
503: #ifdef AUDIO_DEBUG
504: if (amd7930debug > 1)
505: printf("sa_start_output: cc=%d 0x%x (0x%x)\n", cc, intr, arg);
506: #endif
507:
508: if (!sc->sc_locked) {
509: register volatile struct amd7930 *amd;
510:
511: amd = sc->sc_au.au_amd;
512: amd->cr = AMDR_INIT;
513: amd->dr = AMD_INIT_PMS_ACTIVE;
514: sc->sc_locked = 1;
515: DPRINTF(("sa_start_output: started intrs.\n"));
516: }
517: sc->sc_pintr = intr;
518: sc->sc_parg = arg;
519: sc->sc_au.au_pdata = p;
520: sc->sc_au.au_pend = p + cc - 1;
521: return (0);
522: }
523:
524: /* ARGSUSED */
525: int
526: amd7930_start_input(addr, p, cc, intr, arg)
527: void *addr;
528: void *p;
529: int cc;
530: void (*intr)(void *);
531: void *arg;
532: {
533: register struct amd7930_softc *sc = addr;
534:
535: #ifdef AUDIO_DEBUG
536: if (amd7930debug > 1)
537: printf("sa_start_input: cc=%d 0x%x (0x%x)\n", cc, intr, arg);
538: #endif
539:
540: if (!sc->sc_locked) {
541: register volatile struct amd7930 *amd;
542:
543: amd = sc->sc_au.au_amd;
544: amd->cr = AMDR_INIT;
545: amd->dr = AMD_INIT_PMS_ACTIVE;
546: sc->sc_locked = 1;
547: DPRINTF(("sa_start_input: started intrs.\n"));
548: }
549: sc->sc_rintr = intr;
550: sc->sc_rarg = arg;
551: sc->sc_au.au_rdata = p;
552: sc->sc_au.au_rend = p + cc -1;
553: return (0);
554: }
555:
556: int
557: amd7930_halt_output(addr)
558: void *addr;
559: {
560: register struct amd7930_softc *sc = addr;
561: register volatile struct amd7930 *amd;
562:
563: /* XXX only halt, if input is also halted ?? */
564: amd = sc->sc_au.au_amd;
565: amd->cr = AMDR_INIT;
566: amd->dr = AMD_INIT_PMS_ACTIVE | AMD_INIT_INT_DISABLE;
567: sc->sc_locked = 0;
568:
569: return (0);
570: }
571:
572: int
573: amd7930_halt_input(addr)
574: void *addr;
575: {
576: register struct amd7930_softc *sc = addr;
577: register volatile struct amd7930 *amd;
578:
579: /* XXX only halt, if output is also halted ?? */
580: amd = sc->sc_au.au_amd;
581: amd->cr = AMDR_INIT;
582: amd->dr = AMD_INIT_PMS_ACTIVE | AMD_INIT_INT_DISABLE;
583: sc->sc_locked = 0;
584:
585: return (0);
586: }
587:
588: int
589: amd7930_getdev(addr, retp)
590: void *addr;
591: struct audio_device *retp;
592: {
593: *retp = amd7930_device;
594: return (0);
595: }
596:
597: int
598: amd7930_set_port(addr, cp)
599: void *addr;
600: mixer_ctrl_t *cp;
601: {
602: register struct amd7930_softc *sc = addr;
603:
604: DPRINTF(("amd7930_set_port: port=%d type=%d\n", cp->dev, cp->type));
605:
606: if (cp->dev == SUNAUDIO_SOURCE || cp->dev == SUNAUDIO_OUTPUT) {
607: if (cp->type != AUDIO_MIXER_ENUM)
608: return (EINVAL);
609: }
610: else if (cp->type != AUDIO_MIXER_VALUE ||
611: cp->un.value.num_channels != 1)
612: return (EINVAL);
613:
614: switch(cp->dev) {
615: case SUNAUDIO_MIC_PORT:
616: sc->sc_rlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
617: break;
618: case SUNAUDIO_SPEAKER:
619: case SUNAUDIO_HEADPHONES:
620: sc->sc_plevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
621: break;
622: case SUNAUDIO_MONITOR:
623: sc->sc_mlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
624: break;
625: case SUNAUDIO_SOURCE:
626: if (cp->un.ord != SUNAUDIO_MIC_PORT)
627: return (EINVAL);
628: break;
629: case SUNAUDIO_OUTPUT:
630: if (cp->un.ord != SUNAUDIO_SPEAKER &&
631: cp->un.ord != SUNAUDIO_HEADPHONES)
632: return (EINVAL);
633: sc->sc_out_port = cp->un.ord;
634: break;
635: default:
636: return (EINVAL);
637: /* NOTREACHED */
638: }
639: return (0);
640: }
641:
642: int
643: amd7930_get_port(addr, cp)
644: void *addr;
645: mixer_ctrl_t *cp;
646: {
647: register struct amd7930_softc *sc = addr;
648:
649: DPRINTF(("amd7930_get_port: port=%d type=%d\n", cp->dev, cp->type));
650:
651: if (cp->dev == SUNAUDIO_SOURCE || cp->dev == SUNAUDIO_OUTPUT) {
652: if (cp->type != AUDIO_MIXER_ENUM)
653: return (EINVAL);
654: }
655: else if (cp->type != AUDIO_MIXER_VALUE ||
656: cp->un.value.num_channels != 1)
657: return (EINVAL);
658:
659: switch(cp->dev) {
660: case SUNAUDIO_MIC_PORT:
661: cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_rlevel;
662: break;
663: case SUNAUDIO_SPEAKER:
664: case SUNAUDIO_HEADPHONES:
665: cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_plevel;
666: break;
667: case SUNAUDIO_MONITOR:
668: cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_mlevel;
669: break;
670: case SUNAUDIO_SOURCE:
671: cp->un.ord = SUNAUDIO_MIC_PORT;
672: break;
673: case SUNAUDIO_OUTPUT:
674: cp->un.ord = sc->sc_out_port;
675: break;
676: default:
677: return (EINVAL);
678: /* NOTREACHED */
679: }
680: return (0);
681: }
682:
683: int
684: amd7930_get_props(addr)
685: void *addr;
686: {
687: return (AUDIO_PROP_FULLDUPLEX);
688: }
689:
690: int
691: amd7930_query_devinfo(addr, dip)
692: void *addr;
693: register mixer_devinfo_t *dip;
694: {
695: switch(dip->index) {
696: case SUNAUDIO_MIC_PORT:
697: dip->type = AUDIO_MIXER_VALUE;
698: dip->mixer_class = SUNAUDIO_INPUT_CLASS;
699: dip->prev = dip->next = AUDIO_MIXER_LAST;
700: strlcpy(dip->label.name, AudioNmicrophone, sizeof dip->label.name);
701: dip->un.v.num_channels = 1;
702: strlcpy(dip->un.v.units.name, AudioNvolume,
703: sizeof dip->un.v.units.name);
704: break;
705: case SUNAUDIO_SPEAKER:
706: dip->type = AUDIO_MIXER_VALUE;
707: dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
708: dip->prev = dip->next = AUDIO_MIXER_LAST;
709: strlcpy(dip->label.name, AudioNspeaker, sizeof dip->label.name);
710: dip->un.v.num_channels = 1;
711: strlcpy(dip->un.v.units.name, AudioNvolume,
712: sizeof dip->un.v.units.name);
713: break;
714: case SUNAUDIO_HEADPHONES:
715: dip->type = AUDIO_MIXER_VALUE;
716: dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
717: dip->prev = dip->next = AUDIO_MIXER_LAST;
718: strlcpy(dip->label.name, AudioNheadphone, sizeof dip->label.name);
719: dip->un.v.num_channels = 1;
720: strlcpy(dip->un.v.units.name, AudioNvolume,
721: sizeof dip->label.name);
722: break;
723: case SUNAUDIO_MONITOR:
724: dip->type = AUDIO_MIXER_VALUE;
725: dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
726: dip->next = dip->prev = AUDIO_MIXER_LAST;
727: strlcpy(dip->label.name, AudioNmonitor, sizeof dip->label.name);
728: dip->un.v.num_channels = 1;
729: strlcpy(dip->un.v.units.name, AudioNvolume,
730: sizeof dip->label.name);
731: break;
732: case SUNAUDIO_SOURCE:
733: dip->type = AUDIO_MIXER_ENUM;
734: dip->mixer_class = SUNAUDIO_RECORD_CLASS;
735: dip->prev = dip->next = AUDIO_MIXER_LAST;
736: strlcpy(dip->label.name, AudioNsource, sizeof dip->label.name);
737: dip->un.e.num_mem = 1;
738: strlcpy(dip->un.e.member[0].label.name, AudioNmicrophone,
739: sizeof dip->un.e.member[0].label.name);
740: dip->un.e.member[0].ord = SUNAUDIO_MIC_PORT;
741: break;
742: case SUNAUDIO_OUTPUT:
743: dip->type = AUDIO_MIXER_ENUM;
744: dip->mixer_class = SUNAUDIO_MONITOR_CLASS;
745: dip->prev = dip->next = AUDIO_MIXER_LAST;
746: strlcpy(dip->label.name, AudioNoutput, sizeof dip->label.name);
747: dip->un.e.num_mem = 2;
748: strlcpy(dip->un.e.member[0].label.name, AudioNspeaker,
749: sizeof dip->un.e.member[0].label.name);
750: dip->un.e.member[0].ord = SUNAUDIO_SPEAKER;
751: strlcpy(dip->un.e.member[1].label.name, AudioNheadphone,
752: sizeof dip->un.e.member[0].label.name);
753: dip->un.e.member[1].ord = SUNAUDIO_HEADPHONES;
754: break;
755: case SUNAUDIO_INPUT_CLASS:
756: dip->type = AUDIO_MIXER_CLASS;
757: dip->mixer_class = SUNAUDIO_INPUT_CLASS;
758: dip->next = dip->prev = AUDIO_MIXER_LAST;
759: strlcpy(dip->label.name, AudioCinputs, sizeof dip->label.name);
760: break;
761: case SUNAUDIO_OUTPUT_CLASS:
762: dip->type = AUDIO_MIXER_CLASS;
763: dip->mixer_class = SUNAUDIO_OUTPUT_CLASS;
764: dip->next = dip->prev = AUDIO_MIXER_LAST;
765: strlcpy(dip->label.name, AudioCoutputs, sizeof dip->label.name);
766: break;
767: case SUNAUDIO_RECORD_CLASS:
768: dip->type = AUDIO_MIXER_CLASS;
769: dip->mixer_class = SUNAUDIO_RECORD_CLASS;
770: dip->next = dip->prev = AUDIO_MIXER_LAST;
771: strlcpy(dip->label.name, AudioCrecord, sizeof dip->label.name);
772: break;
773: case SUNAUDIO_MONITOR_CLASS:
774: dip->type = AUDIO_MIXER_CLASS;
775: dip->mixer_class = SUNAUDIO_MONITOR_CLASS;
776: dip->next = dip->prev = AUDIO_MIXER_LAST;
777: strlcpy(dip->label.name, AudioCmonitor, sizeof dip->label.name);
778: break;
779: default:
780: return (ENXIO);
781: /*NOTREACHED*/
782: }
783:
784: DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
785:
786: return (0);
787: }
788:
789: int
790: amd7930hwintr(au0)
791: void *au0;
792: {
793: register struct auio *au = au0;
794: register volatile struct amd7930 *amd = au->au_amd;
795: register u_char *d, *e;
796: register int k;
797:
798: k = amd->ir; /* clear interrupt */
799:
800: /* receive incoming data */
801: d = au->au_rdata;
802: e = au->au_rend;
803: if (d && d <= e) {
804: *d = amd->bbrb;
805: au->au_rdata++;
806: if (d == e) {
807: #ifdef AUDIO_DEBUG
808: if (amd7930debug > 1)
809: printf("amd7930hwintr: swintr(r) requested");
810: #endif
811: AUDIO_SET_SWINTR;
812: }
813: }
814:
815: /* send outgoing data */
816: d = au->au_pdata;
817: e = au->au_pend;
818: if (d && d <= e) {
819: amd->bbtb = *d;
820: au->au_pdata++;
821: if (d == e) {
822: #ifdef AUDIO_DEBUG
823: if (amd7930debug > 1)
824: printf("amd7930hwintr: swintr(p) requested");
825: #endif
826: AUDIO_SET_SWINTR;
827: }
828: }
829:
830: return (-1);
831: }
832:
833: int
834: amd7930swintr(sc0)
835: void *sc0;
836: {
837: register struct amd7930_softc *sc = sc0;
838: register struct auio *au;
839: register int s, ret = 0;
840:
841: #ifdef AUDIO_DEBUG
842: if (amd7930debug > 1)
843: printf("audiointr: sc=0x%x\n",sc);
844: #endif
845:
846: au = &sc->sc_au;
847: s = splaudio();
848: if (au->au_rdata > au->au_rend && sc->sc_rintr != NULL) {
849: splx(s);
850: ret = 1;
851: (*sc->sc_rintr)(sc->sc_rarg);
852: s = splaudio();
853: }
854: if (au->au_pdata > au->au_pend && sc->sc_pintr != NULL) {
855: splx(s);
856: ret = 1;
857: (*sc->sc_pintr)(sc->sc_parg);
858: } else
859: splx(s);
860: return (ret);
861: }
862:
863: #ifndef AUDIO_C_HANDLER
864: int
865: amd7930_shareintr(void *arg)
866: {
867: struct amd7930_softc *sc = arg;
868:
869: /*
870: * We are invoked at splhigh(), so there is no need to prevent the chip
871: * from interrupting while we are messing with the handlers. We
872: * however need to properly untie the event counter from the chain,
873: * since it will be reused immediately by intr_establish()...
874: */
875:
876: intr_fastuntrap(sc->sc_hwih.ih_vec);
877: evcount_detach(&sc->sc_hwih.ih_count);
878:
879: sc->sc_hwih.ih_fun = amd7930hwintr;
880: sc->sc_hwih.ih_arg = &sc->sc_au;
881: intr_establish(sc->sc_hwih.ih_vec, &sc->sc_hwih, IPL_AUHARD,
882: sc->sc_dev.dv_xname);
883:
884: return (0);
885: }
886: #endif
CVSweb