2 * ALSA driver for Intel ICH (i8x0) chipsets
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
7 * This code also contains alpha support for SiS 735 chipsets provided
8 * by Mike Pieper <mptei@users.sourceforge.net>. We have no datasheet
9 * for SiS735, so the code is not fully functional.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sound/driver.h>
31 #include <linux/delay.h>
32 #include <linux/interrupt.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/slab.h>
36 #include <linux/gameport.h>
37 #include <linux/moduleparam.h>
38 #include <sound/core.h>
39 #include <sound/pcm.h>
40 #include <sound/ac97_codec.h>
41 #include <sound/info.h>
42 #include <sound/mpu401.h>
43 #include <sound/initval.h>
44 /* for 440MX workaround */
45 #include <asm/pgtable.h>
46 #include <asm/cacheflush.h>
48 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
49 MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
50 MODULE_LICENSE("GPL");
51 MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
52 "{Intel,82901AB-ICH0},"
53 "{Intel,82801BA-ICH2},"
54 "{Intel,82801CA-ICH3},"
55 "{Intel,82801DB-ICH4},"
61 "{NVidia,nForce Audio},"
62 "{NVidia,nForce2 Audio},"
67 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
68 #define SUPPORT_JOYSTICK 1
70 #define SUPPORT_MIDI 1
72 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
73 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
74 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
75 static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
76 static int ac97_quirk[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = AC97_TUNE_DEFAULT};
77 static int buggy_irq[SNDRV_CARDS];
78 #ifdef SUPPORT_JOYSTICK
79 static int joystick[SNDRV_CARDS];
82 static int mpu_port[SNDRV_CARDS]; /* disabled */
86 module_param_array(index, int, boot_devs, 0444);
87 MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
88 module_param_array(id, charp, boot_devs, 0444);
89 MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
90 module_param_array(enable, bool, boot_devs, 0444);
91 MODULE_PARM_DESC(enable, "Enable Intel i8x0 soundcard.");
92 module_param_array(ac97_clock, int, boot_devs, 0444);
93 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
94 module_param_array(ac97_quirk, int, boot_devs, 0444);
95 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
96 module_param_array(buggy_irq, bool, boot_devs, 0444);
97 MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
98 #ifdef SUPPORT_JOYSTICK
99 module_param_array(joystick, bool, boot_devs, 0444);
100 MODULE_PARM_DESC(joystick, "Enable joystick for Intel i8x0 soundcard.");
103 module_param_array(mpu_port, int, boot_devs, 0444);
104 MODULE_PARM_DESC(mpu_port, "MPU401 port # for Intel i8x0 driver.");
111 #ifndef PCI_DEVICE_ID_INTEL_82801
112 #define PCI_DEVICE_ID_INTEL_82801 0x2415
114 #ifndef PCI_DEVICE_ID_INTEL_82901
115 #define PCI_DEVICE_ID_INTEL_82901 0x2425
117 #ifndef PCI_DEVICE_ID_INTEL_82801BA
118 #define PCI_DEVICE_ID_INTEL_82801BA 0x2445
120 #ifndef PCI_DEVICE_ID_INTEL_440MX
121 #define PCI_DEVICE_ID_INTEL_440MX 0x7195
123 #ifndef PCI_DEVICE_ID_INTEL_ICH3
124 #define PCI_DEVICE_ID_INTEL_ICH3 0x2485
126 #ifndef PCI_DEVICE_ID_INTEL_ICH4
127 #define PCI_DEVICE_ID_INTEL_ICH4 0x24c5
129 #ifndef PCI_DEVICE_ID_INTEL_ICH5
130 #define PCI_DEVICE_ID_INTEL_ICH5 0x24d5
132 #ifndef PCI_DEVICE_ID_INTEL_ESB_5
133 #define PCI_DEVICE_ID_INTEL_ESB_5 0x25a6
135 #ifndef PCI_DEVICE_ID_INTEL_ICH6_3
136 #define PCI_DEVICE_ID_INTEL_ICH6_3 0x266e
138 #ifndef PCI_DEVICE_ID_SI_7012
139 #define PCI_DEVICE_ID_SI_7012 0x7012
141 #ifndef PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
142 #define PCI_DEVICE_ID_NVIDIA_MCP_AUDIO 0x01b1
144 #ifndef PCI_DEVICE_ID_NVIDIA_CK804_AUDIO
145 #define PCI_DEVICE_ID_NVIDIA_CK804_AUDIO 0x0059
147 #ifndef PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
148 #define PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO 0x006a
150 #ifndef PCI_DEVICE_ID_NVIDIA_CK8_AUDIO
151 #define PCI_DEVICE_ID_NVIDIA_CK8_AUDIO 0x008a
153 #ifndef PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO
154 #define PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO 0x00da
156 #ifndef PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO
157 #define PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO 0x00ea
160 enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
162 #define ICHREG(x) ICH_REG_##x
164 #define DEFINE_REGSET(name,base) \
166 ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
167 ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
168 ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
169 ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
170 ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
171 ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
172 ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
175 /* busmaster blocks */
176 DEFINE_REGSET(OFF, 0); /* offset */
177 DEFINE_REGSET(PI, 0x00); /* PCM in */
178 DEFINE_REGSET(PO, 0x10); /* PCM out */
179 DEFINE_REGSET(MC, 0x20); /* Mic in */
181 /* ICH4 busmaster blocks */
182 DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
183 DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
184 DEFINE_REGSET(SP, 0x60); /* SPDIF out */
186 /* values for each busmaster block */
189 #define ICH_REG_LVI_MASK 0x1f
192 #define ICH_FIFOE 0x10 /* FIFO error */
193 #define ICH_BCIS 0x08 /* buffer completion interrupt status */
194 #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
195 #define ICH_CELV 0x02 /* current equals last valid */
196 #define ICH_DCH 0x01 /* DMA controller halted */
199 #define ICH_REG_PIV_MASK 0x1f /* mask */
202 #define ICH_IOCE 0x10 /* interrupt on completion enable */
203 #define ICH_FEIE 0x08 /* fifo error interrupt enable */
204 #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
205 #define ICH_RESETREGS 0x02 /* reset busmaster registers */
206 #define ICH_STARTBM 0x01 /* start busmaster operation */
210 #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
211 #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
212 #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
213 #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
214 #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
215 #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
216 #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
217 #define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */
218 #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
219 #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
220 #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
221 #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
222 #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
223 #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
224 #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
225 #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
226 #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
227 #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
228 #define ICH_ACLINK 0x00000008 /* AClink shut off */
229 #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
230 #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
231 #define ICH_GIE 0x00000001 /* GPI interrupt enable */
232 #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
233 #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
234 #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
235 #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
236 #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
237 #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
238 #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
239 #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
240 #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
241 #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
242 #define ICH_MD3 0x00020000 /* modem power down semaphore */
243 #define ICH_AD3 0x00010000 /* audio power down semaphore */
244 #define ICH_RCS 0x00008000 /* read completion status */
245 #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
246 #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
247 #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
248 #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
249 #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
250 #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
251 #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
252 #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
253 #define ICH_POINT 0x00000040 /* playback interrupt */
254 #define ICH_PIINT 0x00000020 /* capture interrupt */
255 #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
256 #define ICH_MOINT 0x00000004 /* modem playback interrupt */
257 #define ICH_MIINT 0x00000002 /* modem capture interrupt */
258 #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
259 #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
260 #define ICH_CAS 0x01 /* codec access semaphore */
261 #define ICH_REG_SDM 0x80
262 #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
263 #define ICH_DI2L_SHIFT 6
264 #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
265 #define ICH_DI1L_SHIFT 4
266 #define ICH_SE 0x00000008 /* steer enable */
267 #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
269 #define ICH_MAX_FRAGS 32 /* max hw frags */
273 * registers for Ali5455
276 /* ALi 5455 busmaster blocks */
277 DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
278 DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
279 DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
280 DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
281 DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
282 DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
283 DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
284 DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
285 DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
286 DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
287 DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
290 ICH_REG_ALI_SCR = 0x00, /* System Control Register */
291 ICH_REG_ALI_SSR = 0x04, /* System Status Register */
292 ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
293 ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
294 ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
295 ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
296 ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
297 ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
298 ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
299 ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
300 ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
301 ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
302 ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
303 ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
304 ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
305 ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
306 ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
307 ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
308 ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
309 ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
310 ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
313 #define ALI_CAS_SEM_BUSY 0x80000000
314 #define ALI_CPR_ADDR_SECONDARY 0x100
315 #define ALI_CPR_ADDR_READ 0x80
316 #define ALI_CSPSR_CODEC_READY 0x08
317 #define ALI_CSPSR_READ_OK 0x02
318 #define ALI_CSPSR_WRITE_OK 0x01
320 /* interrupts for the whole chip by interrupt status register finish */
322 #define ALI_INT_MICIN2 (1<<26)
323 #define ALI_INT_PCMIN2 (1<<25)
324 #define ALI_INT_I2SIN (1<<24)
325 #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
326 #define ALI_INT_SPDIFIN (1<<22)
327 #define ALI_INT_LFEOUT (1<<21)
328 #define ALI_INT_CENTEROUT (1<<20)
329 #define ALI_INT_CODECSPDIFOUT (1<<19)
330 #define ALI_INT_MICIN (1<<18)
331 #define ALI_INT_PCMOUT (1<<17)
332 #define ALI_INT_PCMIN (1<<16)
333 #define ALI_INT_CPRAIS (1<<7) /* command port available */
334 #define ALI_INT_SPRAIS (1<<5) /* status port available */
335 #define ALI_INT_GPIO (1<<1)
336 #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
338 #define ICH_ALI_SC_RESET (1<<31) /* master reset */
339 #define ICH_ALI_SC_AC97_DBL (1<<30)
340 #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
341 #define ICH_ALI_SC_IN_BITS (3<<18)
342 #define ICH_ALI_SC_OUT_BITS (3<<16)
343 #define ICH_ALI_SC_6CH_CFG (3<<14)
344 #define ICH_ALI_SC_PCM_4 (1<<8)
345 #define ICH_ALI_SC_PCM_6 (2<<8)
346 #define ICH_ALI_SC_PCM_246_MASK (3<<8)
348 #define ICH_ALI_SS_SEC_ID (3<<5)
349 #define ICH_ALI_SS_PRI_ID (3<<3)
351 #define ICH_ALI_IF_AC97SP (1<<21)
352 #define ICH_ALI_IF_MC (1<<20)
353 #define ICH_ALI_IF_PI (1<<19)
354 #define ICH_ALI_IF_MC2 (1<<18)
355 #define ICH_ALI_IF_PI2 (1<<17)
356 #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
357 #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
358 #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
359 #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
360 #define ICH_ALI_IF_PO_SPDF (1<<3)
361 #define ICH_ALI_IF_PO (1<<1)
367 enum { ICHD_PCMIN, ICHD_PCMOUT, ICHD_MIC, ICHD_MIC2, ICHD_PCM2IN, ICHD_SPBAR, ICHD_LAST = ICHD_SPBAR };
368 enum { NVD_PCMIN, NVD_PCMOUT, NVD_MIC, NVD_SPBAR, NVD_LAST = NVD_SPBAR };
369 enum { ALID_PCMIN, ALID_PCMOUT, ALID_MIC, ALID_AC97SPDIFOUT, ALID_SPDIFIN, ALID_SPDIFOUT, ALID_LAST = ALID_SPDIFOUT };
371 #define get_ichdev(substream) (ichdev_t *)(substream->runtime->private_data)
374 unsigned int ichd; /* ich device number */
375 unsigned long reg_offset; /* offset to bmaddr */
376 u32 *bdbar; /* CPU address (32bit) */
377 unsigned int bdbar_addr; /* PCI bus address (32bit) */
378 snd_pcm_substream_t *substream;
379 unsigned int physbuf; /* physical address (32bit) */
381 unsigned int fragsize;
382 unsigned int fragsize1;
383 unsigned int position;
384 unsigned int pos_shift;
391 unsigned int ack_bit;
392 unsigned int roff_sr;
393 unsigned int roff_picb;
394 unsigned int int_sta_mask; /* interrupt status mask */
395 unsigned int ali_slot; /* ALI DMA slot */
396 struct ac97_pcm *pcm;
400 typedef struct _snd_intel8x0 intel8x0_t;
402 struct _snd_intel8x0 {
403 unsigned int device_type;
409 void __iomem * remap_addr;
410 unsigned int bm_mmio;
411 unsigned long bmaddr;
412 void __iomem * remap_bmaddr;
424 unsigned in_ac97_init: 1,
426 unsigned fix_nocache: 1; /* workaround for 440MX */
427 unsigned buggy_irq: 1; /* workaround for buggy mobos */
429 ac97_bus_t *ac97_bus;
431 unsigned int ac97_sdin[3];
433 snd_rawmidi_t *rmidi;
436 spinlock_t ac97_lock;
439 struct snd_dma_buffer bdbars;
440 u32 int_sta_reg; /* interrupt status register */
441 u32 int_sta_mask; /* interrupt status mask */
444 static struct pci_device_id snd_intel8x0_ids[] = {
445 { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */
446 { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */
447 { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */
448 { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */
449 { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */
450 { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */
451 { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */
452 { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */
453 { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */
454 { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */
455 { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */
456 { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */
457 { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */
458 { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */
459 { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */
460 { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */
461 { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */
462 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
463 { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
464 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
468 MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
471 * Lowlevel I/O - busmaster
474 static u8 igetbyte(intel8x0_t *chip, u32 offset)
477 return readb(chip->remap_bmaddr + offset);
479 return inb(chip->bmaddr + offset);
482 static u16 igetword(intel8x0_t *chip, u32 offset)
485 return readw(chip->remap_bmaddr + offset);
487 return inw(chip->bmaddr + offset);
490 static u32 igetdword(intel8x0_t *chip, u32 offset)
493 return readl(chip->remap_bmaddr + offset);
495 return inl(chip->bmaddr + offset);
498 static void iputbyte(intel8x0_t *chip, u32 offset, u8 val)
501 writeb(val, chip->remap_bmaddr + offset);
503 outb(val, chip->bmaddr + offset);
506 static void iputword(intel8x0_t *chip, u32 offset, u16 val)
509 writew(val, chip->remap_bmaddr + offset);
511 outw(val, chip->bmaddr + offset);
514 static void iputdword(intel8x0_t *chip, u32 offset, u32 val)
517 writel(val, chip->remap_bmaddr + offset);
519 outl(val, chip->bmaddr + offset);
523 * Lowlevel I/O - AC'97 registers
526 static u16 iagetword(intel8x0_t *chip, u32 offset)
529 return readw(chip->remap_addr + offset);
531 return inw(chip->addr + offset);
534 static void iaputword(intel8x0_t *chip, u32 offset, u16 val)
537 writew(val, chip->remap_addr + offset);
539 outw(val, chip->addr + offset);
547 * access to AC97 codec via normal i/o (for ICH and SIS7012)
550 /* return the GLOB_STA bit for the corresponding codec */
551 static unsigned int get_ich_codec_bit(intel8x0_t *chip, unsigned int codec)
553 static unsigned int codec_bit[3] = {
554 ICH_PCR, ICH_SCR, ICH_TCR
556 snd_assert(codec < 3, return ICH_PCR);
557 if (chip->device_type == DEVICE_INTEL_ICH4)
558 codec = chip->ac97_sdin[codec];
559 return codec_bit[codec];
562 static int snd_intel8x0_codec_semaphore(intel8x0_t *chip, unsigned int codec)
568 if (chip->in_sdin_init) {
569 /* we don't know the ready bit assignment at the moment */
570 /* so we check any */
571 codec = ICH_PCR | ICH_SCR | ICH_TCR;
573 codec = get_ich_codec_bit(chip, codec);
577 if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
580 /* Anyone holding a semaphore for 1 msec should be shot... */
583 if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
588 /* access to some forbidden (non existant) ac97 registers will not
589 * reset the semaphore. So even if you don't get the semaphore, still
590 * continue the access. We don't need the semaphore anyway. */
591 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
592 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
593 iagetword(chip, 0); /* clear semaphore flag */
594 /* I don't care about the semaphore */
598 static void snd_intel8x0_codec_write(ac97_t *ac97,
602 intel8x0_t *chip = ac97->private_data;
604 spin_lock(&chip->ac97_lock);
605 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
606 if (! chip->in_ac97_init)
607 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
609 iaputword(chip, reg + ac97->num * 0x80, val);
610 spin_unlock(&chip->ac97_lock);
613 static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
616 intel8x0_t *chip = ac97->private_data;
620 spin_lock(&chip->ac97_lock);
621 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
622 if (! chip->in_ac97_init)
623 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
626 res = iagetword(chip, reg + ac97->num * 0x80);
627 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
628 /* reset RCS and preserve other R/WC bits */
629 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
630 if (! chip->in_ac97_init)
631 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
635 spin_unlock(&chip->ac97_lock);
639 static void snd_intel8x0_codec_read_test(intel8x0_t *chip, unsigned int codec)
643 spin_lock(&chip->ac97_lock);
644 if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
645 iagetword(chip, codec * 0x80);
646 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
647 /* reset RCS and preserve other R/WC bits */
648 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
651 spin_unlock(&chip->ac97_lock);
655 * access to AC97 for Ali5455
657 static int snd_intel8x0_ali_codec_ready(intel8x0_t *chip, int mask)
660 for (count = 0; count < 0x7f; count++) {
661 int val = igetbyte(chip, ICHREG(ALI_CSPSR));
665 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
669 static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip)
672 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
675 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
676 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
679 static unsigned short snd_intel8x0_ali_codec_read(ac97_t *ac97, unsigned short reg)
681 intel8x0_t *chip = ac97->private_data;
682 unsigned short data = 0xffff;
684 spin_lock(&chip->ac97_lock);
685 if (snd_intel8x0_ali_codec_semaphore(chip))
687 reg |= ALI_CPR_ADDR_READ;
689 reg |= ALI_CPR_ADDR_SECONDARY;
690 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
691 if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
693 data = igetword(chip, ICHREG(ALI_SPR));
695 spin_unlock(&chip->ac97_lock);
699 static void snd_intel8x0_ali_codec_write(ac97_t *ac97, unsigned short reg, unsigned short val)
701 intel8x0_t *chip = ac97->private_data;
703 spin_lock(&chip->ac97_lock);
704 if (snd_intel8x0_ali_codec_semaphore(chip)) {
705 spin_unlock(&chip->ac97_lock);
708 iputword(chip, ICHREG(ALI_CPR), val);
710 reg |= ALI_CPR_ADDR_SECONDARY;
711 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
712 snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
713 spin_unlock(&chip->ac97_lock);
720 static void snd_intel8x0_setup_periods(intel8x0_t *chip, ichdev_t *ichdev)
723 u32 *bdbar = ichdev->bdbar;
724 unsigned long port = ichdev->reg_offset;
726 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
727 if (ichdev->size == ichdev->fragsize) {
728 ichdev->ack_reload = ichdev->ack = 2;
729 ichdev->fragsize1 = ichdev->fragsize >> 1;
730 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
731 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
732 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
733 ichdev->fragsize1 >> ichdev->pos_shift);
734 bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
735 bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
736 ichdev->fragsize1 >> ichdev->pos_shift);
740 ichdev->ack_reload = ichdev->ack = 1;
741 ichdev->fragsize1 = ichdev->fragsize;
742 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
743 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
744 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
745 ichdev->fragsize >> ichdev->pos_shift);
746 // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
748 ichdev->frags = ichdev->size / ichdev->fragsize;
750 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
752 iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
753 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
754 ichdev->position = 0;
756 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
757 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1);
759 /* clear interrupts */
760 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
765 * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
766 * which aborts PCI busmaster for audio transfer. A workaround is to set
767 * the pages as non-cached. For details, see the errata in
768 * http://www.intel.com/design/chipsets/specupdt/245051.htm
770 static void fill_nocache(void *buf, int size, int nocache)
772 size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
773 change_page_attr(virt_to_page(buf), size, nocache ? PAGE_KERNEL_NOCACHE : PAGE_KERNEL);
777 #define fill_nocache(buf,size,nocache)
784 static inline void snd_intel8x0_update(intel8x0_t *chip, ichdev_t *ichdev)
786 unsigned long port = ichdev->reg_offset;
787 int status, civ, i, step;
790 spin_lock(&chip->reg_lock);
791 status = igetbyte(chip, port + ichdev->roff_sr);
792 civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
793 if (!(status & ICH_BCIS)) {
795 } else if (civ == ichdev->civ) {
796 // snd_printd("civ same %d\n", civ);
799 ichdev->civ &= ICH_REG_LVI_MASK;
801 step = civ - ichdev->civ;
803 step += ICH_REG_LVI_MASK + 1;
805 // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
809 ichdev->position += step * ichdev->fragsize1;
810 ichdev->position %= ichdev->size;
812 ichdev->lvi &= ICH_REG_LVI_MASK;
813 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
814 for (i = 0; i < step; i++) {
816 ichdev->lvi_frag %= ichdev->frags;
817 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
818 // printk("new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n", ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), inl(port + 4), inb(port + ICH_REG_OFF_CR));
819 if (--ichdev->ack == 0) {
820 ichdev->ack = ichdev->ack_reload;
824 spin_unlock(&chip->reg_lock);
825 if (ack && ichdev->substream) {
826 snd_pcm_period_elapsed(ichdev->substream);
828 iputbyte(chip, port + ichdev->roff_sr,
829 status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
832 static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id, struct pt_regs *regs)
834 intel8x0_t *chip = dev_id;
839 status = igetdword(chip, chip->int_sta_reg);
840 if (status == 0xffffffff) /* we are not yet resumed */
843 if ((status & chip->int_sta_mask) == 0) {
846 iputdword(chip, chip->int_sta_reg, status);
847 if (! chip->buggy_irq)
850 return IRQ_RETVAL(status);
853 for (i = 0; i < chip->bdbars_count; i++) {
854 ichdev = &chip->ichd[i];
855 if (status & ichdev->int_sta_mask)
856 snd_intel8x0_update(chip, ichdev);
860 iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
869 static int snd_intel8x0_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
871 intel8x0_t *chip = snd_pcm_substream_chip(substream);
872 ichdev_t *ichdev = get_ichdev(substream);
873 unsigned char val = 0;
874 unsigned long port = ichdev->reg_offset;
877 case SNDRV_PCM_TRIGGER_START:
878 case SNDRV_PCM_TRIGGER_RESUME:
879 val = ICH_IOCE | ICH_STARTBM;
881 case SNDRV_PCM_TRIGGER_STOP:
882 case SNDRV_PCM_TRIGGER_SUSPEND:
885 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
888 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
889 val = ICH_IOCE | ICH_STARTBM;
894 iputbyte(chip, port + ICH_REG_OFF_CR, val);
895 if (cmd == SNDRV_PCM_TRIGGER_STOP) {
896 /* wait until DMA stopped */
897 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
898 /* reset whole DMA things */
899 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
904 static int snd_intel8x0_ali_trigger(snd_pcm_substream_t *substream, int cmd)
906 intel8x0_t *chip = snd_pcm_substream_chip(substream);
907 ichdev_t *ichdev = get_ichdev(substream);
908 unsigned long port = ichdev->reg_offset;
909 static int fiforeg[] = { ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3) };
910 unsigned int val, fifo;
912 val = igetdword(chip, ICHREG(ALI_DMACR));
914 case SNDRV_PCM_TRIGGER_START:
915 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
916 case SNDRV_PCM_TRIGGER_RESUME:
917 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
918 /* clear FIFO for synchronization of channels */
919 fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
920 fifo &= ~(0xff << (ichdev->ali_slot % 4));
921 fifo |= 0x83 << (ichdev->ali_slot % 4);
922 iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
924 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
925 val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
926 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot)); /* start DMA */
928 case SNDRV_PCM_TRIGGER_STOP:
929 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
930 case SNDRV_PCM_TRIGGER_SUSPEND:
931 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16))); /* pause */
932 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
933 while (igetbyte(chip, port + ICH_REG_OFF_CR))
935 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
937 /* reset whole DMA things */
938 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
939 /* clear interrupts */
940 iputbyte(chip, port + ICH_REG_OFF_SR, igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
941 iputdword(chip, ICHREG(ALI_INTERRUPTSR),
942 igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
950 static int snd_intel8x0_hw_params(snd_pcm_substream_t * substream,
951 snd_pcm_hw_params_t * hw_params)
953 intel8x0_t *chip = snd_pcm_substream_chip(substream);
954 ichdev_t *ichdev = get_ichdev(substream);
955 snd_pcm_runtime_t *runtime = substream->runtime;
956 size_t size = params_buffer_bytes(hw_params);
959 if (chip->fix_nocache && runtime->dma_area && runtime->dma_bytes < size)
960 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
961 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
964 if (chip->fix_nocache && err > 0)
965 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
966 if (ichdev->pcm_open_flag) {
967 snd_ac97_pcm_close(ichdev->pcm);
968 ichdev->pcm_open_flag = 0;
970 err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
971 params_channels(hw_params),
972 ichdev->pcm->r[0].slots);
974 ichdev->pcm_open_flag = 1;
975 /* FIXME: hack to enable spdif support */
976 if (ichdev->ichd == ICHD_PCMOUT && chip->device_type == DEVICE_SIS)
977 snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF, params_rate(hw_params));
982 static int snd_intel8x0_hw_free(snd_pcm_substream_t * substream)
984 intel8x0_t *chip = snd_pcm_substream_chip(substream);
985 ichdev_t *ichdev = get_ichdev(substream);
987 if (ichdev->pcm_open_flag) {
988 snd_ac97_pcm_close(ichdev->pcm);
989 ichdev->pcm_open_flag = 0;
991 if (chip->fix_nocache && substream->runtime->dma_area)
992 fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
993 return snd_pcm_lib_free_pages(substream);
996 static void snd_intel8x0_setup_pcm_out(intel8x0_t *chip,
997 int channels, int sample_bits)
1000 switch (chip->device_type) {
1002 cnt = igetdword(chip, ICHREG(ALI_SCR));
1003 cnt &= ~ICH_ALI_SC_PCM_246_MASK;
1004 if (chip->multi4 && channels == 4)
1005 cnt |= ICH_ALI_SC_PCM_4;
1006 else if (chip->multi6 && channels == 6)
1007 cnt |= ICH_ALI_SC_PCM_6;
1008 iputdword(chip, ICHREG(ALI_SCR), cnt);
1011 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1012 cnt &= ~ICH_SIS_PCM_246_MASK;
1013 if (chip->multi4 && channels == 4)
1014 cnt |= ICH_SIS_PCM_4;
1015 else if (chip->multi6 && channels == 6)
1016 cnt |= ICH_SIS_PCM_6;
1017 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1020 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1021 cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
1022 if (chip->multi4 && channels == 4)
1024 else if (chip->multi6 && channels == 6)
1026 if (chip->device_type == DEVICE_NFORCE) {
1027 /* reset to 2ch once to keep the 6 channel data in alignment,
1028 * to start from Front Left always
1030 if (cnt & ICH_PCM_246_MASK) {
1031 iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
1032 msleep(50); /* grrr... */
1034 } else if (chip->device_type == DEVICE_INTEL_ICH4) {
1035 if (sample_bits > 16)
1036 cnt |= ICH_PCM_20BIT;
1038 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1043 static int snd_intel8x0_pcm_prepare(snd_pcm_substream_t * substream)
1045 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1046 snd_pcm_runtime_t *runtime = substream->runtime;
1047 ichdev_t *ichdev = get_ichdev(substream);
1049 ichdev->physbuf = runtime->dma_addr;
1050 ichdev->size = snd_pcm_lib_buffer_bytes(substream);
1051 ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
1052 spin_lock_irq(&chip->reg_lock);
1053 if (ichdev->ichd == ICHD_PCMOUT) {
1054 snd_intel8x0_setup_pcm_out(chip, runtime->channels,
1055 runtime->sample_bits);
1056 if (chip->device_type == DEVICE_INTEL_ICH4) {
1057 ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
1060 snd_intel8x0_setup_periods(chip, ichdev);
1061 spin_unlock_irq(&chip->reg_lock);
1065 static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(snd_pcm_substream_t * substream)
1067 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1068 ichdev_t *ichdev = get_ichdev(substream);
1070 int civ, timeout = 10;
1071 unsigned int position;
1073 spin_lock(&chip->reg_lock);
1075 civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
1076 ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
1077 position = ichdev->position;
1080 if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
1081 ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
1083 } while (timeout--);
1084 ptr1 <<= ichdev->pos_shift;
1085 ptr = ichdev->fragsize1 - ptr1;
1087 spin_unlock(&chip->reg_lock);
1088 if (ptr >= ichdev->size)
1090 return bytes_to_frames(substream->runtime, ptr);
1093 static snd_pcm_hardware_t snd_intel8x0_stream =
1095 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1096 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1097 SNDRV_PCM_INFO_MMAP_VALID |
1098 SNDRV_PCM_INFO_PAUSE |
1099 SNDRV_PCM_INFO_RESUME),
1100 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1101 .rates = SNDRV_PCM_RATE_48000,
1106 .buffer_bytes_max = 128 * 1024,
1107 .period_bytes_min = 32,
1108 .period_bytes_max = 128 * 1024,
1110 .periods_max = 1024,
1114 static unsigned int channels4[] = {
1118 static snd_pcm_hw_constraint_list_t hw_constraints_channels4 = {
1119 .count = ARRAY_SIZE(channels4),
1124 static unsigned int channels6[] = {
1128 static snd_pcm_hw_constraint_list_t hw_constraints_channels6 = {
1129 .count = ARRAY_SIZE(channels6),
1134 static int snd_intel8x0_pcm_open(snd_pcm_substream_t * substream, ichdev_t *ichdev)
1136 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1137 snd_pcm_runtime_t *runtime = substream->runtime;
1140 ichdev->substream = substream;
1141 runtime->hw = snd_intel8x0_stream;
1142 runtime->hw.rates = ichdev->pcm->rates;
1143 snd_pcm_limit_hw_rates(runtime);
1144 if (chip->device_type == DEVICE_SIS) {
1145 runtime->hw.buffer_bytes_max = 64*1024;
1146 runtime->hw.period_bytes_max = 64*1024;
1148 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
1150 runtime->private_data = ichdev;
1154 static int snd_intel8x0_playback_open(snd_pcm_substream_t * substream)
1156 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1157 snd_pcm_runtime_t *runtime = substream->runtime;
1160 err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
1165 runtime->hw.channels_max = 6;
1166 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels6);
1167 } else if (chip->multi4) {
1168 runtime->hw.channels_max = 4;
1169 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels4);
1171 if (chip->smp20bit) {
1172 runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
1173 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
1178 static int snd_intel8x0_playback_close(snd_pcm_substream_t * substream)
1180 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1182 chip->ichd[ICHD_PCMOUT].substream = NULL;
1186 static int snd_intel8x0_capture_open(snd_pcm_substream_t * substream)
1188 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1190 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
1193 static int snd_intel8x0_capture_close(snd_pcm_substream_t * substream)
1195 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1197 chip->ichd[ICHD_PCMIN].substream = NULL;
1201 static int snd_intel8x0_mic_open(snd_pcm_substream_t * substream)
1203 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1205 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
1208 static int snd_intel8x0_mic_close(snd_pcm_substream_t * substream)
1210 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1212 chip->ichd[ICHD_MIC].substream = NULL;
1216 static int snd_intel8x0_mic2_open(snd_pcm_substream_t * substream)
1218 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1220 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
1223 static int snd_intel8x0_mic2_close(snd_pcm_substream_t * substream)
1225 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1227 chip->ichd[ICHD_MIC2].substream = NULL;
1231 static int snd_intel8x0_capture2_open(snd_pcm_substream_t * substream)
1233 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1235 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
1238 static int snd_intel8x0_capture2_close(snd_pcm_substream_t * substream)
1240 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1242 chip->ichd[ICHD_PCM2IN].substream = NULL;
1246 static int snd_intel8x0_spdif_open(snd_pcm_substream_t * substream)
1248 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1249 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1251 return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
1254 static int snd_intel8x0_spdif_close(snd_pcm_substream_t * substream)
1256 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1257 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1259 chip->ichd[idx].substream = NULL;
1263 static int snd_intel8x0_ali_ac97spdifout_open(snd_pcm_substream_t * substream)
1265 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1268 spin_lock_irq(&chip->reg_lock);
1269 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1270 val |= ICH_ALI_IF_AC97SP;
1271 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1272 /* also needs to set ALI_SC_CODEC_SPDF correctly */
1273 spin_unlock_irq(&chip->reg_lock);
1275 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
1278 static int snd_intel8x0_ali_ac97spdifout_close(snd_pcm_substream_t * substream)
1280 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1283 chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
1284 spin_lock_irq(&chip->reg_lock);
1285 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1286 val &= ~ICH_ALI_IF_AC97SP;
1287 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1288 spin_unlock_irq(&chip->reg_lock);
1293 static int snd_intel8x0_ali_spdifin_open(snd_pcm_substream_t * substream)
1295 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1297 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
1300 static int snd_intel8x0_ali_spdifin_close(snd_pcm_substream_t * substream)
1302 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1304 chip->ichd[ALID_SPDIFIN].substream = NULL;
1309 static int snd_intel8x0_ali_spdifout_open(snd_pcm_substream_t * substream)
1311 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1313 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
1316 static int snd_intel8x0_ali_spdifout_close(snd_pcm_substream_t * substream)
1318 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1320 chip->ichd[ALID_SPDIFOUT].substream = NULL;
1325 static snd_pcm_ops_t snd_intel8x0_playback_ops = {
1326 .open = snd_intel8x0_playback_open,
1327 .close = snd_intel8x0_playback_close,
1328 .ioctl = snd_pcm_lib_ioctl,
1329 .hw_params = snd_intel8x0_hw_params,
1330 .hw_free = snd_intel8x0_hw_free,
1331 .prepare = snd_intel8x0_pcm_prepare,
1332 .trigger = snd_intel8x0_pcm_trigger,
1333 .pointer = snd_intel8x0_pcm_pointer,
1336 static snd_pcm_ops_t snd_intel8x0_capture_ops = {
1337 .open = snd_intel8x0_capture_open,
1338 .close = snd_intel8x0_capture_close,
1339 .ioctl = snd_pcm_lib_ioctl,
1340 .hw_params = snd_intel8x0_hw_params,
1341 .hw_free = snd_intel8x0_hw_free,
1342 .prepare = snd_intel8x0_pcm_prepare,
1343 .trigger = snd_intel8x0_pcm_trigger,
1344 .pointer = snd_intel8x0_pcm_pointer,
1347 static snd_pcm_ops_t snd_intel8x0_capture_mic_ops = {
1348 .open = snd_intel8x0_mic_open,
1349 .close = snd_intel8x0_mic_close,
1350 .ioctl = snd_pcm_lib_ioctl,
1351 .hw_params = snd_intel8x0_hw_params,
1352 .hw_free = snd_intel8x0_hw_free,
1353 .prepare = snd_intel8x0_pcm_prepare,
1354 .trigger = snd_intel8x0_pcm_trigger,
1355 .pointer = snd_intel8x0_pcm_pointer,
1358 static snd_pcm_ops_t snd_intel8x0_capture_mic2_ops = {
1359 .open = snd_intel8x0_mic2_open,
1360 .close = snd_intel8x0_mic2_close,
1361 .ioctl = snd_pcm_lib_ioctl,
1362 .hw_params = snd_intel8x0_hw_params,
1363 .hw_free = snd_intel8x0_hw_free,
1364 .prepare = snd_intel8x0_pcm_prepare,
1365 .trigger = snd_intel8x0_pcm_trigger,
1366 .pointer = snd_intel8x0_pcm_pointer,
1369 static snd_pcm_ops_t snd_intel8x0_capture2_ops = {
1370 .open = snd_intel8x0_capture2_open,
1371 .close = snd_intel8x0_capture2_close,
1372 .ioctl = snd_pcm_lib_ioctl,
1373 .hw_params = snd_intel8x0_hw_params,
1374 .hw_free = snd_intel8x0_hw_free,
1375 .prepare = snd_intel8x0_pcm_prepare,
1376 .trigger = snd_intel8x0_pcm_trigger,
1377 .pointer = snd_intel8x0_pcm_pointer,
1380 static snd_pcm_ops_t snd_intel8x0_spdif_ops = {
1381 .open = snd_intel8x0_spdif_open,
1382 .close = snd_intel8x0_spdif_close,
1383 .ioctl = snd_pcm_lib_ioctl,
1384 .hw_params = snd_intel8x0_hw_params,
1385 .hw_free = snd_intel8x0_hw_free,
1386 .prepare = snd_intel8x0_pcm_prepare,
1387 .trigger = snd_intel8x0_pcm_trigger,
1388 .pointer = snd_intel8x0_pcm_pointer,
1391 static snd_pcm_ops_t snd_intel8x0_ali_playback_ops = {
1392 .open = snd_intel8x0_playback_open,
1393 .close = snd_intel8x0_playback_close,
1394 .ioctl = snd_pcm_lib_ioctl,
1395 .hw_params = snd_intel8x0_hw_params,
1396 .hw_free = snd_intel8x0_hw_free,
1397 .prepare = snd_intel8x0_pcm_prepare,
1398 .trigger = snd_intel8x0_ali_trigger,
1399 .pointer = snd_intel8x0_pcm_pointer,
1402 static snd_pcm_ops_t snd_intel8x0_ali_capture_ops = {
1403 .open = snd_intel8x0_capture_open,
1404 .close = snd_intel8x0_capture_close,
1405 .ioctl = snd_pcm_lib_ioctl,
1406 .hw_params = snd_intel8x0_hw_params,
1407 .hw_free = snd_intel8x0_hw_free,
1408 .prepare = snd_intel8x0_pcm_prepare,
1409 .trigger = snd_intel8x0_ali_trigger,
1410 .pointer = snd_intel8x0_pcm_pointer,
1413 static snd_pcm_ops_t snd_intel8x0_ali_capture_mic_ops = {
1414 .open = snd_intel8x0_mic_open,
1415 .close = snd_intel8x0_mic_close,
1416 .ioctl = snd_pcm_lib_ioctl,
1417 .hw_params = snd_intel8x0_hw_params,
1418 .hw_free = snd_intel8x0_hw_free,
1419 .prepare = snd_intel8x0_pcm_prepare,
1420 .trigger = snd_intel8x0_ali_trigger,
1421 .pointer = snd_intel8x0_pcm_pointer,
1424 static snd_pcm_ops_t snd_intel8x0_ali_ac97spdifout_ops = {
1425 .open = snd_intel8x0_ali_ac97spdifout_open,
1426 .close = snd_intel8x0_ali_ac97spdifout_close,
1427 .ioctl = snd_pcm_lib_ioctl,
1428 .hw_params = snd_intel8x0_hw_params,
1429 .hw_free = snd_intel8x0_hw_free,
1430 .prepare = snd_intel8x0_pcm_prepare,
1431 .trigger = snd_intel8x0_ali_trigger,
1432 .pointer = snd_intel8x0_pcm_pointer,
1435 static snd_pcm_ops_t snd_intel8x0_ali_spdifin_ops = {
1436 .open = snd_intel8x0_ali_spdifin_open,
1437 .close = snd_intel8x0_ali_spdifin_close,
1438 .ioctl = snd_pcm_lib_ioctl,
1439 .hw_params = snd_intel8x0_hw_params,
1440 .hw_free = snd_intel8x0_hw_free,
1441 .prepare = snd_intel8x0_pcm_prepare,
1442 .trigger = snd_intel8x0_pcm_trigger,
1443 .pointer = snd_intel8x0_pcm_pointer,
1447 static snd_pcm_ops_t snd_intel8x0_ali_spdifout_ops = {
1448 .open = snd_intel8x0_ali_spdifout_open,
1449 .close = snd_intel8x0_ali_spdifout_close,
1450 .ioctl = snd_pcm_lib_ioctl,
1451 .hw_params = snd_intel8x0_hw_params,
1452 .hw_free = snd_intel8x0_hw_free,
1453 .prepare = snd_intel8x0_pcm_prepare,
1454 .trigger = snd_intel8x0_pcm_trigger,
1455 .pointer = snd_intel8x0_pcm_pointer,
1459 struct ich_pcm_table {
1461 snd_pcm_ops_t *playback_ops;
1462 snd_pcm_ops_t *capture_ops;
1463 size_t prealloc_size;
1464 size_t prealloc_max_size;
1468 static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_pcm_table *rec)
1475 sprintf(name, "Intel ICH - %s", rec->suffix);
1477 strcpy(name, "Intel ICH");
1478 err = snd_pcm_new(chip->card, name, device,
1479 rec->playback_ops ? 1 : 0,
1480 rec->capture_ops ? 1 : 0, &pcm);
1484 if (rec->playback_ops)
1485 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
1486 if (rec->capture_ops)
1487 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
1489 pcm->private_data = chip;
1490 pcm->info_flags = 0;
1492 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
1494 strcpy(pcm->name, chip->card->shortname);
1495 chip->pcm[device] = pcm;
1497 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1498 rec->prealloc_size, rec->prealloc_max_size);
1503 static struct ich_pcm_table intel_pcms[] __devinitdata = {
1505 .playback_ops = &snd_intel8x0_playback_ops,
1506 .capture_ops = &snd_intel8x0_capture_ops,
1507 .prealloc_size = 64 * 1024,
1508 .prealloc_max_size = 128 * 1024,
1511 .suffix = "MIC ADC",
1512 .capture_ops = &snd_intel8x0_capture_mic_ops,
1514 .prealloc_max_size = 128 * 1024,
1515 .ac97_idx = ICHD_MIC,
1518 .suffix = "MIC2 ADC",
1519 .capture_ops = &snd_intel8x0_capture_mic2_ops,
1521 .prealloc_max_size = 128 * 1024,
1522 .ac97_idx = ICHD_MIC2,
1526 .capture_ops = &snd_intel8x0_capture2_ops,
1528 .prealloc_max_size = 128 * 1024,
1529 .ac97_idx = ICHD_PCM2IN,
1533 .playback_ops = &snd_intel8x0_spdif_ops,
1534 .prealloc_size = 64 * 1024,
1535 .prealloc_max_size = 128 * 1024,
1536 .ac97_idx = ICHD_SPBAR,
1540 static struct ich_pcm_table nforce_pcms[] __devinitdata = {
1542 .playback_ops = &snd_intel8x0_playback_ops,
1543 .capture_ops = &snd_intel8x0_capture_ops,
1544 .prealloc_size = 64 * 1024,
1545 .prealloc_max_size = 128 * 1024,
1548 .suffix = "MIC ADC",
1549 .capture_ops = &snd_intel8x0_capture_mic_ops,
1551 .prealloc_max_size = 128 * 1024,
1552 .ac97_idx = NVD_MIC,
1556 .playback_ops = &snd_intel8x0_spdif_ops,
1557 .prealloc_size = 64 * 1024,
1558 .prealloc_max_size = 128 * 1024,
1559 .ac97_idx = NVD_SPBAR,
1563 static struct ich_pcm_table ali_pcms[] __devinitdata = {
1565 .playback_ops = &snd_intel8x0_ali_playback_ops,
1566 .capture_ops = &snd_intel8x0_ali_capture_ops,
1567 .prealloc_size = 64 * 1024,
1568 .prealloc_max_size = 128 * 1024,
1571 .suffix = "MIC ADC",
1572 .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
1574 .prealloc_max_size = 128 * 1024,
1575 .ac97_idx = ALID_MIC,
1579 .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
1580 .capture_ops = &snd_intel8x0_ali_spdifin_ops,
1581 .prealloc_size = 64 * 1024,
1582 .prealloc_max_size = 128 * 1024,
1583 .ac97_idx = ALID_AC97SPDIFOUT,
1587 .suffix = "HW IEC958",
1588 .playback_ops = &snd_intel8x0_ali_spdifout_ops,
1589 .prealloc_size = 64 * 1024,
1590 .prealloc_max_size = 128 * 1024,
1595 static int __devinit snd_intel8x0_pcm(intel8x0_t *chip)
1597 int i, tblsize, device, err;
1598 struct ich_pcm_table *tbl, *rec;
1600 switch (chip->device_type) {
1601 case DEVICE_INTEL_ICH4:
1603 tblsize = ARRAY_SIZE(intel_pcms);
1607 tblsize = ARRAY_SIZE(nforce_pcms);
1611 tblsize = ARRAY_SIZE(ali_pcms);
1620 for (i = 0; i < tblsize; i++) {
1622 if (i > 0 && rec->ac97_idx) {
1623 /* activate PCM only when associated AC'97 codec */
1624 if (! chip->ichd[rec->ac97_idx].pcm)
1627 err = snd_intel8x0_pcm1(chip, device, rec);
1633 chip->pcm_devs = device;
1642 static void snd_intel8x0_mixer_free_ac97_bus(ac97_bus_t *bus)
1644 intel8x0_t *chip = bus->private_data;
1645 chip->ac97_bus = NULL;
1648 static void snd_intel8x0_mixer_free_ac97(ac97_t *ac97)
1650 intel8x0_t *chip = ac97->private_data;
1651 chip->ac97[ac97->num] = NULL;
1654 static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
1659 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1660 (1 << AC97_SLOT_PCM_RIGHT) |
1661 (1 << AC97_SLOT_PCM_CENTER) |
1662 (1 << AC97_SLOT_PCM_SLEFT) |
1663 (1 << AC97_SLOT_PCM_SRIGHT) |
1664 (1 << AC97_SLOT_LFE)
1673 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1674 (1 << AC97_SLOT_PCM_RIGHT)
1683 .slots = (1 << AC97_SLOT_MIC)
1692 .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
1693 (1 << AC97_SLOT_SPDIF_RIGHT2)
1702 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1703 (1 << AC97_SLOT_PCM_RIGHT)
1712 .slots = (1 << AC97_SLOT_MIC)
1718 static struct ac97_quirk ac97_quirks[] __devinitdata = {
1722 .name = "Compaq Evo D510C",
1723 .type = AC97_TUNE_HP_ONLY
1729 .type = AC97_TUNE_ALC_JACK
1734 .name = "Dell Precision 530", /* AD1885 */
1735 .type = AC97_TUNE_HP_ONLY
1740 .name = "Dell Optiplex GX260", /* AD1981A */
1741 .type = AC97_TUNE_HP_ONLY
1746 .name = "Dell Precision 450", /* AD1981B*/
1747 .type = AC97_TUNE_HP_ONLY
1749 { /* FIXME: which codec? */
1752 .name = "Hewlett-Packard onboard",
1753 .type = AC97_TUNE_HP_ONLY
1758 .name = "HP xw8200", /* AD1981B*/
1759 .type = AC97_TUNE_HP_ONLY
1764 .name = "HP xw4200", /* AD1981B*/
1765 .type = AC97_TUNE_HP_ONLY
1770 .name = "ASUS ICH5/AD1985",
1771 .type = AC97_TUNE_AD_SHARING
1776 .name = "Fujitsu-Siemens Celsius", /* AD1981? */
1777 .type = AC97_TUNE_HP_ONLY
1782 .name = "AMD64 Mobo", /* ALC650 */
1783 .type = AC97_TUNE_HP_ONLY
1788 .name = "Fujitsu-Siemens Scenic", /* AD1981? */
1789 .type = AC97_TUNE_HP_ONLY
1794 .name = "ADI AD1985 (discrete)",
1795 .type = AC97_TUNE_HP_ONLY
1800 .name = "MSI P4 ATX 645 Ultra",
1801 .type = AC97_TUNE_HP_ONLY
1806 .name = "Fujitsu-Siemens D1522", /* AD1981 */
1807 .type = AC97_TUNE_HP_ONLY
1813 .name = "Intel ICH5/AD1985",
1814 .type = AC97_TUNE_AD_SHARING
1820 .name = "Intel ICH5/AD1985",
1821 .type = AC97_TUNE_AD_SHARING
1826 .name = "Intel D845WN (82801BA)",
1827 .type = AC97_TUNE_SWAP_HP
1832 .name = "Intel D850EMV2", /* AD1885 */
1833 .type = AC97_TUNE_HP_ONLY
1838 .name = "Intel ICH/AD1885",
1839 .type = AC97_TUNE_HP_ONLY
1845 .name = "Intel ICH5/AD1985",
1846 .type = AC97_TUNE_AD_SHARING
1852 .name = "Intel ICH5/AD1985",
1853 .type = AC97_TUNE_AD_SHARING
1855 #if 0 /* FIXME: this seems wrong on most boards */
1860 .name = "Intel ICH5/AD1985",
1861 .type = AC97_TUNE_HP_ONLY
1864 { } /* terminator */
1867 static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock, int ac97_quirk)
1870 ac97_template_t ac97;
1872 unsigned int i, codecs;
1873 unsigned int glob_sta = 0;
1874 int spdif_idx = -1; /* disabled */
1875 ac97_bus_ops_t *ops;
1876 static ac97_bus_ops_t standard_bus_ops = {
1877 .write = snd_intel8x0_codec_write,
1878 .read = snd_intel8x0_codec_read,
1880 static ac97_bus_ops_t ali_bus_ops = {
1881 .write = snd_intel8x0_ali_codec_write,
1882 .read = snd_intel8x0_ali_codec_read,
1885 switch (chip->device_type) {
1887 spdif_idx = NVD_SPBAR;
1890 spdif_idx = ALID_AC97SPDIFOUT;
1893 if (chip->device_type == DEVICE_INTEL_ICH4)
1894 spdif_idx = ICHD_SPBAR;
1898 chip->in_ac97_init = 1;
1900 memset(&ac97, 0, sizeof(ac97));
1901 ac97.private_data = chip;
1902 ac97.private_free = snd_intel8x0_mixer_free_ac97;
1903 ac97.scaps = AC97_SCAP_SKIP_MODEM;
1904 if (chip->device_type != DEVICE_ALI) {
1905 glob_sta = igetdword(chip, ICHREG(GLOB_STA));
1906 ops = &standard_bus_ops;
1907 if (chip->device_type == DEVICE_INTEL_ICH4) {
1909 if (glob_sta & ICH_PCR)
1911 if (glob_sta & ICH_SCR)
1913 if (glob_sta & ICH_TCR)
1915 chip->in_sdin_init = 1;
1916 for (i = 0; i < codecs; i++) {
1917 snd_intel8x0_codec_read_test(chip, i);
1918 chip->ac97_sdin[i] = igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
1920 chip->in_sdin_init = 0;
1922 codecs = glob_sta & ICH_SCR ? 2 : 1;
1927 /* detect the secondary codec */
1928 for (i = 0; i < 100; i++) {
1929 unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
1934 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
1938 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
1940 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
1941 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with modem driver */
1942 if (ac97_clock >= 8000 && ac97_clock <= 48000)
1943 pbus->clock = ac97_clock;
1944 /* FIXME: my test board doesn't work well with VRA... */
1945 if (chip->device_type == DEVICE_ALI)
1947 chip->ac97_bus = pbus;
1949 ac97.pci = chip->pci;
1950 for (i = 0; i < codecs; i++) {
1952 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
1954 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
1960 /* tune up the primary codec */
1961 snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, ac97_quirk);
1962 /* enable separate SDINs for ICH4 */
1963 if (chip->device_type == DEVICE_INTEL_ICH4)
1965 /* find the available PCM streams */
1966 i = ARRAY_SIZE(ac97_pcm_defs);
1967 if (chip->device_type != DEVICE_INTEL_ICH4)
1968 i -= 2; /* do not allocate PCM2IN and MIC2 */
1970 i--; /* do not allocate S/PDIF */
1971 err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
1974 chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
1975 chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
1976 chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
1978 chip->ichd[spdif_idx].pcm = &pbus->pcms[3];
1979 if (chip->device_type == DEVICE_INTEL_ICH4) {
1980 chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
1981 chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
1983 /* enable separate SDINs for ICH4 */
1984 if (chip->device_type == DEVICE_INTEL_ICH4) {
1985 struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
1986 u8 tmp = igetbyte(chip, ICHREG(SDM));
1987 tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
1989 tmp |= ICH_SE; /* steer enable for multiple SDINs */
1990 tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
1991 for (i = 1; i < 4; i++) {
1992 if (pcm->r[0].codec[i]) {
1993 tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
1998 tmp &= ~ICH_SE; /* steer disable */
2000 iputbyte(chip, ICHREG(SDM), tmp);
2002 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2004 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE))
2007 if (chip->device_type == DEVICE_INTEL_ICH4) {
2008 if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
2011 if (chip->device_type == DEVICE_NFORCE) {
2013 chip->ichd[spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
2015 chip->in_ac97_init = 0;
2019 /* clear the cold-reset bit for the next chance */
2020 if (chip->device_type != DEVICE_ALI)
2021 iputdword(chip, ICHREG(GLOB_CNT), igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
2030 static void do_ali_reset(intel8x0_t *chip)
2032 iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
2033 iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
2034 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
2035 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
2036 iputdword(chip, ICHREG(ALI_INTERFACECR),
2037 ICH_ALI_IF_MC|ICH_ALI_IF_PI|ICH_ALI_IF_PO);
2038 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
2039 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2042 #define do_delay(chip) do {\
2043 set_current_state(TASK_UNINTERRUPTIBLE);\
2044 schedule_timeout(1);\
2047 static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
2049 unsigned long end_time;
2050 unsigned int cnt, status, nstatus;
2052 /* put logic to right state */
2053 /* first clear status bits */
2054 status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
2055 if (chip->device_type == DEVICE_NFORCE)
2056 status |= ICH_NVSPINT;
2057 cnt = igetdword(chip, ICHREG(GLOB_STA));
2058 iputdword(chip, ICHREG(GLOB_STA), cnt & status);
2060 /* ACLink on, 2 channels */
2061 cnt = igetdword(chip, ICHREG(GLOB_CNT));
2062 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
2063 /* finish cold or do warm reset */
2064 cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
2065 iputdword(chip, ICHREG(GLOB_CNT), cnt);
2066 end_time = (jiffies + (HZ / 4)) + 1;
2068 if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
2071 } while (time_after_eq(end_time, jiffies));
2072 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
2077 /* wait for any codec ready status.
2078 * Once it becomes ready it should remain ready
2079 * as long as we do not disable the ac97 link.
2081 end_time = jiffies + HZ;
2083 status = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2087 } while (time_after_eq(end_time, jiffies));
2089 /* no codec is found */
2090 snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", igetdword(chip, ICHREG(GLOB_STA)));
2094 if (chip->device_type == DEVICE_INTEL_ICH4)
2095 /* ICH4 can have three codecs */
2096 nstatus = ICH_PCR | ICH_SCR | ICH_TCR;
2098 /* others up to two codecs */
2099 nstatus = ICH_PCR | ICH_SCR;
2101 /* wait for other codecs ready status. */
2102 end_time = jiffies + HZ / 4;
2103 while (status != nstatus && time_after_eq(end_time, jiffies)) {
2105 status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
2112 for (i = 0; i < 3; i++)
2114 status |= get_ich_codec_bit(chip, i);
2115 /* wait until all the probed codecs are ready */
2116 end_time = jiffies + HZ;
2118 nstatus = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2119 if (status == nstatus)
2122 } while (time_after_eq(end_time, jiffies));
2125 if (chip->device_type == DEVICE_SIS) {
2126 /* unmute the output on SIS7012 */
2127 iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
2129 if (chip->device_type == DEVICE_NFORCE) {
2130 /* enable SPDIF interrupt */
2132 pci_read_config_dword(chip->pci, 0x4c, &val);
2134 pci_write_config_dword(chip->pci, 0x4c, val);
2139 static int snd_intel8x0_ali_chip_init(intel8x0_t *chip, int probing)
2144 reg = igetdword(chip, ICHREG(ALI_SCR));
2145 if ((reg & 2) == 0) /* Cold required */
2148 reg |= 1; /* Warm */
2149 reg &= ~0x80000000; /* ACLink on */
2150 iputdword(chip, ICHREG(ALI_SCR), reg);
2152 for (i = 0; i < HZ / 2; i++) {
2153 if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
2157 snd_printk(KERN_ERR "AC'97 reset failed.\n");
2162 for (i = 0; i < HZ / 2; i++) {
2163 reg = igetdword(chip, ICHREG(ALI_RTSR));
2164 if (reg & 0x80) /* primary codec */
2166 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
2174 static int snd_intel8x0_chip_init(intel8x0_t *chip, int probing)
2179 if (chip->device_type != DEVICE_ALI) {
2180 if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
2182 iagetword(chip, 0); /* clear semaphore flag */
2184 if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
2188 /* disable interrupts */
2189 for (i = 0; i < chip->bdbars_count; i++)
2190 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2191 /* reset channels */
2192 for (i = 0; i < chip->bdbars_count; i++)
2193 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2194 /* initialize Buffer Descriptor Lists */
2195 for (i = 0; i < chip->bdbars_count; i++)
2196 iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
2200 static int snd_intel8x0_free(intel8x0_t *chip)
2206 /* disable interrupts */
2207 for (i = 0; i < chip->bdbars_count; i++)
2208 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2209 /* reset channels */
2210 for (i = 0; i < chip->bdbars_count; i++)
2211 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2212 if (chip->device_type == DEVICE_NFORCE) {
2213 /* stop the spdif interrupt */
2215 pci_read_config_dword(chip->pci, 0x4c, &val);
2217 pci_write_config_dword(chip->pci, 0x4c, val);
2220 synchronize_irq(chip->irq);
2223 free_irq(chip->irq, (void *)chip);
2224 if (chip->bdbars.area) {
2225 if (chip->fix_nocache)
2226 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
2227 snd_dma_free_pages(&chip->bdbars);
2229 if (chip->remap_addr)
2230 iounmap(chip->remap_addr);
2231 if (chip->remap_bmaddr)
2232 iounmap(chip->remap_bmaddr);
2233 pci_release_regions(chip->pci);
2242 static int intel8x0_suspend(snd_card_t *card, unsigned int state)
2244 intel8x0_t *chip = card->pm_private_data;
2247 for (i = 0; i < chip->pcm_devs; i++)
2248 snd_pcm_suspend_all(chip->pcm[i]);
2249 for (i = 0; i < 3; i++)
2251 snd_ac97_suspend(chip->ac97[i]);
2252 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2256 static int intel8x0_resume(snd_card_t *card, unsigned int state)
2258 intel8x0_t *chip = card->pm_private_data;
2261 pci_enable_device(chip->pci);
2262 pci_set_master(chip->pci);
2263 snd_intel8x0_chip_init(chip, 0);
2265 /* refill nocache */
2266 if (chip->fix_nocache)
2267 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2269 for (i = 0; i < 3; i++)
2271 snd_ac97_resume(chip->ac97[i]);
2273 /* refill nocache */
2274 if (chip->fix_nocache) {
2275 for (i = 0; i < chip->bdbars_count; i++) {
2276 ichdev_t *ichdev = &chip->ichd[i];
2277 if (ichdev->substream) {
2278 snd_pcm_runtime_t *runtime = ichdev->substream->runtime;
2279 if (runtime->dma_area)
2280 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
2285 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2288 #endif /* CONFIG_PM */
2290 #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
2292 static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2294 snd_pcm_substream_t *subs;
2297 unsigned long pos, t;
2298 struct timeval start_time, stop_time;
2300 if (chip->ac97_bus->clock != 48000)
2301 return; /* specified in module option */
2303 subs = chip->pcm[0]->streams[0].substream;
2304 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2305 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n");
2308 ichdev = &chip->ichd[ICHD_PCMOUT];
2309 ichdev->physbuf = subs->dma_buffer.addr;
2310 ichdev->size = chip->ichd[ICHD_PCMOUT].fragsize = INTEL8X0_TESTBUF_SIZE;
2311 ichdev->substream = NULL; /* don't process interrupts */
2314 if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
2315 snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock);
2318 snd_intel8x0_setup_periods(chip, ichdev);
2319 port = ichdev->reg_offset;
2320 spin_lock_irq(&chip->reg_lock);
2322 if (chip->device_type != DEVICE_ALI)
2323 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
2325 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
2326 iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
2328 do_gettimeofday(&start_time);
2329 spin_unlock_irq(&chip->reg_lock);
2331 set_current_state(TASK_UNINTERRUPTIBLE);
2332 schedule_timeout(HZ / 20);
2334 /* FIXME: schedule() can take too long time and overlap the boundary.. */
2337 spin_lock_irq(&chip->reg_lock);
2338 /* check the position */
2339 pos = ichdev->fragsize1;
2340 pos -= igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << ichdev->pos_shift;
2341 pos += ichdev->position;
2342 do_gettimeofday(&stop_time);
2344 if (chip->device_type == DEVICE_ALI) {
2345 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 8));
2346 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2347 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2350 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2351 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
2354 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
2355 spin_unlock_irq(&chip->reg_lock);
2357 t = stop_time.tv_sec - start_time.tv_sec;
2359 t += stop_time.tv_usec - start_time.tv_usec;
2360 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t);
2362 snd_printk(KERN_ERR "?? calculation error..\n");
2365 pos = (pos / 4) * 1000;
2366 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2367 if (pos < 40000 || pos >= 60000)
2368 /* abnormal value. hw problem? */
2369 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
2370 else if (pos < 47500 || pos > 48500)
2371 /* not 48000Hz, tuning the clock.. */
2372 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
2373 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
2376 static void snd_intel8x0_proc_read(snd_info_entry_t * entry,
2377 snd_info_buffer_t * buffer)
2379 intel8x0_t *chip = entry->private_data;
2382 snd_iprintf(buffer, "Intel8x0\n\n");
2383 if (chip->device_type == DEVICE_ALI)
2385 tmp = igetdword(chip, ICHREG(GLOB_STA));
2386 snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
2387 snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
2388 if (chip->device_type == DEVICE_INTEL_ICH4)
2389 snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
2390 snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
2391 tmp & ICH_PCR ? " primary" : "",
2392 tmp & ICH_SCR ? " secondary" : "",
2393 tmp & ICH_TCR ? " tertiary" : "",
2394 (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
2395 if (chip->device_type == DEVICE_INTEL_ICH4)
2396 snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
2399 chip->ac97_sdin[2]);
2402 static void __devinit snd_intel8x0_proc_init(intel8x0_t * chip)
2404 snd_info_entry_t *entry;
2406 if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
2407 snd_info_set_text_ops(entry, chip, 1024, snd_intel8x0_proc_read);
2410 static int snd_intel8x0_dev_free(snd_device_t *device)
2412 intel8x0_t *chip = device->device_data;
2413 return snd_intel8x0_free(chip);
2416 struct ich_reg_info {
2417 unsigned int int_sta_mask;
2418 unsigned int offset;
2421 static int __devinit snd_intel8x0_create(snd_card_t * card,
2422 struct pci_dev *pci,
2423 unsigned long device_type,
2424 intel8x0_t ** r_intel8x0)
2429 unsigned int int_sta_masks;
2431 static snd_device_ops_t ops = {
2432 .dev_free = snd_intel8x0_dev_free,
2435 static unsigned int bdbars[] = {
2436 3, /* DEVICE_INTEL */
2437 6, /* DEVICE_INTEL_ICH4 */
2440 4, /* DEVICE_NFORCE */
2442 static struct ich_reg_info intel_regs[6] = {
2444 { ICH_POINT, 0x10 },
2445 { ICH_MCINT, 0x20 },
2446 { ICH_M2INT, 0x40 },
2447 { ICH_P2INT, 0x50 },
2448 { ICH_SPINT, 0x60 },
2450 static struct ich_reg_info nforce_regs[4] = {
2452 { ICH_POINT, 0x10 },
2453 { ICH_MCINT, 0x20 },
2454 { ICH_NVSPINT, 0x70 },
2456 static struct ich_reg_info ali_regs[6] = {
2457 { ALI_INT_PCMIN, 0x40 },
2458 { ALI_INT_PCMOUT, 0x50 },
2459 { ALI_INT_MICIN, 0x60 },
2460 { ALI_INT_CODECSPDIFOUT, 0x70 },
2461 { ALI_INT_SPDIFIN, 0xa0 },
2462 { ALI_INT_SPDIFOUT, 0xb0 },
2464 struct ich_reg_info *tbl;
2468 if ((err = pci_enable_device(pci)) < 0)
2471 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
2474 spin_lock_init(&chip->reg_lock);
2475 spin_lock_init(&chip->ac97_lock);
2476 chip->device_type = device_type;
2481 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2482 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2483 chip->fix_nocache = 1; /* enable workaround */
2485 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2486 * Needs to return IRQ_HANDLED for unknown irqs.
2488 if (device_type == DEVICE_NFORCE)
2489 chip->buggy_irq = 1;
2491 if ((err = pci_request_regions(pci, card->shortname)) < 0) {
2496 if (device_type == DEVICE_ALI) {
2497 /* ALI5455 has no ac97 region */
2498 chip->bmaddr = pci_resource_start(pci, 0);
2502 if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */
2504 chip->addr = pci_resource_start(pci, 2);
2505 chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci, 2));
2506 if (!chip->remap_addr) {
2507 snd_printk("AC'97 space ioremap problem\n");
2508 snd_intel8x0_free(chip);
2512 chip->addr = pci_resource_start(pci, 0);
2514 if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */
2516 chip->bmaddr = pci_resource_start(pci, 3);
2517 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, pci_resource_len(pci, 3));
2518 if (!chip->remap_bmaddr) {
2519 snd_printk("Controller space ioremap problem\n");
2520 snd_intel8x0_free(chip);
2524 chip->bmaddr = pci_resource_start(pci, 1);
2528 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2529 snd_printk("unable to grab IRQ %d\n", pci->irq);
2530 snd_intel8x0_free(chip);
2533 chip->irq = pci->irq;
2534 pci_set_master(pci);
2535 synchronize_irq(chip->irq);
2537 chip->bdbars_count = bdbars[device_type];
2539 /* initialize offsets */
2540 switch (device_type) {
2551 for (i = 0; i < chip->bdbars_count; i++) {
2552 ichdev = &chip->ichd[i];
2554 ichdev->reg_offset = tbl[i].offset;
2555 ichdev->int_sta_mask = tbl[i].int_sta_mask;
2556 if (device_type == DEVICE_SIS) {
2557 /* SiS 7012 swaps the registers */
2558 ichdev->roff_sr = ICH_REG_OFF_PICB;
2559 ichdev->roff_picb = ICH_REG_OFF_SR;
2561 ichdev->roff_sr = ICH_REG_OFF_SR;
2562 ichdev->roff_picb = ICH_REG_OFF_PICB;
2564 if (device_type == DEVICE_ALI)
2565 ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
2566 /* SIS7012 handles the pcm data in bytes, others are in samples */
2567 ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
2570 /* allocate buffer descriptor lists */
2571 /* the start of each lists must be aligned to 8 bytes */
2572 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
2573 chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
2574 &chip->bdbars) < 0) {
2575 snd_intel8x0_free(chip);
2576 snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n");
2579 /* tables must be aligned to 8 bytes here, but the kernel pages
2580 are much bigger, so we don't care (on i386) */
2581 /* workaround for 440MX */
2582 if (chip->fix_nocache)
2583 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2585 for (i = 0; i < chip->bdbars_count; i++) {
2586 ichdev = &chip->ichd[i];
2587 ichdev->bdbar = ((u32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2);
2588 ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
2589 int_sta_masks |= ichdev->int_sta_mask;
2591 chip->int_sta_reg = device_type == DEVICE_ALI ? ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
2592 chip->int_sta_mask = int_sta_masks;
2594 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
2595 snd_intel8x0_free(chip);
2599 snd_card_set_pm_callback(card, intel8x0_suspend, intel8x0_resume, chip);
2601 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2602 snd_intel8x0_free(chip);
2606 snd_card_set_dev(card, &pci->dev);
2612 static struct shortname_table {
2615 } shortnames[] __devinitdata = {
2616 { PCI_DEVICE_ID_INTEL_82801, "Intel 82801AA-ICH" },
2617 { PCI_DEVICE_ID_INTEL_82901, "Intel 82901AB-ICH0" },
2618 { PCI_DEVICE_ID_INTEL_82801BA, "Intel 82801BA-ICH2" },
2619 { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
2620 { PCI_DEVICE_ID_INTEL_ICH3, "Intel 82801CA-ICH3" },
2621 { PCI_DEVICE_ID_INTEL_ICH4, "Intel 82801DB-ICH4" },
2622 { PCI_DEVICE_ID_INTEL_ICH5, "Intel ICH5" },
2623 { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
2624 { PCI_DEVICE_ID_INTEL_ICH6_3, "Intel ICH6" },
2625 { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
2626 { PCI_DEVICE_ID_NVIDIA_MCP_AUDIO, "NVidia nForce" },
2627 { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
2628 { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
2629 { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
2630 { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
2631 { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
2632 { 0x003a, "NVidia MCP04" },
2633 { 0x746d, "AMD AMD8111" },
2634 { 0x7445, "AMD AMD768" },
2635 { 0x5455, "ALi M5455" },
2639 static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2640 const struct pci_device_id *pci_id)
2646 struct shortname_table *name;
2648 if (dev >= SNDRV_CARDS)
2655 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2659 switch (pci_id->driver_data) {
2661 strcpy(card->driver, "NFORCE");
2664 strcpy(card->driver, "ICH");
2668 strcpy(card->shortname, "Intel ICH");
2669 for (name = shortnames; name->id; name++) {
2670 if (pci->device == name->id) {
2671 strcpy(card->shortname, name->s);
2676 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip)) < 0) {
2677 snd_card_free(card);
2681 chip->buggy_irq = 1;
2683 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) {
2684 snd_card_free(card);
2687 if ((err = snd_intel8x0_pcm(chip)) < 0) {
2688 snd_card_free(card);
2692 if (mpu_port[dev] == 0x300 || mpu_port[dev] == 0x330) {
2693 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_INTEL8X0,
2695 -1, 0, &chip->rmidi)) < 0) {
2696 printk(KERN_ERR "intel8x0: no UART401 device at 0x%x, skipping.\n", mpu_port[dev]);
2702 snd_intel8x0_proc_init(chip);
2704 sprintf(card->longname, "%s at 0x%lx, irq %i",
2705 card->shortname, chip->addr, chip->irq);
2707 if (! ac97_clock[dev])
2708 intel8x0_measure_ac97_clock(chip);
2710 if ((err = snd_card_register(card)) < 0) {
2711 snd_card_free(card);
2714 pci_set_drvdata(pci, card);
2719 static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
2721 snd_card_free(pci_get_drvdata(pci));
2722 pci_set_drvdata(pci, NULL);
2725 static struct pci_driver driver = {
2726 .name = "Intel ICH",
2727 .id_table = snd_intel8x0_ids,
2728 .probe = snd_intel8x0_probe,
2729 .remove = __devexit_p(snd_intel8x0_remove),
2730 SND_PCI_PM_CALLBACKS
2734 #if defined(SUPPORT_JOYSTICK) || defined(SUPPORT_MIDI)
2736 * initialize joystick/midi addresses
2739 #ifdef SUPPORT_JOYSTICK
2740 /* there is only one available device, so we keep it here */
2741 static struct pci_dev *ich_gameport_pci;
2742 static struct gameport ich_gameport = { .io = 0x200 };
2745 static int __devinit snd_intel8x0_joystick_probe(struct pci_dev *pci,
2746 const struct pci_device_id *id)
2750 if (dev >= SNDRV_CARDS)
2757 pci_read_config_word(pci, 0xe6, &val);
2758 #ifdef SUPPORT_JOYSTICK
2760 if (joystick[dev]) {
2761 if (! request_region(ich_gameport.io, 8, "ICH gameport")) {
2762 printk(KERN_WARNING "intel8x0: cannot grab gameport 0x%x\n", ich_gameport.io);
2765 ich_gameport_pci = pci;
2766 gameport_register_port(&ich_gameport);
2773 if (mpu_port[dev] > 0) {
2774 if (mpu_port[dev] == 0x300 || mpu_port[dev] == 0x330) {
2777 pci_read_config_byte(pci, 0xe2, &b);
2778 if (mpu_port[dev] == 0x300)
2782 pci_write_config_byte(pci, 0xe2, b);
2786 pci_write_config_word(pci, 0xe6, val);
2790 static void __devexit snd_intel8x0_joystick_remove(struct pci_dev *pci)
2793 #ifdef SUPPORT_JOYSTICK
2794 if (ich_gameport_pci == pci) {
2795 gameport_unregister_port(&ich_gameport);
2796 release_region(ich_gameport.io, 8);
2797 ich_gameport_pci = NULL;
2800 /* disable joystick and MIDI */
2801 pci_read_config_word(pci, 0xe6, &val);
2803 pci_write_config_word(pci, 0xe6, val);
2806 static struct pci_device_id snd_intel8x0_joystick_ids[] = {
2807 { 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 82801AA */
2808 { 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 82901AB */
2809 { 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICH2 */
2810 { 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICH2M */
2811 { 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICH3 */
2812 // { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 440MX */
2813 // { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SI7012 */
2814 { 0x10de, 0x01b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* NFORCE */
2815 { 0x10de, 0x006b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* NFORCE2 */
2816 { 0x10de, 0x00db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* NFORCE3 */
2820 static struct pci_driver joystick_driver = {
2821 .name = "Intel ICH Joystick",
2822 .id_table = snd_intel8x0_joystick_ids,
2823 .probe = snd_intel8x0_joystick_probe,
2824 .remove = __devexit_p(snd_intel8x0_joystick_remove),
2827 static int have_joystick;
2830 static int __init alsa_card_intel8x0_init(void)
2834 if ((err = pci_module_init(&driver)) < 0)
2837 #if defined(SUPPORT_JOYSTICK) || defined(SUPPORT_MIDI)
2838 if (pci_module_init(&joystick_driver) < 0) {
2839 snd_printdd(KERN_INFO "no joystick found\n");
2842 snd_printdd(KERN_INFO "joystick(s) found\n");
2850 static void __exit alsa_card_intel8x0_exit(void)
2852 pci_unregister_driver(&driver);
2853 #if defined(SUPPORT_JOYSTICK) || defined(SUPPORT_MIDI)
2855 pci_unregister_driver(&joystick_driver);
2859 module_init(alsa_card_intel8x0_init)
2860 module_exit(alsa_card_intel8x0_exit)