2 * Copyright (c) 2001 Orion Hodson <oho@acm.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
26 * $FreeBSD: src/sys/dev/sound/pci/als4000.c,v 1.2.2.5 2002/04/22 15:49:31 cg Exp $
27 * $DragonFly: src/sys/dev/sound/pci/als4000.c,v 1.8 2006/12/20 18:14:40 dillon Exp $
31 * als4000.c - driver for the Avance Logic ALS 4000 chipset.
33 * The ALS4000 is a effectively an SB16 with a PCI interface.
35 * This driver derives from ALS4000a.PDF, Bart Hartgers alsa driver, and
36 * SB16 register descriptions.
39 #include <dev/sound/pcm/sound.h>
40 #include <dev/sound/isa/sb.h>
41 #include <dev/sound/pci/als4000.h>
43 #include <bus/pci/pcireg.h>
44 #include <bus/pci/pcivar.h>
48 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/als4000.c,v 1.8 2006/12/20 18:14:40 dillon Exp $");
50 /* Debugging macro's */
53 #define DEB(x) /* x */
56 #define ALS_DEFAULT_BUFSZ 16384
58 /* ------------------------------------------------------------------------- */
64 struct sc_info *parent;
65 struct pcm_channel *channel;
66 struct snd_dbuf *buffer;
67 u_int32_t format, speed, phys_buf, bps;
68 u_int32_t dma_active:1, dma_was_active:1;
69 u_int8_t gcr_fifo_status;
76 bus_space_handle_t sh;
77 bus_dma_tag_t parent_dmat;
78 struct resource *reg, *irq;
83 struct sc_chinfo pch, rch;
88 static u_int32_t als_format[] = {
90 AFMT_STEREO | AFMT_U8,
92 AFMT_STEREO | AFMT_S16_LE,
96 static struct pcmchan_caps als_caps = { 4000, 48000, als_format, 0 };
98 /* ------------------------------------------------------------------------- */
99 /* Register Utilities */
102 als_gcr_rd(struct sc_info *sc, int index)
104 bus_space_write_1(sc->st, sc->sh, ALS_GCR_INDEX, index);
105 return bus_space_read_4(sc->st, sc->sh, ALS_GCR_DATA);
109 als_gcr_wr(struct sc_info *sc, int index, int data)
111 bus_space_write_1(sc->st, sc->sh, ALS_GCR_INDEX, index);
112 bus_space_write_4(sc->st, sc->sh, ALS_GCR_DATA, data);
116 als_intr_rd(struct sc_info *sc)
118 return bus_space_read_1(sc->st, sc->sh, ALS_SB_MPU_IRQ);
122 als_intr_wr(struct sc_info *sc, u_int8_t data)
124 bus_space_write_1(sc->st, sc->sh, ALS_SB_MPU_IRQ, data);
128 als_mix_rd(struct sc_info *sc, u_int8_t index)
130 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_INDEX, index);
131 return bus_space_read_1(sc->st, sc->sh, ALS_MIXER_DATA);
135 als_mix_wr(struct sc_info *sc, u_int8_t index, u_int8_t data)
137 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_INDEX, index);
138 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_DATA, data);
142 als_esp_wr(struct sc_info *sc, u_int8_t data)
148 v = bus_space_read_1(sc->st, sc->sh, ALS_ESP_WR_STATUS);
152 } while (--tries != 0);
155 device_printf(sc->dev, "als_esp_wr timeout");
157 bus_space_write_1(sc->st, sc->sh, ALS_ESP_WR_DATA, data);
161 als_esp_reset(struct sc_info *sc)
163 u_int32_t tries, u, v;
165 bus_space_write_1(sc->st, sc->sh, ALS_ESP_RST, 1);
167 bus_space_write_1(sc->st, sc->sh, ALS_ESP_RST, 0);
172 u = bus_space_read_1(sc->st, sc->sh, ALS_ESP_RD_STATUS8);
174 v = bus_space_read_1(sc->st, sc->sh, ALS_ESP_RD_DATA);
181 } while (--tries != 0);
184 device_printf(sc->dev, "als_esp_reset timeout");
189 als_ack_read(struct sc_info *sc, u_int8_t addr)
191 u_int8_t r = bus_space_read_1(sc->st, sc->sh, addr);
195 /* ------------------------------------------------------------------------- */
196 /* Common pcm channel implementation */
199 alschan_init(kobj_t obj, void *devinfo,
200 struct snd_dbuf *b, struct pcm_channel *c, int dir)
202 struct sc_info *sc = devinfo;
203 struct sc_chinfo *ch;
205 if (dir == PCMDIR_PLAY) {
207 ch->gcr_fifo_status = ALS_GCR_FIFO0_STATUS;
210 ch->gcr_fifo_status = ALS_GCR_FIFO1_STATUS;
216 ch->format = AFMT_U8;
217 ch->speed = DSP_DEFAULT_SPEED;
219 if (sndbuf_alloc(ch->buffer, sc->parent_dmat, sc->bufsz) != 0) {
226 alschan_setformat(kobj_t obj, void *data, u_int32_t format)
228 struct sc_chinfo *ch = data;
235 alschan_setspeed(kobj_t obj, void *data, u_int32_t speed)
237 struct sc_chinfo *ch = data, *other;
238 struct sc_info *sc = ch->parent;
240 other = (ch->dir == PCMDIR_PLAY) ? &sc->rch : &sc->pch;
242 /* Deny request if other dma channel is active */
243 if (other->dma_active) {
244 ch->speed = other->speed;
253 alschan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
255 struct sc_chinfo *ch = data;
256 struct sc_info *sc = ch->parent;
258 if (blocksize > sc->bufsz / 2) {
259 blocksize = sc->bufsz / 2;
261 sndbuf_resize(ch->buffer, 2, blocksize);
266 alschan_getptr(kobj_t obj, void *data)
268 struct sc_chinfo *ch = data;
271 pos = als_gcr_rd(ch->parent, ch->gcr_fifo_status) & 0xffff;
272 sz = sndbuf_getsize(ch->buffer);
273 return (2 * sz - pos - 1) % sz;
276 static struct pcmchan_caps*
277 alschan_getcaps(kobj_t obj, void *data)
283 als_set_speed(struct sc_chinfo *ch)
285 struct sc_info *sc = ch->parent;
286 struct sc_chinfo *other;
288 other = (ch->dir == PCMDIR_PLAY) ? &sc->rch : &sc->pch;
289 if (other->dma_active == 0) {
290 als_esp_wr(sc, ALS_ESP_SAMPLE_RATE);
291 als_esp_wr(sc, ch->speed >> 8);
292 als_esp_wr(sc, ch->speed & 0xff);
294 DEB(printf("speed locked at %d (tried %d)\n",
295 other->speed, ch->speed));
299 /* ------------------------------------------------------------------------- */
300 /* Playback channel implementation */
302 #define ALS_8BIT_CMD(x, y) { (x), (y), DSP_DMA8, DSP_CMD_DMAPAUSE_8 }
303 #define ALS_16BIT_CMD(x, y) { (x), (y), DSP_DMA16, DSP_CMD_DMAPAUSE_16 }
305 struct playback_command {
306 u_int32_t pcm_format; /* newpcm format */
307 u_int8_t format_val; /* sb16 format value */
308 u_int8_t dma_prog; /* sb16 dma program */
309 u_int8_t dma_stop; /* sb16 stop register */
310 } static const playback_cmds[] = {
311 ALS_8BIT_CMD(AFMT_U8, DSP_MODE_U8MONO),
312 ALS_8BIT_CMD(AFMT_U8 | AFMT_STEREO, DSP_MODE_U8STEREO),
313 ALS_16BIT_CMD(AFMT_S16_LE, DSP_MODE_S16MONO),
314 ALS_16BIT_CMD(AFMT_S16_LE | AFMT_STEREO, DSP_MODE_S16STEREO),
317 static const struct playback_command*
318 als_get_playback_command(u_int32_t format)
322 n = sizeof(playback_cmds) / sizeof(playback_cmds[0]);
323 for (i = 0; i < n; i++) {
324 if (playback_cmds[i].pcm_format == format) {
325 return &playback_cmds[i];
328 DEB(printf("als_get_playback_command: invalid format 0x%08x\n",
330 return &playback_cmds[0];
334 als_playback_start(struct sc_chinfo *ch)
336 const struct playback_command *p;
337 struct sc_info *sc = ch->parent;
338 u_int32_t buf, bufsz, count, dma_prog;
340 buf = vtophys(sndbuf_getbuf(ch->buffer));
341 bufsz = sndbuf_getsize(ch->buffer);
343 if (ch->format & AFMT_16BIT)
347 als_esp_wr(sc, DSP_CMD_SPKON);
350 als_gcr_wr(sc, ALS_GCR_DMA0_START, buf);
351 als_gcr_wr(sc, ALS_GCR_DMA0_MODE, (bufsz - 1) | 0x180000);
353 p = als_get_playback_command(ch->format);
354 dma_prog = p->dma_prog | DSP_F16_DAC | DSP_F16_AUTO | DSP_F16_FIFO_ON;
356 als_esp_wr(sc, dma_prog);
357 als_esp_wr(sc, p->format_val);
358 als_esp_wr(sc, count & 0xff);
359 als_esp_wr(sc, count >> 8);
365 als_playback_stop(struct sc_chinfo *ch)
367 const struct playback_command *p;
368 struct sc_info *sc = ch->parent;
371 active = ch->dma_active;
373 p = als_get_playback_command(ch->format);
374 als_esp_wr(sc, p->dma_stop);
381 alspchan_trigger(kobj_t obj, void *data, int go)
383 struct sc_chinfo *ch = data;
387 als_playback_start(ch);
390 als_playback_stop(ch);
396 static kobj_method_t alspchan_methods[] = {
397 KOBJMETHOD(channel_init, alschan_init),
398 KOBJMETHOD(channel_setformat, alschan_setformat),
399 KOBJMETHOD(channel_setspeed, alschan_setspeed),
400 KOBJMETHOD(channel_setblocksize, alschan_setblocksize),
401 KOBJMETHOD(channel_trigger, alspchan_trigger),
402 KOBJMETHOD(channel_getptr, alschan_getptr),
403 KOBJMETHOD(channel_getcaps, alschan_getcaps),
406 CHANNEL_DECLARE(alspchan);
408 /* ------------------------------------------------------------------------- */
409 /* Capture channel implementation */
412 als_get_fifo_format(struct sc_info *sc, u_int32_t format)
416 return ALS_FIFO1_8BIT;
417 case AFMT_U8 | AFMT_STEREO:
418 return ALS_FIFO1_8BIT | ALS_FIFO1_STEREO;
420 return ALS_FIFO1_SIGNED;
421 case AFMT_S16_LE | AFMT_STEREO:
422 return ALS_FIFO1_SIGNED | ALS_FIFO1_STEREO;
424 device_printf(sc->dev, "format not found: 0x%08x\n", format);
425 return ALS_FIFO1_8BIT;
429 als_capture_start(struct sc_chinfo *ch)
431 struct sc_info *sc = ch->parent;
432 u_int32_t buf, bufsz, count, dma_prog;
434 buf = vtophys(sndbuf_getbuf(ch->buffer));
435 bufsz = sndbuf_getsize(ch->buffer);
437 if (ch->format & AFMT_16BIT)
441 als_esp_wr(sc, DSP_CMD_SPKON);
444 als_gcr_wr(sc, ALS_GCR_FIFO1_START, buf);
445 als_gcr_wr(sc, ALS_GCR_FIFO1_COUNT, (bufsz - 1));
447 als_mix_wr(sc, ALS_FIFO1_LENGTH_LO, count & 0xff);
448 als_mix_wr(sc, ALS_FIFO1_LENGTH_HI, count >> 8);
450 dma_prog = ALS_FIFO1_RUN | als_get_fifo_format(sc, ch->format);
451 als_mix_wr(sc, ALS_FIFO1_CONTROL, dma_prog);
457 als_capture_stop(struct sc_chinfo *ch)
459 struct sc_info *sc = ch->parent;
462 active = ch->dma_active;
464 als_mix_wr(sc, ALS_FIFO1_CONTROL, ALS_FIFO1_STOP);
471 alsrchan_trigger(kobj_t obj, void *data, int go)
473 struct sc_chinfo *ch = data;
477 als_capture_start(ch);
480 als_capture_stop(ch);
486 static kobj_method_t alsrchan_methods[] = {
487 KOBJMETHOD(channel_init, alschan_init),
488 KOBJMETHOD(channel_setformat, alschan_setformat),
489 KOBJMETHOD(channel_setspeed, alschan_setspeed),
490 KOBJMETHOD(channel_setblocksize, alschan_setblocksize),
491 KOBJMETHOD(channel_trigger, alsrchan_trigger),
492 KOBJMETHOD(channel_getptr, alschan_getptr),
493 KOBJMETHOD(channel_getcaps, alschan_getcaps),
496 CHANNEL_DECLARE(alsrchan);
498 /* ------------------------------------------------------------------------- */
502 * ALS4000 has an sb16 mixer, with some additional controls that we do
503 * not yet a means to support.
511 u_int8_t iselect; /* left input mask */
512 } static const amt[SOUND_MIXER_NRDEVICES] = {
513 [SOUND_MIXER_VOLUME] = { 0x30, 0x31, 5, 0x00, 0x00 },
514 [SOUND_MIXER_PCM] = { 0x32, 0x33, 5, 0x00, 0x00 },
515 [SOUND_MIXER_SYNTH] = { 0x34, 0x35, 5, 0x60, 0x40 },
516 [SOUND_MIXER_CD] = { 0x36, 0x37, 5, 0x06, 0x04 },
517 [SOUND_MIXER_LINE] = { 0x38, 0x39, 5, 0x18, 0x10 },
518 [SOUND_MIXER_MIC] = { 0x3a, 0x00, 5, 0x01, 0x01 },
519 [SOUND_MIXER_SPEAKER] = { 0x3b, 0x00, 2, 0x00, 0x00 },
520 [SOUND_MIXER_IGAIN] = { 0x3f, 0x40, 2, 0x00, 0x00 },
521 [SOUND_MIXER_OGAIN] = { 0x41, 0x42, 2, 0x00, 0x00 },
522 /* The following have register values but no h/w implementation */
523 [SOUND_MIXER_TREBLE] = { 0x44, 0x45, 4, 0x00, 0x00 },
524 [SOUND_MIXER_BASS] = { 0x46, 0x47, 4, 0x00, 0x00 }
528 alsmix_init(struct snd_mixer *m)
532 for (i = v = 0; i < SOUND_MIXER_NRDEVICES; i++) {
533 if (amt[i].bits) v |= 1 << i;
537 for (i = v = 0; i < SOUND_MIXER_NRDEVICES; i++) {
538 if (amt[i].iselect) v |= 1 << i;
540 mix_setrecdevs(m, v);
545 alsmix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
547 struct sc_info *sc = mix_getdevinfo(m);
548 u_int32_t r, l, v, mask;
550 /* Fill upper n bits in mask with 1's */
551 mask = ((1 << amt[dev].bits) - 1) << (8 - amt[dev].bits);
553 l = (left * mask / 100) & mask;
554 v = als_mix_rd(sc, amt[dev].lreg) & ~mask;
555 als_mix_wr(sc, amt[dev].lreg, l | v);
558 r = (right * mask / 100) & mask;
559 v = als_mix_rd(sc, amt[dev].rreg) & ~mask;
560 als_mix_wr(sc, amt[dev].rreg, r | v);
565 /* Zero gain does not mute channel from output, but this does. */
566 v = als_mix_rd(sc, SB16_OMASK);
567 if (l == 0 && r == 0) {
568 v &= ~amt[dev].oselect;
570 v |= amt[dev].oselect;
572 als_mix_wr(sc, SB16_OMASK, v);
577 alsmix_setrecsrc(struct snd_mixer *m, u_int32_t src)
579 struct sc_info *sc = mix_getdevinfo(m);
582 for (i = l = r = 0; i < SOUND_MIXER_NRDEVICES; i++) {
583 if (src & (1 << i)) {
585 r |= amt[i].iselect << 1;
589 als_mix_wr(sc, SB16_IMASK_L, l);
590 als_mix_wr(sc, SB16_IMASK_R, r);
594 static kobj_method_t als_mixer_methods[] = {
595 KOBJMETHOD(mixer_init, alsmix_init),
596 KOBJMETHOD(mixer_set, alsmix_set),
597 KOBJMETHOD(mixer_setrecsrc, alsmix_setrecsrc),
600 MIXER_DECLARE(als_mixer);
602 /* ------------------------------------------------------------------------- */
603 /* Interrupt Handler */
608 struct sc_info *sc = (struct sc_info *)p;
609 u_int8_t intr, sb_status;
611 intr = als_intr_rd(sc);
614 chn_intr(sc->pch.channel);
617 chn_intr(sc->rch.channel);
619 /* ACK interrupt in PCI core */
620 als_intr_wr(sc, intr);
622 /* ACK interrupt in SB core */
623 sb_status = als_mix_rd(sc, IRQ_STAT);
625 if (sb_status & ALS_IRQ_STATUS8)
626 als_ack_read(sc, ALS_ESP_RD_STATUS8);
627 if (sb_status & ALS_IRQ_STATUS16)
628 als_ack_read(sc, ALS_ESP_RD_STATUS16);
629 if (sb_status & ALS_IRQ_MPUIN)
630 als_ack_read(sc, ALS_MIDI_DATA);
631 if (sb_status & ALS_IRQ_CR1E)
632 als_ack_read(sc, ALS_CR1E_ACK_PORT);
636 /* ------------------------------------------------------------------------- */
637 /* H/W initialization */
640 als_init(struct sc_info *sc)
645 if (als_esp_reset(sc)) {
649 /* Enable write on DMA_SETUP register */
650 v = als_mix_rd(sc, ALS_SB16_CONFIG);
651 als_mix_wr(sc, ALS_SB16_CONFIG, v | 0x80);
654 als_mix_wr(sc, ALS_SB16_DMA_SETUP, 0x01);
656 /* Disable write on DMA_SETUP register */
657 als_mix_wr(sc, ALS_SB16_CONFIG, v & 0x7f);
659 /* Enable interrupts */
660 v = als_gcr_rd(sc, ALS_GCR_MISC);
661 als_gcr_wr(sc, ALS_GCR_MISC, v | 0x28000);
663 /* Black out GCR DMA registers */
664 for (i = 0x91; i <= 0x96; i++) {
665 als_gcr_wr(sc, i, 0);
669 v = als_gcr_rd(sc, ALS_GCR_DMA_EMULATION);
670 als_gcr_wr(sc, ALS_GCR_DMA_EMULATION, v);
671 DEB(printf("GCR_DMA_EMULATION 0x%08x\n", v));
676 als_uninit(struct sc_info *sc)
678 /* Disable interrupts */
679 als_gcr_wr(sc, ALS_GCR_MISC, 0);
682 /* ------------------------------------------------------------------------- */
683 /* Probe and attach card */
686 als_pci_probe(device_t dev)
688 if (pci_get_devid(dev) == ALS_PCI_ID0) {
689 device_set_desc(dev, "Avance Logic ALS4000");
696 als_resource_free(device_t dev, struct sc_info *sc)
699 bus_release_resource(dev, SYS_RES_IOPORT, sc->regid, sc->reg);
703 bus_teardown_intr(dev, sc->irq, sc->ih);
707 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
710 if (sc->parent_dmat) {
711 bus_dma_tag_destroy(sc->parent_dmat);
717 als_resource_grab(device_t dev, struct sc_info *sc)
719 sc->regid = PCIR_MAPS;
720 sc->reg = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->regid, 0, ~0,
721 ALS_CONFIG_SPACE_BYTES, RF_ACTIVE);
723 device_printf(dev, "unable to allocate register space\n");
726 sc->st = rman_get_bustag(sc->reg);
727 sc->sh = rman_get_bushandle(sc->reg);
729 sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqid, 0, ~0, 1,
730 RF_ACTIVE | RF_SHAREABLE);
732 device_printf(dev, "unable to allocate interrupt\n");
736 if (bus_setup_intr(dev, sc->irq, 0, als_intr, sc, &sc->ih, NULL)) {
737 device_printf(dev, "unable to setup interrupt\n");
741 sc->bufsz = pcm_getbuffersize(dev, 4096, ALS_DEFAULT_BUFSZ, 65536);
743 if (bus_dma_tag_create(/*parent*/NULL,
744 /*alignment*/2, /*boundary*/0,
745 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
746 /*highaddr*/BUS_SPACE_MAXADDR,
747 /*filter*/NULL, /*filterarg*/NULL,
748 /*maxsize*/sc->bufsz,
749 /*nsegments*/1, /*maxsegz*/0x3ffff,
750 /*flags*/0, &sc->parent_dmat) != 0) {
751 device_printf(dev, "unable to create dma tag\n");
756 als_resource_free(dev, sc);
761 als_pci_attach(device_t dev)
765 char status[SND_STATUSLEN];
767 if ((sc = kmalloc(sizeof(*sc), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
768 device_printf(dev, "cannot allocate softc\n");
774 data = pci_read_config(dev, PCIR_COMMAND, 2);
775 data |= (PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
776 pci_write_config(dev, PCIR_COMMAND, data, 2);
778 * By default the power to the various components on the
779 * ALS4000 is entirely controlled by the pci powerstate. We
780 * could attempt finer grained control by setting GCR6.31.
782 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
783 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
784 /* Reset the power state. */
785 device_printf(dev, "chip is in D%d power mode "
786 "-- setting to D0\n", pci_get_powerstate(dev));
787 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
790 data = pci_read_config(dev, ALS_PCI_POWERREG, 2);
791 if ((data & 0x03) != 0) {
792 device_printf(dev, "chip is in D%d power mode "
793 "-- setting to D0\n", data & 0x03);
795 pci_write_config(dev, ALS_PCI_POWERREG, data, 2);
799 if (als_resource_grab(dev, sc)) {
800 device_printf(dev, "failed to allocate resources\n");
805 device_printf(dev, "failed to initialize hardware\n");
809 if (mixer_init(dev, &als_mixer_class, sc)) {
810 device_printf(dev, "failed to initialize mixer\n");
814 if (pcm_register(dev, sc, 1, 1)) {
815 device_printf(dev, "failed to register pcm entries\n");
819 pcm_addchan(dev, PCMDIR_PLAY, &alspchan_class, sc);
820 pcm_addchan(dev, PCMDIR_REC, &alsrchan_class, sc);
822 ksnprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld",
823 rman_get_start(sc->reg), rman_get_start(sc->irq));
824 pcm_setstatus(dev, status);
828 als_resource_free(dev, sc);
834 als_pci_detach(device_t dev)
839 r = pcm_unregister(dev);
843 sc = pcm_getdevinfo(dev);
845 als_resource_free(dev, sc);
851 als_pci_suspend(device_t dev)
853 struct sc_info *sc = pcm_getdevinfo(dev);
855 sc->pch.dma_was_active = als_playback_stop(&sc->pch);
856 sc->rch.dma_was_active = als_capture_stop(&sc->rch);
862 als_pci_resume(device_t dev)
864 struct sc_info *sc = pcm_getdevinfo(dev);
866 if (als_init(sc) != 0) {
867 device_printf(dev, "unable to reinitialize the card\n");
871 if (mixer_reinit(dev) != 0) {
872 device_printf(dev, "unable to reinitialize the mixer\n");
876 if (sc->pch.dma_was_active) {
877 als_playback_start(&sc->pch);
880 if (sc->rch.dma_was_active) {
881 als_capture_start(&sc->rch);
886 static device_method_t als_methods[] = {
887 /* Device interface */
888 DEVMETHOD(device_probe, als_pci_probe),
889 DEVMETHOD(device_attach, als_pci_attach),
890 DEVMETHOD(device_detach, als_pci_detach),
891 DEVMETHOD(device_suspend, als_pci_suspend),
892 DEVMETHOD(device_resume, als_pci_resume),
896 static driver_t als_driver = {
902 DRIVER_MODULE(snd_als4000, pci, als_driver, pcm_devclass, 0, 0);
903 MODULE_DEPEND(snd_als4000, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
904 MODULE_VERSION(snd_als4000, 1);