30#ifdef HAVE_KERNEL_OPTION_HEADERS
45#define ICH_TIMEOUT 1000
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
55#define INTEL_VENDORID 0x8086
56#define SIS_VENDORID 0x1039
57#define NVIDIA_VENDORID 0x10de
58#define AMD_VENDORID 0x1022
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
66#define INTEL_82801EB 0x24d5
67#define INTEL_6300ESB 0x25a6
68#define INTEL_82801FB 0x266e
69#define INTEL_82801GB 0x27de
70#define SIS_7012 0x7012
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
80#define AMD_8111 0x746d
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)
87#define ICH_DEBUG(stmt) do { \
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)
105#define PROBE_LOW 0x01
111 "Intel ICH (82801AA)" },
113 "Intel ICH (82801AB)" },
115 "Intel ICH2 (82801BA)" },
117 "Intel ICH3 (82801CA)" },
119 "Intel ICH4 (82801DB)" },
121 "Intel ICH5 (82801EB)" },
125 "Intel ICH6 (82801FB)" },
127 "Intel ICH7 (82801GB)" },
135 "nVidia nForce2 400" },
139 "nVidia nForce3 250" },
143 "nVidia nForce 410 MCP" },
145 "nVidia nForce 4 MCP" },
215static __inline uint32_t
256 if ((
data & 0x01) == 0)
262 device_printf(sc->
dev,
"CODEC semaphore timeout\n");
312 device_printf(sc->
dev,
"%s: failed blksz=%u blkcnt=%u\n",
357 device_printf(sc->
dev,
"ignoring reset failure!\n");
362 device_printf(sc->
dev,
"cannot reset channel %d\n", num);
440 device_printf(sc->
dev,
441 "WARNING: %s() called before calibration!\n",
456 device_printf(sc->
dev,
457 "WARNING: %s() called before calibration!\n",
490 device_printf(sc->
dev,
491 "WARNING: %s() called before calibration!\n",
518 device_printf(sc->
dev,
519 "WARNING: %s() called before calibration!\n",
553 device_printf(sc->
dev,
554 "WARNING: %s() called before calibration!\n",
577 "WARNING: %s() called before calibration!\n",
604 uint32_t cbi, lbi, lvi, st, gs;
611 device_printf(sc->
dev,
612 "WARNING: %s() called before calibration!\n",
623 for (i = 0; i < 3; i++) {
625 if ((ch->
imask & gs) == 0)
649 lvi += cbi + ch->
blkcnt - lbi;
660 device_printf(sc->
dev,
661 "Unhandled interrupt, gs_intr = %x\n", gs);
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,
680 "AC97 link rate (default = 48000)");
691 "at io 0x%jx, 0x%jx irq %jd bufsz %u %s",
696 device_printf(sc->
dev,
697 "PCI Master abort workaround enabled\n");
712 struct timeval t1, t2;
714 uint32_t wait_us, actual_48k_rate, oblkcnt;
720 if (sc->
intrhook.ich_func != NULL) {
721 config_intrhook_disestablish(&sc->
intrhook);
740 sc->
flags &= ~ICH_CALIBRATE_DONE;
766 if (t2.tv_sec - t1.tv_sec > 1)
769 }
while (nciv == ociv);
780 wait_us = ((t2.tv_sec - t1.tv_sec) * 1000000) + t2.tv_usec - t1.tv_usec;
783 device_printf(sc->
dev,
"ac97 link rate calibration timed out after %d us\n", wait_us);
792 actual_48k_rate = ((uint64_t)
ch->
blksz * 250000) / wait_us;
794 actual_48k_rate = 48000;
796 if (actual_48k_rate < 47500 || actual_48k_rate > 48500) {
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);
820ich_setmap(
void *arg, bus_dma_segment_t *segs,
int nseg,
int error)
843 device_printf(sc->
dev,
"primary codec not ready!\n");
875 return (BUS_PROBE_LOW_PRIORITY);
876 return (BUS_PROBE_DEFAULT);
891 sc = malloc(
sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
897 subdev = (pci_get_subdevice(
dev) << 16) | pci_get_subvendor(
dev);
923 pci_enable_busmaster(
dev);
951 device_printf(
dev,
"unable to map IO port space\n");
963 if (resource_int_value(device_get_name(
dev),
964 device_get_unit(
dev),
"blocksize", &i) == 0 && i > 0) {
969 sc->
blkcnt = 1 << (i - 1);
977 if (resource_int_value(device_get_name(
dev),
978 device_get_unit(
dev),
"highlatency", &i) == 0 && i != 0) {
983 if (resource_int_value(device_get_name(
dev),
984 device_get_unit(
dev),
"fixedrate", &i) == 0 && i != 0)
987 if (resource_int_value(device_get_name(
dev),
988 device_get_unit(
dev),
"micchannel_enabled", &i) == 0 && i != 0)
992 sc->
irq = bus_alloc_resource_any(
dev, SYS_RES_IRQ, &sc->
irqid,
993 RF_ACTIVE | RF_SHAREABLE);
996 device_printf(
dev,
"unable to map interrupt\n");
1001 device_printf(
dev,
"unable to initialize the card\n");
1006 if (sc->
codec == NULL)
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");
1055 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1057 device_printf(
dev,
"unable to create dma tag\n");
1061 if (bus_dmamem_alloc(sc->
dmat, (
void **)&sc->
dtbl, BUS_DMA_NOWAIT |
1087 config_intrhook_establish(&sc->
intrhook) != 0) {
1099 bus_teardown_intr(
dev, sc->
irq, sc->
ih);
1101 bus_release_resource(
dev, SYS_RES_IRQ, sc->
irqid, sc->
irq);
1115 bus_dma_tag_destroy(sc->
dmat);
1133 bus_teardown_intr(
dev, sc->
irq, sc->
ih);
1134 bus_release_resource(
dev, SYS_RES_IRQ, sc->
irqid, sc->
irq);
1140 bus_dma_tag_destroy(sc->
dmat);
1158 for (i = 500000; i; i--) {
1165 printf(
"%s: time out\n", __func__);
1176 for (i = 0 ; i < 3; i++) {
1178 if (sc->
ch[i].
run) {
1200 device_printf(
dev,
"unable to reinitialize the card\n");
1209 device_printf(
dev,
"unable to reinitialize the mixer\n");
1213 for (i = 0 ; i < 3; i++) {
int ac97_setextmode(struct ac97_info *codec, u_int16_t mode)
u_int16_t ac97_getcaps(struct ac97_info *codec)
u_int32_t ac97_getflags(struct ac97_info *codec)
u_int16_t ac97_getextcaps(struct ac97_info *codec)
kobj_class_t ac97_getmixerclass(void)
void ac97_destroy(struct ac97_info *codec)
void ac97_setflags(struct ac97_info *codec, u_int32_t val)
int ac97_setrate(struct ac97_info *codec, int which, int rate)
#define AC97_CREATE(dev, devinfo, cls)
#define AC97_REGEXT_FDACRATE
#define AC97_REGEXT_MADCRATE
#define AC97_CAP_MICCHANNEL
#define AC97_REGEXT_LADCRATE
int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
unsigned int sndbuf_getblkcnt(struct snd_dbuf *b)
bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf)
unsigned int sndbuf_getblksz(struct snd_dbuf *b)
unsigned int sndbuf_getmaxsize(struct snd_dbuf *b)
int sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
void chn_intr(struct pcm_channel *c)
static driver_t ich_driver
static int ich_pci_attach(device_t dev)
static int ich_rdcd(kobj_t obj, void *devinfo, int regno)
static void ich_setstatus(struct sc_info *sc)
#define ICH_DEFAULT_BUFSZ
static void * ichchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
#define NVIDIA_NFORCE2_400
static device_method_t ich_methods[]
static const struct ich_type ich_devs[]
#define NVIDIA_NFORCE3_250
static kobj_method_t ich_ac97_methods[]
static kobj_method_t ichchan_methods[]
static void ich_calibrate(void *arg)
static __inline void ich_wr(struct sc_info *sc, int regno, uint32_t data, int size)
static int ich_init(struct sc_info *sc)
static int ichchan_setformat(kobj_t obj, void *data, uint32_t format)
#define NVIDIA_NFORCE4_MCP
static struct pcmchan_caps ich_vrcaps
static int ich_pci_suspend(device_t dev)
static void ich_pci_codec_reset(struct sc_info *sc)
static uint32_t ichchan_setspeed(kobj_t obj, void *data, uint32_t speed)
static uint32_t ichchan_setblocksize(kobj_t obj, void *data, uint32_t blocksize)
SND_DECLARE_FILE("$FreeBSD$")
static int ich_wrcd(kobj_t obj, void *devinfo, int regno, uint32_t data)
DRIVER_MODULE(snd_ich, pci, ich_driver, pcm_devclass, 0, 0)
static int ich_pci_resume(device_t dev)
static struct pcmchan_caps ich_caps
static int ichchan_trigger(kobj_t obj, void *data, int go)
#define ICH_CALIBRATE_DONE
static uint32_t ichchan_getptr(kobj_t obj, void *data)
static void ich_filldtbl(struct sc_chinfo *ch)
static int ich_initsys(struct sc_info *sc)
static int ich_pci_detach(device_t dev)
static int ich_pci_probe(device_t dev)
MODULE_VERSION(snd_ich, 1)
static struct pcmchan_caps * ichchan_getcaps(kobj_t obj, void *data)
MODULE_DEPEND(snd_ich, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
#define NVIDIA_NFORCE_410_MCP
static int ich_resetchan(struct sc_info *sc, int num)
static void ich_setmap(void *arg, bus_dma_segment_t *segs, int nseg, int error)
static uint32_t ich_fmt[]
static int ich_waitcd(void *devinfo)
#define ICH_DEFAULT_BLKCNT
static void ich_intr(void *p)
static __inline uint32_t ich_rd(struct sc_info *sc, int regno, int size)
#define ICH_GLOB_CTL_COLD
#define ICH_GLOB_CTL_WARM
#define ICH_GLOB_STA_SRES
#define ICH_GLOB_STA_MINT
#define ICH_GLOB_CTL_PRES
#define ICH_LEGACY_ENABLE
#define ICH_GLOB_CTL_SHUT
#define ICH_GLOB_STA_POINT
#define ICH_GLOB_STA_PIINT
#define ICH_GLOB_STA_PRES
#define ICH_GLOB_STA_IMASK
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
int mixer_reinit(device_t dev)
void * snd_mtxcreate(const char *desc, const char *type)
void * pcm_getdevinfo(device_t dev)
int pcm_setstatus(device_t dev, char *str)
void snd_mtxfree(void *m)
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
int pcm_unregister(device_t dev)
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
#define SND_FORMAT(f, c, e)
struct pcm_channel * channel
struct intr_config_hook intrhook
struct resource * nabmbar
bus_space_handle_t nabmbarh
bus_space_handle_t nambarh