FreeBSD kernel sound device code
ich.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2000 Katsurajima Naoto <raven@katsurajima.seya.yokohama.jp>
5 * Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifdef HAVE_KERNEL_OPTION_HEADERS
31#include "opt_snd.h"
32#endif
33
34#include <dev/sound/pcm/sound.h>
35#include <dev/sound/pcm/ac97.h>
36#include <dev/sound/pci/ich.h>
37
38#include <dev/pci/pcireg.h>
39#include <dev/pci/pcivar.h>
40
41SND_DECLARE_FILE("$FreeBSD$");
42
43/* -------------------------------------------------------------------- */
44
45#define ICH_TIMEOUT 1000 /* semaphore timeout polling count */
46#define ICH_DTBL_LENGTH 32
47#define ICH_DEFAULT_BUFSZ 16384
48#define ICH_MAX_BUFSZ 65536
49#define ICH_MIN_BUFSZ 4096
50#define ICH_DEFAULT_BLKCNT 2
51#define ICH_MAX_BLKCNT 32
52#define ICH_MIN_BLKCNT 2
53#define ICH_MIN_BLKSZ 64
54
55#define INTEL_VENDORID 0x8086
56#define SIS_VENDORID 0x1039
57#define NVIDIA_VENDORID 0x10de
58#define AMD_VENDORID 0x1022
59
60#define INTEL_82440MX 0x7195
61#define INTEL_82801AA 0x2415
62#define INTEL_82801AB 0x2425
63#define INTEL_82801BA 0x2445
64#define INTEL_82801CA 0x2485
65#define INTEL_82801DB 0x24c5 /* ICH4 needs special handling */
66#define INTEL_82801EB 0x24d5 /* ICH5 needs to be treated as ICH4 */
67#define INTEL_6300ESB 0x25a6 /* 6300ESB needs to be treated as ICH4 */
68#define INTEL_82801FB 0x266e /* ICH6 needs to be treated as ICH4 */
69#define INTEL_82801GB 0x27de /* ICH7 needs to be treated as ICH4 */
70#define SIS_7012 0x7012 /* SiS 7012 needs special handling */
71#define NVIDIA_NFORCE 0x01b1
72#define NVIDIA_NFORCE2 0x006a
73#define NVIDIA_NFORCE2_400 0x008a
74#define NVIDIA_NFORCE3 0x00da
75#define NVIDIA_NFORCE3_250 0x00ea
76#define NVIDIA_NFORCE4 0x0059
77#define NVIDIA_NFORCE_410_MCP 0x026b
78#define NVIDIA_NFORCE4_MCP 0x003a
79#define AMD_768 0x7445
80#define AMD_8111 0x746d
81
82#define ICH_LOCK(sc) snd_mtxlock((sc)->ich_lock)
83#define ICH_UNLOCK(sc) snd_mtxunlock((sc)->ich_lock)
84#define ICH_LOCK_ASSERT(sc) snd_mtxassert((sc)->ich_lock)
85
86#if 0
87#define ICH_DEBUG(stmt) do { \
88 stmt \
89} while (0)
90#else
91#define ICH_DEBUG(...)
92#endif
93
94#define ICH_CALIBRATE_DONE (1 << 0)
95#define ICH_IGNORE_PCR (1 << 1)
96#define ICH_IGNORE_RESET (1 << 2)
97#define ICH_FIXED_RATE (1 << 3)
98#define ICH_DMA_NOCACHE (1 << 4)
99#define ICH_HIGH_LATENCY (1 << 5)
100
101static const struct ich_type {
102 uint16_t vendor;
103 uint16_t devid;
104 uint32_t options;
105#define PROBE_LOW 0x01
106 char *name;
107} ich_devs[] = {
109 "Intel 440MX" },
111 "Intel ICH (82801AA)" },
113 "Intel ICH (82801AB)" },
115 "Intel ICH2 (82801BA)" },
117 "Intel ICH3 (82801CA)" },
119 "Intel ICH4 (82801DB)" },
121 "Intel ICH5 (82801EB)" },
123 "Intel 6300ESB" },
125 "Intel ICH6 (82801FB)" },
127 "Intel ICH7 (82801GB)" },
129 "SiS 7012" },
131 "nVidia nForce" },
133 "nVidia nForce2" },
135 "nVidia nForce2 400" },
137 "nVidia nForce3" },
139 "nVidia nForce3 250" },
141 "nVidia nForce4" },
143 "nVidia nForce 410 MCP" },
145 "nVidia nForce 4 MCP" },
146 { AMD_VENDORID, AMD_768, 0,
147 "AMD-768" },
149 "AMD-8111" }
151
152/* buffer descriptor */
153struct ich_desc {
154 volatile uint32_t buffer;
155 volatile uint32_t length;
156};
157
158struct sc_info;
159
160/* channel registers */
161struct sc_chinfo {
162 uint32_t num:8, run:1, run_save:1;
163 uint32_t blksz, blkcnt, spd;
164 uint32_t regbase, spdreg;
165 uint32_t imask;
166 uint32_t civ;
167
168 struct snd_dbuf *buffer;
169 struct pcm_channel *channel;
170 struct sc_info *parent;
171
172 struct ich_desc *dtbl;
173 bus_addr_t desc_addr;
174};
175
176/* device private data */
177struct sc_info {
178 device_t dev;
180 unsigned int chnum, bufsz, blkcnt;
182
183 struct resource *nambar, *nabmbar, *irq;
185 bus_space_tag_t nambart, nabmbart;
186 bus_space_handle_t nambarh, nabmbarh;
187 bus_dma_tag_t dmat, chan_dmat;
188 bus_dmamap_t dtmap;
189 void *ih;
190
192 struct sc_chinfo ch[3];
194 struct ich_desc *dtbl;
195 unsigned int dtbl_size;
196 bus_addr_t desc_addr;
197 struct intr_config_hook intrhook;
198 uint16_t vendor;
199 uint16_t devid;
200 uint32_t flags;
201 struct mtx *ich_lock;
202};
203
204/* -------------------------------------------------------------------- */
205
206static uint32_t ich_fmt[] = {
207 SND_FORMAT(AFMT_S16_LE, 2, 0),
208 0
209};
210static struct pcmchan_caps ich_vrcaps = {8000, 48000, ich_fmt, 0};
211static struct pcmchan_caps ich_caps = {48000, 48000, ich_fmt, 0};
212
213/* -------------------------------------------------------------------- */
214/* Hardware */
215static __inline uint32_t
216ich_rd(struct sc_info *sc, int regno, int size)
217{
218 switch (size) {
219 case 1:
220 return (bus_space_read_1(sc->nabmbart, sc->nabmbarh, regno));
221 case 2:
222 return (bus_space_read_2(sc->nabmbart, sc->nabmbarh, regno));
223 case 4:
224 return (bus_space_read_4(sc->nabmbart, sc->nabmbarh, regno));
225 default:
226 return (0xffffffff);
227 }
228}
229
230static __inline void
231ich_wr(struct sc_info *sc, int regno, uint32_t data, int size)
232{
233 switch (size) {
234 case 1:
235 bus_space_write_1(sc->nabmbart, sc->nabmbarh, regno, data);
236 break;
237 case 2:
238 bus_space_write_2(sc->nabmbart, sc->nabmbarh, regno, data);
239 break;
240 case 4:
241 bus_space_write_4(sc->nabmbart, sc->nabmbarh, regno, data);
242 break;
243 }
244}
245
246/* ac97 codec */
247static int
249{
250 struct sc_info *sc = (struct sc_info *)devinfo;
251 uint32_t data;
252 int i;
253
254 for (i = 0; i < ICH_TIMEOUT; i++) {
255 data = ich_rd(sc, ICH_REG_ACC_SEMA, 1);
256 if ((data & 0x01) == 0)
257 return (0);
258 DELAY(1);
259 }
260 if ((sc->flags & ICH_IGNORE_PCR) != 0)
261 return (0);
262 device_printf(sc->dev, "CODEC semaphore timeout\n");
263 return (ETIMEDOUT);
264}
265
266static int
267ich_rdcd(kobj_t obj, void *devinfo, int regno)
268{
269 struct sc_info *sc = (struct sc_info *)devinfo;
270
271 regno &= 0xff;
272 ich_waitcd(sc);
273
274 return (bus_space_read_2(sc->nambart, sc->nambarh, regno));
275}
276
277static int
278ich_wrcd(kobj_t obj, void *devinfo, int regno, uint32_t data)
279{
280 struct sc_info *sc = (struct sc_info *)devinfo;
281
282 regno &= 0xff;
283 ich_waitcd(sc);
284 bus_space_write_2(sc->nambart, sc->nambarh, regno, data);
285
286 return (0);
287}
288
289static kobj_method_t ich_ac97_methods[] = {
290 KOBJMETHOD(ac97_read, ich_rdcd),
291 KOBJMETHOD(ac97_write, ich_wrcd),
293};
294AC97_DECLARE(ich_ac97);
295
296/* -------------------------------------------------------------------- */
297/* common routines */
298
299static void
301{
302 struct sc_info *sc = ch->parent;
303 uint32_t base;
304 int i;
305
309 if ((sndbuf_getblksz(ch->buffer) != ch->blksz ||
312 device_printf(sc->dev, "%s: failed blksz=%u blkcnt=%u\n",
313 __func__, ch->blksz, ch->blkcnt);
315
316 for (i = 0; i < ICH_DTBL_LENGTH; i++) {
317 ch->dtbl[i].buffer = base + (ch->blksz * (i % ch->blkcnt));
319 | (ch->blksz / ch->parent->sample_size);
320 }
321}
322
323static int
324ich_resetchan(struct sc_info *sc, int num)
325{
326 int i, cr, regbase;
327
328 if (num == 0)
329 regbase = ICH_REG_PO_BASE;
330 else if (num == 1)
331 regbase = ICH_REG_PI_BASE;
332 else if (num == 2)
333 regbase = ICH_REG_MC_BASE;
334 else
335 return (ENXIO);
336
337 ich_wr(sc, regbase + ICH_REG_X_CR, 0, 1);
338#if 1
339 /* This may result in no sound output on NForce 2 MBs, see PR 73987 */
340 DELAY(100);
341#else
342 (void)ich_rd(sc, regbase + ICH_REG_X_CR, 1);
343#endif
344 ich_wr(sc, regbase + ICH_REG_X_CR, ICH_X_CR_RR, 1);
345 for (i = 0; i < ICH_TIMEOUT; i++) {
346 cr = ich_rd(sc, regbase + ICH_REG_X_CR, 1);
347 if (cr == 0)
348 return (0);
349 DELAY(1);
350 }
351
352 if (sc->flags & ICH_IGNORE_RESET)
353 return (0);
354#if 0
355 else if (sc->vendor == NVIDIA_VENDORID) {
356 sc->flags |= ICH_IGNORE_RESET;
357 device_printf(sc->dev, "ignoring reset failure!\n");
358 return (0);
359 }
360#endif
361
362 device_printf(sc->dev, "cannot reset channel %d\n", num);
363 return (ENXIO);
364}
365
366/* -------------------------------------------------------------------- */
367/* channel interface */
368
369static void *
370ichchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
371{
372 struct sc_info *sc = devinfo;
373 struct sc_chinfo *ch;
374 unsigned int num;
375
376 ICH_LOCK(sc);
377 num = sc->chnum++;
378 ch = &sc->ch[num];
379 ch->num = num;
380 ch->buffer = b;
381 ch->channel = c;
382 ch->parent = sc;
383 ch->run = 0;
384 ch->dtbl = sc->dtbl + (ch->num * ICH_DTBL_LENGTH);
385 ch->desc_addr = sc->desc_addr +
386 (ch->num * ICH_DTBL_LENGTH * sizeof(struct ich_desc));
387 ch->blkcnt = sc->blkcnt;
388 ch->blksz = sc->bufsz / ch->blkcnt;
389
390 switch(ch->num) {
391 case 0: /* play */
392 KASSERT(dir == PCMDIR_PLAY, ("wrong direction"));
394 ch->spdreg = (sc->hasvra) ? AC97_REGEXT_FDACRATE : 0;
396 break;
397
398 case 1: /* record */
399 KASSERT(dir == PCMDIR_REC, ("wrong direction"));
401 ch->spdreg = (sc->hasvra) ? AC97_REGEXT_LADCRATE : 0;
403 break;
404
405 case 2: /* mic */
406 KASSERT(dir == PCMDIR_REC, ("wrong direction"));
408 ch->spdreg = (sc->hasvrm) ? AC97_REGEXT_MADCRATE : 0;
410 break;
411
412 default:
413 return (NULL);
414 }
415
416 if (sc->flags & ICH_FIXED_RATE)
417 ch->spdreg = 0;
418
419 ICH_UNLOCK(sc);
420 if (sndbuf_alloc(ch->buffer, sc->chan_dmat,
421 ((sc->flags & ICH_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0),
422 sc->bufsz) != 0)
423 return (NULL);
424
425 ICH_LOCK(sc);
426 ich_wr(sc, ch->regbase + ICH_REG_X_BDBAR, (uint32_t)(ch->desc_addr), 4);
427 ICH_UNLOCK(sc);
428
429 return (ch);
430}
431
432static int
433ichchan_setformat(kobj_t obj, void *data, uint32_t format)
434{
435
436 ICH_DEBUG(
437 struct sc_chinfo *ch = data;
438 struct sc_info *sc = ch->parent;
439 if (!(sc->flags & ICH_CALIBRATE_DONE))
440 device_printf(sc->dev,
441 "WARNING: %s() called before calibration!\n",
442 __func__);
443 );
444
445 return (0);
446}
447
448static uint32_t
449ichchan_setspeed(kobj_t obj, void *data, uint32_t speed)
450{
451 struct sc_chinfo *ch = data;
452 struct sc_info *sc = ch->parent;
453
454 ICH_DEBUG(
455 if (!(sc->flags & ICH_CALIBRATE_DONE))
456 device_printf(sc->dev,
457 "WARNING: %s() called before calibration!\n",
458 __func__);
459 );
460
461 if (ch->spdreg) {
462 int r, ac97rate;
463
464 ICH_LOCK(sc);
465 if (sc->ac97rate <= 32000 || sc->ac97rate >= 64000)
466 sc->ac97rate = 48000;
467 ac97rate = sc->ac97rate;
468 ICH_UNLOCK(sc);
469 r = (speed * 48000) / ac97rate;
470 /*
471 * Cast the return value of ac97_setrate() to uint64 so that
472 * the math don't overflow into the negative range.
473 */
474 ch->spd = ((uint64_t)ac97_setrate(sc->codec, ch->spdreg, r) *
475 ac97rate) / 48000;
476 } else {
477 ch->spd = 48000;
478 }
479 return (ch->spd);
480}
481
482static uint32_t
483ichchan_setblocksize(kobj_t obj, void *data, uint32_t blocksize)
484{
485 struct sc_chinfo *ch = data;
486 struct sc_info *sc = ch->parent;
487
488 ICH_DEBUG(
489 if (!(sc->flags & ICH_CALIBRATE_DONE))
490 device_printf(sc->dev,
491 "WARNING: %s() called before calibration!\n",
492 __func__);
493 );
494
495 if (sc->flags & ICH_HIGH_LATENCY)
497
500 blocksize &= ~(ICH_MIN_BLKSZ - 1);
501 ch->blksz = blocksize;
503 ICH_LOCK(sc);
504 ich_wr(sc, ch->regbase + ICH_REG_X_LVI, ch->blkcnt - 1, 1);
505 ICH_UNLOCK(sc);
506
507 return (ch->blksz);
508}
509
510static int
511ichchan_trigger(kobj_t obj, void *data, int go)
512{
513 struct sc_chinfo *ch = data;
514 struct sc_info *sc = ch->parent;
515
516 ICH_DEBUG(
517 if (!(sc->flags & ICH_CALIBRATE_DONE))
518 device_printf(sc->dev,
519 "WARNING: %s() called before calibration!\n",
520 __func__);
521 );
522
523 switch (go) {
524 case PCMTRIG_START:
525 ch->run = 1;
526 ICH_LOCK(sc);
527 ich_wr(sc, ch->regbase + ICH_REG_X_BDBAR, (uint32_t)(ch->desc_addr), 4);
529 ICH_UNLOCK(sc);
530 break;
531 case PCMTRIG_STOP:
532 case PCMTRIG_ABORT:
533 ICH_LOCK(sc);
534 ich_resetchan(sc, ch->num);
535 ICH_UNLOCK(sc);
536 ch->run = 0;
537 break;
538 default:
539 break;
540 }
541 return (0);
542}
543
544static uint32_t
545ichchan_getptr(kobj_t obj, void *data)
546{
547 struct sc_chinfo *ch = data;
548 struct sc_info *sc = ch->parent;
549 uint32_t pos;
550
551 ICH_DEBUG(
552 if (!(sc->flags & ICH_CALIBRATE_DONE))
553 device_printf(sc->dev,
554 "WARNING: %s() called before calibration!\n",
555 __func__);
556 );
557
558 ICH_LOCK(sc);
559 ch->civ = ich_rd(sc, ch->regbase + ICH_REG_X_CIV, 1) % ch->blkcnt;
560 ICH_UNLOCK(sc);
561
562 pos = ch->civ * ch->blksz;
563
564 return (pos);
565}
566
567static struct pcmchan_caps *
568ichchan_getcaps(kobj_t obj, void *data)
569{
570 struct sc_chinfo *ch = data;
571
572 ICH_DEBUG(
573 struct sc_info *sc = ch->parent;
574
575 if (!(sc->flags & ICH_CALIBRATE_DONE))
576 device_printf(ch->parent->dev,
577 "WARNING: %s() called before calibration!\n",
578 __func__);
579 );
580
581 return ((ch->spdreg) ? &ich_vrcaps : &ich_caps);
582}
583
584static kobj_method_t ichchan_methods[] = {
585 KOBJMETHOD(channel_init, ichchan_init),
586 KOBJMETHOD(channel_setformat, ichchan_setformat),
587 KOBJMETHOD(channel_setspeed, ichchan_setspeed),
588 KOBJMETHOD(channel_setblocksize, ichchan_setblocksize),
589 KOBJMETHOD(channel_trigger, ichchan_trigger),
590 KOBJMETHOD(channel_getptr, ichchan_getptr),
591 KOBJMETHOD(channel_getcaps, ichchan_getcaps),
593};
595
596/* -------------------------------------------------------------------- */
597/* The interrupt handler */
598
599static void
600ich_intr(void *p)
601{
602 struct sc_info *sc = (struct sc_info *)p;
603 struct sc_chinfo *ch;
604 uint32_t cbi, lbi, lvi, st, gs;
605 int i;
606
607 ICH_LOCK(sc);
608
609 ICH_DEBUG(
610 if (!(sc->flags & ICH_CALIBRATE_DONE))
611 device_printf(sc->dev,
612 "WARNING: %s() called before calibration!\n",
613 __func__);
614 );
615
618 /* Clear resume interrupt(s) - nothing doing with them */
619 ich_wr(sc, ICH_REG_GLOB_STA, gs, 4);
620 }
622
623 for (i = 0; i < 3; i++) {
624 ch = &sc->ch[i];
625 if ((ch->imask & gs) == 0)
626 continue;
627 gs &= ~ch->imask;
628 st = ich_rd(sc, ch->regbase +
630 2);
632 if (st & (ICH_X_SR_BCIS | ICH_X_SR_LVBCI)) {
633 /* block complete - update buffer */
634 if (ch->run) {
635 ICH_UNLOCK(sc);
636 chn_intr(ch->channel);
637 ICH_LOCK(sc);
638 }
639 lvi = ich_rd(sc, ch->regbase + ICH_REG_X_LVI, 1);
640 cbi = ch->civ % ch->blkcnt;
641 if (cbi == 0)
642 cbi = ch->blkcnt - 1;
643 else
644 cbi--;
645 lbi = lvi % ch->blkcnt;
646 if (cbi >= lbi)
647 lvi += cbi - lbi;
648 else
649 lvi += cbi + ch->blkcnt - lbi;
650 lvi %= ICH_DTBL_LENGTH;
651 ich_wr(sc, ch->regbase + ICH_REG_X_LVI, lvi, 1);
652 }
653 /* clear status bit */
654 ich_wr(sc, ch->regbase +
656 st, 2);
657 }
658 ICH_UNLOCK(sc);
659 if (gs != 0) {
660 device_printf(sc->dev,
661 "Unhandled interrupt, gs_intr = %x\n", gs);
662 }
663}
664
665/* ------------------------------------------------------------------------- */
666/* Sysctl to control ac97 speed (some boards appear to end up using
667 * XTAL_IN rather than BIT_CLK for link timing).
668 */
669
670static int
672{
673 /* XXX: this should move to a device specific sysctl "dev.pcm.X.yyy"
674 via device_get_sysctl_*() as discussed on multimedia@ in msg-id
675 <861wujij2q.fsf@xps.des.no> */
676 SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->dev),
677 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
678 OID_AUTO, "ac97rate", CTLFLAG_RW,
679 &sc->ac97rate, 48000,
680 "AC97 link rate (default = 48000)");
681
682 return (0);
683}
684
685static void
687{
688 char status[SND_STATUSLEN];
689
690 snprintf(status, SND_STATUSLEN,
691 "at io 0x%jx, 0x%jx irq %jd bufsz %u %s",
692 rman_get_start(sc->nambar), rman_get_start(sc->nabmbar),
693 rman_get_start(sc->irq), sc->bufsz,PCM_KLDSTRING(snd_ich));
694
695 if (bootverbose && (sc->flags & ICH_DMA_NOCACHE))
696 device_printf(sc->dev,
697 "PCI Master abort workaround enabled\n");
698
700}
701
702/* -------------------------------------------------------------------- */
703/* Calibrate card to determine the clock source. The source maybe a
704 * function of the ac97 codec initialization code (to be investigated).
705 */
706
707static void
709{
710 struct sc_info *sc;
711 struct sc_chinfo *ch;
712 struct timeval t1, t2;
713 uint8_t ociv, nciv;
714 uint32_t wait_us, actual_48k_rate, oblkcnt;
715
716 sc = (struct sc_info *)arg;
717 ICH_LOCK(sc);
718 ch = &sc->ch[1];
719
720 if (sc->intrhook.ich_func != NULL) {
721 config_intrhook_disestablish(&sc->intrhook);
722 sc->intrhook.ich_func = NULL;
723 }
724
725 /*
726 * Grab audio from input for fixed interval and compare how
727 * much we actually get with what we expect. Interval needs
728 * to be sufficiently short that no interrupts are
729 * generated.
730 */
731
732 KASSERT(ch->regbase == ICH_REG_PI_BASE, ("wrong direction"));
733
734 oblkcnt = ch->blkcnt;
735 ch->blkcnt = 2;
737 ICH_UNLOCK(sc);
739 ICH_LOCK(sc);
740 sc->flags &= ~ICH_CALIBRATE_DONE;
741
742 /*
743 * our data format is stereo, 16 bit so each sample is 4 bytes.
744 * assuming we get 48000 samples per second, we get 192000 bytes/sec.
745 * we're going to start recording with interrupts disabled and measure
746 * the time taken for one block to complete. we know the block size,
747 * we know the time in microseconds, we calculate the sample rate:
748 *
749 * actual_rate [bps] = bytes / (time [s] * 4)
750 * actual_rate [bps] = (bytes * 1000000) / (time [us] * 4)
751 * actual_rate [Hz] = (bytes * 250000) / time [us]
752 */
753
754 /* prepare */
755 ociv = ich_rd(sc, ch->regbase + ICH_REG_X_CIV, 1);
756 nciv = ociv;
757 ich_wr(sc, ch->regbase + ICH_REG_X_BDBAR, (uint32_t)(ch->desc_addr), 4);
758
759 /* start */
760 microtime(&t1);
762
763 /* wait */
764 do {
765 microtime(&t2);
766 if (t2.tv_sec - t1.tv_sec > 1)
767 break;
768 nciv = ich_rd(sc, ch->regbase + ICH_REG_X_CIV, 1);
769 } while (nciv == ociv);
770
771 /* stop */
772 ich_wr(sc, ch->regbase + ICH_REG_X_CR, 0, 1);
773
774 /* reset */
775 DELAY(100);
777 ch->blkcnt = oblkcnt;
778
779 /* turn time delta into us */
780 wait_us = ((t2.tv_sec - t1.tv_sec) * 1000000) + t2.tv_usec - t1.tv_usec;
781
782 if (nciv == ociv) {
783 device_printf(sc->dev, "ac97 link rate calibration timed out after %d us\n", wait_us);
785 ICH_UNLOCK(sc);
786 ich_setstatus(sc);
787 return;
788 }
789
790 /* Just in case the timecounter screwed. It is possible, really. */
791 if (wait_us > 0)
792 actual_48k_rate = ((uint64_t)ch->blksz * 250000) / wait_us;
793 else
794 actual_48k_rate = 48000;
795
796 if (actual_48k_rate < 47500 || actual_48k_rate > 48500) {
797 sc->ac97rate = actual_48k_rate;
798 } else {
799 sc->ac97rate = 48000;
800 }
801
802 if (bootverbose || sc->ac97rate != 48000) {
803 device_printf(sc->dev, "measured ac97 link rate at %d Hz", actual_48k_rate);
804 if (sc->ac97rate != actual_48k_rate)
805 printf(", will use %d Hz", sc->ac97rate);
806 printf("\n");
807 }
809 ICH_UNLOCK(sc);
810
811 ich_setstatus(sc);
812
813 return;
814}
815
816/* -------------------------------------------------------------------- */
817/* Probe and attach the card */
818
819static void
820ich_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error)
821{
822 struct sc_info *sc = (struct sc_info *)arg;
823 sc->desc_addr = segs->ds_addr;
824 return;
825}
826
827static int
828ich_init(struct sc_info *sc)
829{
830 uint32_t stat;
831
833 DELAY(600000);
834 stat = ich_rd(sc, ICH_REG_GLOB_STA, 4);
835
836 if ((stat & ICH_GLOB_STA_PCR) == 0) {
837 /* ICH4/ICH5 may fail when busmastering is enabled. Continue */
838 if (sc->vendor == INTEL_VENDORID && (
839 sc->devid == INTEL_82801DB || sc->devid == INTEL_82801EB ||
840 sc->devid == INTEL_6300ESB || sc->devid == INTEL_82801FB ||
841 sc->devid == INTEL_82801GB)) {
842 sc->flags |= ICH_IGNORE_PCR;
843 device_printf(sc->dev, "primary codec not ready!\n");
844 }
845 }
846
847#if 0
849#else
851#endif
852
853 if (ich_resetchan(sc, 0) || ich_resetchan(sc, 1))
854 return (ENXIO);
855 if (sc->hasmic && ich_resetchan(sc, 2))
856 return (ENXIO);
857
858 return (0);
859}
860
861static int
863{
864 int i;
865 uint16_t devid, vendor;
866
867 vendor = pci_get_vendor(dev);
868 devid = pci_get_device(dev);
869 for (i = 0; i < sizeof(ich_devs)/sizeof(ich_devs[0]); i++) {
870 if (vendor == ich_devs[i].vendor &&
871 devid == ich_devs[i].devid) {
872 device_set_desc(dev, ich_devs[i].name);
873 /* allow a better driver to override us */
874 if ((ich_devs[i].options & PROBE_LOW) != 0)
875 return (BUS_PROBE_LOW_PRIORITY);
876 return (BUS_PROBE_DEFAULT);
877 }
878 }
879 return (ENXIO);
880}
881
882static int
884{
885 uint32_t subdev;
886 uint16_t extcaps;
887 uint16_t devid, vendor;
888 struct sc_info *sc;
889 int i;
890
891 sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
892 sc->ich_lock = snd_mtxcreate(device_get_nameunit(dev), "snd_ich softc");
893 sc->dev = dev;
894
895 vendor = sc->vendor = pci_get_vendor(dev);
896 devid = sc->devid = pci_get_device(dev);
897 subdev = (pci_get_subdevice(dev) << 16) | pci_get_subvendor(dev);
898 /*
899 * The SiS 7012 register set isn't quite like the standard ich.
900 * There really should be a general "quirks" mechanism.
901 */
902 if (vendor == SIS_VENDORID && devid == SIS_7012) {
903 sc->swap_reg = 1;
904 sc->sample_size = 1;
905 } else {
906 sc->swap_reg = 0;
907 sc->sample_size = 2;
908 }
909
910 /*
911 * Intel 440MX Errata #36
912 * - AC97 Soft Audio and Soft Modem Master Abort Errata
913 *
914 * http://www.intel.com/design/chipsets/specupdt/245051.htm
915 */
917 sc->flags |= ICH_DMA_NOCACHE;
918
919 /*
920 * Enable bus master. On ich4/5 this may prevent the detection of
921 * the primary codec becoming ready in ich_init().
922 */
923 pci_enable_busmaster(dev);
924
925 /*
926 * By default, ich4 has NAMBAR and NABMBAR i/o spaces as
927 * read-only. Need to enable "legacy support", by poking into
928 * pci config space. The driver should use MMBAR and MBBAR,
929 * but doing so will mess things up here. ich4 has enough new
930 * features it warrants it's own driver.
931 */
935 sc->nambarid = PCIR_MMBAR;
936 sc->nabmbarid = PCIR_MBBAR;
937 sc->regtype = SYS_RES_MEMORY;
938 pci_write_config(dev, PCIR_ICH_LEGACY, ICH_LEGACY_ENABLE, 1);
939 } else {
940 sc->nambarid = PCIR_NAMBAR;
942 sc->regtype = SYS_RES_IOPORT;
943 }
944
945 sc->nambar = bus_alloc_resource_any(dev, sc->regtype,
946 &sc->nambarid, RF_ACTIVE);
947 sc->nabmbar = bus_alloc_resource_any(dev, sc->regtype,
948 &sc->nabmbarid, RF_ACTIVE);
949
950 if (!sc->nambar || !sc->nabmbar) {
951 device_printf(dev, "unable to map IO port space\n");
952 goto bad;
953 }
954
955 sc->nambart = rman_get_bustag(sc->nambar);
956 sc->nambarh = rman_get_bushandle(sc->nambar);
957 sc->nabmbart = rman_get_bustag(sc->nabmbar);
958 sc->nabmbarh = rman_get_bushandle(sc->nabmbar);
959
962
963 if (resource_int_value(device_get_name(dev),
964 device_get_unit(dev), "blocksize", &i) == 0 && i > 0) {
965 sc->blkcnt = sc->bufsz / i;
966 i = 0;
967 while (sc->blkcnt >> i)
968 i++;
969 sc->blkcnt = 1 << (i - 1);
970 if (sc->blkcnt < ICH_MIN_BLKCNT)
972 else if (sc->blkcnt > ICH_MAX_BLKCNT)
974 } else
976
977 if (resource_int_value(device_get_name(dev),
978 device_get_unit(dev), "highlatency", &i) == 0 && i != 0) {
979 sc->flags |= ICH_HIGH_LATENCY;
981 }
982
983 if (resource_int_value(device_get_name(dev),
984 device_get_unit(dev), "fixedrate", &i) == 0 && i != 0)
985 sc->flags |= ICH_FIXED_RATE;
986
987 if (resource_int_value(device_get_name(dev),
988 device_get_unit(dev), "micchannel_enabled", &i) == 0 && i != 0)
989 sc->hasmic = 1;
990
991 sc->irqid = 0;
992 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
993 RF_ACTIVE | RF_SHAREABLE);
994 if (!sc->irq || snd_setup_intr(dev, sc->irq, INTR_MPSAFE, ich_intr,
995 sc, &sc->ih)) {
996 device_printf(dev, "unable to map interrupt\n");
997 goto bad;
998 }
999
1000 if (ich_init(sc)) {
1001 device_printf(dev, "unable to initialize the card\n");
1002 goto bad;
1003 }
1004
1005 sc->codec = AC97_CREATE(dev, sc, ich_ac97);
1006 if (sc->codec == NULL)
1007 goto bad;
1008
1009 /*
1010 * Turn on inverted external amplifier sense flags for few
1011 * 'special' boards.
1012 */
1013 switch (subdev) {
1014 case 0x202f161f: /* Gateway 7326GZ */
1015 case 0x203a161f: /* Gateway 4028GZ */
1016 case 0x203e161f: /* Gateway 3520GZ/M210 */
1017 case 0x204c161f: /* Kvazar-Micro Senator 3592XT */
1018 case 0x8144104d: /* Sony VAIO PCG-TR* */
1019 case 0x8197104d: /* Sony S1XP */
1020 case 0x81c0104d: /* Sony VAIO type T */
1021 case 0x81c5104d: /* Sony VAIO VGN B1VP/B1XP */
1022 case 0x3089103c: /* Compaq Presario B3800 */
1023 case 0x309a103c: /* HP Compaq nx4300 */
1024 case 0x82131033: /* NEC VersaPro VJ10F/BH */
1025 case 0x82be1033: /* NEC VersaPro VJ12F/CH */
1027 break;
1028 default:
1029 break;
1030 }
1031
1033
1034 /* check and set VRA function */
1035 extcaps = ac97_getextcaps(sc->codec);
1036 sc->hasvra = extcaps & AC97_EXTCAP_VRA;
1037 sc->hasvrm = extcaps & AC97_EXTCAP_VRM;
1038 sc->hasmic = (sc->hasmic != 0 &&
1039 (ac97_getcaps(sc->codec) & AC97_CAP_MICCHANNEL)) ? 1 : 0;
1040 ac97_setextmode(sc->codec, sc->hasvra | sc->hasvrm);
1041
1042 sc->dtbl_size = sizeof(struct ich_desc) * ICH_DTBL_LENGTH *
1043 ((sc->hasmic) ? 3 : 2);
1044
1045 /* BDL tag */
1046 if (bus_dma_tag_create(bus_get_dma_tag(dev), 8, 0,
1047 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1048 sc->dtbl_size, 1, 0x3ffff, 0, NULL, NULL, &sc->dmat) != 0) {
1049 device_printf(dev, "unable to create dma tag\n");
1050 goto bad;
1051 }
1052
1053 /* PCM channel tag */
1054 if (bus_dma_tag_create(bus_get_dma_tag(dev), ICH_MIN_BLKSZ, 0,
1055 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1056 sc->bufsz, 1, 0x3ffff, 0, NULL, NULL, &sc->chan_dmat) != 0) {
1057 device_printf(dev, "unable to create dma tag\n");
1058 goto bad;
1059 }
1060
1061 if (bus_dmamem_alloc(sc->dmat, (void **)&sc->dtbl, BUS_DMA_NOWAIT |
1062 ((sc->flags & ICH_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0),
1063 &sc->dtmap))
1064 goto bad;
1065
1066 if (bus_dmamap_load(sc->dmat, sc->dtmap, sc->dtbl, sc->dtbl_size,
1067 ich_setmap, sc, 0))
1068 goto bad;
1069
1070 if (pcm_register(dev, sc, 1, (sc->hasmic) ? 2 : 1))
1071 goto bad;
1072
1073 pcm_addchan(dev, PCMDIR_PLAY, &ichchan_class, sc); /* play */
1074 pcm_addchan(dev, PCMDIR_REC, &ichchan_class, sc); /* record */
1075 if (sc->hasmic)
1076 pcm_addchan(dev, PCMDIR_REC, &ichchan_class, sc); /* record mic */
1077
1078 if (sc->flags & ICH_FIXED_RATE) {
1080 ich_setstatus(sc);
1081 } else {
1082 ich_initsys(sc);
1083
1084 sc->intrhook.ich_func = ich_calibrate;
1085 sc->intrhook.ich_arg = sc;
1086 if (cold == 0 ||
1087 config_intrhook_establish(&sc->intrhook) != 0) {
1088 sc->intrhook.ich_func = NULL;
1089 ich_calibrate(sc);
1090 }
1091 }
1092
1093 return (0);
1094
1095bad:
1096 if (sc->codec)
1097 ac97_destroy(sc->codec);
1098 if (sc->ih)
1099 bus_teardown_intr(dev, sc->irq, sc->ih);
1100 if (sc->irq)
1101 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
1102 if (sc->nambar)
1103 bus_release_resource(dev, sc->regtype,
1104 sc->nambarid, sc->nambar);
1105 if (sc->nabmbar)
1106 bus_release_resource(dev, sc->regtype,
1107 sc->nabmbarid, sc->nabmbar);
1108 if (sc->dtmap)
1109 bus_dmamap_unload(sc->dmat, sc->dtmap);
1110 if (sc->dtbl)
1111 bus_dmamem_free(sc->dmat, sc->dtbl, sc->dtmap);
1112 if (sc->chan_dmat)
1113 bus_dma_tag_destroy(sc->chan_dmat);
1114 if (sc->dmat)
1115 bus_dma_tag_destroy(sc->dmat);
1116 if (sc->ich_lock)
1117 snd_mtxfree(sc->ich_lock);
1118 free(sc, M_DEVBUF);
1119 return (ENXIO);
1120}
1121
1122static int
1124{
1125 struct sc_info *sc;
1126 int r;
1127
1128 r = pcm_unregister(dev);
1129 if (r)
1130 return (r);
1131 sc = pcm_getdevinfo(dev);
1132
1133 bus_teardown_intr(dev, sc->irq, sc->ih);
1134 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
1135 bus_release_resource(dev, sc->regtype, sc->nambarid, sc->nambar);
1136 bus_release_resource(dev, sc->regtype, sc->nabmbarid, sc->nabmbar);
1137 bus_dmamap_unload(sc->dmat, sc->dtmap);
1138 bus_dmamem_free(sc->dmat, sc->dtbl, sc->dtmap);
1139 bus_dma_tag_destroy(sc->chan_dmat);
1140 bus_dma_tag_destroy(sc->dmat);
1141 snd_mtxfree(sc->ich_lock);
1142 free(sc, M_DEVBUF);
1143 return (0);
1144}
1145
1146static void
1148{
1149 int i;
1150 uint32_t control;
1151
1152 control = ich_rd(sc, ICH_REG_GLOB_CNT, 4);
1153 control &= ~(ICH_GLOB_CTL_SHUT);
1154 control |= (control & ICH_GLOB_CTL_COLD) ?
1156 ich_wr(sc, ICH_REG_GLOB_CNT, control, 4);
1157
1158 for (i = 500000; i; i--) {
1160 break; /* or ICH_SCR? */
1161 DELAY(1);
1162 }
1163
1164 if (i <= 0)
1165 printf("%s: time out\n", __func__);
1166}
1167
1168static int
1170{
1171 struct sc_info *sc;
1172 int i;
1173
1174 sc = pcm_getdevinfo(dev);
1175 ICH_LOCK(sc);
1176 for (i = 0 ; i < 3; i++) {
1177 sc->ch[i].run_save = sc->ch[i].run;
1178 if (sc->ch[i].run) {
1179 ICH_UNLOCK(sc);
1180 ichchan_trigger(0, &sc->ch[i], PCMTRIG_ABORT);
1181 ICH_LOCK(sc);
1182 }
1183 }
1184 ICH_UNLOCK(sc);
1185 return (0);
1186}
1187
1188static int
1190{
1191 struct sc_info *sc;
1192 int err, i;
1193
1194 sc = pcm_getdevinfo(dev);
1195
1196 ICH_LOCK(sc);
1197 /* Reinit audio device */
1198 err = ich_init(sc);
1199 if (err != 0) {
1200 device_printf(dev, "unable to reinitialize the card\n");
1201 ICH_UNLOCK(sc);
1202 return (err);
1203 }
1204 /* Reinit mixer */
1206 ICH_UNLOCK(sc);
1207 ac97_setextmode(sc->codec, sc->hasvra | sc->hasvrm);
1208 if (mixer_reinit(dev) == -1) {
1209 device_printf(dev, "unable to reinitialize the mixer\n");
1210 return (ENXIO);
1211 }
1212 /* Re-start DMA engines */
1213 for (i = 0 ; i < 3; i++) {
1214 struct sc_chinfo *ch = &sc->ch[i];
1215 if (sc->ch[i].run_save) {
1216 ichchan_setblocksize(0, ch, ch->blksz);
1217 ichchan_setspeed(0, ch, ch->spd);
1219 }
1220 }
1221 return (0);
1222}
1223
1224static device_method_t ich_methods[] = {
1225 /* Device interface */
1226 DEVMETHOD(device_probe, ich_pci_probe),
1227 DEVMETHOD(device_attach, ich_pci_attach),
1228 DEVMETHOD(device_detach, ich_pci_detach),
1229 DEVMETHOD(device_suspend, ich_pci_suspend),
1230 DEVMETHOD(device_resume, ich_pci_resume),
1231 { 0, 0 }
1232};
1233
1234static driver_t ich_driver = {
1235 "pcm",
1238};
1239
1242MODULE_VERSION(snd_ich, 1);
int ac97_setextmode(struct ac97_info *codec, u_int16_t mode)
Definition: ac97.c:383
u_int16_t ac97_getcaps(struct ac97_info *codec)
Definition: ac97.c:411
u_int32_t ac97_getflags(struct ac97_info *codec)
Definition: ac97.c:876
u_int16_t ac97_getextcaps(struct ac97_info *codec)
Definition: ac97.c:405
kobj_class_t ac97_getmixerclass(void)
Definition: ac97.c:1097
void ac97_destroy(struct ac97_info *codec)
Definition: ac97.c:860
void ac97_setflags(struct ac97_info *codec, u_int32_t val)
Definition: ac97.c:870
int ac97_setrate(struct ac97_info *codec, int which, int rate)
Definition: ac97.c:352
#define AC97_EXTCAP_VRM
Definition: ac97.h:70
#define AC97_CREATE(dev, devinfo, cls)
Definition: ac97.h:89
#define AC97_REGEXT_FDACRATE
Definition: ac97.h:75
#define AC97_REGEXT_MADCRATE
Definition: ac97.h:79
#define AC97_F_EAPD_INV
Definition: ac97.h:85
#define AC97_CAP_MICCHANNEL
Definition: ac97.h:34
#define AC97_REGEXT_LADCRATE
Definition: ac97.h:78
#define AC97_EXTCAP_VRA
Definition: ac97.h:68
u_int32_t data
Definition: ac97_if.m:60
int regno
Definition: ac97_if.m:53
void * devinfo
Definition: ac97_if.m:47
uint16_t vendor
Definition: atiixp.c:172
uint16_t devid
Definition: atiixp.c:173
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
const char * name
Definition: audio_soc.c:90
int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
Definition: buffer.c:93
unsigned int sndbuf_getblkcnt(struct snd_dbuf *b)
Definition: buffer.c:391
bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf)
Definition: buffer.c:66
unsigned int sndbuf_getblksz(struct snd_dbuf *b)
Definition: buffer.c:403
unsigned int sndbuf_getmaxsize(struct snd_dbuf *b)
Definition: buffer.c:441
int sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
Definition: buffer.c:164
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 PCMTRIG_STOP
Definition: channel.h:347
#define PCMDIR_REC
Definition: channel.h:341
#define PCMTRIG_ABORT
Definition: channel.h:348
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
uint16_t base
Definition: hdaa.c:124
int dir
Definition: hdac_if.m:45
#define ICH_FIXED_RATE
Definition: ich.c:97
#define INTEL_82801FB
Definition: ich.c:68
#define ICH_IGNORE_RESET
Definition: ich.c:96
#define INTEL_82801EB
Definition: ich.c:66
static driver_t ich_driver
Definition: ich.c:1234
static int ich_pci_attach(device_t dev)
Definition: ich.c:883
#define ICH_DEBUG(...)
Definition: ich.c:91
static int ich_rdcd(kobj_t obj, void *devinfo, int regno)
Definition: ich.c:267
#define ICH_DMA_NOCACHE
Definition: ich.c:98
static void ich_setstatus(struct sc_info *sc)
Definition: ich.c:686
#define ICH_TIMEOUT
Definition: ich.c:45
#define ICH_DEFAULT_BUFSZ
Definition: ich.c:47
#define INTEL_6300ESB
Definition: ich.c:67
#define INTEL_82801BA
Definition: ich.c:63
#define ICH_IGNORE_PCR
Definition: ich.c:95
#define ICH_MIN_BUFSZ
Definition: ich.c:49
static void * ichchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
Definition: ich.c:370
#define AMD_768
Definition: ich.c:79
#define NVIDIA_NFORCE2_400
Definition: ich.c:73
static device_method_t ich_methods[]
Definition: ich.c:1224
#define ICH_HIGH_LATENCY
Definition: ich.c:99
#define ICH_MIN_BLKSZ
Definition: ich.c:53
static const struct ich_type ich_devs[]
#define NVIDIA_NFORCE3_250
Definition: ich.c:75
static kobj_method_t ich_ac97_methods[]
Definition: ich.c:289
#define NVIDIA_VENDORID
Definition: ich.c:57
static kobj_method_t ichchan_methods[]
Definition: ich.c:584
static void ich_calibrate(void *arg)
Definition: ich.c:708
#define ICH_DTBL_LENGTH
Definition: ich.c:46
static __inline void ich_wr(struct sc_info *sc, int regno, uint32_t data, int size)
Definition: ich.c:231
static int ich_init(struct sc_info *sc)
Definition: ich.c:828
static int ichchan_setformat(kobj_t obj, void *data, uint32_t format)
Definition: ich.c:433
#define NVIDIA_NFORCE4_MCP
Definition: ich.c:78
static struct pcmchan_caps ich_vrcaps
Definition: ich.c:210
static int ich_pci_suspend(device_t dev)
Definition: ich.c:1169
#define NVIDIA_NFORCE4
Definition: ich.c:76
#define NVIDIA_NFORCE2
Definition: ich.c:72
#define INTEL_82801GB
Definition: ich.c:69
static void ich_pci_codec_reset(struct sc_info *sc)
Definition: ich.c:1147
#define INTEL_82801AA
Definition: ich.c:61
static uint32_t ichchan_setspeed(kobj_t obj, void *data, uint32_t speed)
Definition: ich.c:449
#define NVIDIA_NFORCE
Definition: ich.c:71
#define INTEL_VENDORID
Definition: ich.c:55
static uint32_t ichchan_setblocksize(kobj_t obj, void *data, uint32_t blocksize)
Definition: ich.c:483
CHANNEL_DECLARE(ichchan)
SND_DECLARE_FILE("$FreeBSD$")
#define ICH_MAX_BLKCNT
Definition: ich.c:51
#define AMD_8111
Definition: ich.c:80
#define PROBE_LOW
Definition: ich.c:105
static int ich_wrcd(kobj_t obj, void *devinfo, int regno, uint32_t data)
Definition: ich.c:278
DRIVER_MODULE(snd_ich, pci, ich_driver, pcm_devclass, 0, 0)
static int ich_pci_resume(device_t dev)
Definition: ich.c:1189
static struct pcmchan_caps ich_caps
Definition: ich.c:211
static int ichchan_trigger(kobj_t obj, void *data, int go)
Definition: ich.c:511
AC97_DECLARE(ich_ac97)
#define ICH_CALIBRATE_DONE
Definition: ich.c:94
static uint32_t ichchan_getptr(kobj_t obj, void *data)
Definition: ich.c:545
#define ICH_MAX_BUFSZ
Definition: ich.c:48
static void ich_filldtbl(struct sc_chinfo *ch)
Definition: ich.c:300
#define ICH_LOCK(sc)
Definition: ich.c:82
#define NVIDIA_NFORCE3
Definition: ich.c:74
static int ich_initsys(struct sc_info *sc)
Definition: ich.c:671
static int ich_pci_detach(device_t dev)
Definition: ich.c:1123
#define INTEL_82440MX
Definition: ich.c:60
static int ich_pci_probe(device_t dev)
Definition: ich.c:862
MODULE_VERSION(snd_ich, 1)
static struct pcmchan_caps * ichchan_getcaps(kobj_t obj, void *data)
Definition: ich.c:568
#define ICH_UNLOCK(sc)
Definition: ich.c:83
#define SIS_7012
Definition: ich.c:70
MODULE_DEPEND(snd_ich, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
#define NVIDIA_NFORCE_410_MCP
Definition: ich.c:77
static int ich_resetchan(struct sc_info *sc, int num)
Definition: ich.c:324
static void ich_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error)
Definition: ich.c:820
static uint32_t ich_fmt[]
Definition: ich.c:206
static int ich_waitcd(void *devinfo)
Definition: ich.c:248
#define ICH_DEFAULT_BLKCNT
Definition: ich.c:50
#define AMD_VENDORID
Definition: ich.c:58
static void ich_intr(void *p)
Definition: ich.c:600
#define INTEL_82801DB
Definition: ich.c:65
#define INTEL_82801CA
Definition: ich.c:64
static __inline uint32_t ich_rd(struct sc_info *sc, int regno, int size)
Definition: ich.c:216
#define SIS_VENDORID
Definition: ich.c:56
#define ICH_MIN_BLKCNT
Definition: ich.c:52
#define INTEL_82801AB
Definition: ich.c:62
#define ICH_GLOB_CTL_COLD
Definition: ich.h:74
#define ICH_BDC_IOC
Definition: ich.h:98
#define ICH_X_CR_RPBM
Definition: ich.h:66
#define ICH_X_CR_LVBIE
Definition: ich.h:68
#define PCIR_NAMBAR
Definition: ich.h:32
#define ICH_GLOB_CTL_WARM
Definition: ich.h:75
#define ICH_X_SR_LVBCI
Definition: ich.h:61
#define ICH_REG_X_CIV
Definition: ich.h:43
#define ICH_X_SR_BCIS
Definition: ich.h:62
#define ICH_REG_ACC_SEMA
Definition: ich.h:56
#define ICH_REG_PI_BASE
Definition: ich.h:50
#define ICH_GLOB_STA_SRES
Definition: ich.h:90
#define ICH_GLOB_STA_MINT
Definition: ich.h:86
#define ICH_REG_X_BDBAR
Definition: ich.h:42
#define ICH_REG_PO_BASE
Definition: ich.h:51
#define ICH_GLOB_CTL_PRES
Definition: ich.h:77
#define PCIR_MBBAR
Definition: ich.h:36
#define ICH_LEGACY_ENABLE
Definition: ich.h:39
#define ICH_REG_X_CR
Definition: ich.h:48
#define ICH_X_CR_IOCE
Definition: ich.h:70
#define ICH_REG_MC_BASE
Definition: ich.h:52
#define ICH_GLOB_CTL_SHUT
Definition: ich.h:76
#define ICH_GLOB_STA_PCR
Definition: ich.h:87
#define PCIR_NABMBAR
Definition: ich.h:33
#define ICH_REG_GLOB_CNT
Definition: ich.h:54
#define ICH_X_CR_RR
Definition: ich.h:67
#define ICH_REG_X_LVI
Definition: ich.h:44
#define ICH_GLOB_STA_POINT
Definition: ich.h:85
#define ICH_GLOB_STA_PIINT
Definition: ich.h:84
#define ICH_GLOB_STA_PRES
Definition: ich.h:89
#define PCIR_ICH_LEGACY
Definition: ich.h:38
#define PCIR_MMBAR
Definition: ich.h:35
#define ICH_REG_X_PICB
Definition: ich.h:46
#define ICH_X_SR_FIFOE
Definition: ich.h:63
#define ICH_GLOB_STA_IMASK
Definition: ich.h:95
#define ICH_REG_GLOB_STA
Definition: ich.h:55
#define ICH_REG_X_SR
Definition: ich.h:45
uint8_t size
uint8_t r
#define KOBJMETHOD_END
Definition: midi.c:76
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
Definition: mixer.c:725
int mixer_reinit(device_t dev)
Definition: mixer.c:860
unsigned dev
Definition: mixer_if.m:59
bool * status
void * snd_mtxcreate(const char *desc, const char *type)
Definition: sound.c:88
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
void snd_mtxfree(void *m)
Definition: sound.c:98
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 SOUND_MINVER
Definition: sound.h:102
#define PCM_SOFTC_SIZE
Definition: sound.h:96
#define SND_STATUSLEN
Definition: sound.h:98
Definition: ac97.c:59
Definition: ich.c:153
volatile uint32_t buffer
Definition: ich.c:154
volatile uint32_t length
Definition: ich.c:155
Definition: ich.c:101
char * name
Definition: ich.c:106
uint32_t options
Definition: ich.c:104
uint16_t devid
Definition: ich.c:103
uint16_t vendor
Definition: ich.c:102
bus_addr_t desc_addr
Definition: ich.c:173
uint32_t num
Definition: ich.c:162
int run
Definition: envy24.c:94
u_int32_t spd
Definition: cmi.c:107
struct pcm_channel * channel
Definition: als4000.c:68
uint32_t regbase
Definition: ich.c:164
uint32_t spdreg
Definition: ich.c:164
uint32_t civ
Definition: ich.c:166
struct sc_info * parent
Definition: als4000.c:67
unsigned num
Definition: envy24.c:79
uint32_t run_save
Definition: ich.c:162
uint32_t blkcnt
Definition: ich.c:163
struct ich_desc * dtbl
Definition: ich.c:172
uint32_t imask
Definition: ich.c:165
struct snd_dbuf * buffer
Definition: als4000.c:69
u_int32_t blksz
Definition: cs4281.c:79
bus_dmamap_t dtmap
Definition: ich.c:188
int swap_reg
Definition: ich.c:181
struct intr_config_hook intrhook
Definition: ich.c:197
unsigned int bufsz
Definition: als4000.c:86
unsigned int blkcnt
Definition: ich.c:180
int ac97rate
Definition: ich.c:193
struct resource * irq
Definition: als4000.c:81
struct mtx * ich_lock
Definition: ich.c:201
int hasvrm
Definition: ich.c:179
device_t dev
Definition: als4000.c:77
int sample_size
Definition: ich.c:181
int irqid
Definition: als4000.c:82
uint16_t devid
Definition: ich.c:199
int hasvra
Definition: ich.c:179
bus_addr_t desc_addr
Definition: ich.c:196
bus_space_tag_t nabmbart
Definition: ich.c:185
struct resource * nabmbar
Definition: ich.c:183
int hasmic
Definition: ich.c:179
struct resource * nambar
Definition: ich.c:183
bus_space_handle_t nabmbarh
Definition: ich.c:186
unsigned chnum
Definition: envy24.c:177
bus_dma_tag_t dmat
Definition: envy24.c:144
void * ih
Definition: als4000.c:83
uint16_t vendor
Definition: ich.c:198
int nabmbarid
Definition: ich.c:184
int regtype
Definition: cs4281.c:94
bus_space_handle_t nambarh
Definition: ich.c:186
struct ich_desc * dtbl
Definition: ich.c:194
struct sc_chinfo ch[3]
Definition: ich.c:192
bus_space_tag_t nambart
Definition: ich.c:185
uint32_t flags
Definition: ich.c:200
bus_dma_tag_t chan_dmat
Definition: ich.c:187
int nambarid
Definition: ich.c:184
struct ac97_info * codec
Definition: ich.c:191
unsigned int dtbl_size
Definition: ich.c:195