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/moduleparam.h>
37 #include <sound/core.h>
38 #include <sound/pcm.h>
39 #include <sound/ac97_codec.h>
40 #include <sound/info.h>
41 #include <sound/initval.h>
42 /* for 440MX workaround */
43 #include <asm/pgtable.h>
44 #include <asm/cacheflush.h>
46 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
47 MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
48 MODULE_LICENSE("GPL");
49 MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
50 "{Intel,82901AB-ICH0},"
51 "{Intel,82801BA-ICH2},"
52 "{Intel,82801CA-ICH3},"
53 "{Intel,82801DB-ICH4},"
61 "{NVidia,nForce Audio},"
62 "{NVidia,nForce2 Audio},"
67 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
68 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
69 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
70 static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
71 static char *ac97_quirk[SNDRV_CARDS];
72 static int buggy_irq[SNDRV_CARDS];
73 static int xbox[SNDRV_CARDS];
76 static int mpu_port[SNDRV_CARDS]; /* disabled */
79 module_param_array(index, int, NULL, 0444);
80 MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
81 module_param_array(id, charp, NULL, 0444);
82 MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
83 module_param_array(enable, bool, NULL, 0444);
84 MODULE_PARM_DESC(enable, "Enable Intel i8x0 soundcard.");
85 module_param_array(ac97_clock, int, NULL, 0444);
86 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
87 module_param_array(ac97_quirk, charp, NULL, 0444);
88 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
89 module_param_array(buggy_irq, bool, NULL, 0444);
90 MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
91 module_param_array(xbox, bool, NULL, 0444);
92 MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
98 #ifndef PCI_DEVICE_ID_INTEL_82801
99 #define PCI_DEVICE_ID_INTEL_82801 0x2415
101 #ifndef PCI_DEVICE_ID_INTEL_82901
102 #define PCI_DEVICE_ID_INTEL_82901 0x2425
104 #ifndef PCI_DEVICE_ID_INTEL_82801BA
105 #define PCI_DEVICE_ID_INTEL_82801BA 0x2445
107 #ifndef PCI_DEVICE_ID_INTEL_440MX
108 #define PCI_DEVICE_ID_INTEL_440MX 0x7195
110 #ifndef PCI_DEVICE_ID_INTEL_ICH3
111 #define PCI_DEVICE_ID_INTEL_ICH3 0x2485
113 #ifndef PCI_DEVICE_ID_INTEL_ICH4
114 #define PCI_DEVICE_ID_INTEL_ICH4 0x24c5
116 #ifndef PCI_DEVICE_ID_INTEL_ICH5
117 #define PCI_DEVICE_ID_INTEL_ICH5 0x24d5
119 #ifndef PCI_DEVICE_ID_INTEL_ESB_5
120 #define PCI_DEVICE_ID_INTEL_ESB_5 0x25a6
122 #ifndef PCI_DEVICE_ID_INTEL_ICH6_18
123 #define PCI_DEVICE_ID_INTEL_ICH6_18 0x266e
125 #ifndef PCI_DEVICE_ID_INTEL_ICH7_20
126 #define PCI_DEVICE_ID_INTEL_ICH7_20 0x27de
128 #ifndef PCI_DEVICE_ID_INTEL_ESB2_14
129 #define PCI_DEVICE_ID_INTEL_ESB2_14 0x2698
131 #ifndef PCI_DEVICE_ID_SI_7012
132 #define PCI_DEVICE_ID_SI_7012 0x7012
134 #ifndef PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
135 #define PCI_DEVICE_ID_NVIDIA_MCP_AUDIO 0x01b1
137 #ifndef PCI_DEVICE_ID_NVIDIA_CK804_AUDIO
138 #define PCI_DEVICE_ID_NVIDIA_CK804_AUDIO 0x0059
140 #ifndef PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
141 #define PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO 0x006a
143 #ifndef PCI_DEVICE_ID_NVIDIA_CK8_AUDIO
144 #define PCI_DEVICE_ID_NVIDIA_CK8_AUDIO 0x008a
146 #ifndef PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO
147 #define PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO 0x00da
149 #ifndef PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO
150 #define PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO 0x00ea
153 enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
155 #define ICHREG(x) ICH_REG_##x
157 #define DEFINE_REGSET(name,base) \
159 ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
160 ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
161 ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
162 ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
163 ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
164 ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
165 ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
168 /* busmaster blocks */
169 DEFINE_REGSET(OFF, 0); /* offset */
170 DEFINE_REGSET(PI, 0x00); /* PCM in */
171 DEFINE_REGSET(PO, 0x10); /* PCM out */
172 DEFINE_REGSET(MC, 0x20); /* Mic in */
174 /* ICH4 busmaster blocks */
175 DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
176 DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
177 DEFINE_REGSET(SP, 0x60); /* SPDIF out */
179 /* values for each busmaster block */
182 #define ICH_REG_LVI_MASK 0x1f
185 #define ICH_FIFOE 0x10 /* FIFO error */
186 #define ICH_BCIS 0x08 /* buffer completion interrupt status */
187 #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
188 #define ICH_CELV 0x02 /* current equals last valid */
189 #define ICH_DCH 0x01 /* DMA controller halted */
192 #define ICH_REG_PIV_MASK 0x1f /* mask */
195 #define ICH_IOCE 0x10 /* interrupt on completion enable */
196 #define ICH_FEIE 0x08 /* fifo error interrupt enable */
197 #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
198 #define ICH_RESETREGS 0x02 /* reset busmaster registers */
199 #define ICH_STARTBM 0x01 /* start busmaster operation */
203 #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
204 #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
205 #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
206 #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
207 #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
208 #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
209 #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
210 #define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */
211 #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
212 #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
213 #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
214 #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
215 #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
216 #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
217 #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
218 #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
219 #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
220 #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
221 #define ICH_ACLINK 0x00000008 /* AClink shut off */
222 #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
223 #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
224 #define ICH_GIE 0x00000001 /* GPI interrupt enable */
225 #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
226 #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
227 #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
228 #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
229 #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
230 #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
231 #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
232 #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
233 #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
234 #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
235 #define ICH_MD3 0x00020000 /* modem power down semaphore */
236 #define ICH_AD3 0x00010000 /* audio power down semaphore */
237 #define ICH_RCS 0x00008000 /* read completion status */
238 #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
239 #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
240 #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
241 #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
242 #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
243 #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
244 #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
245 #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
246 #define ICH_POINT 0x00000040 /* playback interrupt */
247 #define ICH_PIINT 0x00000020 /* capture interrupt */
248 #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
249 #define ICH_MOINT 0x00000004 /* modem playback interrupt */
250 #define ICH_MIINT 0x00000002 /* modem capture interrupt */
251 #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
252 #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
253 #define ICH_CAS 0x01 /* codec access semaphore */
254 #define ICH_REG_SDM 0x80
255 #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
256 #define ICH_DI2L_SHIFT 6
257 #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
258 #define ICH_DI1L_SHIFT 4
259 #define ICH_SE 0x00000008 /* steer enable */
260 #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
262 #define ICH_MAX_FRAGS 32 /* max hw frags */
266 * registers for Ali5455
269 /* ALi 5455 busmaster blocks */
270 DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
271 DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
272 DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
273 DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
274 DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
275 DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
276 DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
277 DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
278 DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
279 DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
280 DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
283 ICH_REG_ALI_SCR = 0x00, /* System Control Register */
284 ICH_REG_ALI_SSR = 0x04, /* System Status Register */
285 ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
286 ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
287 ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
288 ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
289 ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
290 ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
291 ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
292 ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
293 ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
294 ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
295 ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
296 ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
297 ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
298 ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
299 ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
300 ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
301 ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
302 ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
303 ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
306 #define ALI_CAS_SEM_BUSY 0x80000000
307 #define ALI_CPR_ADDR_SECONDARY 0x100
308 #define ALI_CPR_ADDR_READ 0x80
309 #define ALI_CSPSR_CODEC_READY 0x08
310 #define ALI_CSPSR_READ_OK 0x02
311 #define ALI_CSPSR_WRITE_OK 0x01
313 /* interrupts for the whole chip by interrupt status register finish */
315 #define ALI_INT_MICIN2 (1<<26)
316 #define ALI_INT_PCMIN2 (1<<25)
317 #define ALI_INT_I2SIN (1<<24)
318 #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
319 #define ALI_INT_SPDIFIN (1<<22)
320 #define ALI_INT_LFEOUT (1<<21)
321 #define ALI_INT_CENTEROUT (1<<20)
322 #define ALI_INT_CODECSPDIFOUT (1<<19)
323 #define ALI_INT_MICIN (1<<18)
324 #define ALI_INT_PCMOUT (1<<17)
325 #define ALI_INT_PCMIN (1<<16)
326 #define ALI_INT_CPRAIS (1<<7) /* command port available */
327 #define ALI_INT_SPRAIS (1<<5) /* status port available */
328 #define ALI_INT_GPIO (1<<1)
329 #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
331 #define ICH_ALI_SC_RESET (1<<31) /* master reset */
332 #define ICH_ALI_SC_AC97_DBL (1<<30)
333 #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
334 #define ICH_ALI_SC_IN_BITS (3<<18)
335 #define ICH_ALI_SC_OUT_BITS (3<<16)
336 #define ICH_ALI_SC_6CH_CFG (3<<14)
337 #define ICH_ALI_SC_PCM_4 (1<<8)
338 #define ICH_ALI_SC_PCM_6 (2<<8)
339 #define ICH_ALI_SC_PCM_246_MASK (3<<8)
341 #define ICH_ALI_SS_SEC_ID (3<<5)
342 #define ICH_ALI_SS_PRI_ID (3<<3)
344 #define ICH_ALI_IF_AC97SP (1<<21)
345 #define ICH_ALI_IF_MC (1<<20)
346 #define ICH_ALI_IF_PI (1<<19)
347 #define ICH_ALI_IF_MC2 (1<<18)
348 #define ICH_ALI_IF_PI2 (1<<17)
349 #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
350 #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
351 #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
352 #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
353 #define ICH_ALI_IF_PO_SPDF (1<<3)
354 #define ICH_ALI_IF_PO (1<<1)
360 enum { ICHD_PCMIN, ICHD_PCMOUT, ICHD_MIC, ICHD_MIC2, ICHD_PCM2IN, ICHD_SPBAR, ICHD_LAST = ICHD_SPBAR };
361 enum { NVD_PCMIN, NVD_PCMOUT, NVD_MIC, NVD_SPBAR, NVD_LAST = NVD_SPBAR };
362 enum { ALID_PCMIN, ALID_PCMOUT, ALID_MIC, ALID_AC97SPDIFOUT, ALID_SPDIFIN, ALID_SPDIFOUT, ALID_LAST = ALID_SPDIFOUT };
364 #define get_ichdev(substream) (ichdev_t *)(substream->runtime->private_data)
367 unsigned int ichd; /* ich device number */
368 unsigned long reg_offset; /* offset to bmaddr */
369 u32 *bdbar; /* CPU address (32bit) */
370 unsigned int bdbar_addr; /* PCI bus address (32bit) */
371 snd_pcm_substream_t *substream;
372 unsigned int physbuf; /* physical address (32bit) */
374 unsigned int fragsize;
375 unsigned int fragsize1;
376 unsigned int position;
377 unsigned int pos_shift;
384 unsigned int ack_bit;
385 unsigned int roff_sr;
386 unsigned int roff_picb;
387 unsigned int int_sta_mask; /* interrupt status mask */
388 unsigned int ali_slot; /* ALI DMA slot */
389 struct ac97_pcm *pcm;
391 unsigned int page_attr_changed: 1;
394 typedef struct _snd_intel8x0 intel8x0_t;
396 struct _snd_intel8x0 {
397 unsigned int device_type;
403 void __iomem *remap_addr;
404 unsigned int bm_mmio;
405 unsigned long bmaddr;
406 void __iomem *remap_bmaddr;
419 unsigned in_ac97_init: 1,
421 unsigned in_measurement: 1; /* during ac97 clock measurement */
422 unsigned fix_nocache: 1; /* workaround for 440MX */
423 unsigned buggy_irq: 1; /* workaround for buggy mobos */
424 unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
426 int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
427 unsigned int sdm_saved; /* SDM reg value */
429 ac97_bus_t *ac97_bus;
431 unsigned int ac97_sdin[3];
436 struct snd_dma_buffer bdbars;
437 u32 int_sta_reg; /* interrupt status register */
438 u32 int_sta_mask; /* interrupt status mask */
441 static struct pci_device_id snd_intel8x0_ids[] = {
442 { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */
443 { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */
444 { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */
445 { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */
446 { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */
447 { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */
448 { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */
449 { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */
450 { 0x8086, 0x27de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH7 */
451 { 0x8086, 0x2698, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB2 */
452 { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */
453 { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */
454 { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */
455 { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */
456 { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */
457 { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */
458 { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */
459 { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */
460 { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */
461 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
462 { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
463 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
467 MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
470 * Lowlevel I/O - busmaster
473 static u8 igetbyte(intel8x0_t *chip, u32 offset)
476 return readb(chip->remap_bmaddr + offset);
478 return inb(chip->bmaddr + offset);
481 static u16 igetword(intel8x0_t *chip, u32 offset)
484 return readw(chip->remap_bmaddr + offset);
486 return inw(chip->bmaddr + offset);
489 static u32 igetdword(intel8x0_t *chip, u32 offset)
492 return readl(chip->remap_bmaddr + offset);
494 return inl(chip->bmaddr + offset);
497 static void iputbyte(intel8x0_t *chip, u32 offset, u8 val)
500 writeb(val, chip->remap_bmaddr + offset);
502 outb(val, chip->bmaddr + offset);
505 static void iputword(intel8x0_t *chip, u32 offset, u16 val)
508 writew(val, chip->remap_bmaddr + offset);
510 outw(val, chip->bmaddr + offset);
513 static void iputdword(intel8x0_t *chip, u32 offset, u32 val)
516 writel(val, chip->remap_bmaddr + offset);
518 outl(val, chip->bmaddr + offset);
522 * Lowlevel I/O - AC'97 registers
525 static u16 iagetword(intel8x0_t *chip, u32 offset)
528 return readw(chip->remap_addr + offset);
530 return inw(chip->addr + offset);
533 static void iaputword(intel8x0_t *chip, u32 offset, u16 val)
536 writew(val, chip->remap_addr + offset);
538 outw(val, chip->addr + offset);
546 * access to AC97 codec via normal i/o (for ICH and SIS7012)
549 /* return the GLOB_STA bit for the corresponding codec */
550 static unsigned int get_ich_codec_bit(intel8x0_t *chip, unsigned int codec)
552 static unsigned int codec_bit[3] = {
553 ICH_PCR, ICH_SCR, ICH_TCR
555 snd_assert(codec < 3, return ICH_PCR);
556 if (chip->device_type == DEVICE_INTEL_ICH4)
557 codec = chip->ac97_sdin[codec];
558 return codec_bit[codec];
561 static int snd_intel8x0_codec_semaphore(intel8x0_t *chip, unsigned int codec)
567 if (chip->in_sdin_init) {
568 /* we don't know the ready bit assignment at the moment */
569 /* so we check any */
570 codec = ICH_PCR | ICH_SCR | ICH_TCR;
572 codec = get_ich_codec_bit(chip, codec);
576 if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
579 /* Anyone holding a semaphore for 1 msec should be shot... */
582 if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
587 /* access to some forbidden (non existant) ac97 registers will not
588 * reset the semaphore. So even if you don't get the semaphore, still
589 * continue the access. We don't need the semaphore anyway. */
590 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
591 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
592 iagetword(chip, 0); /* clear semaphore flag */
593 /* I don't care about the semaphore */
597 static void snd_intel8x0_codec_write(ac97_t *ac97,
601 intel8x0_t *chip = ac97->private_data;
603 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
604 if (! chip->in_ac97_init)
605 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
607 iaputword(chip, reg + ac97->num * 0x80, val);
610 static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
613 intel8x0_t *chip = ac97->private_data;
617 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
618 if (! chip->in_ac97_init)
619 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
622 res = iagetword(chip, reg + ac97->num * 0x80);
623 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
624 /* reset RCS and preserve other R/WC bits */
625 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
626 if (! chip->in_ac97_init)
627 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
634 static void snd_intel8x0_codec_read_test(intel8x0_t *chip, unsigned int codec)
638 if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
639 iagetword(chip, codec * 0x80);
640 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
641 /* reset RCS and preserve other R/WC bits */
642 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
648 * access to AC97 for Ali5455
650 static int snd_intel8x0_ali_codec_ready(intel8x0_t *chip, int mask)
653 for (count = 0; count < 0x7f; count++) {
654 int val = igetbyte(chip, ICHREG(ALI_CSPSR));
658 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
662 static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip)
665 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
668 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
669 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
672 static unsigned short snd_intel8x0_ali_codec_read(ac97_t *ac97, unsigned short reg)
674 intel8x0_t *chip = ac97->private_data;
675 unsigned short data = 0xffff;
677 if (snd_intel8x0_ali_codec_semaphore(chip))
679 reg |= ALI_CPR_ADDR_READ;
681 reg |= ALI_CPR_ADDR_SECONDARY;
682 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
683 if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
685 data = igetword(chip, ICHREG(ALI_SPR));
690 static void snd_intel8x0_ali_codec_write(ac97_t *ac97, unsigned short reg, unsigned short val)
692 intel8x0_t *chip = ac97->private_data;
694 if (snd_intel8x0_ali_codec_semaphore(chip))
696 iputword(chip, ICHREG(ALI_CPR), val);
698 reg |= ALI_CPR_ADDR_SECONDARY;
699 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
700 snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
707 static void snd_intel8x0_setup_periods(intel8x0_t *chip, ichdev_t *ichdev)
710 u32 *bdbar = ichdev->bdbar;
711 unsigned long port = ichdev->reg_offset;
713 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
714 if (ichdev->size == ichdev->fragsize) {
715 ichdev->ack_reload = ichdev->ack = 2;
716 ichdev->fragsize1 = ichdev->fragsize >> 1;
717 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
718 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
719 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
720 ichdev->fragsize1 >> ichdev->pos_shift);
721 bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
722 bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
723 ichdev->fragsize1 >> ichdev->pos_shift);
727 ichdev->ack_reload = ichdev->ack = 1;
728 ichdev->fragsize1 = ichdev->fragsize;
729 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
730 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
731 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
732 ichdev->fragsize >> ichdev->pos_shift);
733 // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
735 ichdev->frags = ichdev->size / ichdev->fragsize;
737 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
739 iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
740 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
741 ichdev->position = 0;
743 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
744 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1);
746 /* clear interrupts */
747 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
752 * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
753 * which aborts PCI busmaster for audio transfer. A workaround is to set
754 * the pages as non-cached. For details, see the errata in
755 * http://www.intel.com/design/chipsets/specupdt/245051.htm
757 static void fill_nocache(void *buf, int size, int nocache)
759 size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
760 change_page_attr(virt_to_page(buf), size, nocache ? PAGE_KERNEL_NOCACHE : PAGE_KERNEL);
764 #define fill_nocache(buf,size,nocache)
771 static inline void snd_intel8x0_update(intel8x0_t *chip, ichdev_t *ichdev)
773 unsigned long port = ichdev->reg_offset;
774 int status, civ, i, step;
777 spin_lock(&chip->reg_lock);
778 status = igetbyte(chip, port + ichdev->roff_sr);
779 civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
780 if (!(status & ICH_BCIS)) {
782 } else if (civ == ichdev->civ) {
783 // snd_printd("civ same %d\n", civ);
786 ichdev->civ &= ICH_REG_LVI_MASK;
788 step = civ - ichdev->civ;
790 step += ICH_REG_LVI_MASK + 1;
792 // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
796 ichdev->position += step * ichdev->fragsize1;
797 if (! chip->in_measurement)
798 ichdev->position %= ichdev->size;
800 ichdev->lvi &= ICH_REG_LVI_MASK;
801 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
802 for (i = 0; i < step; i++) {
804 ichdev->lvi_frag %= ichdev->frags;
805 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
806 // 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));
807 if (--ichdev->ack == 0) {
808 ichdev->ack = ichdev->ack_reload;
812 spin_unlock(&chip->reg_lock);
813 if (ack && ichdev->substream) {
814 snd_pcm_period_elapsed(ichdev->substream);
816 iputbyte(chip, port + ichdev->roff_sr,
817 status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
820 static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id, struct pt_regs *regs)
822 intel8x0_t *chip = dev_id;
827 status = igetdword(chip, chip->int_sta_reg);
828 if (status == 0xffffffff) /* we are not yet resumed */
831 if ((status & chip->int_sta_mask) == 0) {
834 iputdword(chip, chip->int_sta_reg, status);
835 if (! chip->buggy_irq)
838 return IRQ_RETVAL(status);
841 for (i = 0; i < chip->bdbars_count; i++) {
842 ichdev = &chip->ichd[i];
843 if (status & ichdev->int_sta_mask)
844 snd_intel8x0_update(chip, ichdev);
848 iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
857 static int snd_intel8x0_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
859 intel8x0_t *chip = snd_pcm_substream_chip(substream);
860 ichdev_t *ichdev = get_ichdev(substream);
861 unsigned char val = 0;
862 unsigned long port = ichdev->reg_offset;
865 case SNDRV_PCM_TRIGGER_START:
866 case SNDRV_PCM_TRIGGER_RESUME:
867 val = ICH_IOCE | ICH_STARTBM;
869 case SNDRV_PCM_TRIGGER_STOP:
870 case SNDRV_PCM_TRIGGER_SUSPEND:
873 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
876 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
877 val = ICH_IOCE | ICH_STARTBM;
882 iputbyte(chip, port + ICH_REG_OFF_CR, val);
883 if (cmd == SNDRV_PCM_TRIGGER_STOP) {
884 /* wait until DMA stopped */
885 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
886 /* reset whole DMA things */
887 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
892 static int snd_intel8x0_ali_trigger(snd_pcm_substream_t *substream, int cmd)
894 intel8x0_t *chip = snd_pcm_substream_chip(substream);
895 ichdev_t *ichdev = get_ichdev(substream);
896 unsigned long port = ichdev->reg_offset;
897 static int fiforeg[] = { ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3) };
898 unsigned int val, fifo;
900 val = igetdword(chip, ICHREG(ALI_DMACR));
902 case SNDRV_PCM_TRIGGER_START:
903 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
904 case SNDRV_PCM_TRIGGER_RESUME:
905 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
906 /* clear FIFO for synchronization of channels */
907 fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
908 fifo &= ~(0xff << (ichdev->ali_slot % 4));
909 fifo |= 0x83 << (ichdev->ali_slot % 4);
910 iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
912 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
913 val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
914 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot)); /* start DMA */
916 case SNDRV_PCM_TRIGGER_STOP:
917 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
918 case SNDRV_PCM_TRIGGER_SUSPEND:
919 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16))); /* pause */
920 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
921 while (igetbyte(chip, port + ICH_REG_OFF_CR))
923 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
925 /* reset whole DMA things */
926 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
927 /* clear interrupts */
928 iputbyte(chip, port + ICH_REG_OFF_SR, igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
929 iputdword(chip, ICHREG(ALI_INTERRUPTSR),
930 igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
938 static int snd_intel8x0_hw_params(snd_pcm_substream_t * substream,
939 snd_pcm_hw_params_t * hw_params)
941 intel8x0_t *chip = snd_pcm_substream_chip(substream);
942 ichdev_t *ichdev = get_ichdev(substream);
943 snd_pcm_runtime_t *runtime = substream->runtime;
944 int dbl = params_rate(hw_params) > 48000;
947 if (chip->fix_nocache && ichdev->page_attr_changed) {
948 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
949 ichdev->page_attr_changed = 0;
951 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
954 if (chip->fix_nocache) {
955 if (runtime->dma_area && ! ichdev->page_attr_changed) {
956 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
957 ichdev->page_attr_changed = 1;
960 if (ichdev->pcm_open_flag) {
961 snd_ac97_pcm_close(ichdev->pcm);
962 ichdev->pcm_open_flag = 0;
964 err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
965 params_channels(hw_params),
966 ichdev->pcm->r[dbl].slots);
968 ichdev->pcm_open_flag = 1;
969 /* Force SPDIF setting */
970 if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
971 snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF, params_rate(hw_params));
976 static int snd_intel8x0_hw_free(snd_pcm_substream_t * substream)
978 intel8x0_t *chip = snd_pcm_substream_chip(substream);
979 ichdev_t *ichdev = get_ichdev(substream);
981 if (ichdev->pcm_open_flag) {
982 snd_ac97_pcm_close(ichdev->pcm);
983 ichdev->pcm_open_flag = 0;
985 if (chip->fix_nocache && ichdev->page_attr_changed) {
986 fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
987 ichdev->page_attr_changed = 0;
989 return snd_pcm_lib_free_pages(substream);
992 static void snd_intel8x0_setup_pcm_out(intel8x0_t *chip,
993 snd_pcm_runtime_t *runtime)
996 int dbl = runtime->rate > 48000;
997 switch (chip->device_type) {
999 cnt = igetdword(chip, ICHREG(ALI_SCR));
1000 cnt &= ~ICH_ALI_SC_PCM_246_MASK;
1001 if (runtime->channels == 4 || dbl)
1002 cnt |= ICH_ALI_SC_PCM_4;
1003 else if (runtime->channels == 6)
1004 cnt |= ICH_ALI_SC_PCM_6;
1005 iputdword(chip, ICHREG(ALI_SCR), cnt);
1008 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1009 cnt &= ~ICH_SIS_PCM_246_MASK;
1010 if (runtime->channels == 4 || dbl)
1011 cnt |= ICH_SIS_PCM_4;
1012 else if (runtime->channels == 6)
1013 cnt |= ICH_SIS_PCM_6;
1014 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1017 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1018 cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
1019 if (runtime->channels == 4 || dbl)
1021 else if (runtime->channels == 6)
1023 if (chip->device_type == DEVICE_NFORCE) {
1024 /* reset to 2ch once to keep the 6 channel data in alignment,
1025 * to start from Front Left always
1027 if (cnt & ICH_PCM_246_MASK) {
1028 iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
1029 spin_unlock_irq(&chip->reg_lock);
1030 msleep(50); /* grrr... */
1031 spin_lock_irq(&chip->reg_lock);
1033 } else if (chip->device_type == DEVICE_INTEL_ICH4) {
1034 if (runtime->sample_bits > 16)
1035 cnt |= ICH_PCM_20BIT;
1037 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1042 static int snd_intel8x0_pcm_prepare(snd_pcm_substream_t * substream)
1044 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1045 snd_pcm_runtime_t *runtime = substream->runtime;
1046 ichdev_t *ichdev = get_ichdev(substream);
1048 ichdev->physbuf = runtime->dma_addr;
1049 ichdev->size = snd_pcm_lib_buffer_bytes(substream);
1050 ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
1051 spin_lock_irq(&chip->reg_lock);
1052 if (ichdev->ichd == ICHD_PCMOUT) {
1053 snd_intel8x0_setup_pcm_out(chip, runtime);
1054 if (chip->device_type == DEVICE_INTEL_ICH4) {
1055 ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
1058 snd_intel8x0_setup_periods(chip, ichdev);
1059 spin_unlock_irq(&chip->reg_lock);
1063 static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(snd_pcm_substream_t * substream)
1065 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1066 ichdev_t *ichdev = get_ichdev(substream);
1068 int civ, timeout = 100;
1069 unsigned int position;
1071 spin_lock(&chip->reg_lock);
1073 civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
1074 ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
1075 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);
1172 snd_ac97_pcm_double_rate_rules(runtime);
1174 if (chip->smp20bit) {
1175 runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
1176 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
1181 static int snd_intel8x0_playback_close(snd_pcm_substream_t * substream)
1183 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1185 chip->ichd[ICHD_PCMOUT].substream = NULL;
1189 static int snd_intel8x0_capture_open(snd_pcm_substream_t * substream)
1191 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1193 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
1196 static int snd_intel8x0_capture_close(snd_pcm_substream_t * substream)
1198 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1200 chip->ichd[ICHD_PCMIN].substream = NULL;
1204 static int snd_intel8x0_mic_open(snd_pcm_substream_t * substream)
1206 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1208 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
1211 static int snd_intel8x0_mic_close(snd_pcm_substream_t * substream)
1213 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1215 chip->ichd[ICHD_MIC].substream = NULL;
1219 static int snd_intel8x0_mic2_open(snd_pcm_substream_t * substream)
1221 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1223 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
1226 static int snd_intel8x0_mic2_close(snd_pcm_substream_t * substream)
1228 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1230 chip->ichd[ICHD_MIC2].substream = NULL;
1234 static int snd_intel8x0_capture2_open(snd_pcm_substream_t * substream)
1236 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1238 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
1241 static int snd_intel8x0_capture2_close(snd_pcm_substream_t * substream)
1243 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1245 chip->ichd[ICHD_PCM2IN].substream = NULL;
1249 static int snd_intel8x0_spdif_open(snd_pcm_substream_t * substream)
1251 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1252 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1254 return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
1257 static int snd_intel8x0_spdif_close(snd_pcm_substream_t * substream)
1259 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1260 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1262 chip->ichd[idx].substream = NULL;
1266 static int snd_intel8x0_ali_ac97spdifout_open(snd_pcm_substream_t * substream)
1268 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1271 spin_lock_irq(&chip->reg_lock);
1272 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1273 val |= ICH_ALI_IF_AC97SP;
1274 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1275 /* also needs to set ALI_SC_CODEC_SPDF correctly */
1276 spin_unlock_irq(&chip->reg_lock);
1278 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
1281 static int snd_intel8x0_ali_ac97spdifout_close(snd_pcm_substream_t * substream)
1283 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1286 chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
1287 spin_lock_irq(&chip->reg_lock);
1288 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1289 val &= ~ICH_ALI_IF_AC97SP;
1290 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1291 spin_unlock_irq(&chip->reg_lock);
1296 static int snd_intel8x0_ali_spdifin_open(snd_pcm_substream_t * substream)
1298 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1300 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
1303 static int snd_intel8x0_ali_spdifin_close(snd_pcm_substream_t * substream)
1305 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1307 chip->ichd[ALID_SPDIFIN].substream = NULL;
1312 static int snd_intel8x0_ali_spdifout_open(snd_pcm_substream_t * substream)
1314 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1316 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
1319 static int snd_intel8x0_ali_spdifout_close(snd_pcm_substream_t * substream)
1321 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1323 chip->ichd[ALID_SPDIFOUT].substream = NULL;
1328 static snd_pcm_ops_t snd_intel8x0_playback_ops = {
1329 .open = snd_intel8x0_playback_open,
1330 .close = snd_intel8x0_playback_close,
1331 .ioctl = snd_pcm_lib_ioctl,
1332 .hw_params = snd_intel8x0_hw_params,
1333 .hw_free = snd_intel8x0_hw_free,
1334 .prepare = snd_intel8x0_pcm_prepare,
1335 .trigger = snd_intel8x0_pcm_trigger,
1336 .pointer = snd_intel8x0_pcm_pointer,
1339 static snd_pcm_ops_t snd_intel8x0_capture_ops = {
1340 .open = snd_intel8x0_capture_open,
1341 .close = snd_intel8x0_capture_close,
1342 .ioctl = snd_pcm_lib_ioctl,
1343 .hw_params = snd_intel8x0_hw_params,
1344 .hw_free = snd_intel8x0_hw_free,
1345 .prepare = snd_intel8x0_pcm_prepare,
1346 .trigger = snd_intel8x0_pcm_trigger,
1347 .pointer = snd_intel8x0_pcm_pointer,
1350 static snd_pcm_ops_t snd_intel8x0_capture_mic_ops = {
1351 .open = snd_intel8x0_mic_open,
1352 .close = snd_intel8x0_mic_close,
1353 .ioctl = snd_pcm_lib_ioctl,
1354 .hw_params = snd_intel8x0_hw_params,
1355 .hw_free = snd_intel8x0_hw_free,
1356 .prepare = snd_intel8x0_pcm_prepare,
1357 .trigger = snd_intel8x0_pcm_trigger,
1358 .pointer = snd_intel8x0_pcm_pointer,
1361 static snd_pcm_ops_t snd_intel8x0_capture_mic2_ops = {
1362 .open = snd_intel8x0_mic2_open,
1363 .close = snd_intel8x0_mic2_close,
1364 .ioctl = snd_pcm_lib_ioctl,
1365 .hw_params = snd_intel8x0_hw_params,
1366 .hw_free = snd_intel8x0_hw_free,
1367 .prepare = snd_intel8x0_pcm_prepare,
1368 .trigger = snd_intel8x0_pcm_trigger,
1369 .pointer = snd_intel8x0_pcm_pointer,
1372 static snd_pcm_ops_t snd_intel8x0_capture2_ops = {
1373 .open = snd_intel8x0_capture2_open,
1374 .close = snd_intel8x0_capture2_close,
1375 .ioctl = snd_pcm_lib_ioctl,
1376 .hw_params = snd_intel8x0_hw_params,
1377 .hw_free = snd_intel8x0_hw_free,
1378 .prepare = snd_intel8x0_pcm_prepare,
1379 .trigger = snd_intel8x0_pcm_trigger,
1380 .pointer = snd_intel8x0_pcm_pointer,
1383 static snd_pcm_ops_t snd_intel8x0_spdif_ops = {
1384 .open = snd_intel8x0_spdif_open,
1385 .close = snd_intel8x0_spdif_close,
1386 .ioctl = snd_pcm_lib_ioctl,
1387 .hw_params = snd_intel8x0_hw_params,
1388 .hw_free = snd_intel8x0_hw_free,
1389 .prepare = snd_intel8x0_pcm_prepare,
1390 .trigger = snd_intel8x0_pcm_trigger,
1391 .pointer = snd_intel8x0_pcm_pointer,
1394 static snd_pcm_ops_t snd_intel8x0_ali_playback_ops = {
1395 .open = snd_intel8x0_playback_open,
1396 .close = snd_intel8x0_playback_close,
1397 .ioctl = snd_pcm_lib_ioctl,
1398 .hw_params = snd_intel8x0_hw_params,
1399 .hw_free = snd_intel8x0_hw_free,
1400 .prepare = snd_intel8x0_pcm_prepare,
1401 .trigger = snd_intel8x0_ali_trigger,
1402 .pointer = snd_intel8x0_pcm_pointer,
1405 static snd_pcm_ops_t snd_intel8x0_ali_capture_ops = {
1406 .open = snd_intel8x0_capture_open,
1407 .close = snd_intel8x0_capture_close,
1408 .ioctl = snd_pcm_lib_ioctl,
1409 .hw_params = snd_intel8x0_hw_params,
1410 .hw_free = snd_intel8x0_hw_free,
1411 .prepare = snd_intel8x0_pcm_prepare,
1412 .trigger = snd_intel8x0_ali_trigger,
1413 .pointer = snd_intel8x0_pcm_pointer,
1416 static snd_pcm_ops_t snd_intel8x0_ali_capture_mic_ops = {
1417 .open = snd_intel8x0_mic_open,
1418 .close = snd_intel8x0_mic_close,
1419 .ioctl = snd_pcm_lib_ioctl,
1420 .hw_params = snd_intel8x0_hw_params,
1421 .hw_free = snd_intel8x0_hw_free,
1422 .prepare = snd_intel8x0_pcm_prepare,
1423 .trigger = snd_intel8x0_ali_trigger,
1424 .pointer = snd_intel8x0_pcm_pointer,
1427 static snd_pcm_ops_t snd_intel8x0_ali_ac97spdifout_ops = {
1428 .open = snd_intel8x0_ali_ac97spdifout_open,
1429 .close = snd_intel8x0_ali_ac97spdifout_close,
1430 .ioctl = snd_pcm_lib_ioctl,
1431 .hw_params = snd_intel8x0_hw_params,
1432 .hw_free = snd_intel8x0_hw_free,
1433 .prepare = snd_intel8x0_pcm_prepare,
1434 .trigger = snd_intel8x0_ali_trigger,
1435 .pointer = snd_intel8x0_pcm_pointer,
1438 static snd_pcm_ops_t snd_intel8x0_ali_spdifin_ops = {
1439 .open = snd_intel8x0_ali_spdifin_open,
1440 .close = snd_intel8x0_ali_spdifin_close,
1441 .ioctl = snd_pcm_lib_ioctl,
1442 .hw_params = snd_intel8x0_hw_params,
1443 .hw_free = snd_intel8x0_hw_free,
1444 .prepare = snd_intel8x0_pcm_prepare,
1445 .trigger = snd_intel8x0_pcm_trigger,
1446 .pointer = snd_intel8x0_pcm_pointer,
1450 static snd_pcm_ops_t snd_intel8x0_ali_spdifout_ops = {
1451 .open = snd_intel8x0_ali_spdifout_open,
1452 .close = snd_intel8x0_ali_spdifout_close,
1453 .ioctl = snd_pcm_lib_ioctl,
1454 .hw_params = snd_intel8x0_hw_params,
1455 .hw_free = snd_intel8x0_hw_free,
1456 .prepare = snd_intel8x0_pcm_prepare,
1457 .trigger = snd_intel8x0_pcm_trigger,
1458 .pointer = snd_intel8x0_pcm_pointer,
1462 struct ich_pcm_table {
1464 snd_pcm_ops_t *playback_ops;
1465 snd_pcm_ops_t *capture_ops;
1466 size_t prealloc_size;
1467 size_t prealloc_max_size;
1471 static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_pcm_table *rec)
1478 sprintf(name, "Intel ICH - %s", rec->suffix);
1480 strcpy(name, "Intel ICH");
1481 err = snd_pcm_new(chip->card, name, device,
1482 rec->playback_ops ? 1 : 0,
1483 rec->capture_ops ? 1 : 0, &pcm);
1487 if (rec->playback_ops)
1488 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
1489 if (rec->capture_ops)
1490 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
1492 pcm->private_data = chip;
1493 pcm->info_flags = 0;
1495 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
1497 strcpy(pcm->name, chip->card->shortname);
1498 chip->pcm[device] = pcm;
1500 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1501 rec->prealloc_size, rec->prealloc_max_size);
1506 static struct ich_pcm_table intel_pcms[] __devinitdata = {
1508 .playback_ops = &snd_intel8x0_playback_ops,
1509 .capture_ops = &snd_intel8x0_capture_ops,
1510 .prealloc_size = 64 * 1024,
1511 .prealloc_max_size = 128 * 1024,
1514 .suffix = "MIC ADC",
1515 .capture_ops = &snd_intel8x0_capture_mic_ops,
1517 .prealloc_max_size = 128 * 1024,
1518 .ac97_idx = ICHD_MIC,
1521 .suffix = "MIC2 ADC",
1522 .capture_ops = &snd_intel8x0_capture_mic2_ops,
1524 .prealloc_max_size = 128 * 1024,
1525 .ac97_idx = ICHD_MIC2,
1529 .capture_ops = &snd_intel8x0_capture2_ops,
1531 .prealloc_max_size = 128 * 1024,
1532 .ac97_idx = ICHD_PCM2IN,
1536 .playback_ops = &snd_intel8x0_spdif_ops,
1537 .prealloc_size = 64 * 1024,
1538 .prealloc_max_size = 128 * 1024,
1539 .ac97_idx = ICHD_SPBAR,
1543 static struct ich_pcm_table nforce_pcms[] __devinitdata = {
1545 .playback_ops = &snd_intel8x0_playback_ops,
1546 .capture_ops = &snd_intel8x0_capture_ops,
1547 .prealloc_size = 64 * 1024,
1548 .prealloc_max_size = 128 * 1024,
1551 .suffix = "MIC ADC",
1552 .capture_ops = &snd_intel8x0_capture_mic_ops,
1554 .prealloc_max_size = 128 * 1024,
1555 .ac97_idx = NVD_MIC,
1559 .playback_ops = &snd_intel8x0_spdif_ops,
1560 .prealloc_size = 64 * 1024,
1561 .prealloc_max_size = 128 * 1024,
1562 .ac97_idx = NVD_SPBAR,
1566 static struct ich_pcm_table ali_pcms[] __devinitdata = {
1568 .playback_ops = &snd_intel8x0_ali_playback_ops,
1569 .capture_ops = &snd_intel8x0_ali_capture_ops,
1570 .prealloc_size = 64 * 1024,
1571 .prealloc_max_size = 128 * 1024,
1574 .suffix = "MIC ADC",
1575 .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
1577 .prealloc_max_size = 128 * 1024,
1578 .ac97_idx = ALID_MIC,
1582 .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
1583 .capture_ops = &snd_intel8x0_ali_spdifin_ops,
1584 .prealloc_size = 64 * 1024,
1585 .prealloc_max_size = 128 * 1024,
1586 .ac97_idx = ALID_AC97SPDIFOUT,
1590 .suffix = "HW IEC958",
1591 .playback_ops = &snd_intel8x0_ali_spdifout_ops,
1592 .prealloc_size = 64 * 1024,
1593 .prealloc_max_size = 128 * 1024,
1598 static int __devinit snd_intel8x0_pcm(intel8x0_t *chip)
1600 int i, tblsize, device, err;
1601 struct ich_pcm_table *tbl, *rec;
1603 switch (chip->device_type) {
1604 case DEVICE_INTEL_ICH4:
1606 tblsize = ARRAY_SIZE(intel_pcms);
1610 tblsize = ARRAY_SIZE(nforce_pcms);
1614 tblsize = ARRAY_SIZE(ali_pcms);
1623 for (i = 0; i < tblsize; i++) {
1625 if (i > 0 && rec->ac97_idx) {
1626 /* activate PCM only when associated AC'97 codec */
1627 if (! chip->ichd[rec->ac97_idx].pcm)
1630 err = snd_intel8x0_pcm1(chip, device, rec);
1636 chip->pcm_devs = device;
1645 static void snd_intel8x0_mixer_free_ac97_bus(ac97_bus_t *bus)
1647 intel8x0_t *chip = bus->private_data;
1648 chip->ac97_bus = NULL;
1651 static void snd_intel8x0_mixer_free_ac97(ac97_t *ac97)
1653 intel8x0_t *chip = ac97->private_data;
1654 chip->ac97[ac97->num] = NULL;
1657 static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
1662 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1663 (1 << AC97_SLOT_PCM_RIGHT) |
1664 (1 << AC97_SLOT_PCM_CENTER) |
1665 (1 << AC97_SLOT_PCM_SLEFT) |
1666 (1 << AC97_SLOT_PCM_SRIGHT) |
1667 (1 << AC97_SLOT_LFE)
1670 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1671 (1 << AC97_SLOT_PCM_RIGHT) |
1672 (1 << AC97_SLOT_PCM_LEFT_0) |
1673 (1 << AC97_SLOT_PCM_RIGHT_0)
1682 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1683 (1 << AC97_SLOT_PCM_RIGHT)
1692 .slots = (1 << AC97_SLOT_MIC)
1701 .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
1702 (1 << AC97_SLOT_SPDIF_RIGHT2)
1711 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1712 (1 << AC97_SLOT_PCM_RIGHT)
1721 .slots = (1 << AC97_SLOT_MIC)
1727 static struct ac97_quirk ac97_quirks[] __devinitdata = {
1729 .subvendor = 0x0e11,
1730 .subdevice = 0x008a,
1731 .name = "Compaq Evo W4000", /* AD1885 */
1732 .type = AC97_TUNE_HP_ONLY
1735 .subvendor = 0x0e11,
1736 .subdevice = 0x00b8,
1737 .name = "Compaq Evo D510C",
1738 .type = AC97_TUNE_HP_ONLY
1741 .subvendor = 0x0e11,
1742 .subdevice = 0x0860,
1743 .name = "HP/Compaq nx7010",
1744 .type = AC97_TUNE_MUTE_LED
1747 .subvendor = 0x1014,
1748 .subdevice = 0x1f00,
1750 .type = AC97_TUNE_ALC_JACK
1753 .subvendor = 0x1028,
1754 .subdevice = 0x00d8,
1755 .name = "Dell Precision 530", /* AD1885 */
1756 .type = AC97_TUNE_HP_ONLY
1759 .subvendor = 0x1028,
1760 .subdevice = 0x010d,
1761 .name = "Dell", /* which model? AD1885 */
1762 .type = AC97_TUNE_HP_ONLY
1765 .subvendor = 0x1028,
1766 .subdevice = 0x0126,
1767 .name = "Dell Optiplex GX260", /* AD1981A */
1768 .type = AC97_TUNE_HP_ONLY
1771 .subvendor = 0x1028,
1772 .subdevice = 0x012c,
1773 .name = "Dell Precision 650", /* AD1981A */
1774 .type = AC97_TUNE_HP_ONLY
1777 .subvendor = 0x1028,
1778 .subdevice = 0x012d,
1779 .name = "Dell Precision 450", /* AD1981B*/
1780 .type = AC97_TUNE_HP_ONLY
1783 .subvendor = 0x1028,
1784 .subdevice = 0x0147,
1785 .name = "Dell", /* which model? AD1981B*/
1786 .type = AC97_TUNE_HP_ONLY
1789 .subvendor = 0x1028,
1790 .subdevice = 0x0163,
1791 .name = "Dell Unknown", /* STAC9750/51 */
1792 .type = AC97_TUNE_HP_ONLY
1795 .subvendor = 0x103c,
1796 .subdevice = 0x006d,
1797 .name = "HP zv5000",
1798 .type = AC97_TUNE_MUTE_LED /*AD1981B*/
1800 { /* FIXME: which codec? */
1801 .subvendor = 0x103c,
1802 .subdevice = 0x00c3,
1803 .name = "HP xw6000",
1804 .type = AC97_TUNE_HP_ONLY
1807 .subvendor = 0x103c,
1808 .subdevice = 0x088c,
1809 .name = "HP nc8000",
1810 .type = AC97_TUNE_MUTE_LED
1813 .subvendor = 0x103c,
1814 .subdevice = 0x0890,
1815 .name = "HP nc6000",
1816 .type = AC97_TUNE_MUTE_LED
1819 .subvendor = 0x103c,
1820 .subdevice = 0x129d,
1821 .name = "HP xw8000",
1822 .type = AC97_TUNE_HP_ONLY
1825 .subvendor = 0x103c,
1826 .subdevice = 0x12f1,
1827 .name = "HP xw8200", /* AD1981B*/
1828 .type = AC97_TUNE_HP_ONLY
1831 .subvendor = 0x103c,
1832 .subdevice = 0x12f2,
1833 .name = "HP xw6200",
1834 .type = AC97_TUNE_HP_ONLY
1837 .subvendor = 0x103c,
1838 .subdevice = 0x3008,
1839 .name = "HP xw4200", /* AD1981B*/
1840 .type = AC97_TUNE_HP_ONLY
1843 .subvendor = 0x104d,
1844 .subdevice = 0x8197,
1845 .name = "Sony S1XP",
1846 .type = AC97_TUNE_INV_EAPD
1849 .subvendor = 0x1043,
1850 .subdevice = 0x80f3,
1851 .name = "ASUS ICH5/AD1985",
1852 .type = AC97_TUNE_AD_SHARING
1855 .subvendor = 0x10cf,
1856 .subdevice = 0x11c3,
1857 .name = "Fujitsu-Siemens E4010",
1858 .type = AC97_TUNE_HP_ONLY
1861 .subvendor = 0x10cf,
1862 .subdevice = 0x1225,
1863 .name = "Fujitsu-Siemens T3010",
1864 .type = AC97_TUNE_HP_ONLY
1867 .subvendor = 0x10cf,
1868 .subdevice = 0x1253,
1869 .name = "Fujitsu S6210", /* STAC9750/51 */
1870 .type = AC97_TUNE_HP_ONLY
1873 .subvendor = 0x10f1,
1874 .subdevice = 0x2665,
1875 .name = "Fujitsu-Siemens Celsius", /* AD1981? */
1876 .type = AC97_TUNE_HP_ONLY
1879 .subvendor = 0x10f1,
1880 .subdevice = 0x2885,
1881 .name = "AMD64 Mobo", /* ALC650 */
1882 .type = AC97_TUNE_HP_ONLY
1885 .subvendor = 0x110a,
1886 .subdevice = 0x0056,
1887 .name = "Fujitsu-Siemens Scenic", /* AD1981? */
1888 .type = AC97_TUNE_HP_ONLY
1891 .subvendor = 0x11d4,
1892 .subdevice = 0x5375,
1893 .name = "ADI AD1985 (discrete)",
1894 .type = AC97_TUNE_HP_ONLY
1897 .subvendor = 0x1462,
1898 .subdevice = 0x5470,
1899 .name = "MSI P4 ATX 645 Ultra",
1900 .type = AC97_TUNE_HP_ONLY
1903 .subvendor = 0x1734,
1904 .subdevice = 0x0088,
1905 .name = "Fujitsu-Siemens D1522", /* AD1981 */
1906 .type = AC97_TUNE_HP_ONLY
1909 .subvendor = 0x8086,
1910 .subdevice = 0x2000,
1912 .name = "Intel ICH5/AD1985",
1913 .type = AC97_TUNE_AD_SHARING
1916 .subvendor = 0x8086,
1917 .subdevice = 0x4000,
1919 .name = "Intel ICH5/AD1985",
1920 .type = AC97_TUNE_AD_SHARING
1923 .subvendor = 0x8086,
1924 .subdevice = 0x4856,
1925 .name = "Intel D845WN (82801BA)",
1926 .type = AC97_TUNE_SWAP_HP
1929 .subvendor = 0x8086,
1930 .subdevice = 0x4d44,
1931 .name = "Intel D850EMV2", /* AD1885 */
1932 .type = AC97_TUNE_HP_ONLY
1935 .subvendor = 0x8086,
1936 .subdevice = 0x4d56,
1937 .name = "Intel ICH/AD1885",
1938 .type = AC97_TUNE_HP_ONLY
1941 .subvendor = 0x8086,
1942 .subdevice = 0x6000,
1944 .name = "Intel ICH5/AD1985",
1945 .type = AC97_TUNE_AD_SHARING
1948 .subvendor = 0x8086,
1949 .subdevice = 0xe000,
1951 .name = "Intel ICH5/AD1985",
1952 .type = AC97_TUNE_AD_SHARING
1954 #if 0 /* FIXME: this seems wrong on most boards */
1956 .subvendor = 0x8086,
1957 .subdevice = 0xa000,
1959 .name = "Intel ICH5/AD1985",
1960 .type = AC97_TUNE_HP_ONLY
1963 { } /* terminator */
1966 static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock, const char *quirk_override)
1969 ac97_template_t ac97;
1971 unsigned int i, codecs;
1972 unsigned int glob_sta = 0;
1973 ac97_bus_ops_t *ops;
1974 static ac97_bus_ops_t standard_bus_ops = {
1975 .write = snd_intel8x0_codec_write,
1976 .read = snd_intel8x0_codec_read,
1978 static ac97_bus_ops_t ali_bus_ops = {
1979 .write = snd_intel8x0_ali_codec_write,
1980 .read = snd_intel8x0_ali_codec_read,
1983 chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
1984 switch (chip->device_type) {
1986 chip->spdif_idx = NVD_SPBAR;
1989 chip->spdif_idx = ALID_AC97SPDIFOUT;
1991 case DEVICE_INTEL_ICH4:
1992 chip->spdif_idx = ICHD_SPBAR;
1996 chip->in_ac97_init = 1;
1998 memset(&ac97, 0, sizeof(ac97));
1999 ac97.private_data = chip;
2000 ac97.private_free = snd_intel8x0_mixer_free_ac97;
2001 ac97.scaps = AC97_SCAP_SKIP_MODEM;
2003 ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
2004 if (chip->device_type != DEVICE_ALI) {
2005 glob_sta = igetdword(chip, ICHREG(GLOB_STA));
2006 ops = &standard_bus_ops;
2007 if (chip->device_type == DEVICE_INTEL_ICH4) {
2009 if (glob_sta & ICH_PCR)
2011 if (glob_sta & ICH_SCR)
2013 if (glob_sta & ICH_TCR)
2015 chip->in_sdin_init = 1;
2016 for (i = 0; i < codecs; i++) {
2017 snd_intel8x0_codec_read_test(chip, i);
2018 chip->ac97_sdin[i] = igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
2020 chip->in_sdin_init = 0;
2022 codecs = glob_sta & ICH_SCR ? 2 : 1;
2027 /* detect the secondary codec */
2028 for (i = 0; i < 100; i++) {
2029 unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
2034 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
2038 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
2040 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
2041 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with modem driver */
2042 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2043 pbus->clock = ac97_clock;
2044 /* FIXME: my test board doesn't work well with VRA... */
2045 if (chip->device_type == DEVICE_ALI)
2049 chip->ac97_bus = pbus;
2051 ac97.pci = chip->pci;
2052 for (i = 0; i < codecs; i++) {
2054 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
2056 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
2062 /* tune up the primary codec */
2063 snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
2064 /* enable separate SDINs for ICH4 */
2065 if (chip->device_type == DEVICE_INTEL_ICH4)
2067 /* find the available PCM streams */
2068 i = ARRAY_SIZE(ac97_pcm_defs);
2069 if (chip->device_type != DEVICE_INTEL_ICH4)
2070 i -= 2; /* do not allocate PCM2IN and MIC2 */
2071 if (chip->spdif_idx < 0)
2072 i--; /* do not allocate S/PDIF */
2073 err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
2076 chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
2077 chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
2078 chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
2079 if (chip->spdif_idx >= 0)
2080 chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
2081 if (chip->device_type == DEVICE_INTEL_ICH4) {
2082 chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
2083 chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
2085 /* enable separate SDINs for ICH4 */
2086 if (chip->device_type == DEVICE_INTEL_ICH4) {
2087 struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
2088 u8 tmp = igetbyte(chip, ICHREG(SDM));
2089 tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
2091 tmp |= ICH_SE; /* steer enable for multiple SDINs */
2092 tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
2093 for (i = 1; i < 4; i++) {
2094 if (pcm->r[0].codec[i]) {
2095 tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
2100 tmp &= ~ICH_SE; /* steer disable */
2102 iputbyte(chip, ICHREG(SDM), tmp);
2104 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2106 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE))
2109 if (pbus->pcms[0].r[1].rslots[0]) {
2112 if (chip->device_type == DEVICE_INTEL_ICH4) {
2113 if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
2116 if (chip->device_type == DEVICE_NFORCE) {
2118 chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
2120 if (chip->device_type == DEVICE_INTEL_ICH4) {
2121 /* use slot 10/11 for SPDIF */
2123 val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
2124 val |= ICH_PCM_SPDIF_1011;
2125 iputdword(chip, ICHREG(GLOB_CNT), val);
2126 snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
2128 chip->in_ac97_init = 0;
2132 /* clear the cold-reset bit for the next chance */
2133 if (chip->device_type != DEVICE_ALI)
2134 iputdword(chip, ICHREG(GLOB_CNT), igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
2143 static void do_ali_reset(intel8x0_t *chip)
2145 iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
2146 iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
2147 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
2148 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
2149 iputdword(chip, ICHREG(ALI_INTERFACECR),
2150 ICH_ALI_IF_MC|ICH_ALI_IF_PI|ICH_ALI_IF_PO);
2151 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
2152 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2155 #define do_delay(chip) do {\
2156 set_current_state(TASK_UNINTERRUPTIBLE);\
2157 schedule_timeout(1);\
2160 static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
2162 unsigned long end_time;
2163 unsigned int cnt, status, nstatus;
2165 /* put logic to right state */
2166 /* first clear status bits */
2167 status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
2168 if (chip->device_type == DEVICE_NFORCE)
2169 status |= ICH_NVSPINT;
2170 cnt = igetdword(chip, ICHREG(GLOB_STA));
2171 iputdword(chip, ICHREG(GLOB_STA), cnt & status);
2173 /* ACLink on, 2 channels */
2174 cnt = igetdword(chip, ICHREG(GLOB_CNT));
2175 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
2176 /* finish cold or do warm reset */
2177 cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
2178 iputdword(chip, ICHREG(GLOB_CNT), cnt);
2179 end_time = (jiffies + (HZ / 4)) + 1;
2181 if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
2184 } while (time_after_eq(end_time, jiffies));
2185 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
2190 /* wait for any codec ready status.
2191 * Once it becomes ready it should remain ready
2192 * as long as we do not disable the ac97 link.
2194 end_time = jiffies + HZ;
2196 status = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2200 } while (time_after_eq(end_time, jiffies));
2202 /* no codec is found */
2203 snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", igetdword(chip, ICHREG(GLOB_STA)));
2207 if (chip->device_type == DEVICE_INTEL_ICH4)
2208 /* ICH4 can have three codecs */
2209 nstatus = ICH_PCR | ICH_SCR | ICH_TCR;
2211 /* others up to two codecs */
2212 nstatus = ICH_PCR | ICH_SCR;
2214 /* wait for other codecs ready status. */
2215 end_time = jiffies + HZ / 4;
2216 while (status != nstatus && time_after_eq(end_time, jiffies)) {
2218 status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
2225 for (i = 0; i < 3; i++)
2227 status |= get_ich_codec_bit(chip, i);
2228 /* wait until all the probed codecs are ready */
2229 end_time = jiffies + HZ;
2231 nstatus = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2232 if (status == nstatus)
2235 } while (time_after_eq(end_time, jiffies));
2238 if (chip->device_type == DEVICE_SIS) {
2239 /* unmute the output on SIS7012 */
2240 iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
2242 if (chip->device_type == DEVICE_NFORCE) {
2243 /* enable SPDIF interrupt */
2245 pci_read_config_dword(chip->pci, 0x4c, &val);
2247 pci_write_config_dword(chip->pci, 0x4c, val);
2252 static int snd_intel8x0_ali_chip_init(intel8x0_t *chip, int probing)
2257 reg = igetdword(chip, ICHREG(ALI_SCR));
2258 if ((reg & 2) == 0) /* Cold required */
2261 reg |= 1; /* Warm */
2262 reg &= ~0x80000000; /* ACLink on */
2263 iputdword(chip, ICHREG(ALI_SCR), reg);
2265 for (i = 0; i < HZ / 2; i++) {
2266 if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
2270 snd_printk(KERN_ERR "AC'97 reset failed.\n");
2275 for (i = 0; i < HZ / 2; i++) {
2276 reg = igetdword(chip, ICHREG(ALI_RTSR));
2277 if (reg & 0x80) /* primary codec */
2279 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
2287 static int snd_intel8x0_chip_init(intel8x0_t *chip, int probing)
2292 if (chip->device_type != DEVICE_ALI) {
2293 if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
2295 iagetword(chip, 0); /* clear semaphore flag */
2297 if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
2301 /* disable interrupts */
2302 for (i = 0; i < chip->bdbars_count; i++)
2303 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2304 /* reset channels */
2305 for (i = 0; i < chip->bdbars_count; i++)
2306 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2307 /* initialize Buffer Descriptor Lists */
2308 for (i = 0; i < chip->bdbars_count; i++)
2309 iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
2313 static int snd_intel8x0_free(intel8x0_t *chip)
2319 /* disable interrupts */
2320 for (i = 0; i < chip->bdbars_count; i++)
2321 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2322 /* reset channels */
2323 for (i = 0; i < chip->bdbars_count; i++)
2324 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2325 if (chip->device_type == DEVICE_NFORCE) {
2326 /* stop the spdif interrupt */
2328 pci_read_config_dword(chip->pci, 0x4c, &val);
2330 pci_write_config_dword(chip->pci, 0x4c, val);
2333 synchronize_irq(chip->irq);
2336 free_irq(chip->irq, (void *)chip);
2337 if (chip->bdbars.area) {
2338 if (chip->fix_nocache)
2339 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
2340 snd_dma_free_pages(&chip->bdbars);
2342 if (chip->remap_addr)
2343 iounmap(chip->remap_addr);
2344 if (chip->remap_bmaddr)
2345 iounmap(chip->remap_bmaddr);
2346 pci_release_regions(chip->pci);
2347 pci_disable_device(chip->pci);
2356 static int intel8x0_suspend(snd_card_t *card, pm_message_t state)
2358 intel8x0_t *chip = card->pm_private_data;
2361 for (i = 0; i < chip->pcm_devs; i++)
2362 snd_pcm_suspend_all(chip->pcm[i]);
2364 if (chip->fix_nocache) {
2365 for (i = 0; i < chip->bdbars_count; i++) {
2366 ichdev_t *ichdev = &chip->ichd[i];
2367 if (ichdev->substream && ichdev->page_attr_changed) {
2368 snd_pcm_runtime_t *runtime = ichdev->substream->runtime;
2369 if (runtime->dma_area)
2370 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0);
2374 for (i = 0; i < 3; i++)
2376 snd_ac97_suspend(chip->ac97[i]);
2377 if (chip->device_type == DEVICE_INTEL_ICH4)
2378 chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
2381 free_irq(chip->irq, (void *)chip);
2382 pci_disable_device(chip->pci);
2386 static int intel8x0_resume(snd_card_t *card)
2388 intel8x0_t *chip = card->pm_private_data;
2391 pci_enable_device(chip->pci);
2392 pci_set_master(chip->pci);
2393 request_irq(chip->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip);
2394 synchronize_irq(chip->irq);
2395 snd_intel8x0_chip_init(chip, 1);
2397 /* re-initialize mixer stuff */
2398 if (chip->device_type == DEVICE_INTEL_ICH4) {
2399 /* enable separate SDINs for ICH4 */
2400 iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
2401 /* use slot 10/11 for SPDIF */
2402 iputdword(chip, ICHREG(GLOB_CNT),
2403 (igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK) |
2404 ICH_PCM_SPDIF_1011);
2407 /* refill nocache */
2408 if (chip->fix_nocache)
2409 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2411 for (i = 0; i < 3; i++)
2413 snd_ac97_resume(chip->ac97[i]);
2415 /* refill nocache */
2416 if (chip->fix_nocache) {
2417 for (i = 0; i < chip->bdbars_count; i++) {
2418 ichdev_t *ichdev = &chip->ichd[i];
2419 if (ichdev->substream && ichdev->page_attr_changed) {
2420 snd_pcm_runtime_t *runtime = ichdev->substream->runtime;
2421 if (runtime->dma_area)
2422 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
2429 #endif /* CONFIG_PM */
2431 #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
2433 static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2435 snd_pcm_substream_t *subs;
2438 unsigned long pos, t;
2439 struct timeval start_time, stop_time;
2441 if (chip->ac97_bus->clock != 48000)
2442 return; /* specified in module option */
2444 subs = chip->pcm[0]->streams[0].substream;
2445 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2446 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n");
2449 ichdev = &chip->ichd[ICHD_PCMOUT];
2450 ichdev->physbuf = subs->dma_buffer.addr;
2451 ichdev->size = chip->ichd[ICHD_PCMOUT].fragsize = INTEL8X0_TESTBUF_SIZE;
2452 ichdev->substream = NULL; /* don't process interrupts */
2455 if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
2456 snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock);
2459 snd_intel8x0_setup_periods(chip, ichdev);
2460 port = ichdev->reg_offset;
2461 spin_lock_irq(&chip->reg_lock);
2462 chip->in_measurement = 1;
2464 if (chip->device_type != DEVICE_ALI)
2465 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
2467 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
2468 iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
2470 do_gettimeofday(&start_time);
2471 spin_unlock_irq(&chip->reg_lock);
2473 spin_lock_irq(&chip->reg_lock);
2474 /* check the position */
2475 pos = ichdev->fragsize1;
2476 pos -= igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << ichdev->pos_shift;
2477 pos += ichdev->position;
2478 chip->in_measurement = 0;
2479 do_gettimeofday(&stop_time);
2481 if (chip->device_type == DEVICE_ALI) {
2482 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 8));
2483 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2484 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2487 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2488 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
2491 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
2492 spin_unlock_irq(&chip->reg_lock);
2494 t = stop_time.tv_sec - start_time.tv_sec;
2496 t += stop_time.tv_usec - start_time.tv_usec;
2497 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t);
2499 snd_printk(KERN_ERR "?? calculation error..\n");
2502 pos = (pos / 4) * 1000;
2503 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2504 if (pos < 40000 || pos >= 60000)
2505 /* abnormal value. hw problem? */
2506 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
2507 else if (pos < 47500 || pos > 48500)
2508 /* not 48000Hz, tuning the clock.. */
2509 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
2510 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
2513 static void snd_intel8x0_proc_read(snd_info_entry_t * entry,
2514 snd_info_buffer_t * buffer)
2516 intel8x0_t *chip = entry->private_data;
2519 snd_iprintf(buffer, "Intel8x0\n\n");
2520 if (chip->device_type == DEVICE_ALI)
2522 tmp = igetdword(chip, ICHREG(GLOB_STA));
2523 snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
2524 snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
2525 if (chip->device_type == DEVICE_INTEL_ICH4)
2526 snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
2527 snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
2528 tmp & ICH_PCR ? " primary" : "",
2529 tmp & ICH_SCR ? " secondary" : "",
2530 tmp & ICH_TCR ? " tertiary" : "",
2531 (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
2532 if (chip->device_type == DEVICE_INTEL_ICH4)
2533 snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
2536 chip->ac97_sdin[2]);
2539 static void __devinit snd_intel8x0_proc_init(intel8x0_t * chip)
2541 snd_info_entry_t *entry;
2543 if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
2544 snd_info_set_text_ops(entry, chip, 1024, snd_intel8x0_proc_read);
2547 static int snd_intel8x0_dev_free(snd_device_t *device)
2549 intel8x0_t *chip = device->device_data;
2550 return snd_intel8x0_free(chip);
2553 struct ich_reg_info {
2554 unsigned int int_sta_mask;
2555 unsigned int offset;
2558 static int __devinit snd_intel8x0_create(snd_card_t * card,
2559 struct pci_dev *pci,
2560 unsigned long device_type,
2561 intel8x0_t ** r_intel8x0)
2566 unsigned int int_sta_masks;
2568 static snd_device_ops_t ops = {
2569 .dev_free = snd_intel8x0_dev_free,
2572 static unsigned int bdbars[] = {
2573 3, /* DEVICE_INTEL */
2574 6, /* DEVICE_INTEL_ICH4 */
2577 4, /* DEVICE_NFORCE */
2579 static struct ich_reg_info intel_regs[6] = {
2581 { ICH_POINT, 0x10 },
2582 { ICH_MCINT, 0x20 },
2583 { ICH_M2INT, 0x40 },
2584 { ICH_P2INT, 0x50 },
2585 { ICH_SPINT, 0x60 },
2587 static struct ich_reg_info nforce_regs[4] = {
2589 { ICH_POINT, 0x10 },
2590 { ICH_MCINT, 0x20 },
2591 { ICH_NVSPINT, 0x70 },
2593 static struct ich_reg_info ali_regs[6] = {
2594 { ALI_INT_PCMIN, 0x40 },
2595 { ALI_INT_PCMOUT, 0x50 },
2596 { ALI_INT_MICIN, 0x60 },
2597 { ALI_INT_CODECSPDIFOUT, 0x70 },
2598 { ALI_INT_SPDIFIN, 0xa0 },
2599 { ALI_INT_SPDIFOUT, 0xb0 },
2601 struct ich_reg_info *tbl;
2605 if ((err = pci_enable_device(pci)) < 0)
2608 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
2610 pci_disable_device(pci);
2613 spin_lock_init(&chip->reg_lock);
2614 chip->device_type = device_type;
2619 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2620 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2621 chip->fix_nocache = 1; /* enable workaround */
2623 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2624 * Needs to return IRQ_HANDLED for unknown irqs.
2626 if (device_type == DEVICE_NFORCE)
2627 chip->buggy_irq = 1;
2629 if ((err = pci_request_regions(pci, card->shortname)) < 0) {
2631 pci_disable_device(pci);
2635 if (device_type == DEVICE_ALI) {
2636 /* ALI5455 has no ac97 region */
2637 chip->bmaddr = pci_resource_start(pci, 0);
2641 if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */
2643 chip->addr = pci_resource_start(pci, 2);
2644 chip->remap_addr = ioremap_nocache(chip->addr,
2645 pci_resource_len(pci, 2));
2646 if (chip->remap_addr == NULL) {
2647 snd_printk("AC'97 space ioremap problem\n");
2648 snd_intel8x0_free(chip);
2652 chip->addr = pci_resource_start(pci, 0);
2654 if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */
2656 chip->bmaddr = pci_resource_start(pci, 3);
2657 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
2658 pci_resource_len(pci, 3));
2659 if (chip->remap_bmaddr == NULL) {
2660 snd_printk("Controller space ioremap problem\n");
2661 snd_intel8x0_free(chip);
2665 chip->bmaddr = pci_resource_start(pci, 1);
2669 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2670 snd_printk("unable to grab IRQ %d\n", pci->irq);
2671 snd_intel8x0_free(chip);
2674 chip->irq = pci->irq;
2675 pci_set_master(pci);
2676 synchronize_irq(chip->irq);
2678 chip->bdbars_count = bdbars[device_type];
2680 /* initialize offsets */
2681 switch (device_type) {
2692 for (i = 0; i < chip->bdbars_count; i++) {
2693 ichdev = &chip->ichd[i];
2695 ichdev->reg_offset = tbl[i].offset;
2696 ichdev->int_sta_mask = tbl[i].int_sta_mask;
2697 if (device_type == DEVICE_SIS) {
2698 /* SiS 7012 swaps the registers */
2699 ichdev->roff_sr = ICH_REG_OFF_PICB;
2700 ichdev->roff_picb = ICH_REG_OFF_SR;
2702 ichdev->roff_sr = ICH_REG_OFF_SR;
2703 ichdev->roff_picb = ICH_REG_OFF_PICB;
2705 if (device_type == DEVICE_ALI)
2706 ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
2707 /* SIS7012 handles the pcm data in bytes, others are in samples */
2708 ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
2711 /* allocate buffer descriptor lists */
2712 /* the start of each lists must be aligned to 8 bytes */
2713 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
2714 chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
2715 &chip->bdbars) < 0) {
2716 snd_intel8x0_free(chip);
2717 snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n");
2720 /* tables must be aligned to 8 bytes here, but the kernel pages
2721 are much bigger, so we don't care (on i386) */
2722 /* workaround for 440MX */
2723 if (chip->fix_nocache)
2724 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2726 for (i = 0; i < chip->bdbars_count; i++) {
2727 ichdev = &chip->ichd[i];
2728 ichdev->bdbar = ((u32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2);
2729 ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
2730 int_sta_masks |= ichdev->int_sta_mask;
2732 chip->int_sta_reg = device_type == DEVICE_ALI ? ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
2733 chip->int_sta_mask = int_sta_masks;
2735 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
2736 snd_intel8x0_free(chip);
2740 snd_card_set_pm_callback(card, intel8x0_suspend, intel8x0_resume, chip);
2742 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2743 snd_intel8x0_free(chip);
2747 snd_card_set_dev(card, &pci->dev);
2753 static struct shortname_table {
2756 } shortnames[] __devinitdata = {
2757 { PCI_DEVICE_ID_INTEL_82801, "Intel 82801AA-ICH" },
2758 { PCI_DEVICE_ID_INTEL_82901, "Intel 82901AB-ICH0" },
2759 { PCI_DEVICE_ID_INTEL_82801BA, "Intel 82801BA-ICH2" },
2760 { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
2761 { PCI_DEVICE_ID_INTEL_ICH3, "Intel 82801CA-ICH3" },
2762 { PCI_DEVICE_ID_INTEL_ICH4, "Intel 82801DB-ICH4" },
2763 { PCI_DEVICE_ID_INTEL_ICH5, "Intel ICH5" },
2764 { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
2765 { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
2766 { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
2767 { PCI_DEVICE_ID_INTEL_ESB2_14, "Intel ESB2" },
2768 { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
2769 { PCI_DEVICE_ID_NVIDIA_MCP_AUDIO, "NVidia nForce" },
2770 { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
2771 { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
2772 { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
2773 { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
2774 { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
2775 { 0x003a, "NVidia MCP04" },
2776 { 0x746d, "AMD AMD8111" },
2777 { 0x7445, "AMD AMD768" },
2778 { 0x5455, "ALi M5455" },
2782 static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2783 const struct pci_device_id *pci_id)
2789 struct shortname_table *name;
2791 if (dev >= SNDRV_CARDS)
2798 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2802 switch (pci_id->driver_data) {
2804 strcpy(card->driver, "NFORCE");
2806 case DEVICE_INTEL_ICH4:
2807 strcpy(card->driver, "ICH4");
2810 strcpy(card->driver, "ICH");
2814 strcpy(card->shortname, "Intel ICH");
2815 for (name = shortnames; name->id; name++) {
2816 if (pci->device == name->id) {
2817 strcpy(card->shortname, name->s);
2822 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip)) < 0) {
2823 snd_card_free(card);
2827 chip->buggy_irq = 1;
2831 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) {
2832 snd_card_free(card);
2835 if ((err = snd_intel8x0_pcm(chip)) < 0) {
2836 snd_card_free(card);
2840 snd_intel8x0_proc_init(chip);
2842 snprintf(card->longname, sizeof(card->longname),
2843 "%s with %s at %#lx, irq %i", card->shortname,
2844 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
2846 if (! ac97_clock[dev])
2847 intel8x0_measure_ac97_clock(chip);
2849 if ((err = snd_card_register(card)) < 0) {
2850 snd_card_free(card);
2853 pci_set_drvdata(pci, card);
2858 static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
2860 snd_card_free(pci_get_drvdata(pci));
2861 pci_set_drvdata(pci, NULL);
2864 static struct pci_driver driver = {
2865 .name = "Intel ICH",
2866 .id_table = snd_intel8x0_ids,
2867 .probe = snd_intel8x0_probe,
2868 .remove = __devexit_p(snd_intel8x0_remove),
2869 SND_PCI_PM_CALLBACKS
2873 static int __init alsa_card_intel8x0_init(void)
2875 return pci_register_driver(&driver);
2878 static void __exit alsa_card_intel8x0_exit(void)
2880 pci_unregister_driver(&driver);
2883 module_init(alsa_card_intel8x0_init)
2884 module_exit(alsa_card_intel8x0_exit)