FreeBSD kernel sound device code
fm801.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2000 Dmitry Dicky diwil@dataart.com
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
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, WHETHER IN 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 THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifdef HAVE_KERNEL_OPTION_HEADERS
30#include "opt_snd.h"
31#endif
32
33#include <dev/sound/pcm/sound.h>
34#include <dev/sound/pcm/ac97.h>
35#include <dev/pci/pcireg.h>
36#include <dev/pci/pcivar.h>
37
38SND_DECLARE_FILE("$FreeBSD$");
39
40#define PCI_VENDOR_FORTEMEDIA 0x1319
41#define PCI_DEVICE_FORTEMEDIA1 0x08011319 /* Audio controller */
42#define PCI_DEVICE_FORTEMEDIA2 0x08021319 /* Joystick controller */
43
44#define FM_PCM_VOLUME 0x00
45#define FM_FM_VOLUME 0x02
46#define FM_I2S_VOLUME 0x04
47#define FM_RECORD_SOURCE 0x06
48
49#define FM_PLAY_CTL 0x08
50#define FM_PLAY_RATE_MASK 0x0f00
51#define FM_PLAY_BUF1_LAST 0x0001
52#define FM_PLAY_BUF2_LAST 0x0002
53#define FM_PLAY_START 0x0020
54#define FM_PLAY_PAUSE 0x0040
55#define FM_PLAY_STOPNOW 0x0080
56#define FM_PLAY_16BIT 0x4000
57#define FM_PLAY_STEREO 0x8000
58
59#define FM_PLAY_DMALEN 0x0a
60#define FM_PLAY_DMABUF1 0x0c
61#define FM_PLAY_DMABUF2 0x10
62
63#define FM_REC_CTL 0x14
64#define FM_REC_RATE_MASK 0x0f00
65#define FM_REC_BUF1_LAST 0x0001
66#define FM_REC_BUF2_LAST 0x0002
67#define FM_REC_START 0x0020
68#define FM_REC_PAUSE 0x0040
69#define FM_REC_STOPNOW 0x0080
70#define FM_REC_16BIT 0x4000
71#define FM_REC_STEREO 0x8000
72
73#define FM_REC_DMALEN 0x16
74#define FM_REC_DMABUF1 0x18
75#define FM_REC_DMABUF2 0x1c
76
77#define FM_CODEC_CTL 0x22
78#define FM_VOLUME 0x26
79#define FM_VOLUME_MUTE 0x8000
80
81#define FM_CODEC_CMD 0x2a
82#define FM_CODEC_CMD_READ 0x0080
83#define FM_CODEC_CMD_VALID 0x0100
84#define FM_CODEC_CMD_BUSY 0x0200
85
86#define FM_CODEC_DATA 0x2c
87
88#define FM_IO_CTL 0x52
89#define FM_CARD_CTL 0x54
90
91#define FM_INTMASK 0x56
92#define FM_INTMASK_PLAY 0x0001
93#define FM_INTMASK_REC 0x0002
94#define FM_INTMASK_VOL 0x0040
95#define FM_INTMASK_MPU 0x0080
96
97#define FM_INTSTATUS 0x5a
98#define FM_INTSTATUS_PLAY 0x0100
99#define FM_INTSTATUS_REC 0x0200
100#define FM_INTSTATUS_VOL 0x4000
101#define FM_INTSTATUS_MPU 0x8000
102
103#define FM801_DEFAULT_BUFSZ 4096 /* Other values do not work!!! */
104
105/* debug purposes */
106#define DPRINT if(0) printf
107
108/*
109static int fm801ch_setup(struct pcm_channel *c);
110*/
111
112static u_int32_t fmts[] = {
113 SND_FORMAT(AFMT_U8, 1, 0),
114 SND_FORMAT(AFMT_U8, 2, 0),
115 SND_FORMAT(AFMT_S16_LE, 1, 0),
116 SND_FORMAT(AFMT_S16_LE, 2, 0),
117 0
118};
119
120static struct pcmchan_caps fm801ch_caps = {
121 5500, 48000,
122 fmts, 0
123};
124
125struct fm801_info;
126
131 u_int32_t spd, dir, fmt; /* speed, direction, format */
132 u_int32_t shift;
133};
134
136 int type;
137 bus_space_tag_t st;
138 bus_space_handle_t sh;
139 bus_dma_tag_t parent_dmat;
140
141 device_t dev;
142 int num;
143 u_int32_t unit;
144
145 struct resource *reg, *irq;
147 void *ih;
148
149 u_int32_t play_flip,
156
157 u_int32_t rec_flip,
164
165 unsigned int bufsz;
166
167 struct fm801_chinfo pch, rch;
168
169 device_t radio;
170};
171
172/* Bus Read / Write routines */
173static u_int32_t
174fm801_rd(struct fm801_info *fm801, int regno, int size)
175{
176 switch(size) {
177 case 1:
178 return (bus_space_read_1(fm801->st, fm801->sh, regno));
179 case 2:
180 return (bus_space_read_2(fm801->st, fm801->sh, regno));
181 case 4:
182 return (bus_space_read_4(fm801->st, fm801->sh, regno));
183 default:
184 return 0xffffffff;
185 }
186}
187
188static void
189fm801_wr(struct fm801_info *fm801, int regno, u_int32_t data, int size)
190{
191
192 switch(size) {
193 case 1:
194 bus_space_write_1(fm801->st, fm801->sh, regno, data);
195 break;
196 case 2:
197 bus_space_write_2(fm801->st, fm801->sh, regno, data);
198 break;
199 case 4:
200 bus_space_write_4(fm801->st, fm801->sh, regno, data);
201 break;
202 }
203}
204
205/* -------------------------------------------------------------------- */
206/*
207 * ac97 codec routines
208 */
209#define TIMO 50
210static int
211fm801_rdcd(kobj_t obj, void *devinfo, int regno)
212{
213 struct fm801_info *fm801 = (struct fm801_info *)devinfo;
214 int i;
215
216 for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) {
217 DELAY(10000);
218 DPRINT("fm801 rdcd: 1 - DELAY\n");
219 }
220 if (i >= TIMO) {
221 printf("fm801 rdcd: codec busy\n");
222 return 0;
223 }
224
226
227 for (i = 0; i < TIMO && !(fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_VALID); i++)
228 {
229 DELAY(10000);
230 DPRINT("fm801 rdcd: 2 - DELAY\n");
231 }
232 if (i >= TIMO) {
233 printf("fm801 rdcd: write codec invalid\n");
234 return 0;
235 }
236
237 return fm801_rd(fm801,FM_CODEC_DATA,2);
238}
239
240static int
241fm801_wrcd(kobj_t obj, void *devinfo, int regno, u_int32_t data)
242{
243 struct fm801_info *fm801 = (struct fm801_info *)devinfo;
244 int i;
245
246 DPRINT("fm801_wrcd reg 0x%x val 0x%x\n",regno, data);
247/*
248 if(regno == AC97_REG_RECSEL) return;
249*/
250 /* Poll until codec is ready */
251 for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) {
252 DELAY(10000);
253 DPRINT("fm801 rdcd: 1 - DELAY\n");
254 }
255 if (i >= TIMO) {
256 printf("fm801 wrcd: read codec busy\n");
257 return -1;
258 }
259
260 fm801_wr(fm801,FM_CODEC_DATA,data, 2);
261 fm801_wr(fm801,FM_CODEC_CMD, regno,2);
262
263 /* wait until codec is ready */
264 for (i = 0; i < TIMO && fm801_rd(fm801,FM_CODEC_CMD,2) & FM_CODEC_CMD_BUSY; i++) {
265 DELAY(10000);
266 DPRINT("fm801 wrcd: 2 - DELAY\n");
267 }
268 if (i >= TIMO) {
269 printf("fm801 wrcd: read codec busy\n");
270 return -1;
271 }
272 DPRINT("fm801 wrcd release reg 0x%x val 0x%x\n",regno, data);
273 return 0;
274}
275
276static kobj_method_t fm801_ac97_methods[] = {
277 KOBJMETHOD(ac97_read, fm801_rdcd),
278 KOBJMETHOD(ac97_write, fm801_wrcd),
279 DEVMETHOD_END
280};
281AC97_DECLARE(fm801_ac97);
282
283/* -------------------------------------------------------------------- */
284
285/*
286 * The interrupt handler
287 */
288static void
290{
291 struct fm801_info *fm801 = (struct fm801_info *)p;
292 u_int32_t intsrc = fm801_rd(fm801, FM_INTSTATUS, 2);
293
294 DPRINT("\nfm801_intr intsrc 0x%x ", intsrc);
295
296 if(intsrc & FM_INTSTATUS_PLAY) {
297 fm801->play_flip++;
298 if(fm801->play_flip & 1) {
299 fm801_wr(fm801, FM_PLAY_DMABUF1, fm801->play_start,4);
300 } else
301 fm801_wr(fm801, FM_PLAY_DMABUF2, fm801->play_nextblk,4);
302 chn_intr(fm801->pch.channel);
303 }
304
305 if(intsrc & FM_INTSTATUS_REC) {
306 fm801->rec_flip++;
307 if(fm801->rec_flip & 1) {
308 fm801_wr(fm801, FM_REC_DMABUF1, fm801->rec_start,4);
309 } else
310 fm801_wr(fm801, FM_REC_DMABUF2, fm801->rec_nextblk,4);
311 chn_intr(fm801->rch.channel);
312 }
313
314 if ( intsrc & FM_INTSTATUS_MPU ) {
315 /* This is a TODOish thing... */
316 fm801_wr(fm801, FM_INTSTATUS, intsrc & FM_INTSTATUS_MPU,2);
317 }
318
319 if ( intsrc & FM_INTSTATUS_VOL ) {
320 /* This is a TODOish thing... */
321 fm801_wr(fm801, FM_INTSTATUS, intsrc & FM_INTSTATUS_VOL,2);
322 }
323
324 DPRINT("fm801_intr clear\n\n");
326}
327
328/* -------------------------------------------------------------------- */
329/* channel interface */
330static void *
331fm801ch_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
332{
333 struct fm801_info *fm801 = (struct fm801_info *)devinfo;
334 struct fm801_chinfo *ch = (dir == PCMDIR_PLAY)? &fm801->pch : &fm801->rch;
335
336 DPRINT("fm801ch_init, direction = %d\n", dir);
337 ch->parent = fm801;
338 ch->channel = c;
339 ch->buffer = b;
340 ch->dir = dir;
341 if (sndbuf_alloc(ch->buffer, fm801->parent_dmat, 0, fm801->bufsz) != 0)
342 return NULL;
343 return (void *)ch;
344}
345
346static int
347fm801ch_setformat(kobj_t obj, void *data, u_int32_t format)
348{
349 struct fm801_chinfo *ch = data;
350 struct fm801_info *fm801 = ch->parent;
351
352 DPRINT("fm801ch_setformat 0x%x : %s, %s, %s, %s\n", format,
353 (AFMT_CHANNEL(format) > 1)?"stereo":"mono",
354 (format & AFMT_16BIT) ? "16bit":"8bit",
355 (format & AFMT_SIGNED)? "signed":"unsigned",
356 (format & AFMT_BIGENDIAN)?"bigendiah":"littleendian" );
357
358 if(ch->dir == PCMDIR_PLAY) {
359 fm801->play_fmt =
361 fm801->play_fmt |= (format & AFMT_16BIT) ? FM_PLAY_16BIT : 0;
362 return 0;
363 }
364
365 if(ch->dir == PCMDIR_REC ) {
366 fm801->rec_fmt = (AFMT_CHANNEL(format) > 1)? FM_REC_STEREO:0;
367 fm801->rec_fmt |= (format & AFMT_16BIT) ? FM_PLAY_16BIT : 0;
368 return 0;
369 }
370
371 return 0;
372}
373
374struct {
375 u_int32_t limit;
376 u_int32_t rate;
377} fm801_rates[11] = {
378 { 6600, 5500 },
379 { 8750, 8000 },
380 { 10250, 9600 },
381 { 13200, 11025 },
382 { 17500, 16000 },
383 { 20500, 19200 },
384 { 26500, 22050 },
385 { 35000, 32000 },
386 { 41000, 38400 },
387 { 46000, 44100 },
388 { 48000, 48000 },
389/* anything above -> 48000 */
391
392static u_int32_t
393fm801ch_setspeed(kobj_t obj, void *data, u_int32_t speed)
394{
395 struct fm801_chinfo *ch = data;
396 struct fm801_info *fm801 = ch->parent;
397 int i;
398
399 for (i = 0; i < 10 && fm801_rates[i].limit <= speed; i++) ;
400
401 if(ch->dir == PCMDIR_PLAY) {
402 fm801->pch.spd = fm801_rates[i].rate;
403 fm801->play_shift = (i<<8);
405 }
406
407 if(ch->dir == PCMDIR_REC ) {
408 fm801->rch.spd = fm801_rates[i].rate;
409 fm801->rec_shift = (i<<8);
410 fm801->rec_shift &= FM_REC_RATE_MASK;
411 }
412
413 ch->spd = fm801_rates[i].rate;
414
415 return fm801_rates[i].rate;
416}
417
418static u_int32_t
419fm801ch_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
420{
421 struct fm801_chinfo *ch = data;
422 struct fm801_info *fm801 = ch->parent;
423
424 /*
425 * Don't mind for play_flip, set the blocksize to the
426 * desired values in any case - otherwise sound playback
427 * breaks here.
428 */
429 if(ch->dir == PCMDIR_PLAY)
430 fm801->play_blksize = blocksize;
431
432 if(ch->dir == PCMDIR_REC)
433 fm801->rec_blksize = blocksize;
434
435 DPRINT("fm801ch_setblocksize %d (dir %d)\n",blocksize, ch->dir);
436
437 return blocksize;
438}
439
440static int
441fm801ch_trigger(kobj_t obj, void *data, int go)
442{
443 struct fm801_chinfo *ch = data;
444 struct fm801_info *fm801 = ch->parent;
445 u_int32_t baseaddr = sndbuf_getbufaddr(ch->buffer);
446 u_int32_t k1;
447
448 DPRINT("fm801ch_trigger go %d , ", go);
449
450 if (!PCMTRIG_COMMON(go))
451 return 0;
452
453 if (ch->dir == PCMDIR_PLAY) {
454 if (go == PCMTRIG_START) {
455 fm801->play_start = baseaddr;
456 fm801->play_nextblk = fm801->play_start + fm801->play_blksize;
457 fm801->play_flip = 0;
458 fm801_wr(fm801, FM_PLAY_DMALEN, fm801->play_blksize - 1, 2);
459 fm801_wr(fm801, FM_PLAY_DMABUF1,fm801->play_start,4);
460 fm801_wr(fm801, FM_PLAY_DMABUF2,fm801->play_nextblk,4);
461 fm801_wr(fm801, FM_PLAY_CTL,
463 2 );
464 } else {
465 fm801->play_flip = 0;
466 k1 = fm801_rd(fm801, FM_PLAY_CTL,2);
467 fm801_wr(fm801, FM_PLAY_CTL,
468 (k1 & ~(FM_PLAY_STOPNOW | FM_PLAY_START)) |
470 }
471 } else if(ch->dir == PCMDIR_REC) {
472 if (go == PCMTRIG_START) {
473 fm801->rec_start = baseaddr;
474 fm801->rec_nextblk = fm801->rec_start + fm801->rec_blksize;
475 fm801->rec_flip = 0;
476 fm801_wr(fm801, FM_REC_DMALEN, fm801->rec_blksize - 1, 2);
477 fm801_wr(fm801, FM_REC_DMABUF1,fm801->rec_start,4);
478 fm801_wr(fm801, FM_REC_DMABUF2,fm801->rec_nextblk,4);
479 fm801_wr(fm801, FM_REC_CTL,
480 FM_REC_START | FM_REC_STOPNOW | fm801->rec_fmt | fm801->rec_shift,
481 2 );
482 } else {
483 fm801->rec_flip = 0;
484 k1 = fm801_rd(fm801, FM_REC_CTL,2);
485 fm801_wr(fm801, FM_REC_CTL,
486 (k1 & ~(FM_REC_STOPNOW | FM_REC_START)) |
488 }
489 }
490
491 return 0;
492}
493
494/* Almost ALSA copy */
495static u_int32_t
496fm801ch_getptr(kobj_t obj, void *data)
497{
498 struct fm801_chinfo *ch = data;
499 struct fm801_info *fm801 = ch->parent;
500 u_int32_t result = 0;
501
502 if (ch->dir == PCMDIR_PLAY) {
503 result = fm801_rd(fm801,
504 (fm801->play_flip&1) ?
506 }
507
508 if (ch->dir == PCMDIR_REC) {
509 result = fm801_rd(fm801,
510 (fm801->rec_flip&1) ?
512 }
513
514 return result;
515}
516
517static struct pcmchan_caps *
518fm801ch_getcaps(kobj_t obj, void *data)
519{
520 return &fm801ch_caps;
521}
522
523static kobj_method_t fm801ch_methods[] = {
524 KOBJMETHOD(channel_init, fm801ch_init),
525 KOBJMETHOD(channel_setformat, fm801ch_setformat),
526 KOBJMETHOD(channel_setspeed, fm801ch_setspeed),
527 KOBJMETHOD(channel_setblocksize, fm801ch_setblocksize),
528 KOBJMETHOD(channel_trigger, fm801ch_trigger),
529 KOBJMETHOD(channel_getptr, fm801ch_getptr),
530 KOBJMETHOD(channel_getcaps, fm801ch_getcaps),
531 DEVMETHOD_END
532};
534
535/* -------------------------------------------------------------------- */
536
537/*
538 * Init routine is taken from an original NetBSD driver
539 */
540static int
541fm801_init(struct fm801_info *fm801)
542{
543 u_int32_t k1;
544
545 /* reset codec */
546 fm801_wr(fm801, FM_CODEC_CTL, 0x0020,2);
547 DELAY(100000);
548 fm801_wr(fm801, FM_CODEC_CTL, 0x0000,2);
549 DELAY(100000);
550
551 fm801_wr(fm801, FM_PCM_VOLUME, 0x0808,2);
552 fm801_wr(fm801, FM_FM_VOLUME, 0x0808,2);
553 fm801_wr(fm801, FM_I2S_VOLUME, 0x0808,2);
554 fm801_wr(fm801, 0x40,0x107f,2); /* enable legacy audio */
555
556 fm801_wr((void *)fm801, FM_RECORD_SOURCE, 0x0000,2);
557
558 /* Unmask playback, record and mpu interrupts, mask the rest */
559 k1 = fm801_rd((void *)fm801, FM_INTMASK,2);
560 fm801_wr(fm801, FM_INTMASK,
563 fm801_wr(fm801, FM_INTSTATUS,
566
567 DPRINT("FM801 init Ok\n");
568 return 0;
569}
570
571static int
573{
574 struct ac97_info *codec = NULL;
575 struct fm801_info *fm801;
576 int i;
577 int mapped = 0;
578 char status[SND_STATUSLEN];
579
580 fm801 = malloc(sizeof(*fm801), M_DEVBUF, M_WAITOK | M_ZERO);
581 fm801->type = pci_get_devid(dev);
582
583 pci_enable_busmaster(dev);
584
585 for (i = 0; (mapped == 0) && (i < PCI_MAXMAPS_0); i++) {
586 fm801->regid = PCIR_BAR(i);
587 fm801->regtype = SYS_RES_MEMORY;
588 fm801->reg = bus_alloc_resource_any(dev, fm801->regtype,
589 &fm801->regid, RF_ACTIVE);
590 if(!fm801->reg)
591 {
592 fm801->regtype = SYS_RES_IOPORT;
593 fm801->reg = bus_alloc_resource_any(dev,
594 fm801->regtype,
595 &fm801->regid,
596 RF_ACTIVE);
597 }
598
599 if(fm801->reg) {
600 fm801->st = rman_get_bustag(fm801->reg);
601 fm801->sh = rman_get_bushandle(fm801->reg);
602 mapped++;
603 }
604 }
605
606 if (mapped == 0) {
607 device_printf(dev, "unable to map register space\n");
608 goto oops;
609 }
610
611 fm801->bufsz = pcm_getbuffersize(dev, 4096, FM801_DEFAULT_BUFSZ, 65536);
612
613 fm801_init(fm801);
614
615 codec = AC97_CREATE(dev, fm801, fm801_ac97);
616 if (codec == NULL) goto oops;
617
618 if (mixer_init(dev, ac97_getmixerclass(), codec) == -1) goto oops;
619
620 fm801->irqid = 0;
621 fm801->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fm801->irqid,
622 RF_ACTIVE | RF_SHAREABLE);
623 if (!fm801->irq ||
624 snd_setup_intr(dev, fm801->irq, 0, fm801_intr, fm801, &fm801->ih)) {
625 device_printf(dev, "unable to map interrupt\n");
626 goto oops;
627 }
628
629 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev), /*alignment*/2,
630 /*boundary*/0,
631 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
632 /*highaddr*/BUS_SPACE_MAXADDR,
633 /*filter*/NULL, /*filterarg*/NULL,
634 /*maxsize*/fm801->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff,
635 /*flags*/0, /*lockfunc*/NULL, /*lockarg*/NULL,
636 &fm801->parent_dmat) != 0) {
637 device_printf(dev, "unable to create dma tag\n");
638 goto oops;
639 }
640
641 snprintf(status, 64, "at %s 0x%jx irq %jd %s",
642 (fm801->regtype == SYS_RES_IOPORT)? "io" : "memory",
643 rman_get_start(fm801->reg), rman_get_start(fm801->irq),PCM_KLDSTRING(snd_fm801));
644
645#define FM801_MAXPLAYCH 1
646 if (pcm_register(dev, fm801, FM801_MAXPLAYCH, 1)) goto oops;
647 pcm_addchan(dev, PCMDIR_PLAY, &fm801ch_class, fm801);
648 pcm_addchan(dev, PCMDIR_REC, &fm801ch_class, fm801);
650
651 fm801->radio = device_add_child(dev, "radio", -1);
652 bus_generic_attach(dev);
653
654 return 0;
655
656oops:
657 if (codec) ac97_destroy(codec);
658 if (fm801->reg) bus_release_resource(dev, fm801->regtype, fm801->regid, fm801->reg);
659 if (fm801->ih) bus_teardown_intr(dev, fm801->irq, fm801->ih);
660 if (fm801->irq) bus_release_resource(dev, SYS_RES_IRQ, fm801->irqid, fm801->irq);
661 if (fm801->parent_dmat) bus_dma_tag_destroy(fm801->parent_dmat);
662 free(fm801, M_DEVBUF);
663 return ENXIO;
664}
665
666static int
668{
669 int r;
670 struct fm801_info *fm801;
671
672 DPRINT("Forte Media FM801 detach\n");
673
674 fm801 = pcm_getdevinfo(dev);
675
676 r = bus_generic_detach(dev);
677 if (r)
678 return r;
679 if (fm801->radio != NULL) {
680 r = device_delete_child(dev, fm801->radio);
681 if (r)
682 return r;
683 fm801->radio = NULL;
684 }
685
687 if (r)
688 return r;
689
690 bus_release_resource(dev, fm801->regtype, fm801->regid, fm801->reg);
691 bus_teardown_intr(dev, fm801->irq, fm801->ih);
692 bus_release_resource(dev, SYS_RES_IRQ, fm801->irqid, fm801->irq);
693 bus_dma_tag_destroy(fm801->parent_dmat);
694 free(fm801, M_DEVBUF);
695 return 0;
696}
697
698static int
700{
701 int id;
702
703 if ((id = pci_get_devid(dev)) == PCI_DEVICE_FORTEMEDIA1 ) {
704 device_set_desc(dev, "Forte Media FM801 Audio Controller");
705 return BUS_PROBE_DEFAULT;
706 }
707/*
708 if ((id = pci_get_devid(dev)) == PCI_DEVICE_FORTEMEDIA2 ) {
709 device_set_desc(dev, "Forte Media FM801 Joystick (Not Supported)");
710 return ENXIO;
711 }
712*/
713 return ENXIO;
714}
715
716static struct resource *
717fm801_alloc_resource(device_t bus, device_t child, int type, int *rid,
718 rman_res_t start, rman_res_t end, rman_res_t count,
719 u_int flags)
720{
721 struct fm801_info *fm801;
722
723 fm801 = pcm_getdevinfo(bus);
724
725 if (type == SYS_RES_IOPORT && *rid == PCIR_BAR(0))
726 return (fm801->reg);
727
728 return (NULL);
729}
730
731static int
732fm801_release_resource(device_t bus, device_t child, int type, int rid,
733 struct resource *r)
734{
735 return (0);
736}
737
738static device_method_t fm801_methods[] = {
739 /* Device interface */
740 DEVMETHOD(device_probe, fm801_pci_probe),
741 DEVMETHOD(device_attach, fm801_pci_attach),
742 DEVMETHOD(device_detach, fm801_pci_detach),
743 DEVMETHOD(device_shutdown, bus_generic_shutdown),
744 DEVMETHOD(device_suspend, bus_generic_suspend),
745 DEVMETHOD(device_resume, bus_generic_resume),
746
747 /* Bus interface */
748 DEVMETHOD(bus_alloc_resource, fm801_alloc_resource),
749 DEVMETHOD(bus_release_resource, fm801_release_resource),
750 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
751 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
752
753 DEVMETHOD_END
754};
755
756static driver_t fm801_driver = {
757 "pcm",
760};
761
764MODULE_VERSION(snd_fm801, 1);
kobj_class_t ac97_getmixerclass(void)
Definition: ac97.c:1097
void ac97_destroy(struct ac97_info *codec)
Definition: ac97.c:860
#define AC97_CREATE(dev, devinfo, cls)
Definition: ac97.h:89
u_int32_t data
Definition: ac97_if.m:60
int regno
Definition: ac97_if.m:53
void * devinfo
Definition: ac97_if.m:47
uint32_t format
Definition: audio_dai_if.m:39
uint32_t speed
Definition: audio_dai_if.m:86
int go
Definition: audio_dai_if.m:64
int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
Definition: buffer.c:93
bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf)
Definition: buffer.c:66
void chn_intr(struct pcm_channel *c)
Definition: channel.c:660
#define PCMDIR_PLAY
Definition: channel.h:339
#define PCMTRIG_START
Definition: channel.h:344
#define PCMDIR_REC
Definition: channel.h:341
#define PCMTRIG_COMMON(x)
Definition: channel.h:350
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
u_int32_t blocksize
Definition: channel_if.m:140
struct snd_dbuf * b
Definition: channel_if.m:105
int type
Definition: dsp.c:386
u_int32_t count
Definition: feeder_if.m:86
#define FM_PLAY_BUF2_LAST
Definition: fm801.c:52
#define FM_PLAY_STOPNOW
Definition: fm801.c:55
static int fm801_rdcd(kobj_t obj, void *devinfo, int regno)
Definition: fm801.c:211
#define FM_REC_RATE_MASK
Definition: fm801.c:64
#define FM_CODEC_CMD_BUSY
Definition: fm801.c:84
u_int32_t rate
Definition: fm801.c:376
static int fm801_pci_probe(device_t dev)
Definition: fm801.c:699
static int fm801_pci_detach(device_t dev)
Definition: fm801.c:667
static void fm801_intr(void *p)
Definition: fm801.c:289
static int fm801ch_trigger(kobj_t obj, void *data, int go)
Definition: fm801.c:441
static u_int32_t fmts[]
Definition: fm801.c:112
#define DPRINT
Definition: fm801.c:106
#define FM_REC_START
Definition: fm801.c:67
#define TIMO
Definition: fm801.c:209
#define FM_REC_BUF1_LAST
Definition: fm801.c:65
#define FM_INTMASK
Definition: fm801.c:91
#define FM_FM_VOLUME
Definition: fm801.c:45
#define FM_REC_STOPNOW
Definition: fm801.c:69
AC97_DECLARE(fm801_ac97)
#define FM_CODEC_DATA
Definition: fm801.c:86
#define FM801_DEFAULT_BUFSZ
Definition: fm801.c:103
static void * fm801ch_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
Definition: fm801.c:331
static u_int32_t fm801ch_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
Definition: fm801.c:419
static int fm801ch_setformat(kobj_t obj, void *data, u_int32_t format)
Definition: fm801.c:347
SND_DECLARE_FILE("$FreeBSD$")
#define FM_PLAY_DMALEN
Definition: fm801.c:59
static int fm801_wrcd(kobj_t obj, void *devinfo, int regno, u_int32_t data)
Definition: fm801.c:241
static driver_t fm801_driver
Definition: fm801.c:756
#define FM_CODEC_CMD_VALID
Definition: fm801.c:83
#define FM_INTMASK_REC
Definition: fm801.c:93
#define FM801_MAXPLAYCH
#define FM_INTMASK_VOL
Definition: fm801.c:94
#define FM_REC_STEREO
Definition: fm801.c:71
MODULE_DEPEND(snd_fm801, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
#define FM_RECORD_SOURCE
Definition: fm801.c:47
#define FM_PLAY_CTL
Definition: fm801.c:49
#define FM_PLAY_STEREO
Definition: fm801.c:57
#define PCI_DEVICE_FORTEMEDIA1
Definition: fm801.c:41
static u_int32_t fm801ch_setspeed(kobj_t obj, void *data, u_int32_t speed)
Definition: fm801.c:393
#define FM_REC_DMABUF1
Definition: fm801.c:74
static int fm801_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r)
Definition: fm801.c:732
#define FM_INTMASK_MPU
Definition: fm801.c:95
static void fm801_wr(struct fm801_info *fm801, int regno, u_int32_t data, int size)
Definition: fm801.c:189
#define FM_PLAY_DMABUF2
Definition: fm801.c:61
#define FM_CODEC_CTL
Definition: fm801.c:77
MODULE_VERSION(snd_fm801, 1)
#define FM_REC_BUF2_LAST
Definition: fm801.c:66
#define FM_INTSTATUS_REC
Definition: fm801.c:99
#define FM_I2S_VOLUME
Definition: fm801.c:46
static u_int32_t fm801_rd(struct fm801_info *fm801, int regno, int size)
Definition: fm801.c:174
#define FM_PLAY_DMABUF1
Definition: fm801.c:60
#define FM_PCM_VOLUME
Definition: fm801.c:44
static kobj_method_t fm801ch_methods[]
Definition: fm801.c:523
#define FM_PLAY_16BIT
Definition: fm801.c:56
#define FM_CODEC_CMD
Definition: fm801.c:81
static kobj_method_t fm801_ac97_methods[]
Definition: fm801.c:276
#define FM_REC_DMABUF2
Definition: fm801.c:75
#define FM_INTSTATUS_PLAY
Definition: fm801.c:98
static struct pcmchan_caps fm801ch_caps
Definition: fm801.c:120
static u_int32_t fm801ch_getptr(kobj_t obj, void *data)
Definition: fm801.c:496
#define FM_REC_DMALEN
Definition: fm801.c:73
#define FM_PLAY_BUF1_LAST
Definition: fm801.c:51
struct @8 fm801_rates[11]
#define FM_INTSTATUS_MPU
Definition: fm801.c:101
static device_method_t fm801_methods[]
Definition: fm801.c:738
#define FM_INTMASK_PLAY
Definition: fm801.c:92
CHANNEL_DECLARE(fm801ch)
static int fm801_init(struct fm801_info *fm801)
Definition: fm801.c:541
u_int32_t limit
Definition: fm801.c:375
DRIVER_MODULE(snd_fm801, pci, fm801_driver, pcm_devclass, 0, 0)
static struct pcmchan_caps * fm801ch_getcaps(kobj_t obj, void *data)
Definition: fm801.c:518
static struct resource * fm801_alloc_resource(device_t bus, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
Definition: fm801.c:717
#define FM_PLAY_RATE_MASK
Definition: fm801.c:50
#define FM_REC_CTL
Definition: fm801.c:63
#define FM_CODEC_CMD_READ
Definition: fm801.c:82
#define FM_INTSTATUS
Definition: fm801.c:97
#define FM_PLAY_START
Definition: fm801.c:53
#define FM_INTSTATUS_VOL
Definition: fm801.c:100
static int fm801_pci_attach(device_t dev)
Definition: fm801.c:572
uint32_t id
Definition: hdaa_patches.c:54
device_t child
Definition: hdac_if.m:33
int dir
Definition: hdac_if.m:45
uint8_t size
uint8_t r
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
Definition: mixer.c:725
unsigned dev
Definition: mixer_if.m:59
bool * status
uint16_t rid
u_int bus
#define PCIR_BAR(x)
#define PCI_MAXMAPS_0
void * pcm_getdevinfo(device_t dev)
Definition: sound.c:832
int pcm_setstatus(device_t dev, char *str)
Definition: sound.c:766
devclass_t pcm_devclass
Definition: sound.c:49
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
Definition: sound.c:692
int pcm_unregister(device_t dev)
Definition: sound.c:1170
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
Definition: sound.c:1080
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
Definition: sound.c:117
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
Definition: sound.c:840
#define PCM_KLDSTRING(a)
Definition: sound.h:619
#define SND_FORMAT(f, c, e)
Definition: sound.h:238
#define SOUND_PREFVER
Definition: sound.h:103
#define SOUND_MAXVER
Definition: sound.h:104
#define AFMT_BIGENDIAN
Definition: sound.h:196
#define AFMT_CHANNEL(v)
Definition: sound.h:227
#define SOUND_MINVER
Definition: sound.h:102
#define PCM_SOFTC_SIZE
Definition: sound.h:96
#define AFMT_SIGNED
Definition: sound.h:194
#define SND_STATUSLEN
Definition: sound.h:98
#define AFMT_16BIT
Definition: sound.h:191
Definition: ac97.c:59
u_int32_t spd
Definition: fm801.c:131
struct pcm_channel * channel
Definition: fm801.c:129
struct fm801_info * parent
Definition: fm801.c:128
struct snd_dbuf * buffer
Definition: fm801.c:130
u_int32_t dir
Definition: fm801.c:131
u_int32_t fmt
Definition: fm801.c:131
u_int32_t shift
Definition: fm801.c:132
bus_dma_tag_t parent_dmat
Definition: fm801.c:139
void * ih
Definition: fm801.c:147
u_int32_t rec_shift
Definition: fm801.c:162
device_t radio
Definition: fm801.c:169
u_int32_t play_fmt
Definition: fm801.c:153
struct resource * irq
Definition: fm801.c:145
bus_space_handle_t sh
Definition: fm801.c:138
u_int32_t rec_flip
Definition: fm801.c:157
int type
Definition: fm801.c:136
u_int32_t rec_size
Definition: fm801.c:163
struct resource * reg
Definition: fm801.c:145
u_int32_t rec_fmt
Definition: fm801.c:161
device_t dev
Definition: fm801.c:141
struct fm801_chinfo pch rch
Definition: fm801.c:167
u_int32_t play_start
Definition: fm801.c:151
bus_space_tag_t st
Definition: fm801.c:137
u_int32_t play_shift
Definition: fm801.c:154
u_int32_t rec_nextblk
Definition: fm801.c:158
int regtype
Definition: fm801.c:146
u_int32_t play_flip
Definition: fm801.c:149
u_int32_t rec_blksize
Definition: fm801.c:160
int regid
Definition: fm801.c:146
int irqid
Definition: fm801.c:146
u_int32_t play_blksize
Definition: fm801.c:152
u_int32_t rec_start
Definition: fm801.c:159
int num
Definition: fm801.c:142
u_int32_t play_nextblk
Definition: fm801.c:150
unsigned int bufsz
Definition: fm801.c:165
u_int32_t unit
Definition: fm801.c:143
u_int32_t play_size
Definition: fm801.c:155