2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * $FreeBSD: src/sys/dev/sound/pci/solo.c,v 1.9.2.8 2002/04/22 15:49:32 cg Exp $
26 * $DragonFly: src/sys/dev/sound/pci/solo.c,v 1.4 2005/05/24 20:59:04 dillon Exp $
29 #include <dev/sound/pcm/sound.h>
31 #include <bus/pci/pcireg.h>
32 #include <bus/pci/pcivar.h>
34 #include <dev/sound/isa/sb.h>
35 #include <dev/sound/chip.h>
39 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/solo.c,v 1.4 2005/05/24 20:59:04 dillon Exp $");
41 #define SOLO_DEFAULT_BUFSZ 16384
42 #define ABS(x) (((x) < 0)? -(x) : (x))
44 /* if defined, playback always uses the 2nd channel and full duplex works */
47 /* more accurate clocks and split audio1/audio2 rates */
48 #define ESS18XX_NEWSPEED
50 static u_int32_t ess_playfmt[] = {
52 AFMT_STEREO | AFMT_U8,
54 AFMT_STEREO | AFMT_S8,
56 AFMT_STEREO | AFMT_S16_LE,
58 AFMT_STEREO | AFMT_U16_LE,
61 static struct pcmchan_caps ess_playcaps = {5000, 49000, ess_playfmt, 0};
64 * Recording output is byte-swapped
66 static u_int32_t ess_recfmt[] = {
68 AFMT_STEREO | AFMT_U8,
70 AFMT_STEREO | AFMT_S8,
72 AFMT_STEREO | AFMT_S16_BE,
74 AFMT_STEREO | AFMT_U16_BE,
77 static struct pcmchan_caps ess_reccaps = {5000, 49000, ess_recfmt, 0};
82 struct ess_info *parent;
83 struct pcm_channel *channel;
84 struct snd_dbuf *buffer;
85 int dir, hwch, stopping;
86 u_int32_t fmt, spd, blksz;
90 struct resource *io, *sb, *vc, *mpu, *gp; /* I/O address for the board */
93 bus_dma_tag_t parent_dmat;
95 int simplex_dir, type, duplex:1, newspeed:1, dmasz[2];
98 struct ess_chinfo pch, rch;
101 static int ess_rd(struct ess_info *sc, int reg);
102 static void ess_wr(struct ess_info *sc, int reg, u_int8_t val);
103 static int ess_dspready(struct ess_info *sc);
104 static int ess_cmd(struct ess_info *sc, u_char val);
105 static int ess_cmd1(struct ess_info *sc, u_char cmd, int val);
106 static int ess_get_byte(struct ess_info *sc);
107 static void ess_setmixer(struct ess_info *sc, u_int port, u_int value);
108 static int ess_getmixer(struct ess_info *sc, u_int port);
109 static int ess_reset_dsp(struct ess_info *sc);
111 static int ess_write(struct ess_info *sc, u_char reg, int val);
112 static int ess_read(struct ess_info *sc, u_char reg);
114 static void ess_intr(void *arg);
115 static int ess_setupch(struct ess_info *sc, int ch, int dir, int spd, u_int32_t fmt, int len);
116 static int ess_start(struct ess_chinfo *ch);
117 static int ess_stop(struct ess_chinfo *ch);
119 static int ess_dmasetup(struct ess_info *sc, int ch, u_int32_t base, u_int16_t cnt, int dir);
120 static int ess_dmapos(struct ess_info *sc, int ch);
121 static int ess_dmatrigger(struct ess_info *sc, int ch, int go);
124 * Common code for the midi and pcm functions
126 * ess_cmd write a single byte to the CMD port.
127 * ess_cmd1 write a CMD + 1 byte arg
128 * ess_cmd2 write a CMD + 2 byte arg
129 * ess_get_byte returns a single byte from the DSP data port
131 * ess_write is actually ess_cmd1
132 * ess_read access ext. regs via ess_cmd(0xc0, reg) followed by ess_get_byte
136 port_rd(struct resource *port, int regno, int size)
138 bus_space_tag_t st = rman_get_bustag(port);
139 bus_space_handle_t sh = rman_get_bushandle(port);
143 return bus_space_read_1(st, sh, regno);
145 return bus_space_read_2(st, sh, regno);
147 return bus_space_read_4(st, sh, regno);
154 port_wr(struct resource *port, int regno, u_int32_t data, int size)
156 bus_space_tag_t st = rman_get_bustag(port);
157 bus_space_handle_t sh = rman_get_bushandle(port);
161 bus_space_write_1(st, sh, regno, data);
164 bus_space_write_2(st, sh, regno, data);
167 bus_space_write_4(st, sh, regno, data);
173 ess_rd(struct ess_info *sc, int reg)
175 return port_rd(sc->sb, reg, 1);
179 ess_wr(struct ess_info *sc, int reg, u_int8_t val)
181 port_wr(sc->sb, reg, val, 1);
185 ess_dspready(struct ess_info *sc)
187 return ((ess_rd(sc, SBDSP_STATUS) & 0x80) == 0);
191 ess_dspwr(struct ess_info *sc, u_char val)
195 for (i = 0; i < 1000; i++) {
196 if (ess_dspready(sc)) {
197 ess_wr(sc, SBDSP_CMD, val);
200 if (i > 10) DELAY((i > 100)? 1000 : 10);
202 printf("ess_dspwr(0x%02x) timed out.\n", val);
207 ess_cmd(struct ess_info *sc, u_char val)
209 DEB(printf("ess_cmd: %x\n", val));
210 return ess_dspwr(sc, val);
214 ess_cmd1(struct ess_info *sc, u_char cmd, int val)
216 DEB(printf("ess_cmd1: %x, %x\n", cmd, val));
217 if (ess_dspwr(sc, cmd)) {
218 return ess_dspwr(sc, val & 0xff);
223 ess_setmixer(struct ess_info *sc, u_int port, u_int value)
227 DEB(printf("ess_setmixer: reg=%x, val=%x\n", port, value);)
229 ess_wr(sc, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
231 ess_wr(sc, SB_MIX_DATA, (u_char) (value & 0xff));
237 ess_getmixer(struct ess_info *sc, u_int port)
243 ess_wr(sc, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
245 val = ess_rd(sc, SB_MIX_DATA);
253 ess_get_byte(struct ess_info *sc)
257 for (i = 1000; i > 0; i--) {
258 if (ess_rd(sc, 0xc) & 0x40)
259 return ess_rd(sc, DSP_READ);
267 ess_write(struct ess_info *sc, u_char reg, int val)
269 return ess_cmd1(sc, reg, val);
273 ess_read(struct ess_info *sc, u_char reg)
275 return (ess_cmd(sc, 0xc0) && ess_cmd(sc, reg))? ess_get_byte(sc) : -1;
279 ess_reset_dsp(struct ess_info *sc)
281 DEB(printf("ess_reset_dsp\n"));
282 ess_wr(sc, SBDSP_RST, 3);
284 ess_wr(sc, SBDSP_RST, 0);
285 if (ess_get_byte(sc) != 0xAA) {
286 DEB(printf("ess_reset_dsp failed\n"));
288 rman_get_start(d->io_base)));
290 return ENXIO; /* Sorry */
299 struct ess_info *sc = (struct ess_info *)arg;
300 int src, pirq = 0, rirq = 0;
303 if (ess_getmixer(sc, 0x7a) & 0x80)
305 if (ess_rd(sc, 0x0c) & 0x01)
312 pirq = (src & sc->pch.hwch)? 1 : 0;
313 rirq = (src & sc->rch.hwch)? 1 : 0;
315 if (sc->simplex_dir == PCMDIR_PLAY)
317 if (sc->simplex_dir == PCMDIR_REC)
320 printf("solo: IRQ neither playback nor rec!\n");
323 DEB(printf("ess_intr: pirq:%d rirq:%d\n",pirq,rirq));
326 if (sc->pch.stopping) {
327 ess_dmatrigger(sc, sc->pch.hwch, 0);
328 sc->pch.stopping = 0;
329 if (sc->pch.hwch == 1)
330 ess_write(sc, 0xb8, ess_read(sc, 0xb8) & ~0x01);
332 ess_setmixer(sc, 0x78, ess_getmixer(sc, 0x78) & ~0x03);
334 chn_intr(sc->pch.channel);
338 if (sc->rch.stopping) {
339 ess_dmatrigger(sc, sc->rch.hwch, 0);
340 sc->rch.stopping = 0;
341 /* XXX: will this stop audio2? */
342 ess_write(sc, 0xb8, ess_read(sc, 0xb8) & ~0x01);
344 chn_intr(sc->rch.channel);
348 ess_setmixer(sc, 0x7a, ess_getmixer(sc, 0x7a) & ~0x80);
350 ess_rd(sc, DSP_DATA_AVAIL);
353 /* utility functions for ESS */
355 ess_calcspeed8(int *spd)
361 t = (795500 + speed / 2) / speed;
362 speed = (795500 + t / 2) / t;
363 t = (256 - t) | 0x80;
365 t = (397700 + speed / 2) / speed;
366 speed = (397700 + t / 2) / t;
370 return t & 0x000000ff;
374 ess_calcspeed9(int *spd)
376 int speed, s0, s1, use0;
379 /* rate = source / (256 - divisor) */
380 /* divisor = 256 - (source / rate) */
382 t0 = 128 - (793800 / speed);
383 s0 = 793800 / (128 - t0);
385 t1 = 128 - (768000 / speed);
386 s1 = 768000 / (128 - t1);
389 use0 = (ABS(speed - s0) < ABS(speed - s1))? 1 : 0;
391 *spd = use0? s0 : s1;
392 return use0? t0 : t1;
396 ess_calcfilter(int spd)
400 /* cutoff = 7160000 / (256 - divisor) */
401 /* divisor = 256 - (7160000 / cutoff) */
402 cutoff = (spd * 9 * 82) / 20;
403 return (256 - (7160000 / cutoff));
407 ess_setupch(struct ess_info *sc, int ch, int dir, int spd, u_int32_t fmt, int len)
409 int play = (dir == PCMDIR_PLAY)? 1 : 0;
410 int b16 = (fmt & AFMT_16BIT)? 1 : 0;
411 int stereo = (fmt & AFMT_STEREO)? 1 : 0;
412 int unsign = (fmt == AFMT_U8 || fmt == AFMT_U16_LE || fmt == AFMT_U16_BE)? 1 : 0;
413 u_int8_t spdval, fmtval;
415 DEB(printf("ess_setupch\n"));
416 spdval = (sc->newspeed)? ess_calcspeed9(&spd) : ess_calcspeed8(&spd);
418 sc->simplex_dir = play ? PCMDIR_PLAY : PCMDIR_REC ;
421 KASSERT((dir == PCMDIR_PLAY) || (dir == PCMDIR_REC), ("ess_setupch: dir1 bad"));
423 /* transfer length low */
424 ess_write(sc, 0xa4, len & 0x00ff);
425 /* transfer length high */
426 ess_write(sc, 0xa5, (len & 0xff00) >> 8);
427 /* autoinit, dma dir */
428 ess_write(sc, 0xb8, 0x04 | (play? 0x00 : 0x0a));
430 ess_write(sc, 0xa8, (ess_read(sc, 0xa8) & ~0x03) | (stereo? 0x01 : 0x02));
431 /* demand mode, 4 bytes/xfer */
432 ess_write(sc, 0xb9, 0x02);
434 ess_write(sc, 0xa1, spdval);
436 ess_write(sc, 0xa2, ess_calcfilter(spd));
440 ess_write(sc, 0xb6, unsign? 0x80 : 0x00);
442 /* mono, b16: signed, load signal */
444 ess_write(sc, 0xb7, 0x51 | (unsign? 0x00 : 0x20));
447 ess_write(sc, 0xb7, 0x91 | (unsign? 0x00 : 0x20) |
449 (stereo? 0x08 : 0x40));
451 ess_write(sc, 0xb1, (ess_read(sc, 0xb1) & 0x0f) | 0x50);
453 ess_write(sc, 0xb2, (ess_read(sc, 0xb2) & 0x0f) | 0x50);
454 } else if (ch == 2) {
455 KASSERT(dir == PCMDIR_PLAY, ("ess_setupch: dir2 bad"));
458 /* transfer length low */
459 ess_setmixer(sc, 0x74, len & 0x00ff);
460 /* transfer length high */
461 ess_setmixer(sc, 0x76, (len & 0xff00) >> 8);
462 /* autoinit, 4 bytes/req */
463 ess_setmixer(sc, 0x78, 0x10);
464 fmtval = b16 | (stereo << 1) | ((!unsign) << 2);
465 /* enable irq, set format */
466 ess_setmixer(sc, 0x7a, 0x40 | fmtval);
469 ess_setmixer(sc, 0x70, spdval);
471 ess_setmixer(sc, 0x72, ess_calcfilter(spd));
478 ess_start(struct ess_chinfo *ch)
480 struct ess_info *sc = ch->parent;
482 DEB(printf("ess_start\n"););
483 ess_setupch(sc, ch->hwch, ch->dir, ch->spd, ch->fmt, ch->blksz);
486 ess_write(sc, 0xb8, ess_read(sc, 0xb8) | 0x01);
487 if (ch->dir == PCMDIR_PLAY) {
489 DELAY(100000); /* 100 ms */
494 ess_setmixer(sc, 0x78, ess_getmixer(sc, 0x78) | 0x03);
499 ess_stop(struct ess_chinfo *ch)
501 struct ess_info *sc = ch->parent;
503 DEB(printf("ess_stop\n"));
506 ess_write(sc, 0xb8, ess_read(sc, 0xb8) & ~0x04);
508 ess_setmixer(sc, 0x78, ess_getmixer(sc, 0x78) & ~0x10);
509 DEB(printf("done with stop\n"));
513 /* -------------------------------------------------------------------- */
514 /* channel interface for ESS18xx */
516 esschan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
518 struct ess_info *sc = devinfo;
519 struct ess_chinfo *ch = (dir == PCMDIR_PLAY)? &sc->pch : &sc->rch;
521 DEB(printf("esschan_init\n"));
526 if (sndbuf_alloc(ch->buffer, sc->parent_dmat, sc->bufsz) == -1)
529 if ((dir == PCMDIR_PLAY) && (sc->duplex))
535 esschan_setformat(kobj_t obj, void *data, u_int32_t format)
537 struct ess_chinfo *ch = data;
544 esschan_setspeed(kobj_t obj, void *data, u_int32_t speed)
546 struct ess_chinfo *ch = data;
547 struct ess_info *sc = ch->parent;
551 ess_calcspeed9(&ch->spd);
553 ess_calcspeed8(&ch->spd);
558 esschan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
560 struct ess_chinfo *ch = data;
562 ch->blksz = blocksize;
567 esschan_trigger(kobj_t obj, void *data, int go)
569 struct ess_chinfo *ch = data;
570 struct ess_info *sc = ch->parent;
572 DEB(printf("esschan_trigger: %d\n",go));
573 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
578 ess_dmasetup(sc, ch->hwch, vtophys(sndbuf_getbuf(ch->buffer)), sndbuf_getsize(ch->buffer), ch->dir);
579 ess_dmatrigger(sc, ch->hwch, 1);
593 esschan_getptr(kobj_t obj, void *data)
595 struct ess_chinfo *ch = data;
596 struct ess_info *sc = ch->parent;
598 return ess_dmapos(sc, ch->hwch);
601 static struct pcmchan_caps *
602 esschan_getcaps(kobj_t obj, void *data)
604 struct ess_chinfo *ch = data;
606 return (ch->dir == PCMDIR_PLAY)? &ess_playcaps : &ess_reccaps;
609 static kobj_method_t esschan_methods[] = {
610 KOBJMETHOD(channel_init, esschan_init),
611 KOBJMETHOD(channel_setformat, esschan_setformat),
612 KOBJMETHOD(channel_setspeed, esschan_setspeed),
613 KOBJMETHOD(channel_setblocksize, esschan_setblocksize),
614 KOBJMETHOD(channel_trigger, esschan_trigger),
615 KOBJMETHOD(channel_getptr, esschan_getptr),
616 KOBJMETHOD(channel_getcaps, esschan_getcaps),
619 CHANNEL_DECLARE(esschan);
621 /************************************************************/
624 essmix_init(struct snd_mixer *m)
626 struct ess_info *sc = mix_getdevinfo(m);
628 mix_setrecdevs(m, SOUND_MASK_CD | SOUND_MASK_MIC | SOUND_MASK_LINE |
631 mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE |
632 SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME |
635 ess_setmixer(sc, 0, 0); /* reset */
641 essmix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
643 struct ess_info *sc = mix_getdevinfo(m);
644 int preg = 0, rreg = 0, l, r;
646 l = (left * 15) / 100;
647 r = (right * 15) / 100;
649 case SOUND_MIXER_SYNTH:
654 case SOUND_MIXER_PCM:
659 case SOUND_MIXER_LINE:
664 case SOUND_MIXER_MIC:
669 case SOUND_MIXER_LINE1:
679 case SOUND_MIXER_VOLUME:
680 l = left? (left * 63) / 100 : 64;
681 r = right? (right * 63) / 100 : 64;
682 ess_setmixer(sc, 0x60, l);
683 ess_setmixer(sc, 0x62, r);
684 left = (l == 64)? 0 : (l * 100) / 63;
685 right = (r == 64)? 0 : (r * 100) / 63;
686 return left | (right << 8);
690 ess_setmixer(sc, preg, (l << 4) | r);
692 ess_setmixer(sc, rreg, (l << 4) | r);
694 left = (l * 100) / 15;
695 right = (r * 100) / 15;
697 return left | (right << 8);
701 essmix_setrecsrc(struct snd_mixer *m, u_int32_t src)
703 struct ess_info *sc = mix_getdevinfo(m);
711 case SOUND_MASK_LINE:
715 case SOUND_MASK_IMIX:
722 src = SOUND_MASK_MIC;
726 ess_setmixer(sc, 0x1c, recdev);
731 static kobj_method_t solomixer_methods[] = {
732 KOBJMETHOD(mixer_init, essmix_init),
733 KOBJMETHOD(mixer_set, essmix_set),
734 KOBJMETHOD(mixer_setrecsrc, essmix_setrecsrc),
737 MIXER_DECLARE(solomixer);
739 /************************************************************/
742 ess_dmasetup(struct ess_info *sc, int ch, u_int32_t base, u_int16_t cnt, int dir)
744 KASSERT(ch == 1 || ch == 2, ("bad ch"));
745 sc->dmasz[ch - 1] = cnt;
747 port_wr(sc->vc, 0x8, 0xc4, 1); /* command */
748 port_wr(sc->vc, 0xd, 0xff, 1); /* reset */
749 port_wr(sc->vc, 0xf, 0x01, 1); /* mask */
750 port_wr(sc->vc, 0xb, dir == PCMDIR_PLAY? 0x58 : 0x54, 1); /* mode */
751 port_wr(sc->vc, 0x0, base, 4);
752 port_wr(sc->vc, 0x4, cnt - 1, 2);
754 } else if (ch == 2) {
755 port_wr(sc->io, 0x6, 0x08, 1); /* autoinit */
756 port_wr(sc->io, 0x0, base, 4);
757 port_wr(sc->io, 0x4, cnt, 2);
763 ess_dmapos(struct ess_info *sc, int ch)
765 int p = 0, i = 0, j = 0;
768 KASSERT(ch == 1 || ch == 2, ("bad ch"));
773 * During recording, this register is known to give back
774 * garbage if it's not quiescent while being read. That's
775 * why we spl, stop the DMA, and try over and over until
776 * adjacent reads are "close", in the right order and not
777 * bigger than is otherwise possible.
779 ess_dmatrigger(sc, ch, 0);
784 printf("DMA count reg bogus: %04x & %04x\n",
786 i = port_rd(sc->vc, 0x4, 2) + 1;
787 p = port_rd(sc->vc, 0x4, 2) + 1;
788 } while ((p > sc->dmasz[ch - 1] || i < p || (p - i) > 0x8) && j++ < 1000);
789 ess_dmatrigger(sc, ch, 1);
792 p = port_rd(sc->io, 0x4, 2);
794 return sc->dmasz[ch - 1] - p;
798 ess_dmatrigger(struct ess_info *sc, int ch, int go)
800 KASSERT(ch == 1 || ch == 2, ("bad ch"));
802 port_wr(sc->vc, 0xf, go? 0x00 : 0x01, 1); /* mask */
804 port_wr(sc->io, 0x6, 0x08 | (go? 0x02 : 0x00), 1); /* autoinit */
809 ess_release_resources(struct ess_info *sc, device_t dev)
813 bus_teardown_intr(dev, sc->irq, sc->ih);
814 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
818 bus_release_resource(dev, SYS_RES_IOPORT, 0 * 4 + PCIR_MAPS, sc->io);
823 bus_release_resource(dev, SYS_RES_IOPORT, 1 * 4 + PCIR_MAPS, sc->sb);
828 bus_release_resource(dev, SYS_RES_IOPORT, 2 * 4 + PCIR_MAPS, sc->vc);
833 bus_release_resource(dev, SYS_RES_IOPORT, 3 * 4 + PCIR_MAPS, sc->mpu);
838 bus_release_resource(dev, SYS_RES_IOPORT, 4 * 4 + PCIR_MAPS, sc->gp);
842 if (sc->parent_dmat) {
843 bus_dma_tag_destroy(sc->parent_dmat);
851 ess_alloc_resources(struct ess_info *sc, device_t dev)
855 rid = 0 * 4 + PCIR_MAPS;
856 sc->io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
858 rid = 1 * 4 + PCIR_MAPS;
859 sc->sb = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
861 rid = 2 * 4 + PCIR_MAPS;
862 sc->vc = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
864 rid = 3 * 4 + PCIR_MAPS;
865 sc->mpu = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
867 rid = 4 * 4 + PCIR_MAPS;
868 sc->gp = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
871 sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
873 return (sc->irq && sc->io && sc->sb && sc->vc && sc->mpu && sc->gp)? 0 : ENXIO;
877 ess_probe(device_t dev)
882 subdev = (pci_get_subdevice(dev) << 16) | pci_get_subvendor(dev);
883 switch (pci_get_devid(dev)) {
885 if (subdev == 0x8888125d)
887 else if (subdev == 0x1818125d)
890 s = "ESS Solo-1 (unknown vendor)";
895 device_set_desc(dev, s);
899 #define PCI_LEGACYCONTROL 0x40
900 #define PCI_CONFIG 0x50
901 #define PCI_DDMACONTROL 0x60
904 ess_attach(device_t dev)
907 char status[SND_STATUSLEN];
911 sc = (struct ess_info *)malloc(sizeof *sc, M_DEVBUF, M_NOWAIT | M_ZERO);
915 data = pci_read_config(dev, PCIR_COMMAND, 2);
916 data |= PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN;
917 pci_write_config(dev, PCIR_COMMAND, data, 2);
918 data = pci_read_config(dev, PCIR_COMMAND, 2);
920 if (ess_alloc_resources(sc, dev))
923 sc->bufsz = pcm_getbuffersize(dev, 4096, SOLO_DEFAULT_BUFSZ, 65536);
925 ddma = rman_get_start(sc->vc) | 1;
926 pci_write_config(dev, PCI_LEGACYCONTROL, 0x805f, 2);
927 pci_write_config(dev, PCI_DDMACONTROL, ddma, 2);
928 pci_write_config(dev, PCI_CONFIG, 0, 2);
930 if (ess_reset_dsp(sc))
932 if (mixer_init(dev, &solomixer_class, sc))
935 port_wr(sc->io, 0x7, 0xb0, 1); /* enable irqs */
936 #ifdef ESS18XX_DUPLEX
942 #ifdef ESS18XX_NEWSPEED
948 ess_setmixer(sc, 0x71, 0x2a);
950 snd_setup_intr(dev, sc->irq, 0, ess_intr, sc, &sc->ih, NULL);
952 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
954 if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/65536, /*boundary*/0,
955 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
956 /*highaddr*/BUS_SPACE_MAXADDR,
957 /*filter*/NULL, /*filterarg*/NULL,
958 /*maxsize*/sc->bufsz, /*nsegments*/1,
960 /*flags*/0, &sc->parent_dmat) != 0) {
961 device_printf(dev, "unable to create dma tag\n");
965 snprintf(status, SND_STATUSLEN, "at io 0x%lx,0x%lx,0x%lx irq %ld",
966 rman_get_start(sc->io), rman_get_start(sc->sb), rman_get_start(sc->vc),
967 rman_get_start(sc->irq));
969 if (pcm_register(dev, sc, 1, 1))
971 pcm_addchan(dev, PCMDIR_REC, &esschan_class, sc);
972 pcm_addchan(dev, PCMDIR_PLAY, &esschan_class, sc);
973 pcm_setstatus(dev, status);
978 ess_release_resources(sc, dev);
983 ess_detach(device_t dev)
988 r = pcm_unregister(dev);
992 sc = pcm_getdevinfo(dev);
993 ess_release_resources(sc, dev);
997 static device_method_t ess_methods[] = {
998 /* Device interface */
999 DEVMETHOD(device_probe, ess_probe),
1000 DEVMETHOD(device_attach, ess_attach),
1001 DEVMETHOD(device_detach, ess_detach),
1002 DEVMETHOD(device_resume, bus_generic_resume),
1003 DEVMETHOD(device_suspend, bus_generic_suspend),
1008 static driver_t ess_driver = {
1014 DRIVER_MODULE(snd_solo, pci, ess_driver, pcm_devclass, 0, 0);
1015 MODULE_DEPEND(snd_solo, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
1016 MODULE_VERSION(snd_solo, 1);