FreeBSD/Linux Kernel Cross Reference
sys/dev/sound/isa/sb8.c
1 /*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * Copyright 1997,1998 Luigi Rizzo.
4 *
5 * Derived from files in the Voxware 3.5 distribution,
6 * Copyright by Hannu Savolainen 1994, under the same copyright
7 * conditions.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <dev/sound/pcm/sound.h>
33
34 #include <dev/sound/isa/sb.h>
35 #include <dev/sound/chip.h>
36
37 #include <isa/isavar.h>
38
39 #include "mixer_if.h"
40
41 SND_DECLARE_FILE("$FreeBSD: releng/5.1/sys/dev/sound/isa/sb8.c 110499 2003-02-07 14:05:34Z nyan $");
42
43 #define SB_DEFAULT_BUFSZ 4096
44
45 static u_int32_t sb_fmt[] = {
46 AFMT_U8,
47 0
48 };
49 static struct pcmchan_caps sb200_playcaps = {4000, 23000, sb_fmt, 0};
50 static struct pcmchan_caps sb200_reccaps = {4000, 13000, sb_fmt, 0};
51 static struct pcmchan_caps sb201_playcaps = {4000, 44100, sb_fmt, 0};
52 static struct pcmchan_caps sb201_reccaps = {4000, 15000, sb_fmt, 0};
53
54 static u_int32_t sbpro_fmt[] = {
55 AFMT_U8,
56 AFMT_STEREO | AFMT_U8,
57 0
58 };
59 static struct pcmchan_caps sbpro_playcaps = {4000, 44100, sbpro_fmt, 0};
60 static struct pcmchan_caps sbpro_reccaps = {4000, 44100, sbpro_fmt, 0};
61
62 struct sb_info;
63
64 struct sb_chinfo {
65 struct sb_info *parent;
66 struct pcm_channel *channel;
67 struct snd_dbuf *buffer;
68 int dir;
69 u_int32_t fmt, spd, blksz;
70 };
71
72 struct sb_info {
73 device_t parent_dev;
74 struct resource *io_base; /* I/O address for the board */
75 struct resource *irq;
76 struct resource *drq;
77 void *ih;
78 bus_dma_tag_t parent_dmat;
79
80 unsigned int bufsize;
81 int bd_id;
82 u_long bd_flags; /* board-specific flags */
83 struct sb_chinfo pch, rch;
84 };
85
86 static int sb_rd(struct sb_info *sb, int reg);
87 static void sb_wr(struct sb_info *sb, int reg, u_int8_t val);
88 static int sb_dspready(struct sb_info *sb);
89 static int sb_cmd(struct sb_info *sb, u_char val);
90 static int sb_cmd1(struct sb_info *sb, u_char cmd, int val);
91 static int sb_cmd2(struct sb_info *sb, u_char cmd, int val);
92 static u_int sb_get_byte(struct sb_info *sb);
93 static void sb_setmixer(struct sb_info *sb, u_int port, u_int value);
94 static int sb_getmixer(struct sb_info *sb, u_int port);
95 static int sb_reset_dsp(struct sb_info *sb);
96
97 static void sb_intr(void *arg);
98 static int sb_speed(struct sb_chinfo *ch);
99 static int sb_start(struct sb_chinfo *ch);
100 static int sb_stop(struct sb_chinfo *ch);
101
102 /*
103 * Common code for the midi and pcm functions
104 *
105 * sb_cmd write a single byte to the CMD port.
106 * sb_cmd1 write a CMD + 1 byte arg
107 * sb_cmd2 write a CMD + 2 byte arg
108 * sb_get_byte returns a single byte from the DSP data port
109 */
110
111 static void
112 sb_lock(struct sb_info *sb) {
113
114 sbc_lock(device_get_softc(sb->parent_dev));
115 }
116
117 static void
118 sb_unlock(struct sb_info *sb) {
119
120 sbc_unlock(device_get_softc(sb->parent_dev));
121 }
122
123 static int
124 port_rd(struct resource *port, int off)
125 {
126 return bus_space_read_1(rman_get_bustag(port), rman_get_bushandle(port), off);
127 }
128
129 static void
130 port_wr(struct resource *port, int off, u_int8_t data)
131 {
132 bus_space_write_1(rman_get_bustag(port), rman_get_bushandle(port), off, data);
133 }
134
135 static int
136 sb_rd(struct sb_info *sb, int reg)
137 {
138 return port_rd(sb->io_base, reg);
139 }
140
141 static void
142 sb_wr(struct sb_info *sb, int reg, u_int8_t val)
143 {
144 port_wr(sb->io_base, reg, val);
145 }
146
147 static int
148 sb_dspready(struct sb_info *sb)
149 {
150 return ((sb_rd(sb, SBDSP_STATUS) & 0x80) == 0);
151 }
152
153 static int
154 sb_dspwr(struct sb_info *sb, u_char val)
155 {
156 int i;
157
158 for (i = 0; i < 1000; i++) {
159 if (sb_dspready(sb)) {
160 sb_wr(sb, SBDSP_CMD, val);
161 return 1;
162 }
163 if (i > 10) DELAY((i > 100)? 1000 : 10);
164 }
165 printf("sb_dspwr(0x%02x) timed out.\n", val);
166 return 0;
167 }
168
169 static int
170 sb_cmd(struct sb_info *sb, u_char val)
171 {
172 #if 0
173 printf("sb_cmd: %x\n", val);
174 #endif
175 return sb_dspwr(sb, val);
176 }
177
178 static int
179 sb_cmd1(struct sb_info *sb, u_char cmd, int val)
180 {
181 #if 0
182 printf("sb_cmd1: %x, %x\n", cmd, val);
183 #endif
184 if (sb_dspwr(sb, cmd)) {
185 return sb_dspwr(sb, val & 0xff);
186 } else return 0;
187 }
188
189 static int
190 sb_cmd2(struct sb_info *sb, u_char cmd, int val)
191 {
192 #if 0
193 printf("sb_cmd2: %x, %x\n", cmd, val);
194 #endif
195 if (sb_dspwr(sb, cmd)) {
196 return sb_dspwr(sb, val & 0xff) &&
197 sb_dspwr(sb, (val >> 8) & 0xff);
198 } else return 0;
199 }
200
201 /*
202 * in the SB, there is a set of indirect "mixer" registers with
203 * address at offset 4, data at offset 5
204 *
205 * we don't need to interlock these, the mixer lock will suffice.
206 */
207 static void
208 sb_setmixer(struct sb_info *sb, u_int port, u_int value)
209 {
210 sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
211 DELAY(10);
212 sb_wr(sb, SB_MIX_DATA, (u_char) (value & 0xff));
213 DELAY(10);
214 }
215
216 static int
217 sb_getmixer(struct sb_info *sb, u_int port)
218 {
219 int val;
220
221 sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
222 DELAY(10);
223 val = sb_rd(sb, SB_MIX_DATA);
224 DELAY(10);
225
226 return val;
227 }
228
229 static u_int
230 sb_get_byte(struct sb_info *sb)
231 {
232 int i;
233
234 for (i = 1000; i > 0; i--) {
235 if (sb_rd(sb, DSP_DATA_AVAIL) & 0x80)
236 return sb_rd(sb, DSP_READ);
237 else
238 DELAY(20);
239 }
240 return 0xffff;
241 }
242
243 static int
244 sb_reset_dsp(struct sb_info *sb)
245 {
246 sb_wr(sb, SBDSP_RST, 3);
247 DELAY(100);
248 sb_wr(sb, SBDSP_RST, 0);
249 if (sb_get_byte(sb) != 0xAA) {
250 DEB(printf("sb_reset_dsp 0x%lx failed\n",
251 rman_get_start(sb->io_base)));
252 return ENXIO; /* Sorry */
253 }
254 return 0;
255 }
256
257 static void
258 sb_release_resources(struct sb_info *sb, device_t dev)
259 {
260 if (sb->irq) {
261 if (sb->ih)
262 bus_teardown_intr(dev, sb->irq, sb->ih);
263 bus_release_resource(dev, SYS_RES_IRQ, 0, sb->irq);
264 sb->irq = 0;
265 }
266 if (sb->drq) {
267 isa_dma_release(rman_get_start(sb->drq));
268 bus_release_resource(dev, SYS_RES_DRQ, 0, sb->drq);
269 sb->drq = 0;
270 }
271 if (sb->io_base) {
272 bus_release_resource(dev, SYS_RES_IOPORT, 0, sb->io_base);
273 sb->io_base = 0;
274 }
275 if (sb->parent_dmat) {
276 bus_dma_tag_destroy(sb->parent_dmat);
277 sb->parent_dmat = 0;
278 }
279 free(sb, M_DEVBUF);
280 }
281
282 static int
283 sb_alloc_resources(struct sb_info *sb, device_t dev)
284 {
285 int rid;
286
287 rid = 0;
288 if (!sb->io_base)
289 sb->io_base = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
290 rid = 0;
291 if (!sb->irq)
292 sb->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
293 rid = 0;
294 if (!sb->drq)
295 sb->drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 0, ~0, 1, RF_ACTIVE);
296
297 if (sb->io_base && sb->drq && sb->irq) {
298 isa_dma_acquire(rman_get_start(sb->drq));
299 isa_dmainit(rman_get_start(sb->drq), sb->bufsize);
300
301 return 0;
302 } else return ENXIO;
303 }
304
305 /************************************************************/
306
307 static int
308 sbpromix_init(struct snd_mixer *m)
309 {
310 struct sb_info *sb = mix_getdevinfo(m);
311
312 mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE |
313 SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME);
314
315 mix_setrecdevs(m, SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD);
316
317 sb_setmixer(sb, 0, 1); /* reset mixer */
318
319 return 0;
320 }
321
322 static int
323 sbpromix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
324 {
325 struct sb_info *sb = mix_getdevinfo(m);
326 int reg, max;
327 u_char val;
328
329 max = 7;
330 switch (dev) {
331 case SOUND_MIXER_PCM:
332 reg = 0x04;
333 break;
334
335 case SOUND_MIXER_MIC:
336 reg = 0x0a;
337 max = 3;
338 break;
339
340 case SOUND_MIXER_VOLUME:
341 reg = 0x22;
342 break;
343
344 case SOUND_MIXER_SYNTH:
345 reg = 0x26;
346 break;
347
348 case SOUND_MIXER_CD:
349 reg = 0x28;
350 break;
351
352 case SOUND_MIXER_LINE:
353 reg = 0x2e;
354 break;
355
356 default:
357 return -1;
358 }
359
360 left = (left * max) / 100;
361 right = (dev == SOUND_MIXER_MIC)? left : ((right * max) / 100);
362
363 val = (dev == SOUND_MIXER_MIC)? (left << 1) : (left << 5 | right << 1);
364 sb_setmixer(sb, reg, val);
365
366 left = (left * 100) / max;
367 right = (right * 100) / max;
368
369 return left | (right << 8);
370 }
371
372 static int
373 sbpromix_setrecsrc(struct snd_mixer *m, u_int32_t src)
374 {
375 struct sb_info *sb = mix_getdevinfo(m);
376 u_char recdev;
377
378 if (src == SOUND_MASK_LINE)
379 recdev = 0x06;
380 else if (src == SOUND_MASK_CD)
381 recdev = 0x02;
382 else { /* default: mic */
383 src = SOUND_MASK_MIC;
384 recdev = 0;
385 }
386 sb_setmixer(sb, RECORD_SRC, recdev | (sb_getmixer(sb, RECORD_SRC) & ~0x07));
387
388 return src;
389 }
390
391 static kobj_method_t sbpromix_mixer_methods[] = {
392 KOBJMETHOD(mixer_init, sbpromix_init),
393 KOBJMETHOD(mixer_set, sbpromix_set),
394 KOBJMETHOD(mixer_setrecsrc, sbpromix_setrecsrc),
395 { 0, 0 }
396 };
397 MIXER_DECLARE(sbpromix_mixer);
398
399 /************************************************************/
400
401 static int
402 sbmix_init(struct snd_mixer *m)
403 {
404 struct sb_info *sb = mix_getdevinfo(m);
405
406 mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_CD | SOUND_MASK_VOLUME);
407
408 mix_setrecdevs(m, 0);
409
410 sb_setmixer(sb, 0, 1); /* reset mixer */
411
412 return 0;
413 }
414
415 static int
416 sbmix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
417 {
418 struct sb_info *sb = mix_getdevinfo(m);
419 int reg, max;
420
421 max = 7;
422 switch (dev) {
423 case SOUND_MIXER_VOLUME:
424 reg = 0x2;
425 break;
426
427 case SOUND_MIXER_SYNTH:
428 reg = 0x6;
429 break;
430
431 case SOUND_MIXER_CD:
432 reg = 0x8;
433 break;
434
435 case SOUND_MIXER_PCM:
436 reg = 0x0a;
437 max = 3;
438 break;
439
440 default:
441 return -1;
442 }
443
444 left = (left * max) / 100;
445
446 sb_setmixer(sb, reg, left << 1);
447
448 left = (left * 100) / max;
449
450 return left | (left << 8);
451 }
452
453 static int
454 sbmix_setrecsrc(struct snd_mixer *m, u_int32_t src)
455 {
456 return 0;
457 }
458
459 static kobj_method_t sbmix_mixer_methods[] = {
460 KOBJMETHOD(mixer_init, sbmix_init),
461 KOBJMETHOD(mixer_set, sbmix_set),
462 KOBJMETHOD(mixer_setrecsrc, sbmix_setrecsrc),
463 { 0, 0 }
464 };
465 MIXER_DECLARE(sbmix_mixer);
466
467 /************************************************************/
468
469 static void
470 sb_intr(void *arg)
471 {
472 struct sb_info *sb = (struct sb_info *)arg;
473
474 sb_lock(sb);
475 if (sndbuf_runsz(sb->pch.buffer) > 0)
476 chn_intr(sb->pch.channel);
477
478 if (sndbuf_runsz(sb->rch.buffer) > 0)
479 chn_intr(sb->rch.channel);
480
481 sb_rd(sb, DSP_DATA_AVAIL); /* int ack */
482 sb_unlock(sb);
483 }
484
485 static int
486 sb_speed(struct sb_chinfo *ch)
487 {
488 struct sb_info *sb = ch->parent;
489 int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
490 int stereo = (ch->fmt & AFMT_STEREO)? 1 : 0;
491 int speed, tmp, thresh, max;
492 u_char tconst;
493
494 if (sb->bd_id >= 0x300) {
495 thresh = stereo? 11025 : 23000;
496 max = stereo? 22050 : 44100;
497 } else if (sb->bd_id > 0x200) {
498 thresh = play? 23000 : 13000;
499 max = play? 44100 : 15000;
500 } else {
501 thresh = 999999;
502 max = play? 23000 : 13000;
503 }
504
505 speed = ch->spd;
506 if (speed > max)
507 speed = max;
508
509 sb_lock(sb);
510 sb->bd_flags &= ~BD_F_HISPEED;
511 if (speed > thresh)
512 sb->bd_flags |= BD_F_HISPEED;
513
514 tmp = 65536 - (256000000 / (speed << stereo));
515 tconst = tmp >> 8;
516
517 sb_cmd1(sb, 0x40, tconst); /* set time constant */
518
519 speed = (256000000 / (65536 - tmp)) >> stereo;
520
521 ch->spd = speed;
522 sb_unlock(sb);
523 return speed;
524 }
525
526 static int
527 sb_start(struct sb_chinfo *ch)
528 {
529 struct sb_info *sb = ch->parent;
530 int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
531 int stereo = (ch->fmt & AFMT_STEREO)? 1 : 0;
532 int l = ch->blksz;
533 u_char i;
534
535 l--;
536
537 sb_lock(sb);
538 if (play)
539 sb_cmd(sb, DSP_CMD_SPKON);
540
541 if (sb->bd_flags & BD_F_HISPEED)
542 i = play? 0x90 : 0x98;
543 else
544 i = play? 0x1c : 0x2c;
545
546 sb_setmixer(sb, 0x0e, stereo? 2 : 0);
547 sb_cmd2(sb, 0x48, l);
548 sb_cmd(sb, i);
549
550 sb->bd_flags |= BD_F_DMARUN;
551 sb_unlock(sb);
552 return 0;
553 }
554
555 static int
556 sb_stop(struct sb_chinfo *ch)
557 {
558 struct sb_info *sb = ch->parent;
559 int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
560
561 sb_lock(sb);
562 if (sb->bd_flags & BD_F_HISPEED)
563 sb_reset_dsp(sb);
564 else
565 sb_cmd(sb, DSP_CMD_DMAEXIT_8);
566
567 if (play)
568 sb_cmd(sb, DSP_CMD_SPKOFF); /* speaker off */
569 sb_unlock(sb);
570 sb->bd_flags &= ~BD_F_DMARUN;
571 return 0;
572 }
573
574 /* channel interface */
575 static void *
576 sbchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
577 {
578 struct sb_info *sb = devinfo;
579 struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch;
580
581 ch->parent = sb;
582 ch->channel = c;
583 ch->dir = dir;
584 ch->buffer = b;
585 if (sndbuf_alloc(ch->buffer, sb->parent_dmat, sb->bufsize) == -1)
586 return NULL;
587 sndbuf_dmasetup(ch->buffer, sb->drq);
588 return ch;
589 }
590
591 static int
592 sbchan_setformat(kobj_t obj, void *data, u_int32_t format)
593 {
594 struct sb_chinfo *ch = data;
595
596 ch->fmt = format;
597 return 0;
598 }
599
600 static int
601 sbchan_setspeed(kobj_t obj, void *data, u_int32_t speed)
602 {
603 struct sb_chinfo *ch = data;
604
605 ch->spd = speed;
606 return sb_speed(ch);
607 }
608
609 static int
610 sbchan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
611 {
612 struct sb_chinfo *ch = data;
613
614 ch->blksz = blocksize;
615 return ch->blksz;
616 }
617
618 static int
619 sbchan_trigger(kobj_t obj, void *data, int go)
620 {
621 struct sb_chinfo *ch = data;
622
623 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
624 return 0;
625
626 sndbuf_dma(ch->buffer, go);
627 if (go == PCMTRIG_START)
628 sb_start(ch);
629 else
630 sb_stop(ch);
631 return 0;
632 }
633
634 static int
635 sbchan_getptr(kobj_t obj, void *data)
636 {
637 struct sb_chinfo *ch = data;
638
639 return sndbuf_dmaptr(ch->buffer);
640 }
641
642 static struct pcmchan_caps *
643 sbchan_getcaps(kobj_t obj, void *data)
644 {
645 struct sb_chinfo *ch = data;
646 int p = (ch->dir == PCMDIR_PLAY)? 1 : 0;
647
648 if (ch->parent->bd_id == 0x200)
649 return p? &sb200_playcaps : &sb200_reccaps;
650 if (ch->parent->bd_id < 0x300)
651 return p? &sb201_playcaps : &sb201_reccaps;
652 return p? &sbpro_playcaps : &sbpro_reccaps;
653 }
654
655 static kobj_method_t sbchan_methods[] = {
656 KOBJMETHOD(channel_init, sbchan_init),
657 KOBJMETHOD(channel_setformat, sbchan_setformat),
658 KOBJMETHOD(channel_setspeed, sbchan_setspeed),
659 KOBJMETHOD(channel_setblocksize, sbchan_setblocksize),
660 KOBJMETHOD(channel_trigger, sbchan_trigger),
661 KOBJMETHOD(channel_getptr, sbchan_getptr),
662 KOBJMETHOD(channel_getcaps, sbchan_getcaps),
663 { 0, 0 }
664 };
665 CHANNEL_DECLARE(sbchan);
666
667 /************************************************************/
668
669 static int
670 sb_probe(device_t dev)
671 {
672 char buf[64];
673 uintptr_t func, ver, r, f;
674
675 /* The parent device has already been probed. */
676 r = BUS_READ_IVAR(device_get_parent(dev), dev, 0, &func);
677 if (func != SCF_PCM)
678 return (ENXIO);
679
680 r = BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
681 f = (ver & 0xffff0000) >> 16;
682 ver &= 0x0000ffff;
683 if ((f & BD_F_ESS) || (ver >= 0x400))
684 return (ENXIO);
685
686 snprintf(buf, sizeof buf, "SB DSP %d.%02d", (int) ver >> 8, (int) ver & 0xff);
687
688 device_set_desc_copy(dev, buf);
689
690 return 0;
691 }
692
693 static int
694 sb_attach(device_t dev)
695 {
696 struct sb_info *sb;
697 char status[SND_STATUSLEN];
698 uintptr_t ver;
699
700 sb = (struct sb_info *)malloc(sizeof *sb, M_DEVBUF, M_NOWAIT | M_ZERO);
701 if (!sb)
702 return ENXIO;
703
704 sb->parent_dev = device_get_parent(dev);
705 BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
706 sb->bd_id = ver & 0x0000ffff;
707 sb->bd_flags = (ver & 0xffff0000) >> 16;
708 sb->bufsize = pcm_getbuffersize(dev, 4096, SB_DEFAULT_BUFSZ, 65536);
709
710 if (sb_alloc_resources(sb, dev))
711 goto no;
712 if (sb_reset_dsp(sb))
713 goto no;
714 if (mixer_init(dev, (sb->bd_id < 0x300)? &sbmix_mixer_class : &sbpromix_mixer_class, sb))
715 goto no;
716 if (snd_setup_intr(dev, sb->irq, INTR_MPSAFE, sb_intr, sb, &sb->ih))
717 goto no;
718
719 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
720
721 if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
722 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
723 /*highaddr*/BUS_SPACE_MAXADDR,
724 /*filter*/NULL, /*filterarg*/NULL,
725 /*maxsize*/sb->bufsize, /*nsegments*/1,
726 /*maxsegz*/0x3ffff,
727 /*flags*/0, &sb->parent_dmat) != 0) {
728 device_printf(dev, "unable to create dma tag\n");
729 goto no;
730 }
731
732 snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld bufsz %u",
733 rman_get_start(sb->io_base), rman_get_start(sb->irq), rman_get_start(sb->drq), sb->bufsize);
734
735 if (pcm_register(dev, sb, 1, 1))
736 goto no;
737 pcm_addchan(dev, PCMDIR_REC, &sbchan_class, sb);
738 pcm_addchan(dev, PCMDIR_PLAY, &sbchan_class, sb);
739
740 pcm_setstatus(dev, status);
741
742 return 0;
743
744 no:
745 sb_release_resources(sb, dev);
746 return ENXIO;
747 }
748
749 static int
750 sb_detach(device_t dev)
751 {
752 int r;
753 struct sb_info *sb;
754
755 r = pcm_unregister(dev);
756 if (r)
757 return r;
758
759 sb = pcm_getdevinfo(dev);
760 sb_release_resources(sb, dev);
761 return 0;
762 }
763
764 static device_method_t sb_methods[] = {
765 /* Device interface */
766 DEVMETHOD(device_probe, sb_probe),
767 DEVMETHOD(device_attach, sb_attach),
768 DEVMETHOD(device_detach, sb_detach),
769
770 { 0, 0 }
771 };
772
773 static driver_t sb_driver = {
774 "pcm",
775 sb_methods,
776 PCM_SOFTC_SIZE,
777 };
778
779 DRIVER_MODULE(snd_sb8, sbc, sb_driver, pcm_devclass, 0, 0);
780 MODULE_DEPEND(snd_sb8, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
781 MODULE_DEPEND(snd_sb8, snd_sbc, 1, 1, 1);
782 MODULE_VERSION(snd_sb8, 1);
783
784
785
786
Cache object: b7574ff13adfd34cf86d2fe5c4c716ad
|