2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 Orion Hodson <oho@acm.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
30 * als4000.c - driver for the Avance Logic ALS 4000 chipset.
32 * The ALS4000 is effectively an SB16 with a PCI interface.
34 * This driver derives from ALS4000a.PDF, Bart Hartgers alsa driver, and
35 * SB16 register descriptions.
38 #ifdef HAVE_KERNEL_OPTION_HEADERS
42 #include <dev/sound/pcm/sound.h>
43 #include <dev/sound/isa/sb.h>
44 #include <dev/sound/pci/als4000.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
51 SND_DECLARE_FILE("$FreeBSD$");
53 /* Debugging macro's */
56 #define DEB(x) /* x */
59 #define ALS_DEFAULT_BUFSZ 16384
61 /* ------------------------------------------------------------------------- */
67 struct sc_info *parent;
68 struct pcm_channel *channel;
69 struct snd_dbuf *buffer;
70 u_int32_t format, speed, phys_buf, bps;
71 u_int32_t dma_active:1, dma_was_active:1;
72 u_int8_t gcr_fifo_status;
79 bus_space_handle_t sh;
80 bus_dma_tag_t parent_dmat;
81 struct resource *reg, *irq;
87 struct sc_chinfo pch, rch;
92 static u_int32_t als_format[] = {
93 SND_FORMAT(AFMT_U8, 1, 0),
94 SND_FORMAT(AFMT_U8, 2, 0),
95 SND_FORMAT(AFMT_S16_LE, 1, 0),
96 SND_FORMAT(AFMT_S16_LE, 2, 0),
101 * I don't believe this rotten soundcard can do 48k, really,
104 static struct pcmchan_caps als_caps = { 4000, 44100, als_format, 0 };
106 /* ------------------------------------------------------------------------- */
107 /* Register Utilities */
110 als_gcr_rd(struct sc_info *sc, int index)
112 bus_space_write_1(sc->st, sc->sh, ALS_GCR_INDEX, index);
113 return bus_space_read_4(sc->st, sc->sh, ALS_GCR_DATA);
117 als_gcr_wr(struct sc_info *sc, int index, int data)
119 bus_space_write_1(sc->st, sc->sh, ALS_GCR_INDEX, index);
120 bus_space_write_4(sc->st, sc->sh, ALS_GCR_DATA, data);
124 als_intr_rd(struct sc_info *sc)
126 return bus_space_read_1(sc->st, sc->sh, ALS_SB_MPU_IRQ);
130 als_intr_wr(struct sc_info *sc, u_int8_t data)
132 bus_space_write_1(sc->st, sc->sh, ALS_SB_MPU_IRQ, data);
136 als_mix_rd(struct sc_info *sc, u_int8_t index)
138 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_INDEX, index);
139 return bus_space_read_1(sc->st, sc->sh, ALS_MIXER_DATA);
143 als_mix_wr(struct sc_info *sc, u_int8_t index, u_int8_t data)
145 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_INDEX, index);
146 bus_space_write_1(sc->st, sc->sh, ALS_MIXER_DATA, data);
150 als_esp_wr(struct sc_info *sc, u_int8_t data)
156 v = bus_space_read_1(sc->st, sc->sh, ALS_ESP_WR_STATUS);
160 } while (--tries != 0);
163 device_printf(sc->dev, "als_esp_wr timeout");
165 bus_space_write_1(sc->st, sc->sh, ALS_ESP_WR_DATA, data);
169 als_esp_reset(struct sc_info *sc)
171 u_int32_t tries, u, v;
173 bus_space_write_1(sc->st, sc->sh, ALS_ESP_RST, 1);
175 bus_space_write_1(sc->st, sc->sh, ALS_ESP_RST, 0);
180 u = bus_space_read_1(sc->st, sc->sh, ALS_ESP_RD_STATUS8);
182 v = bus_space_read_1(sc->st, sc->sh, ALS_ESP_RD_DATA);
189 } while (--tries != 0);
192 device_printf(sc->dev, "als_esp_reset timeout");
197 als_ack_read(struct sc_info *sc, u_int8_t addr)
199 u_int8_t r = bus_space_read_1(sc->st, sc->sh, addr);
203 /* ------------------------------------------------------------------------- */
204 /* Common pcm channel implementation */
207 alschan_init(kobj_t obj, void *devinfo,
208 struct snd_dbuf *b, struct pcm_channel *c, int dir)
210 struct sc_info *sc = devinfo;
211 struct sc_chinfo *ch;
213 snd_mtxlock(sc->lock);
214 if (dir == PCMDIR_PLAY) {
216 ch->gcr_fifo_status = ALS_GCR_FIFO0_STATUS;
219 ch->gcr_fifo_status = ALS_GCR_FIFO1_STATUS;
225 ch->format = SND_FORMAT(AFMT_U8, 1, 0);
226 ch->speed = DSP_DEFAULT_SPEED;
228 snd_mtxunlock(sc->lock);
230 if (sndbuf_alloc(ch->buffer, sc->parent_dmat, 0, sc->bufsz) != 0)
237 alschan_setformat(kobj_t obj, void *data, u_int32_t format)
239 struct sc_chinfo *ch = data;
246 alschan_setspeed(kobj_t obj, void *data, u_int32_t speed)
248 struct sc_chinfo *ch = data, *other;
249 struct sc_info *sc = ch->parent;
251 other = (ch->dir == PCMDIR_PLAY) ? &sc->rch : &sc->pch;
253 /* Deny request if other dma channel is active */
254 if (other->dma_active) {
255 ch->speed = other->speed;
264 alschan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
266 struct sc_chinfo *ch = data;
267 struct sc_info *sc = ch->parent;
269 if (blocksize > sc->bufsz / 2) {
270 blocksize = sc->bufsz / 2;
272 sndbuf_resize(ch->buffer, 2, blocksize);
277 alschan_getptr(kobj_t obj, void *data)
279 struct sc_chinfo *ch = data;
280 struct sc_info *sc = ch->parent;
283 snd_mtxlock(sc->lock);
284 pos = als_gcr_rd(ch->parent, ch->gcr_fifo_status) & 0xffff;
285 snd_mtxunlock(sc->lock);
286 sz = sndbuf_getsize(ch->buffer);
287 return (2 * sz - pos - 1) % sz;
290 static struct pcmchan_caps*
291 alschan_getcaps(kobj_t obj, void *data)
297 als_set_speed(struct sc_chinfo *ch)
299 struct sc_info *sc = ch->parent;
300 struct sc_chinfo *other;
302 other = (ch->dir == PCMDIR_PLAY) ? &sc->rch : &sc->pch;
303 if (other->dma_active == 0) {
304 als_esp_wr(sc, ALS_ESP_SAMPLE_RATE);
305 als_esp_wr(sc, ch->speed >> 8);
306 als_esp_wr(sc, ch->speed & 0xff);
308 DEB(printf("speed locked at %d (tried %d)\n",
309 other->speed, ch->speed));
313 /* ------------------------------------------------------------------------- */
314 /* Playback channel implementation */
315 #define ALS_8BIT_CMD(x, y) { (x), (y), DSP_DMA8, DSP_CMD_DMAPAUSE_8 }
316 #define ALS_16BIT_CMD(x, y) { (x), (y), DSP_DMA16, DSP_CMD_DMAPAUSE_16 }
318 struct playback_command {
319 u_int32_t pcm_format; /* newpcm format */
320 u_int8_t format_val; /* sb16 format value */
321 u_int8_t dma_prog; /* sb16 dma program */
322 u_int8_t dma_stop; /* sb16 stop register */
323 } static const playback_cmds[] = {
324 ALS_8BIT_CMD(SND_FORMAT(AFMT_U8, 1, 0), DSP_MODE_U8MONO),
325 ALS_8BIT_CMD(SND_FORMAT(AFMT_U8, 2, 0), DSP_MODE_U8STEREO),
326 ALS_16BIT_CMD(SND_FORMAT(AFMT_S16_LE, 1, 0), DSP_MODE_S16MONO),
327 ALS_16BIT_CMD(SND_FORMAT(AFMT_S16_LE, 2, 0), DSP_MODE_S16STEREO),
330 static const struct playback_command*
331 als_get_playback_command(u_int32_t format)
335 n = sizeof(playback_cmds) / sizeof(playback_cmds[0]);
336 for (i = 0; i < n; i++) {
337 if (playback_cmds[i].pcm_format == format) {
338 return &playback_cmds[i];
341 DEB(printf("als_get_playback_command: invalid format 0x%08x\n",
343 return &playback_cmds[0];
347 als_playback_start(struct sc_chinfo *ch)
349 const struct playback_command *p;
350 struct sc_info *sc = ch->parent;
351 u_int32_t buf, bufsz, count, dma_prog;
353 buf = sndbuf_getbufaddr(ch->buffer);
354 bufsz = sndbuf_getsize(ch->buffer);
356 if (ch->format & AFMT_16BIT)
360 als_esp_wr(sc, DSP_CMD_SPKON);
363 als_gcr_wr(sc, ALS_GCR_DMA0_START, buf);
364 als_gcr_wr(sc, ALS_GCR_DMA0_MODE, (bufsz - 1) | 0x180000);
366 p = als_get_playback_command(ch->format);
367 dma_prog = p->dma_prog | DSP_F16_DAC | DSP_F16_AUTO | DSP_F16_FIFO_ON;
369 als_esp_wr(sc, dma_prog);
370 als_esp_wr(sc, p->format_val);
371 als_esp_wr(sc, count & 0xff);
372 als_esp_wr(sc, count >> 8);
378 als_playback_stop(struct sc_chinfo *ch)
380 const struct playback_command *p;
381 struct sc_info *sc = ch->parent;
384 active = ch->dma_active;
386 p = als_get_playback_command(ch->format);
387 als_esp_wr(sc, p->dma_stop);
394 alspchan_trigger(kobj_t obj, void *data, int go)
396 struct sc_chinfo *ch = data;
397 struct sc_info *sc = ch->parent;
399 if (!PCMTRIG_COMMON(go))
402 snd_mtxlock(sc->lock);
405 als_playback_start(ch);
409 als_playback_stop(ch);
414 snd_mtxunlock(sc->lock);
418 static kobj_method_t alspchan_methods[] = {
419 KOBJMETHOD(channel_init, alschan_init),
420 KOBJMETHOD(channel_setformat, alschan_setformat),
421 KOBJMETHOD(channel_setspeed, alschan_setspeed),
422 KOBJMETHOD(channel_setblocksize, alschan_setblocksize),
423 KOBJMETHOD(channel_trigger, alspchan_trigger),
424 KOBJMETHOD(channel_getptr, alschan_getptr),
425 KOBJMETHOD(channel_getcaps, alschan_getcaps),
428 CHANNEL_DECLARE(alspchan);
430 /* ------------------------------------------------------------------------- */
431 /* Capture channel implementation */
434 als_get_fifo_format(struct sc_info *sc, u_int32_t format)
437 case SND_FORMAT(AFMT_U8, 1, 0):
438 return ALS_FIFO1_8BIT;
439 case SND_FORMAT(AFMT_U8, 2, 0):
440 return ALS_FIFO1_8BIT | ALS_FIFO1_STEREO;
441 case SND_FORMAT(AFMT_S16_LE, 1, 0):
442 return ALS_FIFO1_SIGNED;
443 case SND_FORMAT(AFMT_S16_LE, 2, 0):
444 return ALS_FIFO1_SIGNED | ALS_FIFO1_STEREO;
446 device_printf(sc->dev, "format not found: 0x%08x\n", format);
447 return ALS_FIFO1_8BIT;
451 als_capture_start(struct sc_chinfo *ch)
453 struct sc_info *sc = ch->parent;
454 u_int32_t buf, bufsz, count, dma_prog;
456 buf = sndbuf_getbufaddr(ch->buffer);
457 bufsz = sndbuf_getsize(ch->buffer);
459 if (ch->format & AFMT_16BIT)
463 als_esp_wr(sc, DSP_CMD_SPKON);
466 als_gcr_wr(sc, ALS_GCR_FIFO1_START, buf);
467 als_gcr_wr(sc, ALS_GCR_FIFO1_COUNT, (bufsz - 1));
469 als_mix_wr(sc, ALS_FIFO1_LENGTH_LO, count & 0xff);
470 als_mix_wr(sc, ALS_FIFO1_LENGTH_HI, count >> 8);
472 dma_prog = ALS_FIFO1_RUN | als_get_fifo_format(sc, ch->format);
473 als_mix_wr(sc, ALS_FIFO1_CONTROL, dma_prog);
479 als_capture_stop(struct sc_chinfo *ch)
481 struct sc_info *sc = ch->parent;
484 active = ch->dma_active;
486 als_mix_wr(sc, ALS_FIFO1_CONTROL, ALS_FIFO1_STOP);
493 alsrchan_trigger(kobj_t obj, void *data, int go)
495 struct sc_chinfo *ch = data;
496 struct sc_info *sc = ch->parent;
498 snd_mtxlock(sc->lock);
501 als_capture_start(ch);
505 als_capture_stop(ch);
508 snd_mtxunlock(sc->lock);
512 static kobj_method_t alsrchan_methods[] = {
513 KOBJMETHOD(channel_init, alschan_init),
514 KOBJMETHOD(channel_setformat, alschan_setformat),
515 KOBJMETHOD(channel_setspeed, alschan_setspeed),
516 KOBJMETHOD(channel_setblocksize, alschan_setblocksize),
517 KOBJMETHOD(channel_trigger, alsrchan_trigger),
518 KOBJMETHOD(channel_getptr, alschan_getptr),
519 KOBJMETHOD(channel_getcaps, alschan_getcaps),
522 CHANNEL_DECLARE(alsrchan);
524 /* ------------------------------------------------------------------------- */
528 * ALS4000 has an sb16 mixer, with some additional controls that we do
529 * not yet a means to support.
537 u_int8_t iselect; /* left input mask */
538 } static const amt[SOUND_MIXER_NRDEVICES] = {
539 [SOUND_MIXER_VOLUME] = { 0x30, 0x31, 5, 0x00, 0x00 },
540 [SOUND_MIXER_PCM] = { 0x32, 0x33, 5, 0x00, 0x00 },
541 [SOUND_MIXER_SYNTH] = { 0x34, 0x35, 5, 0x60, 0x40 },
542 [SOUND_MIXER_CD] = { 0x36, 0x37, 5, 0x06, 0x04 },
543 [SOUND_MIXER_LINE] = { 0x38, 0x39, 5, 0x18, 0x10 },
544 [SOUND_MIXER_MIC] = { 0x3a, 0x00, 5, 0x01, 0x01 },
545 [SOUND_MIXER_SPEAKER] = { 0x3b, 0x00, 2, 0x00, 0x00 },
546 [SOUND_MIXER_IGAIN] = { 0x3f, 0x40, 2, 0x00, 0x00 },
547 [SOUND_MIXER_OGAIN] = { 0x41, 0x42, 2, 0x00, 0x00 },
548 /* The following have register values but no h/w implementation */
549 [SOUND_MIXER_TREBLE] = { 0x44, 0x45, 4, 0x00, 0x00 },
550 [SOUND_MIXER_BASS] = { 0x46, 0x47, 4, 0x00, 0x00 }
554 alsmix_init(struct snd_mixer *m)
558 for (i = v = 0; i < SOUND_MIXER_NRDEVICES; i++) {
559 if (amt[i].bits) v |= 1 << i;
563 for (i = v = 0; i < SOUND_MIXER_NRDEVICES; i++) {
564 if (amt[i].iselect) v |= 1 << i;
566 mix_setrecdevs(m, v);
571 alsmix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
573 struct sc_info *sc = mix_getdevinfo(m);
574 u_int32_t r, l, v, mask;
576 /* Fill upper n bits in mask with 1's */
577 mask = ((1 << amt[dev].bits) - 1) << (8 - amt[dev].bits);
579 l = (left * mask / 100) & mask;
580 v = als_mix_rd(sc, amt[dev].lreg) & ~mask;
581 als_mix_wr(sc, amt[dev].lreg, l | v);
584 r = (right * mask / 100) & mask;
585 v = als_mix_rd(sc, amt[dev].rreg) & ~mask;
586 als_mix_wr(sc, amt[dev].rreg, r | v);
591 /* Zero gain does not mute channel from output, but this does. */
592 v = als_mix_rd(sc, SB16_OMASK);
593 if (l == 0 && r == 0) {
594 v &= ~amt[dev].oselect;
596 v |= amt[dev].oselect;
598 als_mix_wr(sc, SB16_OMASK, v);
603 alsmix_setrecsrc(struct snd_mixer *m, u_int32_t src)
605 struct sc_info *sc = mix_getdevinfo(m);
608 for (i = l = r = 0; i < SOUND_MIXER_NRDEVICES; i++) {
609 if (src & (1 << i)) {
610 if (amt[i].iselect == 1) { /* microphone */
615 r |= amt[i].iselect >> 1;
620 als_mix_wr(sc, SB16_IMASK_L, l);
621 als_mix_wr(sc, SB16_IMASK_R, r);
625 static kobj_method_t als_mixer_methods[] = {
626 KOBJMETHOD(mixer_init, alsmix_init),
627 KOBJMETHOD(mixer_set, alsmix_set),
628 KOBJMETHOD(mixer_setrecsrc, alsmix_setrecsrc),
631 MIXER_DECLARE(als_mixer);
633 /* ------------------------------------------------------------------------- */
634 /* Interrupt Handler */
639 struct sc_info *sc = (struct sc_info *)p;
640 u_int8_t intr, sb_status;
642 snd_mtxlock(sc->lock);
643 intr = als_intr_rd(sc);
646 snd_mtxunlock(sc->lock);
647 chn_intr(sc->pch.channel);
648 snd_mtxlock(sc->lock);
652 snd_mtxunlock(sc->lock);
653 chn_intr(sc->rch.channel);
654 snd_mtxlock(sc->lock);
657 /* ACK interrupt in PCI core */
658 als_intr_wr(sc, intr);
660 /* ACK interrupt in SB core */
661 sb_status = als_mix_rd(sc, IRQ_STAT);
663 if (sb_status & ALS_IRQ_STATUS8)
664 als_ack_read(sc, ALS_ESP_RD_STATUS8);
665 if (sb_status & ALS_IRQ_STATUS16)
666 als_ack_read(sc, ALS_ESP_RD_STATUS16);
667 if (sb_status & ALS_IRQ_MPUIN)
668 als_ack_read(sc, ALS_MIDI_DATA);
669 if (sb_status & ALS_IRQ_CR1E)
670 als_ack_read(sc, ALS_CR1E_ACK_PORT);
672 snd_mtxunlock(sc->lock);
676 /* ------------------------------------------------------------------------- */
677 /* H/W initialization */
680 als_init(struct sc_info *sc)
685 if (als_esp_reset(sc)) {
689 /* Enable write on DMA_SETUP register */
690 v = als_mix_rd(sc, ALS_SB16_CONFIG);
691 als_mix_wr(sc, ALS_SB16_CONFIG, v | 0x80);
694 als_mix_wr(sc, ALS_SB16_DMA_SETUP, 0x01);
696 /* Disable write on DMA_SETUP register */
697 als_mix_wr(sc, ALS_SB16_CONFIG, v & 0x7f);
699 /* Enable interrupts */
700 v = als_gcr_rd(sc, ALS_GCR_MISC);
701 als_gcr_wr(sc, ALS_GCR_MISC, v | 0x28000);
703 /* Black out GCR DMA registers */
704 for (i = 0x91; i <= 0x96; i++) {
705 als_gcr_wr(sc, i, 0);
709 v = als_gcr_rd(sc, ALS_GCR_DMA_EMULATION);
710 als_gcr_wr(sc, ALS_GCR_DMA_EMULATION, v);
711 DEB(printf("GCR_DMA_EMULATION 0x%08x\n", v));
716 als_uninit(struct sc_info *sc)
718 /* Disable interrupts */
719 als_gcr_wr(sc, ALS_GCR_MISC, 0);
722 /* ------------------------------------------------------------------------- */
723 /* Probe and attach card */
726 als_pci_probe(device_t dev)
728 if (pci_get_devid(dev) == ALS_PCI_ID0) {
729 device_set_desc(dev, "Avance Logic ALS4000");
730 return BUS_PROBE_DEFAULT;
736 als_resource_free(device_t dev, struct sc_info *sc)
739 bus_release_resource(dev, SYS_RES_IOPORT, sc->regid, sc->reg);
743 bus_teardown_intr(dev, sc->irq, sc->ih);
747 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
750 if (sc->parent_dmat) {
751 bus_dma_tag_destroy(sc->parent_dmat);
755 snd_mtxfree(sc->lock);
761 als_resource_grab(device_t dev, struct sc_info *sc)
763 sc->regid = PCIR_BAR(0);
764 sc->reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->regid,
766 if (sc->reg == NULL) {
767 device_printf(dev, "unable to allocate register space\n");
770 sc->st = rman_get_bustag(sc->reg);
771 sc->sh = rman_get_bushandle(sc->reg);
773 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
774 RF_ACTIVE | RF_SHAREABLE);
775 if (sc->irq == NULL) {
776 device_printf(dev, "unable to allocate interrupt\n");
780 if (snd_setup_intr(dev, sc->irq, INTR_MPSAFE, als_intr,
782 device_printf(dev, "unable to setup interrupt\n");
786 sc->bufsz = pcm_getbuffersize(dev, 4096, ALS_DEFAULT_BUFSZ, 65536);
788 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev),
789 /*alignment*/2, /*boundary*/0,
790 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
791 /*highaddr*/BUS_SPACE_MAXADDR,
792 /*filter*/NULL, /*filterarg*/NULL,
793 /*maxsize*/sc->bufsz,
794 /*nsegments*/1, /*maxsegz*/0x3ffff,
795 /*flags*/0, /*lockfunc*/NULL,
796 /*lockarg*/NULL, &sc->parent_dmat) != 0) {
797 device_printf(dev, "unable to create dma tag\n");
802 als_resource_free(dev, sc);
807 als_pci_attach(device_t dev)
810 char status[SND_STATUSLEN];
812 sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
813 sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_als4000 softc");
816 pci_enable_busmaster(dev);
818 * By default the power to the various components on the
819 * ALS4000 is entirely controlled by the pci powerstate. We
820 * could attempt finer grained control by setting GCR6.31.
822 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
823 /* Reset the power state. */
824 device_printf(dev, "chip is in D%d power mode "
825 "-- setting to D0\n", pci_get_powerstate(dev));
826 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
829 if (als_resource_grab(dev, sc)) {
830 device_printf(dev, "failed to allocate resources\n");
835 device_printf(dev, "failed to initialize hardware\n");
839 if (mixer_init(dev, &als_mixer_class, sc)) {
840 device_printf(dev, "failed to initialize mixer\n");
844 if (pcm_register(dev, sc, 1, 1)) {
845 device_printf(dev, "failed to register pcm entries\n");
849 pcm_addchan(dev, PCMDIR_PLAY, &alspchan_class, sc);
850 pcm_addchan(dev, PCMDIR_REC, &alsrchan_class, sc);
852 snprintf(status, SND_STATUSLEN, "at io 0x%jx irq %jd %s",
853 rman_get_start(sc->reg), rman_get_start(sc->irq),PCM_KLDSTRING(snd_als4000));
854 pcm_setstatus(dev, status);
858 als_resource_free(dev, sc);
864 als_pci_detach(device_t dev)
869 r = pcm_unregister(dev);
873 sc = pcm_getdevinfo(dev);
875 als_resource_free(dev, sc);
881 als_pci_suspend(device_t dev)
883 struct sc_info *sc = pcm_getdevinfo(dev);
885 snd_mtxlock(sc->lock);
886 sc->pch.dma_was_active = als_playback_stop(&sc->pch);
887 sc->rch.dma_was_active = als_capture_stop(&sc->rch);
889 snd_mtxunlock(sc->lock);
894 als_pci_resume(device_t dev)
896 struct sc_info *sc = pcm_getdevinfo(dev);
898 snd_mtxlock(sc->lock);
899 if (als_init(sc) != 0) {
900 device_printf(dev, "unable to reinitialize the card\n");
901 snd_mtxunlock(sc->lock);
905 if (mixer_reinit(dev) != 0) {
906 device_printf(dev, "unable to reinitialize the mixer\n");
907 snd_mtxunlock(sc->lock);
911 if (sc->pch.dma_was_active) {
912 als_playback_start(&sc->pch);
915 if (sc->rch.dma_was_active) {
916 als_capture_start(&sc->rch);
918 snd_mtxunlock(sc->lock);
923 static device_method_t als_methods[] = {
924 /* Device interface */
925 DEVMETHOD(device_probe, als_pci_probe),
926 DEVMETHOD(device_attach, als_pci_attach),
927 DEVMETHOD(device_detach, als_pci_detach),
928 DEVMETHOD(device_suspend, als_pci_suspend),
929 DEVMETHOD(device_resume, als_pci_resume),
933 static driver_t als_driver = {
939 DRIVER_MODULE(snd_als4000, pci, als_driver, pcm_devclass, 0, 0);
940 MODULE_DEPEND(snd_als4000, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
941 MODULE_VERSION(snd_als4000, 1);