diff options
author | 1998-05-08 18:37:18 +0000 | |
---|---|---|
committer | 1998-05-08 18:37:18 +0000 | |
commit | 4229ea0a1cc89b563d86e7fa40296ffbc800af00 (patch) | |
tree | 391abffb094a406134b9f225debe4f2868edfe5e /sys/dev/isa/gus.c | |
parent | use what we can from mips/include (diff) | |
download | wireguard-openbsd-4229ea0a1cc89b563d86e7fa40296ffbc800af00.tar.xz wireguard-openbsd-4229ea0a1cc89b563d86e7fa40296ffbc800af00.zip |
Cleaned up AD1848 driver and added driver for Yamaha OPL3-SA3 to tree.
Diffstat (limited to 'sys/dev/isa/gus.c')
-rw-r--r-- | sys/dev/isa/gus.c | 330 |
1 files changed, 45 insertions, 285 deletions
diff --git a/sys/dev/isa/gus.c b/sys/dev/isa/gus.c index eb01c44a1a8..6ba8eaa4046 100644 --- a/sys/dev/isa/gus.c +++ b/sys/dev/isa/gus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gus.c,v 1.14 1998/04/26 21:02:41 provos Exp $ */ +/* $OpenBSD: gus.c,v 1.15 1998/05/08 18:37:21 csapuntz Exp $ */ /* $NetBSD: gus.c,v 1.51 1998/01/25 23:48:06 mycroft Exp $ */ /*- @@ -428,9 +428,6 @@ STATIC void gusics_mic_mute __P((struct ics2101_softc *, int)); STATIC void gusics_linein_mute __P((struct ics2101_softc *, int)); STATIC void gusics_cd_mute __P((struct ics2101_softc *, int)); -STATIC __inline int gus_to_vol __P((mixer_ctrl_t *, struct ad1848_volume *)); -STATIC __inline int gus_from_vol __P((mixer_ctrl_t *, struct ad1848_volume *)); - void stereo_dmaintr __P((void *)); /* @@ -1067,11 +1064,11 @@ gusopen(addr, flags) if (HAS_CODEC(sc)) { ad1848_open(&sc->sc_codec, flags); - sc->sc_codec.aux1_mute = 0; - ad1848_mute_aux1(&sc->sc_codec, 0); /* turn on DAC output */ + sc->sc_codec.mute[AD1848_AUX1_CHANNEL] = 0; + ad1848_mute_channel(&sc->sc_codec, AD1848_AUX1_CHANNEL, 0); /* turn on DAC output */ if (flags & FREAD) { - sc->sc_codec.mono_mute = 0; - cs4231_mute_mono(&sc->sc_codec, 0); + sc->sc_codec.mute[AD1848_MONO_CHANNEL] = 0; + ad1848_mute_channel(&sc->sc_codec, AD1848_MONO_CHANNEL, 0); } } else if (flags & FREAD) { /* enable/unmute the microphone */ @@ -1299,8 +1296,8 @@ gusmax_close(addr) struct ad1848_softc *ac = addr; struct gus_softc *sc = ac->parent; #if 0 - ac->aux1_mute = 1; - ad1848_mute_aux1(ac, 1); /* turn off DAC output */ + ac->mute[AD1848_AUX1_CHANNEL] = MUTE_ALL; + ad1848_mute_channel(ac, MUTE_ALL); /* turn off DAC output */ #endif ad1848_close(ac); gusclose(sc); @@ -3131,39 +3128,24 @@ gus_halt_in_dma(addr) return 0; } -STATIC __inline int -gus_to_vol(cp, vol) - mixer_ctrl_t *cp; - struct ad1848_volume *vol; -{ - if (cp->un.value.num_channels == 1) { - vol->left = vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]; - return(1); - } - else if (cp->un.value.num_channels == 2) { - vol->left = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]; - vol->right = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]; - return(1); - } - return(0); -} -STATIC __inline int -gus_from_vol(cp, vol) - mixer_ctrl_t *cp; - struct ad1848_volume *vol; -{ - if (cp->un.value.num_channels == 1) { - cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = vol->left; - return(1); - } - else if (cp->un.value.num_channels == 2) { - cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = vol->left; - cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = vol->right; - return(1); - } - return(0); -} +static ad1848_devmap_t gusmapping[] = { + {GUSMAX_DAC_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL}, + {GUSMAX_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL}, + {GUSMAX_MONO_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL}, + {GUSMAX_CD_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL}, + {GUSMAX_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL}, + {GUSMAX_OUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL}, + {GUSMAX_DAC_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL}, + {GUSMAX_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL}, + {GUSMAX_MONO_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL}, + {GUSMAX_CD_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL}, + {GUSMAX_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL}, + {GUSMAX_REC_LVL, AD1848_KIND_RECORDGAIN, -1}, + {GUSMAX_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1} +}; + +static int nummap = sizeof(gusmapping) / sizeof(gusmapping[0]); STATIC int gusmax_mixer_get_port(addr, cp) @@ -3173,72 +3155,14 @@ gusmax_mixer_get_port(addr, cp) struct ad1848_softc *ac = addr; struct gus_softc *sc = ac->parent; struct ad1848_volume vol; - int error = EINVAL; + int error = ad1848_mixer_get_port(ac, gusmapping, nummap, cp); - DPRINTF(("gusmax_mixer_get_port: port=%d\n", cp->dev)); - - switch (cp->dev) { -#if 0 /* use mono level instead */ - case GUSMAX_MIC_IN_LVL: /* Microphone */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = ad1848_get_mic_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; -#endif - - case GUSMAX_DAC_LVL: /* dac out */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = ad1848_get_aux1_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; + if (error != ENXIO) + return (error); - case GUSMAX_LINE_IN_LVL: /* line in */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = cs4231_get_linein_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; - - case GUSMAX_MONO_LVL: /* mono */ - if (cp->type == AUDIO_MIXER_VALUE && - cp->un.value.num_channels == 1) { - error = cs4231_get_mono_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; - - case GUSMAX_CD_LVL: /* CD */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = ad1848_get_aux2_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; - - case GUSMAX_MONITOR_LVL: /* monitor level */ - if (cp->type == AUDIO_MIXER_VALUE && - cp->un.value.num_channels == 1) { - error = ad1848_get_mon_gain(ac, &vol); - if (!error) - cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = - vol.left; - } - break; - - case GUSMAX_OUT_LVL: /* output level */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = ad1848_get_out_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; + error = EINVAL; + switch (cp->dev) { case GUSMAX_SPEAKER_LVL: /* fake speaker for mute naming */ if (cp->type == AUDIO_MIXER_VALUE) { if (sc->sc_mixcontrol & GUSMASK_LINE_OUT) @@ -3246,43 +3170,7 @@ gusmax_mixer_get_port(addr, cp) else vol.left = vol.right = AUDIO_MIN_GAIN; error = 0; - gus_from_vol(cp, &vol); - } - break; - - case GUSMAX_LINE_IN_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ac->line_mute; - error = 0; - } - break; - - - case GUSMAX_DAC_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ac->aux1_mute; - error = 0; - } - break; - - case GUSMAX_CD_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ac->aux2_mute; - error = 0; - } - break; - - case GUSMAX_MONO_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ac->mono_mute; - error = 0; - } - break; - - case GUSMAX_MONITOR_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ac->mon_mute; - error = 0; + ad1848_from_vol(cp, &vol); } break; @@ -3292,22 +3180,6 @@ gusmax_mixer_get_port(addr, cp) error = 0; } break; - - case GUSMAX_REC_LVL: /* record level */ - if (cp->type == AUDIO_MIXER_VALUE) { - error = ad1848_get_rec_gain(ac, &vol); - if (!error) - gus_from_vol(cp, &vol); - } - break; - - case GUSMAX_RECORD_SOURCE: - if (cp->type == AUDIO_MIXER_ENUM) { - cp->un.ord = ad1848_get_rec_port(ac); - error = 0; - } - break; - default: error = ENXIO; break; @@ -3384,7 +3256,7 @@ gus_mixer_get_port(addr, cp) if (cp->type == AUDIO_MIXER_VALUE) { vol.left = ic->sc_setting[GUSMIX_CHAN_MASTER][ICSMIX_LEFT]; vol.right = ic->sc_setting[GUSMIX_CHAN_MASTER][ICSMIX_RIGHT]; - if (gus_from_vol(cp, &vol)) + if (ad1848_from_vol(cp, &vol)) error = 0; } break; @@ -3393,7 +3265,7 @@ gus_mixer_get_port(addr, cp) if (cp->type == AUDIO_MIXER_VALUE) { vol.left = ic->sc_setting[GUSMIX_CHAN_MIC][ICSMIX_LEFT]; vol.right = ic->sc_setting[GUSMIX_CHAN_MIC][ICSMIX_RIGHT]; - if (gus_from_vol(cp, &vol)) + if (ad1848_from_vol(cp, &vol)) error = 0; } break; @@ -3402,7 +3274,7 @@ gus_mixer_get_port(addr, cp) if (cp->type == AUDIO_MIXER_VALUE) { vol.left = ic->sc_setting[GUSMIX_CHAN_LINE][ICSMIX_LEFT]; vol.right = ic->sc_setting[GUSMIX_CHAN_LINE][ICSMIX_RIGHT]; - if (gus_from_vol(cp, &vol)) + if (ad1848_from_vol(cp, &vol)) error = 0; } break; @@ -3412,7 +3284,7 @@ gus_mixer_get_port(addr, cp) if (cp->type == AUDIO_MIXER_VALUE) { vol.left = ic->sc_setting[GUSMIX_CHAN_CD][ICSMIX_LEFT]; vol.right = ic->sc_setting[GUSMIX_CHAN_CD][ICSMIX_RIGHT]; - if (gus_from_vol(cp, &vol)) + if (ad1848_from_vol(cp, &vol)) error = 0; } break; @@ -3421,7 +3293,7 @@ gus_mixer_get_port(addr, cp) if (cp->type == AUDIO_MIXER_VALUE) { vol.left = ic->sc_setting[GUSMIX_CHAN_DAC][ICSMIX_LEFT]; vol.right = ic->sc_setting[GUSMIX_CHAN_DAC][ICSMIX_RIGHT]; - if (gus_from_vol(cp, &vol)) + if (ad1848_from_vol(cp, &vol)) error = 0; } break; @@ -3494,70 +3366,18 @@ gusmax_mixer_set_port(addr, cp) struct ad1848_softc *ac = addr; struct gus_softc *sc = ac->parent; struct ad1848_volume vol; - int error = EINVAL; + int error = ad1848_mixer_set_port(ac, gusmapping, nummap, cp); + if (error != ENXIO) + return (error); + DPRINTF(("gusmax_mixer_set_port: dev=%d type=%d\n", cp->dev, cp->type)); switch (cp->dev) { -#if 0 - case GUSMAX_MIC_IN_LVL: /* Microphone */ - if (cp->type == AUDIO_MIXER_VALUE && - cp->un.value.num_channels == 1) { - /* XXX enable/disable pre-MUX fixed gain */ - if (gus_to_vol(cp, &vol)) - error = ad1848_set_mic_gain(ac, &vol); - } - break; -#endif - - case GUSMAX_DAC_LVL: /* dac out */ - if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) - error = ad1848_set_aux1_gain(ac, &vol); - } - break; - - case GUSMAX_LINE_IN_LVL: /* line in */ - if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) - error = cs4231_set_linein_gain(ac, &vol); - } - break; - - case GUSMAX_MONO_LVL: /* mic/mono in */ - if (cp->type == AUDIO_MIXER_VALUE && - cp->un.value.num_channels == 1) { - if (gus_to_vol(cp, &vol)) - error = cs4231_set_mono_gain(ac, &vol); - } - break; - - case GUSMAX_CD_LVL: /* CD: AUX2 */ - if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) - error = ad1848_set_aux2_gain(ac, &vol); - } - break; - - case GUSMAX_MONITOR_LVL: - if (cp->type == AUDIO_MIXER_VALUE && - cp->un.value.num_channels == 1) { - vol.left = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]; - error = ad1848_set_mon_gain(ac, &vol); - } - break; - - case GUSMAX_OUT_LVL: /* output volume */ - if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) - error = ad1848_set_out_gain(ac, &vol); - } - break; - case GUSMAX_SPEAKER_LVL: if (cp->type == AUDIO_MIXER_VALUE && cp->un.value.num_channels == 1) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { gus_speaker_ctl(sc, vol.left > AUDIO_MIN_GAIN ? SPKR_ON : SPKR_OFF); error = 0; @@ -3565,53 +3385,6 @@ gusmax_mixer_set_port(addr, cp) } break; - case GUSMAX_LINE_IN_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - ac->line_mute = cp->un.ord ? 1 : 0; - DPRINTF(("line mute %d\n", cp->un.ord)); - cs4231_mute_line(ac, ac->line_mute); - gus_linein_ctl(sc, ac->line_mute ? SPKR_OFF : SPKR_ON); - error = 0; - } - break; - - case GUSMAX_DAC_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - ac->aux1_mute = cp->un.ord ? 1 : 0; - DPRINTF(("dac mute %d\n", cp->un.ord)); - ad1848_mute_aux1(ac, ac->aux1_mute); - error = 0; - } - break; - - case GUSMAX_CD_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - ac->aux2_mute = cp->un.ord ? 1 : 0; - DPRINTF(("cd mute %d\n", cp->un.ord)); - ad1848_mute_aux2(ac, ac->aux2_mute); - error = 0; - } - break; - - case GUSMAX_MONO_MUTE: /* Microphone */ - if (cp->type == AUDIO_MIXER_ENUM) { - ac->mono_mute = cp->un.ord ? 1 : 0; - DPRINTF(("mono mute %d\n", cp->un.ord)); - cs4231_mute_mono(ac, ac->mono_mute); - gus_mic_ctl(sc, ac->mono_mute ? SPKR_OFF : SPKR_ON); - error = 0; - } - break; - - case GUSMAX_MONITOR_MUTE: - if (cp->type == AUDIO_MIXER_ENUM) { - ac->mon_mute = cp->un.ord ? 1 : 0; - DPRINTF(("mono mute %d\n", cp->un.ord)); - cs4231_mute_monitor(ac, ac->mon_mute); - error = 0; - } - break; - case GUSMAX_SPEAKER_MUTE: if (cp->type == AUDIO_MIXER_ENUM) { gus_speaker_ctl(sc, cp->un.ord ? SPKR_OFF : SPKR_ON); @@ -3619,19 +3392,6 @@ gusmax_mixer_set_port(addr, cp) } break; - case GUSMAX_REC_LVL: /* record level */ - if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) - error = ad1848_set_rec_gain(ac, &vol); - } - break; - - case GUSMAX_RECORD_SOURCE: - if (cp->type == AUDIO_MIXER_ENUM) { - error = ad1848_set_rec_port(ac, cp->un.ord); - } - break; - default: return ENXIO; /*NOTREACHED*/ @@ -3705,7 +3465,7 @@ gus_mixer_set_port(addr, cp) case GUSICS_MASTER_LVL: if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { ics2101_mix_attenuate(ic, GUSMIX_CHAN_MASTER, ICSMIX_LEFT, @@ -3721,7 +3481,7 @@ gus_mixer_set_port(addr, cp) case GUSICS_MIC_IN_LVL: /* Microphone */ if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { ics2101_mix_attenuate(ic, GUSMIX_CHAN_MIC, ICSMIX_LEFT, @@ -3737,7 +3497,7 @@ gus_mixer_set_port(addr, cp) case GUSICS_LINE_IN_LVL: /* line in */ if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { ics2101_mix_attenuate(ic, GUSMIX_CHAN_LINE, ICSMIX_LEFT, @@ -3754,7 +3514,7 @@ gus_mixer_set_port(addr, cp) case GUSICS_CD_LVL: if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { ics2101_mix_attenuate(ic, GUSMIX_CHAN_CD, ICSMIX_LEFT, @@ -3770,7 +3530,7 @@ gus_mixer_set_port(addr, cp) case GUSICS_DAC_LVL: /* dac out */ if (cp->type == AUDIO_MIXER_VALUE) { - if (gus_to_vol(cp, &vol)) { + if (ad1848_to_vol(cp, &vol)) { ics2101_mix_attenuate(ic, GUSMIX_CHAN_DAC, ICSMIX_LEFT, |