diff options
author | cg <cg@FreeBSD.org> | 2000-12-18 01:36:41 +0000 |
---|---|---|
committer | cg <cg@FreeBSD.org> | 2000-12-18 01:36:41 +0000 |
commit | 2fae4aec24ea4529882b3ec4cda45661ccd48ea8 (patch) | |
tree | e7e32573ed48df98bed54daa386c3520e959e951 /sys/dev/sound/isa | |
parent | 1fd2c926a884cc824e7da7ee1a51dad72b1dec5b (diff) | |
download | FreeBSD-src-2fae4aec24ea4529882b3ec4cda45661ccd48ea8.zip FreeBSD-src-2fae4aec24ea4529882b3ec4cda45661ccd48ea8.tar.gz |
kobjify.
this gives us several benefits, including:
* easier extensibility- new optional methods can be added to
ac97/mixer/channel classes without having to fixup every driver.
* forward compatibility for drivers, provided no new mandatory methods are
added.
Diffstat (limited to 'sys/dev/sound/isa')
-rw-r--r-- | sys/dev/sound/isa/ad1816.c | 92 | ||||
-rw-r--r-- | sys/dev/sound/isa/ess.c | 262 | ||||
-rw-r--r-- | sys/dev/sound/isa/mss.c | 1365 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb.h | 89 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb16.c | 114 | ||||
-rw-r--r-- | sys/dev/sound/isa/sb8.c | 104 |
6 files changed, 914 insertions, 1112 deletions
diff --git a/sys/dev/sound/isa/ad1816.c b/sys/dev/sound/isa/ad1816.c index 3184dd8..d6e1dd7 100644 --- a/sys/dev/sound/isa/ad1816.c +++ b/sys/dev/sound/isa/ad1816.c @@ -31,6 +31,8 @@ #include <dev/sound/pcm/sound.h> #include <dev/sound/isa/ad1816.h> +#include "mixer_if.h" + struct ad1816_info; struct ad1816_chinfo { @@ -64,30 +66,8 @@ static int ad1816_wait_init(struct ad1816_info *ad1816, int x); static u_short ad1816_read(struct ad1816_info *ad1816, u_int reg); static void ad1816_write(struct ad1816_info *ad1816, u_int reg, u_short data); -static int ad1816mix_init(snd_mixer *m); -static int ad1816mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src); -static snd_mixer ad1816_mixer = { - "ad1816 mixer", - ad1816mix_init, - NULL, - NULL, - ad1816mix_set, - ad1816mix_setrecsrc, -}; - static devclass_t pcm_devclass; -/* channel interface */ -static void *ad1816chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); -static int ad1816chan_setdir(void *data, int dir); -static int ad1816chan_setformat(void *data, u_int32_t format); -static int ad1816chan_setspeed(void *data, u_int32_t speed); -static int ad1816chan_setblocksize(void *data, u_int32_t blocksize); -static int ad1816chan_trigger(void *data, int go); -static int ad1816chan_getptr(void *data); -static pcmchan_caps *ad1816chan_getcaps(void *data); - static u_int32_t ad1816_fmt[] = { AFMT_U8, AFMT_STEREO | AFMT_U8, @@ -102,25 +82,6 @@ static u_int32_t ad1816_fmt[] = { static pcmchan_caps ad1816_caps = {4000, 55200, ad1816_fmt, 0}; -static pcm_channel ad1816_chantemplate = { - ad1816chan_init, - ad1816chan_setdir, - ad1816chan_setformat, - ad1816chan_setspeed, - ad1816chan_setblocksize, - ad1816chan_trigger, - ad1816chan_getptr, - ad1816chan_getcaps, - NULL, /* free */ - NULL, /* nop1 */ - NULL, /* nop2 */ - NULL, /* nop3 */ - NULL, /* nop4 */ - NULL, /* nop5 */ - NULL, /* nop6 */ - NULL, /* nop7 */ -}; - #define AD1816_MUTE 31 /* value for mute */ static int @@ -232,6 +193,8 @@ ad1816_write(struct ad1816_info *ad1816, unsigned int reg, unsigned short data) splx(flags); } +/* -------------------------------------------------------------------- */ + static int ad1816mix_init(snd_mixer *m) { @@ -329,9 +292,18 @@ ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src) return src; } +static kobj_method_t ad1816mixer_methods[] = { + KOBJMETHOD(mixer_init, ad1816mix_init), + KOBJMETHOD(mixer_set, ad1816mix_set), + KOBJMETHOD(mixer_setrecsrc, ad1816mix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(ad1816mixer); + +/* -------------------------------------------------------------------- */ /* channel interface */ static void * -ad1816chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) +ad1816chan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) { struct ad1816_info *ad1816 = devinfo; struct ad1816_chinfo *ch = (dir == PCMDIR_PLAY)? &ad1816->pch : &ad1816->rch; @@ -345,7 +317,7 @@ ad1816chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int -ad1816chan_setdir(void *data, int dir) +ad1816chan_setdir(kobj_t obj, void *data, int dir) { struct ad1816_chinfo *ch = data; struct ad1816_info *ad1816 = ch->parent; @@ -357,7 +329,7 @@ ad1816chan_setdir(void *data, int dir) } static int -ad1816chan_setformat(void *data, u_int32_t format) +ad1816chan_setformat(kobj_t obj, void *data, u_int32_t format) { struct ad1816_chinfo *ch = data; struct ad1816_info *ad1816 = ch->parent; @@ -399,7 +371,7 @@ ad1816chan_setformat(void *data, u_int32_t format) } static int -ad1816chan_setspeed(void *data, u_int32_t speed) +ad1816chan_setspeed(kobj_t obj, void *data, u_int32_t speed) { struct ad1816_chinfo *ch = data; struct ad1816_info *ad1816 = ch->parent; @@ -410,13 +382,13 @@ ad1816chan_setspeed(void *data, u_int32_t speed) } static int -ad1816chan_setblocksize(void *data, u_int32_t blocksize) +ad1816chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize) { return blocksize; } static int -ad1816chan_trigger(void *data, int go) +ad1816chan_trigger(kobj_t obj, void *data, int go) { struct ad1816_chinfo *ch = data; struct ad1816_info *ad1816 = ch->parent; @@ -466,18 +438,33 @@ ad1816chan_trigger(void *data, int go) } static int -ad1816chan_getptr(void *data) +ad1816chan_getptr(kobj_t obj, void *data) { struct ad1816_chinfo *ch = data; return buf_isadmaptr(ch->buffer); } static pcmchan_caps * -ad1816chan_getcaps(void *data) +ad1816chan_getcaps(kobj_t obj, void *data) { return &ad1816_caps; } +static kobj_method_t ad1816chan_methods[] = { + KOBJMETHOD(channel_init, ad1816chan_init), + KOBJMETHOD(channel_setdir, ad1816chan_setdir), + KOBJMETHOD(channel_setformat, ad1816chan_setformat), + KOBJMETHOD(channel_setspeed, ad1816chan_setspeed), + KOBJMETHOD(channel_setblocksize, ad1816chan_setblocksize), + KOBJMETHOD(channel_trigger, ad1816chan_trigger), + KOBJMETHOD(channel_getptr, ad1816chan_getptr), + KOBJMETHOD(channel_getcaps, ad1816chan_getcaps), + { 0, 0 } +}; +CHANNEL_DECLARE(ad1816chan); + +/* -------------------------------------------------------------------- */ + static void ad1816_release_resources(struct ad1816_info *ad1816, device_t dev) { @@ -596,7 +583,8 @@ ad1816_attach(device_t dev) if (!ad1816_alloc_resources(ad1816, dev)) goto no; ad1816_init(ad1816, dev); - mixer_init(dev, &ad1816_mixer, ad1816); + if (mixer_init(dev, &ad1816mixer_class, ad1816)) goto no; + bus_setup_intr(dev, ad1816->irq, INTR_TYPE_TTY, ad1816_intr, ad1816, &ad1816->ih); if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_24BIT, @@ -617,8 +605,8 @@ ad1816_attach(device_t dev) rman_get_start(ad1816->drq2)); if (pcm_register(dev, ad1816, 1, 1)) goto no; - pcm_addchan(dev, PCMDIR_REC, &ad1816_chantemplate, ad1816); - pcm_addchan(dev, PCMDIR_PLAY, &ad1816_chantemplate, ad1816); + pcm_addchan(dev, PCMDIR_REC, &ad1816chan_class, ad1816); + pcm_addchan(dev, PCMDIR_PLAY, &ad1816chan_class, ad1816); pcm_setstatus(dev, status); return 0; diff --git a/sys/dev/sound/isa/ess.c b/sys/dev/sound/isa/ess.c index 7841e35..f353289 100644 --- a/sys/dev/sound/isa/ess.c +++ b/sys/dev/sound/isa/ess.c @@ -36,6 +36,8 @@ #include <dev/sound/isa/sb.h> #include <dev/sound/chip.h> +#include "mixer_if.h" + #define ESS_BUFFSIZE (4096) #define ABS(x) (((x) < 0)? -(x) : (x)) @@ -45,15 +47,6 @@ /* more accurate clocks and split audio1/audio2 rates */ #define ESS18XX_NEWSPEED -/* channel interface for ESS */ -static void *esschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); -static int esschan_setformat(void *data, u_int32_t format); -static int esschan_setspeed(void *data, u_int32_t speed); -static int esschan_setblocksize(void *data, u_int32_t blocksize); -static int esschan_trigger(void *data, int go); -static int esschan_getptr(void *data); -static pcmchan_caps *esschan_getcaps(void *data); - static u_int32_t ess_pfmt[] = { AFMT_U8, AFMT_STEREO | AFMT_U8, @@ -82,32 +75,13 @@ static u_int32_t ess_rfmt[] = { static pcmchan_caps ess_reccaps = {5000, 49000, ess_rfmt, 0}; -static pcm_channel ess_chantemplate = { - esschan_init, - NULL, /* setdir */ - esschan_setformat, - esschan_setspeed, - esschan_setblocksize, - esschan_trigger, - esschan_getptr, - esschan_getcaps, - NULL, /* free */ - NULL, /* nop1 */ - NULL, /* nop2 */ - NULL, /* nop3 */ - NULL, /* nop4 */ - NULL, /* nop5 */ - NULL, /* nop6 */ - NULL, /* nop7 */ -}; - struct ess_info; struct ess_chinfo { struct ess_info *parent; pcm_channel *channel; snd_dbuf *buffer; - int dir, hwch, stopping; + int dir, hwch, stopping, run; u_int32_t fmt, spd; }; @@ -142,19 +116,6 @@ static int ess_setupch(struct ess_info *sc, int ch, int dir, int spd, u_int32_t static int ess_start(struct ess_chinfo *ch); static int ess_stop(struct ess_chinfo *ch); -static int essmix_init(snd_mixer *m); -static int essmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int essmix_setrecsrc(snd_mixer *m, u_int32_t src); - -static snd_mixer ess_mixer = { - "ESS mixer", - essmix_init, - NULL, - NULL, - essmix_set, - essmix_setrecsrc, -}; - static devclass_t pcm_devclass; /* @@ -377,94 +338,6 @@ ess_alloc_resources(struct ess_info *sc, device_t dev) } else return ENXIO; } -static int -ess_doattach(device_t dev, struct ess_info *sc) -{ - char status[SND_STATUSLEN], buf[64]; - int ver; - - if (ess_alloc_resources(sc, dev)) - goto no; - if (ess_reset_dsp(sc)) - goto no; - mixer_init(dev, &ess_mixer, sc); - - sc->duplex = 0; - sc->newspeed = 0; - ver = (ess_getmixer(sc, 0x40) << 8) | ess_rd(sc, SB_MIX_DATA); - snprintf(buf, sizeof buf, "ESS %x DSP", ver); - device_set_desc_copy(dev, buf); - if (bootverbose) - device_printf(dev, "ESS%x detected", ver); - - switch (ver) { - case 0x1869: - case 0x1879: -#ifdef ESS18XX_DUPLEX - sc->duplex = sc->drq2? 1 : 0; -#endif -#ifdef ESS18XX_NEWSPEED - sc->newspeed = 1; -#endif - break; - } - if (bootverbose) - printf("%s%s\n", sc->duplex? ", duplex" : "", - sc->newspeed? ", newspeed" : ""); - - if (sc->newspeed) - ess_setmixer(sc, 0x71, 0x22); - - bus_setup_intr(dev, sc->irq, INTR_TYPE_TTY, ess_intr, sc, &sc->ih); - if (!sc->duplex) - pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX); - - if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, - /*lowaddr*/BUS_SPACE_MAXADDR_24BIT, - /*highaddr*/BUS_SPACE_MAXADDR, - /*filter*/NULL, /*filterarg*/NULL, - /*maxsize*/ESS_BUFFSIZE, /*nsegments*/1, - /*maxsegz*/0x3ffff, - /*flags*/0, &sc->parent_dmat) != 0) { - device_printf(dev, "unable to create dma tag\n"); - goto no; - } - - snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld", - rman_get_start(sc->io_base), rman_get_start(sc->irq), - rman_get_start(sc->drq1)); - if (sc->drq2) - snprintf(status + strlen(status), SND_STATUSLEN - strlen(status), - ":%ld", rman_get_start(sc->drq2)); - - if (pcm_register(dev, sc, 1, 1)) - goto no; - pcm_addchan(dev, PCMDIR_REC, &ess_chantemplate, sc); - pcm_addchan(dev, PCMDIR_PLAY, &ess_chantemplate, sc); - pcm_setstatus(dev, status); - - return 0; - -no: - ess_release_resources(sc, dev); - return ENXIO; -} - -static int -ess_detach(device_t dev) -{ - int r; - struct ess_info *sc; - - r = pcm_unregister(dev); - if (r) - return r; - - sc = pcm_getdevinfo(dev); - ess_release_resources(sc, dev); - return 0; -} - static void ess_intr(void *arg) { @@ -481,7 +354,10 @@ ess_intr(void *arg) rirq = (src & sc->rch.hwch)? 1 : 0; if (pirq) { + if (!sc->pch.run) + printf("ess: play intr while not running\n"); if (sc->pch.stopping) { + sc->pch.run = 0; buf_isadma(sc->pch.buffer, PCMTRIG_STOP); sc->pch.stopping = 0; if (sc->pch.hwch == 1) @@ -493,7 +369,10 @@ ess_intr(void *arg) } if (rirq) { + if (!sc->rch.run) + printf("ess: record intr while not running\n"); if (sc->rch.stopping) { + sc->rch.run = 0; buf_isadma(sc->rch.buffer, PCMTRIG_STOP); sc->rch.stopping = 0; /* XXX: will this stop audio2? */ @@ -657,9 +536,10 @@ ess_stop(struct ess_chinfo *ch) return 0; } +/* -------------------------------------------------------------------- */ /* channel interface for ESS18xx */ static void * -esschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) +esschan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) { struct ess_info *sc = devinfo; struct ess_chinfo *ch = (dir == PCMDIR_PLAY)? &sc->pch : &sc->rch; @@ -679,7 +559,7 @@ esschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int -esschan_setformat(void *data, u_int32_t format) +esschan_setformat(kobj_t obj, void *data, u_int32_t format) { struct ess_chinfo *ch = data; @@ -688,7 +568,7 @@ esschan_setformat(void *data, u_int32_t format) } static int -esschan_setspeed(void *data, u_int32_t speed) +esschan_setspeed(kobj_t obj, void *data, u_int32_t speed) { struct ess_chinfo *ch = data; struct ess_info *sc = ch->parent; @@ -702,13 +582,13 @@ esschan_setspeed(void *data, u_int32_t speed) } static int -esschan_setblocksize(void *data, u_int32_t blocksize) +esschan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize) { return blocksize; } static int -esschan_trigger(void *data, int go) +esschan_trigger(kobj_t obj, void *data, int go) { struct ess_chinfo *ch = data; @@ -717,6 +597,7 @@ esschan_trigger(void *data, int go) switch (go) { case PCMTRIG_START: + ch->run = 1; buf_isadma(ch->buffer, go); ess_start(ch); break; @@ -731,7 +612,7 @@ esschan_trigger(void *data, int go) } static int -esschan_getptr(void *data) +esschan_getptr(kobj_t obj, void *data) { struct ess_chinfo *ch = data; @@ -739,13 +620,25 @@ esschan_getptr(void *data) } static pcmchan_caps * -esschan_getcaps(void *data) +esschan_getcaps(kobj_t obj, void *data) { struct ess_chinfo *ch = data; return (ch->dir == PCMDIR_PLAY)? &ess_playcaps : &ess_reccaps; } +static kobj_method_t esschan_methods[] = { + KOBJMETHOD(channel_init, esschan_init), + KOBJMETHOD(channel_setformat, esschan_setformat), + KOBJMETHOD(channel_setspeed, esschan_setspeed), + KOBJMETHOD(channel_setblocksize, esschan_setblocksize), + KOBJMETHOD(channel_trigger, esschan_trigger), + KOBJMETHOD(channel_getptr, esschan_getptr), + KOBJMETHOD(channel_getcaps, esschan_getcaps), + { 0, 0 } +}; +CHANNEL_DECLARE(esschan); + /************************************************************/ static int @@ -856,6 +749,16 @@ essmix_setrecsrc(snd_mixer *m, u_int32_t src) return src; } +static kobj_method_t essmixer_methods[] = { + KOBJMETHOD(mixer_init, essmix_init), + KOBJMETHOD(mixer_set, essmix_set), + KOBJMETHOD(mixer_setrecsrc, essmix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(essmixer); + +/************************************************************/ + static int ess_probe(device_t dev) { @@ -880,13 +783,95 @@ static int ess_attach(device_t dev) { struct ess_info *sc; + char status[SND_STATUSLEN], buf[64]; + int ver; sc = (struct ess_info *)malloc(sizeof *sc, M_DEVBUF, M_NOWAIT); if (!sc) return ENXIO; bzero(sc, sizeof *sc); - return ess_doattach(dev, sc); + if (ess_alloc_resources(sc, dev)) + goto no; + if (ess_reset_dsp(sc)) + goto no; + if (mixer_init(dev, &essmixer_class, sc)) + goto no; + + sc->duplex = 0; + sc->newspeed = 0; + ver = (ess_getmixer(sc, 0x40) << 8) | ess_rd(sc, SB_MIX_DATA); + snprintf(buf, sizeof buf, "ESS %x DSP", ver); + device_set_desc_copy(dev, buf); + if (bootverbose) + device_printf(dev, "ESS%x detected", ver); + + switch (ver) { + case 0x1869: + case 0x1879: +#ifdef ESS18XX_DUPLEX + sc->duplex = sc->drq2? 1 : 0; +#endif +#ifdef ESS18XX_NEWSPEED + sc->newspeed = 1; +#endif + break; + } + if (bootverbose) + printf("%s%s\n", sc->duplex? ", duplex" : "", + sc->newspeed? ", newspeed" : ""); + + if (sc->newspeed) + ess_setmixer(sc, 0x71, 0x22); + + bus_setup_intr(dev, sc->irq, INTR_TYPE_TTY, ess_intr, sc, &sc->ih); + if (!sc->duplex) + pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX); + + if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR_24BIT, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + /*maxsize*/ESS_BUFFSIZE, /*nsegments*/1, + /*maxsegz*/0x3ffff, + /*flags*/0, &sc->parent_dmat) != 0) { + device_printf(dev, "unable to create dma tag\n"); + goto no; + } + + snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld", + rman_get_start(sc->io_base), rman_get_start(sc->irq), + rman_get_start(sc->drq1)); + if (sc->drq2) + snprintf(status + strlen(status), SND_STATUSLEN - strlen(status), + ":%ld", rman_get_start(sc->drq2)); + + if (pcm_register(dev, sc, 1, 1)) + goto no; + pcm_addchan(dev, PCMDIR_REC, &esschan_class, sc); + pcm_addchan(dev, PCMDIR_PLAY, &esschan_class, sc); + pcm_setstatus(dev, status); + + return 0; + +no: + ess_release_resources(sc, dev); + return ENXIO; +} + +static int +ess_detach(device_t dev) +{ + int r; + struct ess_info *sc; + + r = pcm_unregister(dev); + if (r) + return r; + + sc = pcm_getdevinfo(dev); + ess_release_resources(sc, dev); + return 0; } static device_method_t ess_methods[] = { @@ -908,6 +893,7 @@ DRIVER_MODULE(snd_ess, sbc, ess_driver, pcm_devclass, 0, 0); MODULE_DEPEND(snd_ess, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER); MODULE_VERSION(snd_ess, 1); +/************************************************************/ static devclass_t esscontrol_devclass; diff --git a/sys/dev/sound/isa/mss.c b/sys/dev/sound/isa/mss.c index 3b24a75..3c6a126 100644 --- a/sys/dev/sound/isa/mss.c +++ b/sys/dev/sound/isa/mss.c @@ -34,6 +34,8 @@ #include <dev/sound/isa/mss.h> #include <dev/sound/chip.h> +#include "mixer_if.h" + #define MSS_BUFFSIZE (4096) #define abs(x) (((x) < 0) ? -(x) : (x)) #define MSS_INDEXED_REGS 0x20 @@ -105,42 +107,8 @@ static int pnpmss_attach(device_t dev); static driver_intr_t opti931_intr; -static int mssmix_init(snd_mixer *m); -static int mssmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int mssmix_setrecsrc(snd_mixer *m, u_int32_t src); -static snd_mixer mss_mixer = { - "MSS mixer", - mssmix_init, - NULL, - NULL, - mssmix_set, - mssmix_setrecsrc, -}; - -static int ymmix_init(snd_mixer *m); -static int ymmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int ymmix_setrecsrc(snd_mixer *m, u_int32_t src); -static snd_mixer yamaha_mixer = { - "OPL3-SAx mixer", - ymmix_init, - NULL, - NULL, - ymmix_set, - ymmix_setrecsrc, -}; - static devclass_t pcm_devclass; -/* channel interface */ -static void *msschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); -static int msschan_setdir(void *data, int dir); -static int msschan_setformat(void *data, u_int32_t format); -static int msschan_setspeed(void *data, u_int32_t speed); -static int msschan_setblocksize(void *data, u_int32_t blocksize); -static int msschan_trigger(void *data, int go); -static int msschan_getptr(void *data); -static pcmchan_caps *msschan_getcaps(void *data); - static u_int32_t mss_fmt[] = { AFMT_U8, AFMT_STEREO | AFMT_U8, @@ -174,25 +142,6 @@ static u_int32_t opti931_fmt[] = { }; static pcmchan_caps opti931_caps = {4000, 48000, opti931_fmt, 0}; -static pcm_channel mss_chantemplate = { - msschan_init, - msschan_setdir, - msschan_setformat, - msschan_setspeed, - msschan_setblocksize, - msschan_trigger, - msschan_getptr, - msschan_getcaps, - NULL, /* free */ - NULL, /* nop1 */ - NULL, /* nop2 */ - NULL, /* nop3 */ - NULL, /* nop4 */ - NULL, /* nop5 */ - NULL, /* nop6 */ - NULL, /* nop7 */ -}; - #define MD_AD1848 0x91 #define MD_AD1845 0x92 #define MD_CS42XX 0xA1 @@ -361,6 +310,214 @@ mss_alloc_resources(struct mss_info *mss, device_t dev) return ok; } +/* -------------------------------------------------------------------- */ +/* only one source can be set... */ +static int +mss_set_recsrc(struct mss_info *mss, int mask) +{ + u_char recdev; + + switch (mask) { + case SOUND_MASK_LINE: + case SOUND_MASK_LINE3: + recdev = 0; + break; + + case SOUND_MASK_CD: + case SOUND_MASK_LINE1: + recdev = 0x40; + break; + + case SOUND_MASK_IMIX: + recdev = 0xc0; + break; + + case SOUND_MASK_MIC: + default: + mask = SOUND_MASK_MIC; + recdev = 0x80; + } + ad_write(mss, 0, (ad_read(mss, 0) & 0x3f) | recdev); + ad_write(mss, 1, (ad_read(mss, 1) & 0x3f) | recdev); + return mask; +} + +/* there are differences in the mixer depending on the actual sound card. */ +static int +mss_mixer_set(struct mss_info *mss, int dev, int left, int right) +{ + int regoffs; + mixer_tab *mix_d = (mss->bd_id == MD_OPTI931)? &opti931_devices : &mix_devices; + u_char old, val; + + if ((*mix_d)[dev][LEFT_CHN].nbits == 0) { + DEB(printf("nbits = 0 for dev %d\n", dev)); + return -1; + } + + if ((*mix_d)[dev][RIGHT_CHN].nbits == 0) right = left; /* mono */ + + /* Set the left channel */ + + regoffs = (*mix_d)[dev][LEFT_CHN].regno; + old = val = ad_read(mss, regoffs); + /* if volume is 0, mute chan. Otherwise, unmute. */ + if (regoffs != 0) val = (left == 0)? old | 0x80 : old & 0x7f; + change_bits(mix_d, &val, dev, LEFT_CHN, left); + ad_write(mss, regoffs, val); + + DEB(printf("LEFT: dev %d reg %d old 0x%02x new 0x%02x\n", + dev, regoffs, old, val)); + + if ((*mix_d)[dev][RIGHT_CHN].nbits != 0) { /* have stereo */ + /* Set the right channel */ + regoffs = (*mix_d)[dev][RIGHT_CHN].regno; + old = val = ad_read(mss, regoffs); + if (regoffs != 1) val = (right == 0)? old | 0x80 : old & 0x7f; + change_bits(mix_d, &val, dev, RIGHT_CHN, right); + ad_write(mss, regoffs, val); + + DEB(printf("RIGHT: dev %d reg %d old 0x%02x new 0x%02x\n", + dev, regoffs, old, val)); + } + return 0; /* success */ +} + +/* -------------------------------------------------------------------- */ + +static int +mssmix_init(snd_mixer *m) +{ + struct mss_info *mss = mix_getdevinfo(m); + + mix_setdevs(m, MODE2_MIXER_DEVICES); + mix_setrecdevs(m, MSS_REC_DEVICES); + switch(mss->bd_id) { + case MD_OPTI931: + mix_setdevs(m, OPTI931_MIXER_DEVICES); + ad_write(mss, 20, 0x88); + ad_write(mss, 21, 0x88); + break; + + case MD_AD1848: + mix_setdevs(m, MODE1_MIXER_DEVICES); + break; + + case MD_GUSPNP: + case MD_GUSMAX: + /* this is only necessary in mode 3 ... */ + ad_write(mss, 22, 0x88); + ad_write(mss, 23, 0x88); + break; + } + return 0; +} + +static int +mssmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) +{ + struct mss_info *mss = mix_getdevinfo(m); + + mss_mixer_set(mss, dev, left, right); + + return left | (right << 8); +} + +static int +mssmix_setrecsrc(snd_mixer *m, u_int32_t src) +{ + struct mss_info *mss = mix_getdevinfo(m); + + src = mss_set_recsrc(mss, src); + return src; +} + +static kobj_method_t mssmix_mixer_methods[] = { + KOBJMETHOD(mixer_init, mssmix_init), + KOBJMETHOD(mixer_set, mssmix_set), + KOBJMETHOD(mixer_setrecsrc, mssmix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(mssmix_mixer); + +/* -------------------------------------------------------------------- */ + +static int +ymmix_init(snd_mixer *m) +{ + struct mss_info *mss = mix_getdevinfo(m); + + mssmix_init(m); + mix_setdevs(m, mix_getdevs(m) | SOUND_MASK_VOLUME | SOUND_MASK_MIC + | SOUND_MASK_BASS | SOUND_MASK_TREBLE); + /* Set master volume */ + conf_wr(mss, OPL3SAx_VOLUMEL, 7); + conf_wr(mss, OPL3SAx_VOLUMER, 7); + + return 0; +} + +static int +ymmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) +{ + struct mss_info *mss = mix_getdevinfo(m); + int t, l, r; + + switch (dev) { + case SOUND_MIXER_VOLUME: + if (left) t = 15 - (left * 15) / 100; + else t = 0x80; /* mute */ + conf_wr(mss, OPL3SAx_VOLUMEL, t); + if (right) t = 15 - (right * 15) / 100; + else t = 0x80; /* mute */ + conf_wr(mss, OPL3SAx_VOLUMER, t); + break; + + case SOUND_MIXER_MIC: + t = left; + if (left) t = 31 - (left * 31) / 100; + else t = 0x80; /* mute */ + conf_wr(mss, OPL3SAx_MIC, t); + break; + + case SOUND_MIXER_BASS: + l = (left * 7) / 100; + r = (right * 7) / 100; + t = (r << 4) | l; + conf_wr(mss, OPL3SAx_BASS, t); + break; + + case SOUND_MIXER_TREBLE: + l = (left * 7) / 100; + r = (right * 7) / 100; + t = (r << 4) | l; + conf_wr(mss, OPL3SAx_TREBLE, t); + break; + + default: + mss_mixer_set(mss, dev, left, right); + } + + return left | (right << 8); +} + +static int +ymmix_setrecsrc(snd_mixer *m, u_int32_t src) +{ + struct mss_info *mss = mix_getdevinfo(m); + src = mss_set_recsrc(mss, src); + return src; +} + +static kobj_method_t ymmix_mixer_methods[] = { + KOBJMETHOD(mixer_init, ymmix_init), + KOBJMETHOD(mixer_set, ymmix_set), + KOBJMETHOD(mixer_setrecsrc, ymmix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(ymmix_mixer); + +/* -------------------------------------------------------------------- */ /* * XXX This might be better off in the gusc driver. */ @@ -503,6 +660,464 @@ mss_init(struct mss_info *mss, device_t dev) return 0; } + +/* + * main irq handler for the CS423x. The OPTi931 code is + * a separate one. + * The correct way to operate for a device with multiple internal + * interrupt sources is to loop on the status register and ack + * interrupts until all interrupts are served and none are reported. At + * this point the IRQ line to the ISA IRQ controller should go low + * and be raised at the next interrupt. + * + * Since the ISA IRQ controller is sent EOI _before_ passing control + * to the isr, it might happen that we serve an interrupt early, in + * which case the status register at the next interrupt should just + * say that there are no more interrupts... + */ + +static void +mss_intr(void *arg) +{ + struct mss_info *mss = arg; + u_char c = 0, served = 0; + int i; + + DEB(printf("mss_intr\n")); + ad_read(mss, 11); /* fake read of status bits */ + + /* loop until there are interrupts, but no more than 10 times. */ + for (i = 10; i > 0 && io_rd(mss, MSS_STATUS) & 1; i--) { + /* get exact reason for full-duplex boards */ + c = FULL_DUPLEX(mss)? ad_read(mss, 24) : 0x30; + c &= ~served; + if (mss->pch.buffer->dl && (c & 0x10)) { + served |= 0x10; + chn_intr(mss->pch.channel); + } + if (mss->rch.buffer->dl && (c & 0x20)) { + served |= 0x20; + chn_intr(mss->rch.channel); + } + /* now ack the interrupt */ + if (FULL_DUPLEX(mss)) ad_write(mss, 24, ~c); /* ack selectively */ + else io_wr(mss, MSS_STATUS, 0); /* Clear interrupt status */ + } + if (i == 10) { + BVDDB(printf("mss_intr: irq, but not from mss\n")); + } else if (served == 0) { + BVDDB(printf("mss_intr: unexpected irq with reason %x\n", c)); + /* + * this should not happen... I have no idea what to do now. + * maybe should do a sanity check and restart dmas ? + */ + io_wr(mss, MSS_STATUS, 0); /* Clear interrupt status */ + } +} + +/* + * AD_WAIT_INIT waits if we are initializing the board and + * we cannot modify its settings + */ +static int +ad_wait_init(struct mss_info *mss, int x) +{ + int arg = x, n = 0; /* to shut up the compiler... */ + for (; x > 0; x--) + if ((n = io_rd(mss, MSS_INDEX)) & MSS_IDXBUSY) DELAY(10); + else return n; + printf("AD_WAIT_INIT FAILED %d 0x%02x\n", arg, n); + return n; +} + +static int +ad_read(struct mss_info *mss, int reg) +{ + u_long flags; + int x; + + flags = spltty(); + ad_wait_init(mss, 201); + x = io_rd(mss, MSS_INDEX) & ~MSS_IDXMASK; + io_wr(mss, MSS_INDEX, (u_char)(reg & MSS_IDXMASK) | x); + x = io_rd(mss, MSS_IDATA); + splx(flags); + /* printf("ad_read %d, %x\n", reg, x); */ + return x; +} + +static void +ad_write(struct mss_info *mss, int reg, u_char data) +{ + u_long flags; + + int x; + /* printf("ad_write %d, %x\n", reg, data); */ + flags = spltty(); + ad_wait_init(mss, 1002); + x = io_rd(mss, MSS_INDEX) & ~MSS_IDXMASK; + io_wr(mss, MSS_INDEX, (u_char)(reg & MSS_IDXMASK) | x); + io_wr(mss, MSS_IDATA, data); + splx(flags); +} + +static void +ad_write_cnt(struct mss_info *mss, int reg, u_short cnt) +{ + ad_write(mss, reg+1, cnt & 0xff); + ad_write(mss, reg, cnt >> 8); /* upper base must be last */ +} + +static void +wait_for_calibration(struct mss_info *mss) +{ + int t; + + /* + * Wait until the auto calibration process has finished. + * + * 1) Wait until the chip becomes ready (reads don't return 0x80). + * 2) Wait until the ACI bit of I11 gets on + * 3) Wait until the ACI bit of I11 gets off + */ + + t = ad_wait_init(mss, 1000); + if (t & MSS_IDXBUSY) printf("mss: Auto calibration timed out(1).\n"); + + /* + * The calibration mode for chips that support it is set so that + * we never see ACI go on. + */ + if (mss->bd_id == MD_GUSMAX || mss->bd_id == MD_GUSPNP) { + for (t = 100; t > 0 && (ad_read(mss, 11) & 0x20) == 0; t--); + } else { + /* + * XXX This should only be enabled for cards that *really* + * need it. Are there any? + */ + for (t = 100; t > 0 && (ad_read(mss, 11) & 0x20) == 0; t--) DELAY(100); + } + for (t = 100; t > 0 && ad_read(mss, 11) & 0x20; t--) DELAY(100); +} + +static void +ad_unmute(struct mss_info *mss) +{ + ad_write(mss, 6, ad_read(mss, 6) & ~I6_MUTE); + ad_write(mss, 7, ad_read(mss, 7) & ~I6_MUTE); +} + +static void +ad_enter_MCE(struct mss_info *mss) +{ + int prev; + + mss->bd_flags |= BD_F_MCE_BIT; + ad_wait_init(mss, 203); + prev = io_rd(mss, MSS_INDEX); + prev &= ~MSS_TRD; + io_wr(mss, MSS_INDEX, prev | MSS_MCE); +} + +static void +ad_leave_MCE(struct mss_info *mss) +{ + u_long flags; + u_char prev; + + if ((mss->bd_flags & BD_F_MCE_BIT) == 0) { + DEB(printf("--- hey, leave_MCE: MCE bit was not set!\n")); + return; + } + + ad_wait_init(mss, 1000); + + flags = spltty(); + mss->bd_flags &= ~BD_F_MCE_BIT; + + prev = io_rd(mss, MSS_INDEX); + prev &= ~MSS_TRD; + io_wr(mss, MSS_INDEX, prev & ~MSS_MCE); /* Clear the MCE bit */ + wait_for_calibration(mss); + splx(flags); +} + +static int +mss_speed(struct mss_chinfo *ch, int speed) +{ + struct mss_info *mss = ch->parent; + /* + * In the CS4231, the low 4 bits of I8 are used to hold the + * sample rate. Only a fixed number of values is allowed. This + * table lists them. The speed-setting routines scans the table + * looking for the closest match. This is the only supported method. + * + * In the CS4236, there is an alternate metod (which we do not + * support yet) which provides almost arbitrary frequency setting. + * In the AD1845, it looks like the sample rate can be + * almost arbitrary, and written directly to a register. + * In the OPTi931, there is a SB command which provides for + * almost arbitrary frequency setting. + * + */ + ad_enter_MCE(mss); + if (mss->bd_id == MD_AD1845) { /* Use alternate speed select regs */ + ad_write(mss, 22, (speed >> 8) & 0xff); /* Speed MSB */ + ad_write(mss, 23, speed & 0xff); /* Speed LSB */ + /* XXX must also do something in I27 for the ad1845 */ + } else { + int i, sel = 0; /* assume entry 0 does not contain -1 */ + static int speeds[] = + {8000, 5512, 16000, 11025, 27429, 18900, 32000, 22050, + -1, 37800, -1, 44100, 48000, 33075, 9600, 6615}; + + for (i = 1; i < 16; i++) + if (speeds[i] > 0 && + abs(speed-speeds[i]) < abs(speed-speeds[sel])) sel = i; + speed = speeds[sel]; + ad_write(mss, 8, (ad_read(mss, 8) & 0xf0) | sel); + } + ad_leave_MCE(mss); + + return speed; +} + +/* + * mss_format checks that the format is supported (or defaults to AFMT_U8) + * and returns the bit setting for the 1848 register corresponding to + * the desired format. + * + * fixed lr970724 + */ + +static int +mss_format(struct mss_chinfo *ch, u_int32_t format) +{ + struct mss_info *mss = ch->parent; + int i, arg = format & ~AFMT_STEREO; + + /* + * The data format uses 3 bits (just 2 on the 1848). For each + * bit setting, the following array returns the corresponding format. + * The code scans the array looking for a suitable format. In + * case it is not found, default to AFMT_U8 (not such a good + * choice, but let's do it for compatibility...). + */ + + static int fmts[] = + {AFMT_U8, AFMT_MU_LAW, AFMT_S16_LE, AFMT_A_LAW, + -1, AFMT_IMA_ADPCM, AFMT_U16_BE, -1}; + + ch->fmt = format; + for (i = 0; i < 8; i++) if (arg == fmts[i]) break; + arg = i << 1; + if (format & AFMT_STEREO) arg |= 1; + arg <<= 4; + ad_enter_MCE(mss); + ad_write(mss, 8, (ad_read(mss, 8) & 0x0f) | arg); + if (FULL_DUPLEX(mss)) ad_write(mss, 28, arg); /* capture mode */ + ad_leave_MCE(mss); + return format; +} + +static int +mss_trigger(struct mss_chinfo *ch, int go) +{ + struct mss_info *mss = ch->parent; + u_char m; + int retry, wr, cnt, ss; + + ss = 1; + ss <<= (ch->fmt & AFMT_STEREO)? 1 : 0; + ss <<= (ch->fmt & AFMT_16BIT)? 1 : 0; + + wr = (ch->dir == PCMDIR_PLAY)? 1 : 0; + m = ad_read(mss, 9); + switch (go) { + case PCMTRIG_START: + cnt = (ch->buffer->dl / ss) - 1; + + DEB(if (m & 4) printf("OUCH! reg 9 0x%02x\n", m);); + m |= wr? I9_PEN : I9_CEN; /* enable DMA */ + ad_write_cnt(mss, (wr || !FULL_DUPLEX(mss))? 14 : 30, cnt); + break; + + case PCMTRIG_STOP: + case PCMTRIG_ABORT: /* XXX check this... */ + m &= ~(wr? I9_PEN : I9_CEN); /* Stop DMA */ +#if 0 + /* + * try to disable DMA by clearing count registers. Not sure it + * is needed, and it might cause false interrupts when the + * DMA is re-enabled later. + */ + ad_write_cnt(mss, (wr || !FULL_DUPLEX(mss))? 14 : 30, 0); +#endif + } + /* on the OPTi931 the enable bit seems hard to set... */ + for (retry = 10; retry > 0; retry--) { + ad_write(mss, 9, m); + if (ad_read(mss, 9) == m) break; + } + if (retry == 0) BVDDB(printf("stop dma, failed to set bit 0x%02x 0x%02x\n", \ + m, ad_read(mss, 9))); + return 0; +} + + +/* + * the opti931 seems to miss interrupts when working in full + * duplex, so we try some heuristics to catch them. + */ +static void +opti931_intr(void *arg) +{ + struct mss_info *mss = (struct mss_info *)arg; + u_char masked = 0, i11, mc11, c = 0; + u_char reason; /* b0 = playback, b1 = capture, b2 = timer */ + int loops = 10; + +#if 0 + reason = io_rd(mss, MSS_STATUS); + if (!(reason & 1)) {/* no int, maybe a shared line ? */ + DEB(printf("intr: flag 0, mcir11 0x%02x\n", ad_read(mss, 11))); + return; + } +#endif + i11 = ad_read(mss, 11); /* XXX what's for ? */ + again: + + c = mc11 = FULL_DUPLEX(mss)? opti_rd(mss, 11) : 0xc; + mc11 &= 0x0c; + if (c & 0x10) { + DEB(printf("Warning: CD interrupt\n");) + mc11 |= 0x10; + } + if (c & 0x20) { + DEB(printf("Warning: MPU interrupt\n");) + mc11 |= 0x20; + } + if (mc11 & masked) BVDDB(printf("irq reset failed, mc11 0x%02x, 0x%02x\n",\ + mc11, masked)); + masked |= mc11; + /* + * the nice OPTi931 sets the IRQ line before setting the bits in + * mc11. So, on some occasions I have to retry (max 10 times). + */ + if (mc11 == 0) { /* perhaps can return ... */ + reason = io_rd(mss, MSS_STATUS); + if (reason & 1) { + DEB(printf("one more try...\n");) + if (--loops) goto again; + else DDB(printf("intr, but mc11 not set\n");) + } + if (loops == 0) BVDDB(printf("intr, nothing in mcir11 0x%02x\n", mc11)); + return; + } + + if (mss->rch.buffer->dl && (mc11 & 8)) chn_intr(mss->rch.channel); + if (mss->pch.buffer->dl && (mc11 & 4)) chn_intr(mss->pch.channel); + opti_wr(mss, 11, ~mc11); /* ack */ + if (--loops) goto again; + DEB(printf("xxx too many loops\n");) +} + +/* -------------------------------------------------------------------- */ +/* channel interface */ +static void * +msschan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) +{ + struct mss_info *mss = devinfo; + struct mss_chinfo *ch = (dir == PCMDIR_PLAY)? &mss->pch : &mss->rch; + + ch->parent = mss; + ch->channel = c; + ch->buffer = b; + ch->buffer->bufsize = MSS_BUFFSIZE; + ch->buffer->chan = (dir == PCMDIR_PLAY)? mss->pdma : mss->rdma; + ch->dir = dir; + if (chn_allocbuf(ch->buffer, mss->parent_dmat) == -1) return NULL; + return ch; +} + +static int +msschan_setformat(kobj_t obj, void *data, u_int32_t format) +{ + struct mss_chinfo *ch = data; + + mss_format(ch, format); + return 0; +} + +static int +msschan_setspeed(kobj_t obj, void *data, u_int32_t speed) +{ + struct mss_chinfo *ch = data; + + return mss_speed(ch, speed); +} + +static int +msschan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize) +{ + return blocksize; +} + +static int +msschan_trigger(kobj_t obj, void *data, int go) +{ + struct mss_chinfo *ch = data; + + if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD) + return 0; + + buf_isadma(ch->buffer, go); + mss_trigger(ch, go); + return 0; +} + +static int +msschan_getptr(kobj_t obj, void *data) +{ + struct mss_chinfo *ch = data; + return buf_isadmaptr(ch->buffer); +} + +static pcmchan_caps * +msschan_getcaps(kobj_t obj, void *data) +{ + struct mss_chinfo *ch = data; + + switch(ch->parent->bd_id) { + case MD_OPTI931: + return &opti931_caps; + break; + + case MD_GUSPNP: + case MD_GUSMAX: + return &guspnp_caps; + break; + + default: + return &mss_caps; + break; + } +} + +static kobj_method_t msschan_methods[] = { + KOBJMETHOD(channel_init, msschan_init), + KOBJMETHOD(channel_setformat, msschan_setformat), + KOBJMETHOD(channel_setspeed, msschan_setspeed), + KOBJMETHOD(channel_setblocksize, msschan_setblocksize), + KOBJMETHOD(channel_trigger, msschan_trigger), + KOBJMETHOD(channel_getptr, msschan_getptr), + KOBJMETHOD(channel_getcaps, msschan_getcaps), + { 0, 0 } +}; +CHANNEL_DECLARE(msschan); + +/* -------------------------------------------------------------------- */ + /* * mss_probe() is the probe routine. Note, it is not necessary to * go through this for PnP devices, since they are already @@ -919,7 +1534,7 @@ mss_doattach(device_t dev, struct mss_info *mss) io_wr(mss, 0, bits); printf("drq/irq conf %x\n", io_rd(mss, 0)); } - mixer_init(dev, (mss->bd_id == MD_YM0020)? &yamaha_mixer : &mss_mixer, mss); + mixer_init(dev, (mss->bd_id == MD_YM0020)? &ymmix_mixer_class : &mssmix_mixer_class, mss); switch (mss->bd_id) { case MD_OPTI931: bus_setup_intr(dev, mss->irq, INTR_TYPE_TTY, opti931_intr, mss, &mss->ih); @@ -945,8 +1560,8 @@ mss_doattach(device_t dev, struct mss_info *mss) SND_STATUSLEN - strlen(status), ":%d", mss->rdma); if (pcm_register(dev, mss, 1, 1)) goto no; - pcm_addchan(dev, PCMDIR_REC, &mss_chantemplate, mss); - pcm_addchan(dev, PCMDIR_PLAY, &mss_chantemplate, mss); + pcm_addchan(dev, PCMDIR_REC, &msschan_class, mss); + pcm_addchan(dev, PCMDIR_PLAY, &msschan_class, mss); pcm_setstatus(dev, status); return 0; @@ -1084,384 +1699,6 @@ DRIVER_MODULE(snd_mss, isa, mss_driver, pcm_devclass, 0, 0); MODULE_DEPEND(snd_mss, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER); MODULE_VERSION(snd_mss, 1); - -/* - * main irq handler for the CS423x. The OPTi931 code is - * a separate one. - * The correct way to operate for a device with multiple internal - * interrupt sources is to loop on the status register and ack - * interrupts until all interrupts are served and none are reported. At - * this point the IRQ line to the ISA IRQ controller should go low - * and be raised at the next interrupt. - * - * Since the ISA IRQ controller is sent EOI _before_ passing control - * to the isr, it might happen that we serve an interrupt early, in - * which case the status register at the next interrupt should just - * say that there are no more interrupts... - */ - -static void -mss_intr(void *arg) -{ - struct mss_info *mss = arg; - u_char c = 0, served = 0; - int i; - - DEB(printf("mss_intr\n")); - ad_read(mss, 11); /* fake read of status bits */ - - /* loop until there are interrupts, but no more than 10 times. */ - for (i = 10; i > 0 && io_rd(mss, MSS_STATUS) & 1; i--) { - /* get exact reason for full-duplex boards */ - c = FULL_DUPLEX(mss)? ad_read(mss, 24) : 0x30; - c &= ~served; - if (mss->pch.buffer->dl && (c & 0x10)) { - served |= 0x10; - chn_intr(mss->pch.channel); - } - if (mss->rch.buffer->dl && (c & 0x20)) { - served |= 0x20; - chn_intr(mss->rch.channel); - } - /* now ack the interrupt */ - if (FULL_DUPLEX(mss)) ad_write(mss, 24, ~c); /* ack selectively */ - else io_wr(mss, MSS_STATUS, 0); /* Clear interrupt status */ - } - if (i == 10) { - BVDDB(printf("mss_intr: irq, but not from mss\n")); - } else if (served == 0) { - BVDDB(printf("mss_intr: unexpected irq with reason %x\n", c)); - /* - * this should not happen... I have no idea what to do now. - * maybe should do a sanity check and restart dmas ? - */ - io_wr(mss, MSS_STATUS, 0); /* Clear interrupt status */ - } -} - -/* - * AD_WAIT_INIT waits if we are initializing the board and - * we cannot modify its settings - */ -static int -ad_wait_init(struct mss_info *mss, int x) -{ - int arg = x, n = 0; /* to shut up the compiler... */ - for (; x > 0; x--) - if ((n = io_rd(mss, MSS_INDEX)) & MSS_IDXBUSY) DELAY(10); - else return n; - printf("AD_WAIT_INIT FAILED %d 0x%02x\n", arg, n); - return n; -} - -static int -ad_read(struct mss_info *mss, int reg) -{ - u_long flags; - int x; - - flags = spltty(); - ad_wait_init(mss, 201); - x = io_rd(mss, MSS_INDEX) & ~MSS_IDXMASK; - io_wr(mss, MSS_INDEX, (u_char)(reg & MSS_IDXMASK) | x); - x = io_rd(mss, MSS_IDATA); - splx(flags); - /* printf("ad_read %d, %x\n", reg, x); */ - return x; -} - -static void -ad_write(struct mss_info *mss, int reg, u_char data) -{ - u_long flags; - - int x; - /* printf("ad_write %d, %x\n", reg, data); */ - flags = spltty(); - ad_wait_init(mss, 1002); - x = io_rd(mss, MSS_INDEX) & ~MSS_IDXMASK; - io_wr(mss, MSS_INDEX, (u_char)(reg & MSS_IDXMASK) | x); - io_wr(mss, MSS_IDATA, data); - splx(flags); -} - -static void -ad_write_cnt(struct mss_info *mss, int reg, u_short cnt) -{ - ad_write(mss, reg+1, cnt & 0xff); - ad_write(mss, reg, cnt >> 8); /* upper base must be last */ -} - -static void -wait_for_calibration(struct mss_info *mss) -{ - int t; - - /* - * Wait until the auto calibration process has finished. - * - * 1) Wait until the chip becomes ready (reads don't return 0x80). - * 2) Wait until the ACI bit of I11 gets on - * 3) Wait until the ACI bit of I11 gets off - */ - - t = ad_wait_init(mss, 1000); - if (t & MSS_IDXBUSY) printf("mss: Auto calibration timed out(1).\n"); - - /* - * The calibration mode for chips that support it is set so that - * we never see ACI go on. - */ - if (mss->bd_id == MD_GUSMAX || mss->bd_id == MD_GUSPNP) { - for (t = 100; t > 0 && (ad_read(mss, 11) & 0x20) == 0; t--); - } else { - /* - * XXX This should only be enabled for cards that *really* - * need it. Are there any? - */ - for (t = 100; t > 0 && (ad_read(mss, 11) & 0x20) == 0; t--) DELAY(100); - } - for (t = 100; t > 0 && ad_read(mss, 11) & 0x20; t--) DELAY(100); -} - -static void -ad_unmute(struct mss_info *mss) -{ - ad_write(mss, 6, ad_read(mss, 6) & ~I6_MUTE); - ad_write(mss, 7, ad_read(mss, 7) & ~I6_MUTE); -} - -static void -ad_enter_MCE(struct mss_info *mss) -{ - int prev; - - mss->bd_flags |= BD_F_MCE_BIT; - ad_wait_init(mss, 203); - prev = io_rd(mss, MSS_INDEX); - prev &= ~MSS_TRD; - io_wr(mss, MSS_INDEX, prev | MSS_MCE); -} - -static void -ad_leave_MCE(struct mss_info *mss) -{ - u_long flags; - u_char prev; - - if ((mss->bd_flags & BD_F_MCE_BIT) == 0) { - DEB(printf("--- hey, leave_MCE: MCE bit was not set!\n")); - return; - } - - ad_wait_init(mss, 1000); - - flags = spltty(); - mss->bd_flags &= ~BD_F_MCE_BIT; - - prev = io_rd(mss, MSS_INDEX); - prev &= ~MSS_TRD; - io_wr(mss, MSS_INDEX, prev & ~MSS_MCE); /* Clear the MCE bit */ - wait_for_calibration(mss); - splx(flags); -} - -/* - * only one source can be set... - */ -static int -mss_set_recsrc(struct mss_info *mss, int mask) -{ - u_char recdev; - - switch (mask) { - case SOUND_MASK_LINE: - case SOUND_MASK_LINE3: - recdev = 0; - break; - - case SOUND_MASK_CD: - case SOUND_MASK_LINE1: - recdev = 0x40; - break; - - case SOUND_MASK_IMIX: - recdev = 0xc0; - break; - - case SOUND_MASK_MIC: - default: - mask = SOUND_MASK_MIC; - recdev = 0x80; - } - ad_write(mss, 0, (ad_read(mss, 0) & 0x3f) | recdev); - ad_write(mss, 1, (ad_read(mss, 1) & 0x3f) | recdev); - return mask; -} - -/* there are differences in the mixer depending on the actual sound card. */ -static int -mss_mixer_set(struct mss_info *mss, int dev, int left, int right) -{ - int regoffs; - mixer_tab *mix_d = (mss->bd_id == MD_OPTI931)? &opti931_devices : &mix_devices; - u_char old, val; - - if ((*mix_d)[dev][LEFT_CHN].nbits == 0) { - DEB(printf("nbits = 0 for dev %d\n", dev)); - return -1; - } - - if ((*mix_d)[dev][RIGHT_CHN].nbits == 0) right = left; /* mono */ - - /* Set the left channel */ - - regoffs = (*mix_d)[dev][LEFT_CHN].regno; - old = val = ad_read(mss, regoffs); - /* if volume is 0, mute chan. Otherwise, unmute. */ - if (regoffs != 0) val = (left == 0)? old | 0x80 : old & 0x7f; - change_bits(mix_d, &val, dev, LEFT_CHN, left); - ad_write(mss, regoffs, val); - - DEB(printf("LEFT: dev %d reg %d old 0x%02x new 0x%02x\n", - dev, regoffs, old, val)); - - if ((*mix_d)[dev][RIGHT_CHN].nbits != 0) { /* have stereo */ - /* Set the right channel */ - regoffs = (*mix_d)[dev][RIGHT_CHN].regno; - old = val = ad_read(mss, regoffs); - if (regoffs != 1) val = (right == 0)? old | 0x80 : old & 0x7f; - change_bits(mix_d, &val, dev, RIGHT_CHN, right); - ad_write(mss, regoffs, val); - - DEB(printf("RIGHT: dev %d reg %d old 0x%02x new 0x%02x\n", - dev, regoffs, old, val)); - } - return 0; /* success */ -} - -static int -mss_speed(struct mss_chinfo *ch, int speed) -{ - struct mss_info *mss = ch->parent; - /* - * In the CS4231, the low 4 bits of I8 are used to hold the - * sample rate. Only a fixed number of values is allowed. This - * table lists them. The speed-setting routines scans the table - * looking for the closest match. This is the only supported method. - * - * In the CS4236, there is an alternate metod (which we do not - * support yet) which provides almost arbitrary frequency setting. - * In the AD1845, it looks like the sample rate can be - * almost arbitrary, and written directly to a register. - * In the OPTi931, there is a SB command which provides for - * almost arbitrary frequency setting. - * - */ - ad_enter_MCE(mss); - if (mss->bd_id == MD_AD1845) { /* Use alternate speed select regs */ - ad_write(mss, 22, (speed >> 8) & 0xff); /* Speed MSB */ - ad_write(mss, 23, speed & 0xff); /* Speed LSB */ - /* XXX must also do something in I27 for the ad1845 */ - } else { - int i, sel = 0; /* assume entry 0 does not contain -1 */ - static int speeds[] = - {8000, 5512, 16000, 11025, 27429, 18900, 32000, 22050, - -1, 37800, -1, 44100, 48000, 33075, 9600, 6615}; - - for (i = 1; i < 16; i++) - if (speeds[i] > 0 && - abs(speed-speeds[i]) < abs(speed-speeds[sel])) sel = i; - speed = speeds[sel]; - ad_write(mss, 8, (ad_read(mss, 8) & 0xf0) | sel); - } - ad_leave_MCE(mss); - - return speed; -} - -/* - * mss_format checks that the format is supported (or defaults to AFMT_U8) - * and returns the bit setting for the 1848 register corresponding to - * the desired format. - * - * fixed lr970724 - */ - -static int -mss_format(struct mss_chinfo *ch, u_int32_t format) -{ - struct mss_info *mss = ch->parent; - int i, arg = format & ~AFMT_STEREO; - - /* - * The data format uses 3 bits (just 2 on the 1848). For each - * bit setting, the following array returns the corresponding format. - * The code scans the array looking for a suitable format. In - * case it is not found, default to AFMT_U8 (not such a good - * choice, but let's do it for compatibility...). - */ - - static int fmts[] = - {AFMT_U8, AFMT_MU_LAW, AFMT_S16_LE, AFMT_A_LAW, - -1, AFMT_IMA_ADPCM, AFMT_U16_BE, -1}; - - ch->fmt = format; - for (i = 0; i < 8; i++) if (arg == fmts[i]) break; - arg = i << 1; - if (format & AFMT_STEREO) arg |= 1; - arg <<= 4; - ad_enter_MCE(mss); - ad_write(mss, 8, (ad_read(mss, 8) & 0x0f) | arg); - if (FULL_DUPLEX(mss)) ad_write(mss, 28, arg); /* capture mode */ - ad_leave_MCE(mss); - return format; -} - -static int -mss_trigger(struct mss_chinfo *ch, int go) -{ - struct mss_info *mss = ch->parent; - u_char m; - int retry, wr, cnt, ss; - - ss = 1; - ss <<= (ch->fmt & AFMT_STEREO)? 1 : 0; - ss <<= (ch->fmt & AFMT_16BIT)? 1 : 0; - - wr = (ch->dir == PCMDIR_PLAY)? 1 : 0; - m = ad_read(mss, 9); - switch (go) { - case PCMTRIG_START: - cnt = (ch->buffer->dl / ss) - 1; - - DEB(if (m & 4) printf("OUCH! reg 9 0x%02x\n", m);); - m |= wr? I9_PEN : I9_CEN; /* enable DMA */ - ad_write_cnt(mss, (wr || !FULL_DUPLEX(mss))? 14 : 30, cnt); - break; - - case PCMTRIG_STOP: - case PCMTRIG_ABORT: /* XXX check this... */ - m &= ~(wr? I9_PEN : I9_CEN); /* Stop DMA */ -#if 0 - /* - * try to disable DMA by clearing count registers. Not sure it - * is needed, and it might cause false interrupts when the - * DMA is re-enabled later. - */ - ad_write_cnt(mss, (wr || !FULL_DUPLEX(mss))? 14 : 30, 0); -#endif - } - /* on the OPTi931 the enable bit seems hard to set... */ - for (retry = 10; retry > 0; retry--) { - ad_write(mss, 9, m); - if (ad_read(mss, 9) == m) break; - } - if (retry == 0) BVDDB(printf("stop dma, failed to set bit 0x%02x 0x%02x\n", \ - m, ad_read(mss, 9))); - return 0; -} - static struct isa_pnp_id pnpmss_ids[] = { {0x0000630e, "CS423x"}, /* CSC0000 */ {0x0001630e, "CS423x-PCI"}, /* CSC0100 */ @@ -1582,64 +1819,6 @@ DRIVER_MODULE(snd_pnpmss, isa, pnpmss_driver, pcm_devclass, 0, 0); MODULE_DEPEND(snd_pnpmss, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER); MODULE_VERSION(snd_pnpmss, 1); - -/* - * the opti931 seems to miss interrupts when working in full - * duplex, so we try some heuristics to catch them. - */ -static void -opti931_intr(void *arg) -{ - struct mss_info *mss = (struct mss_info *)arg; - u_char masked = 0, i11, mc11, c = 0; - u_char reason; /* b0 = playback, b1 = capture, b2 = timer */ - int loops = 10; - -#if 0 - reason = io_rd(mss, MSS_STATUS); - if (!(reason & 1)) {/* no int, maybe a shared line ? */ - DEB(printf("intr: flag 0, mcir11 0x%02x\n", ad_read(mss, 11))); - return; - } -#endif - i11 = ad_read(mss, 11); /* XXX what's for ? */ - again: - - c = mc11 = FULL_DUPLEX(mss)? opti_rd(mss, 11) : 0xc; - mc11 &= 0x0c; - if (c & 0x10) { - DEB(printf("Warning: CD interrupt\n");) - mc11 |= 0x10; - } - if (c & 0x20) { - DEB(printf("Warning: MPU interrupt\n");) - mc11 |= 0x20; - } - if (mc11 & masked) BVDDB(printf("irq reset failed, mc11 0x%02x, 0x%02x\n",\ - mc11, masked)); - masked |= mc11; - /* - * the nice OPTi931 sets the IRQ line before setting the bits in - * mc11. So, on some occasions I have to retry (max 10 times). - */ - if (mc11 == 0) { /* perhaps can return ... */ - reason = io_rd(mss, MSS_STATUS); - if (reason & 1) { - DEB(printf("one more try...\n");) - if (--loops) goto again; - else DDB(printf("intr, but mc11 not set\n");) - } - if (loops == 0) BVDDB(printf("intr, nothing in mcir11 0x%02x\n", mc11)); - return; - } - - if (mss->rch.buffer->dl && (mc11 & 8)) chn_intr(mss->rch.channel); - if (mss->pch.buffer->dl && (mc11 & 4)) chn_intr(mss->pch.channel); - opti_wr(mss, 11, ~mc11); /* ack */ - if (--loops) goto again; - DEB(printf("xxx too many loops\n");) -} - static int guspcm_probe(device_t dev) { @@ -1726,205 +1905,3 @@ MODULE_DEPEND(snd_guspcm, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER); MODULE_VERSION(snd_guspcm, 1); -static int -mssmix_init(snd_mixer *m) -{ - struct mss_info *mss = mix_getdevinfo(m); - - mix_setdevs(m, MODE2_MIXER_DEVICES); - mix_setrecdevs(m, MSS_REC_DEVICES); - switch(mss->bd_id) { - case MD_OPTI931: - mix_setdevs(m, OPTI931_MIXER_DEVICES); - ad_write(mss, 20, 0x88); - ad_write(mss, 21, 0x88); - break; - - case MD_AD1848: - mix_setdevs(m, MODE1_MIXER_DEVICES); - break; - - case MD_GUSPNP: - case MD_GUSMAX: - /* this is only necessary in mode 3 ... */ - ad_write(mss, 22, 0x88); - ad_write(mss, 23, 0x88); - break; - } - return 0; -} - -static int -mssmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) -{ - struct mss_info *mss = mix_getdevinfo(m); - - mss_mixer_set(mss, dev, left, right); - - return left | (right << 8); -} - -static int -mssmix_setrecsrc(snd_mixer *m, u_int32_t src) -{ - struct mss_info *mss = mix_getdevinfo(m); - - src = mss_set_recsrc(mss, src); - return src; -} - -static int -ymmix_init(snd_mixer *m) -{ - struct mss_info *mss = mix_getdevinfo(m); - - mssmix_init(m); - mix_setdevs(m, mix_getdevs(m) | SOUND_MASK_VOLUME | SOUND_MASK_MIC - | SOUND_MASK_BASS | SOUND_MASK_TREBLE); - /* Set master volume */ - conf_wr(mss, OPL3SAx_VOLUMEL, 7); - conf_wr(mss, OPL3SAx_VOLUMER, 7); - - return 0; -} - -static int -ymmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right) -{ - struct mss_info *mss = mix_getdevinfo(m); - int t, l, r; - - switch (dev) { - case SOUND_MIXER_VOLUME: - if (left) t = 15 - (left * 15) / 100; - else t = 0x80; /* mute */ - conf_wr(mss, OPL3SAx_VOLUMEL, t); - if (right) t = 15 - (right * 15) / 100; - else t = 0x80; /* mute */ - conf_wr(mss, OPL3SAx_VOLUMER, t); - break; - - case SOUND_MIXER_MIC: - t = left; - if (left) t = 31 - (left * 31) / 100; - else t = 0x80; /* mute */ - conf_wr(mss, OPL3SAx_MIC, t); - break; - - case SOUND_MIXER_BASS: - l = (left * 7) / 100; - r = (right * 7) / 100; - t = (r << 4) | l; - conf_wr(mss, OPL3SAx_BASS, t); - break; - - case SOUND_MIXER_TREBLE: - l = (left * 7) / 100; - r = (right * 7) / 100; - t = (r << 4) | l; - conf_wr(mss, OPL3SAx_TREBLE, t); - break; - - default: - mss_mixer_set(mss, dev, left, right); - } - - return left | (right << 8); -} - -static int -ymmix_setrecsrc(snd_mixer *m, u_int32_t src) -{ - struct mss_info *mss = mix_getdevinfo(m); - src = mss_set_recsrc(mss, src); - return src; -} - -/* channel interface */ -static void * -msschan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) -{ - struct mss_info *mss = devinfo; - struct mss_chinfo *ch = (dir == PCMDIR_PLAY)? &mss->pch : &mss->rch; - - ch->parent = mss; - ch->channel = c; - ch->buffer = b; - ch->buffer->bufsize = MSS_BUFFSIZE; - if (chn_allocbuf(ch->buffer, mss->parent_dmat) == -1) return NULL; - return ch; -} - -static int -msschan_setdir(void *data, int dir) -{ - struct mss_chinfo *ch = data; - - ch->buffer->chan = (dir == PCMDIR_PLAY)? ch->parent->pdma : ch->parent->rdma; - ch->dir = dir; - return 0; -} - -static int -msschan_setformat(void *data, u_int32_t format) -{ - struct mss_chinfo *ch = data; - - mss_format(ch, format); - return 0; -} - -static int -msschan_setspeed(void *data, u_int32_t speed) -{ - struct mss_chinfo *ch = data; - - return mss_speed(ch, speed); -} - -static int -msschan_setblocksize(void *data, u_int32_t blocksize) -{ - return blocksize; -} - -static int -msschan_trigger(void *data, int go) -{ - struct mss_chinfo *ch = data; - - if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD) - return 0; - - buf_isadma(ch->buffer, go); - mss_trigger(ch, go); - return 0; -} - -static int -msschan_getptr(void *data) -{ - struct mss_chinfo *ch = data; - return buf_isadmaptr(ch->buffer); -} - -static pcmchan_caps * -msschan_getcaps(void *data) -{ - struct mss_chinfo *ch = data; - - switch(ch->parent->bd_id) { - case MD_OPTI931: - return &opti931_caps; - break; - - case MD_GUSPNP: - case MD_GUSMAX: - return &guspnp_caps; - break; - - default: - return &mss_caps; - break; - } -} diff --git a/sys/dev/sound/isa/sb.h b/sys/dev/sound/isa/sb.h index 98a0227..8b2a2f6 100644 --- a/sys/dev/sound/isa/sb.h +++ b/sys/dev/sound/isa/sb.h @@ -141,13 +141,6 @@ #define BD_F_MIDIBUSY 0x0400 /* midi busy */ #endif #define BD_F_ESS 0x0800 /* this is an ESS chip */ -/* - * on some SB16 cards, at times I swap DMA channels. Remember this - * so that they can be restored later. - */ -#if 0 -#define BD_F_SWAPPED 0x1000 /* have swapped DMA channels */ -#endif #define BD_F_DMARUN 0x2000 #define BD_F_DMARUN2 0x4000 @@ -190,87 +183,5 @@ #define SB16_IMASK_R 0x3e #define SB16_OMASK 0x3c -/* - * sound/sb_mixer.h - * - * Definitions for the SB Pro and SB16 mixers - * - * Copyright by Hannu Savolainen 1993 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. 2. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Modified: Hunyue Yau Jan 6 1994 Added defines for the Sound Galaxy NX Pro - * mixer. - * - */ -#define SBPRO_RECORDING_DEVICES \ - (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD) - -#define SBPRO_MIXER_DEVICES \ - (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \ - SOUND_MASK_CD | SOUND_MASK_VOLUME) - -#define SB16_RECORDING_DEVICES \ - (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD) - -#define SB16_MIXER_DEVICES \ - (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | \ - SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD | \ - SOUND_MASK_IGAIN | SOUND_MASK_OGAIN | \ - SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE) - -#ifdef __SB_MIXER_C__ -mixer_tab sbpro_mix = { - PMIX_ENT(SOUND_MIXER_VOLUME, 0x22, 4, 4, 0x22, 0, 4), - PMIX_ENT(SOUND_MIXER_SYNTH, 0x26, 4, 4, 0x26, 0, 4), - PMIX_ENT(SOUND_MIXER_PCM, 0x04, 4, 4, 0x04, 0, 4), - PMIX_ENT(SOUND_MIXER_LINE, 0x2e, 4, 4, 0x2e, 0, 4), - PMIX_ENT(SOUND_MIXER_MIC, 0x0a, 0, 3, 0x00, 0, 0), - PMIX_ENT(SOUND_MIXER_CD, 0x28, 4, 4, 0x28, 0, 4), -}; - -mixer_tab ess_mix = { - PMIX_ENT(SOUND_MIXER_VOLUME, 0x32, 4, 4, 0x32, 0, 4), - PMIX_ENT(SOUND_MIXER_SYNTH, 0x36, 4, 4, 0x26, 0, 4), - PMIX_ENT(SOUND_MIXER_PCM, 0x14, 4, 4, 0x04, 0, 4), - PMIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 0, 3, 0x00, 0, 0), - PMIX_ENT(SOUND_MIXER_LINE, 0x3e, 4, 4, 0x2e, 0, 4), - PMIX_ENT(SOUND_MIXER_MIC, 0x1a, 4, 4, 0x1a, 0, 4), - PMIX_ENT(SOUND_MIXER_CD, 0x38, 4, 4, 0x28, 0, 4), -}; - -mixer_tab sb16_mix = { - PMIX_ENT(SOUND_MIXER_VOLUME, 0x30, 3, 5, 0x31, 3, 5), - PMIX_ENT(SOUND_MIXER_BASS, 0x46, 4, 4, 0x47, 4, 4), - PMIX_ENT(SOUND_MIXER_TREBLE, 0x44, 4, 4, 0x45, 4, 4), - PMIX_ENT(SOUND_MIXER_SYNTH, 0x34, 3, 5, 0x35, 3, 5), - PMIX_ENT(SOUND_MIXER_PCM, 0x32, 3, 5, 0x33, 3, 5), - PMIX_ENT(SOUND_MIXER_SPEAKER, 0x3b, 6, 2, 0x00, 0, 0), - PMIX_ENT(SOUND_MIXER_LINE, 0x38, 3, 5, 0x39, 3, 5), - PMIX_ENT(SOUND_MIXER_MIC, 0x3a, 3, 5, 0x00, 0, 0), - PMIX_ENT(SOUND_MIXER_CD, 0x36, 3, 5, 0x37, 3, 5), - PMIX_ENT(SOUND_MIXER_IGAIN, 0x3f, 6, 2, 0x40, 6, 2), - PMIX_ENT(SOUND_MIXER_OGAIN, 0x41, 6, 2, 0x42, 6, 2) -}; - -#endif /* __SB_MIXER_C__ */ diff --git a/sys/dev/sound/isa/sb16.c b/sys/dev/sound/isa/sb16.c index 9869226..e1485fa 100644 --- a/sys/dev/sound/isa/sb16.c +++ b/sys/dev/sound/isa/sb16.c @@ -36,20 +36,11 @@ #include <dev/sound/isa/sb.h> #include <dev/sound/chip.h> +#include "mixer_if.h" + #define SB16_BUFFSIZE 4096 #define PLAIN_SB16(x) ((((x)->bd_flags) & (BD_F_SB16|BD_F_SB16X)) == BD_F_SB16) -/* channel interface */ -static void *sb16chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); -static int sb16chan_setformat(void *data, u_int32_t format); -static int sb16chan_setspeed(void *data, u_int32_t speed); -static int sb16chan_setblocksize(void *data, u_int32_t blocksize); -static int sb16chan_trigger(void *data, int go); -static int sb16chan_getptr(void *data); -static pcmchan_caps *sb16chan_getcaps(void *data); -static int sb16chan_reset(void *data); -static int sb16chan_resetdone(void *data); - static u_int32_t sb16_fmt8[] = { AFMT_U8, AFMT_STEREO | AFMT_U8, @@ -73,25 +64,6 @@ static u_int32_t sb16x_fmt[] = { }; static pcmchan_caps sb16x_caps = {5000, 49000, sb16x_fmt, 0}; -static pcm_channel sb_chantemplate = { - sb16chan_init, - NULL, - sb16chan_setformat, - sb16chan_setspeed, - sb16chan_setblocksize, - sb16chan_trigger, - sb16chan_getptr, - sb16chan_getcaps, - NULL, /* free */ - sb16chan_reset, /* reset */ - sb16chan_resetdone, /* resetdone */ - NULL, /* nop3 */ - NULL, /* nop4 */ - NULL, /* nop5 */ - NULL, /* nop6 */ - NULL, /* nop7 */ -}; - struct sb_info; struct sb_chinfo { @@ -118,7 +90,6 @@ struct sb_info { static int sb_rd(struct sb_info *sb, int reg); static void sb_wr(struct sb_info *sb, int reg, u_int8_t val); -static int sb_dspready(struct sb_info *sb); static int sb_cmd(struct sb_info *sb, u_char val); /* static int sb_cmd1(struct sb_info *sb, u_char cmd, int val); */ static int sb_cmd2(struct sb_info *sb, u_char cmd, int val); @@ -129,19 +100,6 @@ static int sb_reset_dsp(struct sb_info *sb); static void sb_intr(void *arg); -static int sb16mix_init(snd_mixer *m); -static int sb16mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int sb16mix_setrecsrc(snd_mixer *m, u_int32_t src); - -static snd_mixer sb16_mixer = { - "SoundBlaster 16 mixer", - sb16mix_init, - NULL, - NULL, - sb16mix_set, - sb16mix_setrecsrc, -}; - static devclass_t pcm_devclass; /* @@ -178,22 +136,17 @@ sb_wr(struct sb_info *sb, int reg, u_int8_t val) } static int -sb_dspready(struct sb_info *sb) -{ - return ((sb_rd(sb, SBDSP_STATUS) & 0x80) == 0); -} - -static int sb_dspwr(struct sb_info *sb, u_char val) { int i; for (i = 0; i < 1000; i++) { - if (sb_dspready(sb)) { - sb_wr(sb, SBDSP_CMD, val); - return 1; + if ((sb_rd(sb, SBDSP_STATUS) & 0x80)) + DELAY((i > 100)? 1000 : 10); + else { + sb_wr(sb, SBDSP_CMD, val); + return 1; } - if (i > 10) DELAY((i > 100)? 1000 : 10); } printf("sb_dspwr(0x%02x) timed out.\n", val); return 0; @@ -398,6 +351,14 @@ sb16mix_setrecsrc(snd_mixer *m, u_int32_t src) return src; } +static kobj_method_t sb16mix_mixer_methods[] = { + KOBJMETHOD(mixer_init, sb16mix_init), + KOBJMETHOD(mixer_set, sb16mix_set), + KOBJMETHOD(mixer_setrecsrc, sb16mix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(sb16mix_mixer); + /************************************************************/ static void @@ -626,7 +587,7 @@ sb_setup(struct sb_info *sb) /* channel interface */ static void * -sb16chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) +sb16chan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) { struct sb_info *sb = devinfo; struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch; @@ -644,7 +605,7 @@ sb16chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int -sb16chan_setformat(void *data, u_int32_t format) +sb16chan_setformat(kobj_t obj, void *data, u_int32_t format) { struct sb_chinfo *ch = data; struct sb_info *sb = ch->parent; @@ -657,7 +618,7 @@ sb16chan_setformat(void *data, u_int32_t format) } static int -sb16chan_setspeed(void *data, u_int32_t speed) +sb16chan_setspeed(kobj_t obj, void *data, u_int32_t speed) { struct sb_chinfo *ch = data; @@ -666,7 +627,7 @@ sb16chan_setspeed(void *data, u_int32_t speed) } static int -sb16chan_setblocksize(void *data, u_int32_t blocksize) +sb16chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize) { struct sb_chinfo *ch = data; @@ -675,7 +636,7 @@ sb16chan_setblocksize(void *data, u_int32_t blocksize) } static int -sb16chan_trigger(void *data, int go) +sb16chan_trigger(kobj_t obj, void *data, int go) { struct sb_chinfo *ch = data; struct sb_info *sb = ch->parent; @@ -694,7 +655,7 @@ sb16chan_trigger(void *data, int go) } static int -sb16chan_getptr(void *data) +sb16chan_getptr(kobj_t obj, void *data) { struct sb_chinfo *ch = data; @@ -702,7 +663,7 @@ sb16chan_getptr(void *data) } static pcmchan_caps * -sb16chan_getcaps(void *data) +sb16chan_getcaps(kobj_t obj, void *data) { struct sb_chinfo *ch = data; struct sb_info *sb = ch->parent; @@ -714,17 +675,7 @@ sb16chan_getcaps(void *data) } static int -sb16chan_reset(void *data) -{ -/* - struct sb_chinfo *ch = data; - struct sb_info *sb = ch->parent; -*/ - return 0; -} - -static int -sb16chan_resetdone(void *data) +sb16chan_resetdone(kobj_t obj, void *data) { struct sb_chinfo *ch = data; struct sb_info *sb = ch->parent; @@ -734,6 +685,19 @@ sb16chan_resetdone(void *data) return 0; } +static kobj_method_t sb16chan_methods[] = { + KOBJMETHOD(channel_init, sb16chan_init), + KOBJMETHOD(channel_resetdone, sb16chan_resetdone), + KOBJMETHOD(channel_setformat, sb16chan_setformat), + KOBJMETHOD(channel_setspeed, sb16chan_setspeed), + KOBJMETHOD(channel_setblocksize, sb16chan_setblocksize), + KOBJMETHOD(channel_trigger, sb16chan_trigger), + KOBJMETHOD(channel_getptr, sb16chan_getptr), + KOBJMETHOD(channel_getcaps, sb16chan_getcaps), + { 0, 0 } +}; +CHANNEL_DECLARE(sb16chan); + /************************************************************/ static int @@ -780,7 +744,7 @@ sb16_attach(device_t dev) goto no; if (sb_reset_dsp(sb)) goto no; - if (mixer_init(dev, &sb16_mixer, sb)) + if (mixer_init(dev, &sb16mix_mixer_class, sb)) goto no; if (bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &sb->ih)) goto no; @@ -812,8 +776,8 @@ sb16_attach(device_t dev) if (pcm_register(dev, sb, 1, 1)) goto no; - pcm_addchan(dev, PCMDIR_REC, &sb_chantemplate, sb); - pcm_addchan(dev, PCMDIR_PLAY, &sb_chantemplate, sb); + pcm_addchan(dev, PCMDIR_REC, &sb16chan_class, sb); + pcm_addchan(dev, PCMDIR_PLAY, &sb16chan_class, sb); pcm_setstatus(dev, status); diff --git a/sys/dev/sound/isa/sb8.c b/sys/dev/sound/isa/sb8.c index 091c6e2..b2e66b3 100644 --- a/sys/dev/sound/isa/sb8.c +++ b/sys/dev/sound/isa/sb8.c @@ -36,16 +36,9 @@ #include <dev/sound/isa/sb.h> #include <dev/sound/chip.h> -#define SB_BUFFSIZE 4096 +#include "mixer_if.h" -/* channel interface */ -static void *sbchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir); -static int sbchan_setformat(void *data, u_int32_t format); -static int sbchan_setspeed(void *data, u_int32_t speed); -static int sbchan_setblocksize(void *data, u_int32_t blocksize); -static int sbchan_trigger(void *data, int go); -static int sbchan_getptr(void *data); -static pcmchan_caps *sbchan_getcaps(void *data); +#define SB_BUFFSIZE 4096 static u_int32_t sb_fmt[] = { AFMT_U8, @@ -64,25 +57,6 @@ static u_int32_t sbpro_fmt[] = { static pcmchan_caps sbpro_playcaps = {4000, 44100, sbpro_fmt, 0}; static pcmchan_caps sbpro_reccaps = {4000, 44100, sbpro_fmt, 0}; -static pcm_channel sb_chantemplate = { - sbchan_init, - NULL, - sbchan_setformat, - sbchan_setspeed, - sbchan_setblocksize, - sbchan_trigger, - sbchan_getptr, - sbchan_getcaps, - NULL, /* free */ - NULL, /* nop1 */ - NULL, /* nop2 */ - NULL, /* nop3 */ - NULL, /* nop4 */ - NULL, /* nop5 */ - NULL, /* nop6 */ - NULL, /* nop7 */ -}; - struct sb_info; struct sb_chinfo { @@ -121,32 +95,6 @@ static int sb_speed(struct sb_chinfo *ch); static int sb_start(struct sb_chinfo *ch); static int sb_stop(struct sb_chinfo *ch); -static int sbmix_init(snd_mixer *m); -static int sbmix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int sbmix_setrecsrc(snd_mixer *m, u_int32_t src); - -static int sbpromix_init(snd_mixer *m); -static int sbpromix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right); -static int sbpromix_setrecsrc(snd_mixer *m, u_int32_t src); - -static snd_mixer sb_mixer = { - "SoundBlaster 2.0 mixer", - sbmix_init, - NULL, - NULL, - sbmix_set, - sbmix_setrecsrc, -}; - -static snd_mixer sbpro_mixer = { - "SoundBlaster Pro mixer", - sbpromix_init, - NULL, - NULL, - sbpromix_set, - sbpromix_setrecsrc, -}; - static devclass_t pcm_devclass; /* @@ -432,6 +380,14 @@ sbpromix_setrecsrc(snd_mixer *m, u_int32_t src) return src; } +static kobj_method_t sbpromix_mixer_methods[] = { + KOBJMETHOD(mixer_init, sbpromix_init), + KOBJMETHOD(mixer_set, sbpromix_set), + KOBJMETHOD(mixer_setrecsrc, sbpromix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(sbpromix_mixer); + /************************************************************/ static int @@ -492,6 +448,14 @@ sbmix_setrecsrc(snd_mixer *m, u_int32_t src) return 0; } +static kobj_method_t sbmix_mixer_methods[] = { + KOBJMETHOD(mixer_init, sbmix_init), + KOBJMETHOD(mixer_set, sbmix_set), + KOBJMETHOD(mixer_setrecsrc, sbmix_setrecsrc), + { 0, 0 } +}; +MIXER_DECLARE(sbmix_mixer); + /************************************************************/ static void @@ -593,7 +557,7 @@ sb_stop(struct sb_chinfo *ch) /* channel interface */ static void * -sbchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) +sbchan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) { struct sb_info *sb = devinfo; struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch; @@ -610,7 +574,7 @@ sbchan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir) } static int -sbchan_setformat(void *data, u_int32_t format) +sbchan_setformat(kobj_t obj, void *data, u_int32_t format) { struct sb_chinfo *ch = data; @@ -619,7 +583,7 @@ sbchan_setformat(void *data, u_int32_t format) } static int -sbchan_setspeed(void *data, u_int32_t speed) +sbchan_setspeed(kobj_t obj, void *data, u_int32_t speed) { struct sb_chinfo *ch = data; @@ -628,13 +592,13 @@ sbchan_setspeed(void *data, u_int32_t speed) } static int -sbchan_setblocksize(void *data, u_int32_t blocksize) +sbchan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize) { return blocksize; } static int -sbchan_trigger(void *data, int go) +sbchan_trigger(kobj_t obj, void *data, int go) { struct sb_chinfo *ch = data; @@ -650,7 +614,7 @@ sbchan_trigger(void *data, int go) } static int -sbchan_getptr(void *data) +sbchan_getptr(kobj_t obj, void *data) { struct sb_chinfo *ch = data; @@ -658,7 +622,7 @@ sbchan_getptr(void *data) } static pcmchan_caps * -sbchan_getcaps(void *data) +sbchan_getcaps(kobj_t obj, void *data) { struct sb_chinfo *ch = data; int p = (ch->dir == PCMDIR_PLAY)? 1 : 0; @@ -670,6 +634,18 @@ sbchan_getcaps(void *data) return p? &sbpro_playcaps : &sbpro_reccaps; } +static kobj_method_t sbchan_methods[] = { + KOBJMETHOD(channel_init, sbchan_init), + KOBJMETHOD(channel_setformat, sbchan_setformat), + KOBJMETHOD(channel_setspeed, sbchan_setspeed), + KOBJMETHOD(channel_setblocksize, sbchan_setblocksize), + KOBJMETHOD(channel_trigger, sbchan_trigger), + KOBJMETHOD(channel_getptr, sbchan_getptr), + KOBJMETHOD(channel_getcaps, sbchan_getcaps), + { 0, 0 } +}; +CHANNEL_DECLARE(sbchan); + /************************************************************/ static int @@ -717,7 +693,7 @@ sb_attach(device_t dev) goto no; if (sb_reset_dsp(sb)) goto no; - if (mixer_init(dev, (sb->bd_id < 0x300)? &sb_mixer : &sbpro_mixer, sb)) + if (mixer_init(dev, (sb->bd_id < 0x300)? &sbmix_mixer_class : &sbpromix_mixer_class, sb)) goto no; if (bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &sb->ih)) goto no; @@ -740,8 +716,8 @@ sb_attach(device_t dev) if (pcm_register(dev, sb, 1, 1)) goto no; - pcm_addchan(dev, PCMDIR_REC, &sb_chantemplate, sb); - pcm_addchan(dev, PCMDIR_PLAY, &sb_chantemplate, sb); + pcm_addchan(dev, PCMDIR_REC, &sbchan_class, sb); + pcm_addchan(dev, PCMDIR_PLAY, &sbchan_class, sb); pcm_setstatus(dev, status); |