2 * ALSA driver for Intel ICH (i8x0) chipsets
7 * This code also contains alpha support for SiS 735 chipsets provided
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>
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},"
60 "{NVidia,nForce Audio},"
61 "{NVidia,nForce2 Audio},"
66 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
67 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
68 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
69 static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
70 static char *ac97_quirk[SNDRV_CARDS];
71 static int buggy_irq[SNDRV_CARDS];
72 static int xbox[SNDRV_CARDS];
75 static int mpu_port[SNDRV_CARDS]; /* disabled */
78 module_param_array(index, int, NULL, 0444);
79 MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
80 module_param_array(id, charp, NULL, 0444);
81 MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
82 module_param_array(enable, bool, NULL, 0444);
83 MODULE_PARM_DESC(enable, "Enable Intel i8x0 soundcard.");
84 module_param_array(ac97_clock, int, NULL, 0444);
85 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
86 module_param_array(ac97_quirk, charp, NULL, 0444);
87 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
88 module_param_array(buggy_irq, bool, NULL, 0444);
89 MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
90 module_param_array(xbox, bool, NULL, 0444);
91 MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
97 #ifndef PCI_DEVICE_ID_INTEL_82801
98 #define PCI_DEVICE_ID_INTEL_82801 0x2415
100 #ifndef PCI_DEVICE_ID_INTEL_82901
101 #define PCI_DEVICE_ID_INTEL_82901 0x2425
103 #ifndef PCI_DEVICE_ID_INTEL_82801BA
104 #define PCI_DEVICE_ID_INTEL_82801BA 0x2445
106 #ifndef PCI_DEVICE_ID_INTEL_440MX
107 #define PCI_DEVICE_ID_INTEL_440MX 0x7195
109 #ifndef PCI_DEVICE_ID_INTEL_ICH3
110 #define PCI_DEVICE_ID_INTEL_ICH3 0x2485
112 #ifndef PCI_DEVICE_ID_INTEL_ICH4
113 #define PCI_DEVICE_ID_INTEL_ICH4 0x24c5
115 #ifndef PCI_DEVICE_ID_INTEL_ICH5
116 #define PCI_DEVICE_ID_INTEL_ICH5 0x24d5
118 #ifndef PCI_DEVICE_ID_INTEL_ESB_5
119 #define PCI_DEVICE_ID_INTEL_ESB_5 0x25a6
121 #ifndef PCI_DEVICE_ID_INTEL_ICH6_18
122 #define PCI_DEVICE_ID_INTEL_ICH6_18 0x266e
124 #ifndef PCI_DEVICE_ID_INTEL_ICH7_20
125 #define PCI_DEVICE_ID_INTEL_ICH7_20 0x27de
127 #ifndef PCI_DEVICE_ID_SI_7012
128 #define PCI_DEVICE_ID_SI_7012 0x7012
130 #ifndef PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
131 #define PCI_DEVICE_ID_NVIDIA_MCP_AUDIO 0x01b1
133 #ifndef PCI_DEVICE_ID_NVIDIA_CK804_AUDIO
134 #define PCI_DEVICE_ID_NVIDIA_CK804_AUDIO 0x0059
136 #ifndef PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
137 #define PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO 0x006a
139 #ifndef PCI_DEVICE_ID_NVIDIA_CK8_AUDIO
140 #define PCI_DEVICE_ID_NVIDIA_CK8_AUDIO 0x008a
142 #ifndef PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO
143 #define PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO 0x00da
145 #ifndef PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO
146 #define PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO 0x00ea
149 enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
151 #define ICHREG(x) ICH_REG_##x
153 #define DEFINE_REGSET(name,base) \
155 ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
156 ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
157 ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
158 ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
159 ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
160 ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
161 ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
164 /* busmaster blocks */
165 DEFINE_REGSET(OFF, 0); /* offset */
166 DEFINE_REGSET(PI, 0x00); /* PCM in */
167 DEFINE_REGSET(PO, 0x10); /* PCM out */
168 DEFINE_REGSET(MC, 0x20); /* Mic in */
170 /* ICH4 busmaster blocks */
171 DEFINE_REGSET(MC2, 0x40); /* Mic in 2 */
172 DEFINE_REGSET(PI2, 0x50); /* PCM in 2 */
173 DEFINE_REGSET(SP, 0x60); /* SPDIF out */
175 /* values for each busmaster block */
178 #define ICH_REG_LVI_MASK 0x1f
181 #define ICH_FIFOE 0x10 /* FIFO error */
182 #define ICH_BCIS 0x08 /* buffer completion interrupt status */
183 #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
184 #define ICH_CELV 0x02 /* current equals last valid */
185 #define ICH_DCH 0x01 /* DMA controller halted */
188 #define ICH_REG_PIV_MASK 0x1f /* mask */
191 #define ICH_IOCE 0x10 /* interrupt on completion enable */
192 #define ICH_FEIE 0x08 /* fifo error interrupt enable */
193 #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
194 #define ICH_RESETREGS 0x02 /* reset busmaster registers */
195 #define ICH_STARTBM 0x01 /* start busmaster operation */
199 #define ICH_REG_GLOB_CNT 0x2c /* dword - global control */
200 #define ICH_PCM_SPDIF_MASK 0xc0000000 /* s/pdif pcm slot mask (ICH4) */
201 #define ICH_PCM_SPDIF_NONE 0x00000000 /* reserved - undefined */
202 #define ICH_PCM_SPDIF_78 0x40000000 /* s/pdif pcm on slots 7&8 */
203 #define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
204 #define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
205 #define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
206 #define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */
207 #define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
208 #define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
209 #define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
210 #define ICH_SIS_PCM_246_MASK 0x000000c0 /* 6 channels (SIS7012) */
211 #define ICH_SIS_PCM_6 0x00000080 /* 6 channels (SIS7012) */
212 #define ICH_SIS_PCM_4 0x00000040 /* 4 channels (SIS7012) */
213 #define ICH_SIS_PCM_2 0x00000000 /* 2 channels (SIS7012) */
214 #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
215 #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
216 #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
217 #define ICH_ACLINK 0x00000008 /* AClink shut off */
218 #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
219 #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
220 #define ICH_GIE 0x00000001 /* GPI interrupt enable */
221 #define ICH_REG_GLOB_STA 0x30 /* dword - global status */
222 #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
223 #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
224 #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
225 #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
226 #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
227 #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
228 #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
229 #define ICH_SAMPLE_16_20 0x00400000 /* ICH4: 16- and 20-bit samples */
230 #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
231 #define ICH_MD3 0x00020000 /* modem power down semaphore */
232 #define ICH_AD3 0x00010000 /* audio power down semaphore */
233 #define ICH_RCS 0x00008000 /* read completion status */
234 #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
235 #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
236 #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
237 #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
238 #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
239 #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
240 #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
241 #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
242 #define ICH_POINT 0x00000040 /* playback interrupt */
243 #define ICH_PIINT 0x00000020 /* capture interrupt */
244 #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
245 #define ICH_MOINT 0x00000004 /* modem playback interrupt */
246 #define ICH_MIINT 0x00000002 /* modem capture interrupt */
247 #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
248 #define ICH_REG_ACC_SEMA 0x34 /* byte - codec write semaphore */
249 #define ICH_CAS 0x01 /* codec access semaphore */
250 #define ICH_REG_SDM 0x80
251 #define ICH_DI2L_MASK 0x000000c0 /* PCM In 2, Mic In 2 data in line */
252 #define ICH_DI2L_SHIFT 6
253 #define ICH_DI1L_MASK 0x00000030 /* PCM In 1, Mic In 1 data in line */
254 #define ICH_DI1L_SHIFT 4
255 #define ICH_SE 0x00000008 /* steer enable */
256 #define ICH_LDI_MASK 0x00000003 /* last codec read data input */
258 #define ICH_MAX_FRAGS 32 /* max hw frags */
262 * registers for Ali5455
265 /* ALi 5455 busmaster blocks */
266 DEFINE_REGSET(AL_PI, 0x40); /* ALi PCM in */
267 DEFINE_REGSET(AL_PO, 0x50); /* Ali PCM out */
268 DEFINE_REGSET(AL_MC, 0x60); /* Ali Mic in */
269 DEFINE_REGSET(AL_CDC_SPO, 0x70); /* Ali Codec SPDIF out */
270 DEFINE_REGSET(AL_CENTER, 0x80); /* Ali center out */
271 DEFINE_REGSET(AL_LFE, 0x90); /* Ali center out */
272 DEFINE_REGSET(AL_CLR_SPI, 0xa0); /* Ali Controller SPDIF in */
273 DEFINE_REGSET(AL_CLR_SPO, 0xb0); /* Ali Controller SPDIF out */
274 DEFINE_REGSET(AL_I2S, 0xc0); /* Ali I2S in */
275 DEFINE_REGSET(AL_PI2, 0xd0); /* Ali PCM2 in */
276 DEFINE_REGSET(AL_MC2, 0xe0); /* Ali Mic2 in */
279 ICH_REG_ALI_SCR = 0x00, /* System Control Register */
280 ICH_REG_ALI_SSR = 0x04, /* System Status Register */
281 ICH_REG_ALI_DMACR = 0x08, /* DMA Control Register */
282 ICH_REG_ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
283 ICH_REG_ALI_INTERFACECR = 0x10, /* Interface Control Register */
284 ICH_REG_ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
285 ICH_REG_ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
286 ICH_REG_ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
287 ICH_REG_ALI_CPR = 0x20, /* Command Port Register */
288 ICH_REG_ALI_CPR_ADDR = 0x22, /* ac97 addr write */
289 ICH_REG_ALI_SPR = 0x24, /* Status Port Register */
290 ICH_REG_ALI_SPR_ADDR = 0x26, /* ac97 addr read */
291 ICH_REG_ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
292 ICH_REG_ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
293 ICH_REG_ALI_RTSR = 0x34, /* Receive Tag Slot Register */
294 ICH_REG_ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
295 ICH_REG_ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
296 ICH_REG_ALI_HWVOL = 0xf0, /* hardware volume control/status */
297 ICH_REG_ALI_I2SCR = 0xf4, /* I2S control/status */
298 ICH_REG_ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
299 ICH_REG_ALI_SPDIFICS = 0xfc, /* spdif interface control/status */
302 #define ALI_CAS_SEM_BUSY 0x80000000
303 #define ALI_CPR_ADDR_SECONDARY 0x100
304 #define ALI_CPR_ADDR_READ 0x80
305 #define ALI_CSPSR_CODEC_READY 0x08
306 #define ALI_CSPSR_READ_OK 0x02
307 #define ALI_CSPSR_WRITE_OK 0x01
309 /* interrupts for the whole chip by interrupt status register finish */
311 #define ALI_INT_MICIN2 (1<<26)
312 #define ALI_INT_PCMIN2 (1<<25)
313 #define ALI_INT_I2SIN (1<<24)
314 #define ALI_INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
315 #define ALI_INT_SPDIFIN (1<<22)
316 #define ALI_INT_LFEOUT (1<<21)
317 #define ALI_INT_CENTEROUT (1<<20)
318 #define ALI_INT_CODECSPDIFOUT (1<<19)
319 #define ALI_INT_MICIN (1<<18)
320 #define ALI_INT_PCMOUT (1<<17)
321 #define ALI_INT_PCMIN (1<<16)
322 #define ALI_INT_CPRAIS (1<<7) /* command port available */
323 #define ALI_INT_SPRAIS (1<<5) /* status port available */
324 #define ALI_INT_GPIO (1<<1)
325 #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
327 #define ICH_ALI_SC_RESET (1<<31) /* master reset */
328 #define ICH_ALI_SC_AC97_DBL (1<<30)
329 #define ICH_ALI_SC_CODEC_SPDF (3<<20) /* 1=7/8, 2=6/9, 3=10/11 */
330 #define ICH_ALI_SC_IN_BITS (3<<18)
331 #define ICH_ALI_SC_OUT_BITS (3<<16)
332 #define ICH_ALI_SC_6CH_CFG (3<<14)
333 #define ICH_ALI_SC_PCM_4 (1<<8)
334 #define ICH_ALI_SC_PCM_6 (2<<8)
335 #define ICH_ALI_SC_PCM_246_MASK (3<<8)
337 #define ICH_ALI_SS_SEC_ID (3<<5)
338 #define ICH_ALI_SS_PRI_ID (3<<3)
340 #define ICH_ALI_IF_AC97SP (1<<21)
341 #define ICH_ALI_IF_MC (1<<20)
342 #define ICH_ALI_IF_PI (1<<19)
343 #define ICH_ALI_IF_MC2 (1<<18)
344 #define ICH_ALI_IF_PI2 (1<<17)
345 #define ICH_ALI_IF_LINE_SRC (1<<15) /* 0/1 = slot 3/6 */
346 #define ICH_ALI_IF_MIC_SRC (1<<14) /* 0/1 = slot 3/6 */
347 #define ICH_ALI_IF_SPDF_SRC (3<<12) /* 00 = PCM, 01 = AC97-in, 10 = spdif-in, 11 = i2s */
348 #define ICH_ALI_IF_AC97_OUT (3<<8) /* 00 = PCM, 10 = spdif-in, 11 = i2s */
349 #define ICH_ALI_IF_PO_SPDF (1<<3)
350 #define ICH_ALI_IF_PO (1<<1)
356 enum { ICHD_PCMIN, ICHD_PCMOUT, ICHD_MIC, ICHD_MIC2, ICHD_PCM2IN, ICHD_SPBAR, ICHD_LAST = ICHD_SPBAR };
357 enum { NVD_PCMIN, NVD_PCMOUT, NVD_MIC, NVD_SPBAR, NVD_LAST = NVD_SPBAR };
358 enum { ALID_PCMIN, ALID_PCMOUT, ALID_MIC, ALID_AC97SPDIFOUT, ALID_SPDIFIN, ALID_SPDIFOUT, ALID_LAST = ALID_SPDIFOUT };
360 #define get_ichdev(substream) (ichdev_t *)(substream->runtime->private_data)
363 unsigned int ichd; /* ich device number */
364 unsigned long reg_offset; /* offset to bmaddr */
365 u32 *bdbar; /* CPU address (32bit) */
366 unsigned int bdbar_addr; /* PCI bus address (32bit) */
367 snd_pcm_substream_t *substream;
368 unsigned int physbuf; /* physical address (32bit) */
370 unsigned int fragsize;
371 unsigned int fragsize1;
372 unsigned int position;
373 unsigned int pos_shift;
380 unsigned int ack_bit;
381 unsigned int roff_sr;
382 unsigned int roff_picb;
383 unsigned int int_sta_mask; /* interrupt status mask */
384 unsigned int ali_slot; /* ALI DMA slot */
385 struct ac97_pcm *pcm;
387 unsigned int page_attr_changed: 1;
390 typedef struct _snd_intel8x0 intel8x0_t;
392 struct _snd_intel8x0 {
393 unsigned int device_type;
399 void __iomem *remap_addr;
400 unsigned int bm_mmio;
401 unsigned long bmaddr;
402 void __iomem *remap_bmaddr;
415 unsigned in_ac97_init: 1,
417 unsigned in_measurement: 1; /* during ac97 clock measurement */
418 unsigned fix_nocache: 1; /* workaround for 440MX */
419 unsigned buggy_irq: 1; /* workaround for buggy mobos */
420 unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
422 int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
424 ac97_bus_t *ac97_bus;
426 unsigned int ac97_sdin[3];
431 struct snd_dma_buffer bdbars;
432 u32 int_sta_reg; /* interrupt status register */
433 u32 int_sta_mask; /* interrupt status mask */
436 static struct pci_device_id snd_intel8x0_ids[] = {
437 { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */
438 { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */
439 { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */
440 { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */
441 { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */
442 { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */
443 { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */
444 { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */
445 { 0x8086, 0x27de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH7 */
446 { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */
447 { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */
448 { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */
449 { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */
450 { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */
451 { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */
452 { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */
453 { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */
454 { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */
455 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
456 { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
457 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
461 MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
464 * Lowlevel I/O - busmaster
467 static u8 igetbyte(intel8x0_t *chip, u32 offset)
470 return readb(chip->remap_bmaddr + offset);
472 return inb(chip->bmaddr + offset);
475 static u16 igetword(intel8x0_t *chip, u32 offset)
478 return readw(chip->remap_bmaddr + offset);
480 return inw(chip->bmaddr + offset);
483 static u32 igetdword(intel8x0_t *chip, u32 offset)
486 return readl(chip->remap_bmaddr + offset);
488 return inl(chip->bmaddr + offset);
491 static void iputbyte(intel8x0_t *chip, u32 offset, u8 val)
494 writeb(val, chip->remap_bmaddr + offset);
496 outb(val, chip->bmaddr + offset);
499 static void iputword(intel8x0_t *chip, u32 offset, u16 val)
502 writew(val, chip->remap_bmaddr + offset);
504 outw(val, chip->bmaddr + offset);
507 static void iputdword(intel8x0_t *chip, u32 offset, u32 val)
510 writel(val, chip->remap_bmaddr + offset);
512 outl(val, chip->bmaddr + offset);
516 * Lowlevel I/O - AC'97 registers
519 static u16 iagetword(intel8x0_t *chip, u32 offset)
522 return readw(chip->remap_addr + offset);
524 return inw(chip->addr + offset);
527 static void iaputword(intel8x0_t *chip, u32 offset, u16 val)
530 writew(val, chip->remap_addr + offset);
532 outw(val, chip->addr + offset);
540 * access to AC97 codec via normal i/o (for ICH and SIS7012)
543 /* return the GLOB_STA bit for the corresponding codec */
544 static unsigned int get_ich_codec_bit(intel8x0_t *chip, unsigned int codec)
546 static unsigned int codec_bit[3] = {
547 ICH_PCR, ICH_SCR, ICH_TCR
549 snd_assert(codec < 3, return ICH_PCR);
550 if (chip->device_type == DEVICE_INTEL_ICH4)
551 codec = chip->ac97_sdin[codec];
552 return codec_bit[codec];
555 static int snd_intel8x0_codec_semaphore(intel8x0_t *chip, unsigned int codec)
561 if (chip->in_sdin_init) {
562 /* we don't know the ready bit assignment at the moment */
563 /* so we check any */
564 codec = ICH_PCR | ICH_SCR | ICH_TCR;
566 codec = get_ich_codec_bit(chip, codec);
570 if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
573 /* Anyone holding a semaphore for 1 msec should be shot... */
576 if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
581 /* access to some forbidden (non existant) ac97 registers will not
582 * reset the semaphore. So even if you don't get the semaphore, still
583 * continue the access. We don't need the semaphore anyway. */
584 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
585 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
586 iagetword(chip, 0); /* clear semaphore flag */
587 /* I don't care about the semaphore */
591 static void snd_intel8x0_codec_write(ac97_t *ac97,
595 intel8x0_t *chip = ac97->private_data;
597 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
598 if (! chip->in_ac97_init)
599 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
601 iaputword(chip, reg + ac97->num * 0x80, val);
604 static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
607 intel8x0_t *chip = ac97->private_data;
611 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
612 if (! chip->in_ac97_init)
613 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
616 res = iagetword(chip, reg + ac97->num * 0x80);
617 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
618 /* reset RCS and preserve other R/WC bits */
619 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
620 if (! chip->in_ac97_init)
621 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
628 static void snd_intel8x0_codec_read_test(intel8x0_t *chip, unsigned int codec)
632 if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
633 iagetword(chip, codec * 0x80);
634 if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
635 /* reset RCS and preserve other R/WC bits */
636 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
642 * access to AC97 for Ali5455
644 static int snd_intel8x0_ali_codec_ready(intel8x0_t *chip, int mask)
647 for (count = 0; count < 0x7f; count++) {
648 int val = igetbyte(chip, ICHREG(ALI_CSPSR));
652 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
656 static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip)
659 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
662 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
663 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
666 static unsigned short snd_intel8x0_ali_codec_read(ac97_t *ac97, unsigned short reg)
668 intel8x0_t *chip = ac97->private_data;
669 unsigned short data = 0xffff;
671 if (snd_intel8x0_ali_codec_semaphore(chip))
673 reg |= ALI_CPR_ADDR_READ;
675 reg |= ALI_CPR_ADDR_SECONDARY;
676 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
677 if (snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_READ_OK))
679 data = igetword(chip, ICHREG(ALI_SPR));
684 static void snd_intel8x0_ali_codec_write(ac97_t *ac97, unsigned short reg, unsigned short val)
686 intel8x0_t *chip = ac97->private_data;
688 if (snd_intel8x0_ali_codec_semaphore(chip))
690 iputword(chip, ICHREG(ALI_CPR), val);
692 reg |= ALI_CPR_ADDR_SECONDARY;
693 iputword(chip, ICHREG(ALI_CPR_ADDR), reg);
694 snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_WRITE_OK);
701 static void snd_intel8x0_setup_periods(intel8x0_t *chip, ichdev_t *ichdev)
704 u32 *bdbar = ichdev->bdbar;
705 unsigned long port = ichdev->reg_offset;
707 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
708 if (ichdev->size == ichdev->fragsize) {
709 ichdev->ack_reload = ichdev->ack = 2;
710 ichdev->fragsize1 = ichdev->fragsize >> 1;
711 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
712 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
713 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
714 ichdev->fragsize1 >> ichdev->pos_shift);
715 bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
716 bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
717 ichdev->fragsize1 >> ichdev->pos_shift);
721 ichdev->ack_reload = ichdev->ack = 1;
722 ichdev->fragsize1 = ichdev->fragsize;
723 for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
724 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
725 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
726 ichdev->fragsize >> ichdev->pos_shift);
727 // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
729 ichdev->frags = ichdev->size / ichdev->fragsize;
731 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
733 iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
734 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
735 ichdev->position = 0;
737 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
738 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1);
740 /* clear interrupts */
741 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
746 * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
747 * which aborts PCI busmaster for audio transfer. A workaround is to set
748 * the pages as non-cached. For details, see the errata in
749 * http://www.intel.com/design/chipsets/specupdt/245051.htm
751 static void fill_nocache(void *buf, int size, int nocache)
753 size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
754 change_page_attr(virt_to_page(buf), size, nocache ? PAGE_KERNEL_NOCACHE : PAGE_KERNEL);
758 #define fill_nocache(buf,size,nocache)
765 static inline void snd_intel8x0_update(intel8x0_t *chip, ichdev_t *ichdev)
767 unsigned long port = ichdev->reg_offset;
768 int status, civ, i, step;
771 spin_lock(&chip->reg_lock);
772 status = igetbyte(chip, port + ichdev->roff_sr);
773 civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
774 if (!(status & ICH_BCIS)) {
776 } else if (civ == ichdev->civ) {
777 // snd_printd("civ same %d\n", civ);
780 ichdev->civ &= ICH_REG_LVI_MASK;
782 step = civ - ichdev->civ;
784 step += ICH_REG_LVI_MASK + 1;
786 // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
790 ichdev->position += step * ichdev->fragsize1;
791 if (! chip->in_measurement)
792 ichdev->position %= ichdev->size;
794 ichdev->lvi &= ICH_REG_LVI_MASK;
795 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
796 for (i = 0; i < step; i++) {
798 ichdev->lvi_frag %= ichdev->frags;
799 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
800 // 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));
801 if (--ichdev->ack == 0) {
802 ichdev->ack = ichdev->ack_reload;
806 spin_unlock(&chip->reg_lock);
807 if (ack && ichdev->substream) {
808 snd_pcm_period_elapsed(ichdev->substream);
810 iputbyte(chip, port + ichdev->roff_sr,
811 status & (ICH_FIFOE | ICH_BCIS | ICH_LVBCI));
814 static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id, struct pt_regs *regs)
816 intel8x0_t *chip = dev_id;
821 status = igetdword(chip, chip->int_sta_reg);
822 if (status == 0xffffffff) /* we are not yet resumed */
825 if ((status & chip->int_sta_mask) == 0) {
828 iputdword(chip, chip->int_sta_reg, status);
829 if (! chip->buggy_irq)
832 return IRQ_RETVAL(status);
835 for (i = 0; i < chip->bdbars_count; i++) {
836 ichdev = &chip->ichd[i];
837 if (status & ichdev->int_sta_mask)
838 snd_intel8x0_update(chip, ichdev);
842 iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
851 static int snd_intel8x0_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
853 intel8x0_t *chip = snd_pcm_substream_chip(substream);
854 ichdev_t *ichdev = get_ichdev(substream);
855 unsigned char val = 0;
856 unsigned long port = ichdev->reg_offset;
859 case SNDRV_PCM_TRIGGER_START:
860 case SNDRV_PCM_TRIGGER_RESUME:
861 val = ICH_IOCE | ICH_STARTBM;
863 case SNDRV_PCM_TRIGGER_STOP:
864 case SNDRV_PCM_TRIGGER_SUSPEND:
867 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
870 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
871 val = ICH_IOCE | ICH_STARTBM;
876 iputbyte(chip, port + ICH_REG_OFF_CR, val);
877 if (cmd == SNDRV_PCM_TRIGGER_STOP) {
878 /* wait until DMA stopped */
879 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
880 /* reset whole DMA things */
881 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
886 static int snd_intel8x0_ali_trigger(snd_pcm_substream_t *substream, int cmd)
888 intel8x0_t *chip = snd_pcm_substream_chip(substream);
889 ichdev_t *ichdev = get_ichdev(substream);
890 unsigned long port = ichdev->reg_offset;
891 static int fiforeg[] = { ICHREG(ALI_FIFOCR1), ICHREG(ALI_FIFOCR2), ICHREG(ALI_FIFOCR3) };
892 unsigned int val, fifo;
894 val = igetdword(chip, ICHREG(ALI_DMACR));
896 case SNDRV_PCM_TRIGGER_START:
897 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
898 case SNDRV_PCM_TRIGGER_RESUME:
899 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
900 /* clear FIFO for synchronization of channels */
901 fifo = igetdword(chip, fiforeg[ichdev->ali_slot / 4]);
902 fifo &= ~(0xff << (ichdev->ali_slot % 4));
903 fifo |= 0x83 << (ichdev->ali_slot % 4);
904 iputdword(chip, fiforeg[ichdev->ali_slot / 4], fifo);
906 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
907 val &= ~(1 << (ichdev->ali_slot + 16)); /* clear PAUSE flag */
908 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << ichdev->ali_slot)); /* start DMA */
910 case SNDRV_PCM_TRIGGER_STOP:
911 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
912 case SNDRV_PCM_TRIGGER_SUSPEND:
913 iputdword(chip, ICHREG(ALI_DMACR), val | (1 << (ichdev->ali_slot + 16))); /* pause */
914 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
915 while (igetbyte(chip, port + ICH_REG_OFF_CR))
917 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
919 /* reset whole DMA things */
920 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
921 /* clear interrupts */
922 iputbyte(chip, port + ICH_REG_OFF_SR, igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
923 iputdword(chip, ICHREG(ALI_INTERRUPTSR),
924 igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ichdev->int_sta_mask);
932 static int snd_intel8x0_hw_params(snd_pcm_substream_t * substream,
933 snd_pcm_hw_params_t * hw_params)
935 intel8x0_t *chip = snd_pcm_substream_chip(substream);
936 ichdev_t *ichdev = get_ichdev(substream);
937 snd_pcm_runtime_t *runtime = substream->runtime;
938 int dbl = params_rate(hw_params) > 48000;
941 if (chip->fix_nocache && ichdev->page_attr_changed) {
942 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0); /* clear */
943 ichdev->page_attr_changed = 0;
945 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
948 if (chip->fix_nocache) {
949 if (runtime->dma_area && ! ichdev->page_attr_changed) {
950 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
951 ichdev->page_attr_changed = 1;
954 if (ichdev->pcm_open_flag) {
955 snd_ac97_pcm_close(ichdev->pcm);
956 ichdev->pcm_open_flag = 0;
958 err = snd_ac97_pcm_open(ichdev->pcm, params_rate(hw_params),
959 params_channels(hw_params),
960 ichdev->pcm->r[dbl].slots);
962 ichdev->pcm_open_flag = 1;
963 /* Force SPDIF setting */
964 if (ichdev->ichd == ICHD_PCMOUT && chip->spdif_idx < 0)
965 snd_ac97_set_rate(ichdev->pcm->r[0].codec[0], AC97_SPDIF, params_rate(hw_params));
970 static int snd_intel8x0_hw_free(snd_pcm_substream_t * substream)
972 intel8x0_t *chip = snd_pcm_substream_chip(substream);
973 ichdev_t *ichdev = get_ichdev(substream);
975 if (ichdev->pcm_open_flag) {
976 snd_ac97_pcm_close(ichdev->pcm);
977 ichdev->pcm_open_flag = 0;
979 if (chip->fix_nocache && ichdev->page_attr_changed) {
980 fill_nocache(substream->runtime->dma_area, substream->runtime->dma_bytes, 0);
981 ichdev->page_attr_changed = 0;
983 return snd_pcm_lib_free_pages(substream);
986 static void snd_intel8x0_setup_pcm_out(intel8x0_t *chip,
987 snd_pcm_runtime_t *runtime)
990 int dbl = runtime->rate > 48000;
991 switch (chip->device_type) {
993 cnt = igetdword(chip, ICHREG(ALI_SCR));
994 cnt &= ~ICH_ALI_SC_PCM_246_MASK;
995 if (runtime->channels == 4 || dbl)
996 cnt |= ICH_ALI_SC_PCM_4;
997 else if (runtime->channels == 6)
998 cnt |= ICH_ALI_SC_PCM_6;
999 iputdword(chip, ICHREG(ALI_SCR), cnt);
1002 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1003 cnt &= ~ICH_SIS_PCM_246_MASK;
1004 if (runtime->channels == 4 || dbl)
1005 cnt |= ICH_SIS_PCM_4;
1006 else if (runtime->channels == 6)
1007 cnt |= ICH_SIS_PCM_6;
1008 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1011 cnt = igetdword(chip, ICHREG(GLOB_CNT));
1012 cnt &= ~(ICH_PCM_246_MASK | ICH_PCM_20BIT);
1013 if (runtime->channels == 4 || dbl)
1015 else if (runtime->channels == 6)
1017 if (chip->device_type == DEVICE_NFORCE) {
1018 /* reset to 2ch once to keep the 6 channel data in alignment,
1019 * to start from Front Left always
1021 if (cnt & ICH_PCM_246_MASK) {
1022 iputdword(chip, ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
1023 spin_unlock_irq(&chip->reg_lock);
1024 msleep(50); /* grrr... */
1025 spin_lock_irq(&chip->reg_lock);
1027 } else if (chip->device_type == DEVICE_INTEL_ICH4) {
1028 if (runtime->sample_bits > 16)
1029 cnt |= ICH_PCM_20BIT;
1031 iputdword(chip, ICHREG(GLOB_CNT), cnt);
1036 static int snd_intel8x0_pcm_prepare(snd_pcm_substream_t * substream)
1038 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1039 snd_pcm_runtime_t *runtime = substream->runtime;
1040 ichdev_t *ichdev = get_ichdev(substream);
1042 ichdev->physbuf = runtime->dma_addr;
1043 ichdev->size = snd_pcm_lib_buffer_bytes(substream);
1044 ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
1045 spin_lock_irq(&chip->reg_lock);
1046 if (ichdev->ichd == ICHD_PCMOUT) {
1047 snd_intel8x0_setup_pcm_out(chip, runtime);
1048 if (chip->device_type == DEVICE_INTEL_ICH4) {
1049 ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
1052 snd_intel8x0_setup_periods(chip, ichdev);
1053 spin_unlock_irq(&chip->reg_lock);
1057 static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(snd_pcm_substream_t * substream)
1059 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1060 ichdev_t *ichdev = get_ichdev(substream);
1062 int civ, timeout = 100;
1063 unsigned int position;
1065 spin_lock(&chip->reg_lock);
1067 civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
1068 ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
1069 position = ichdev->position;
1074 if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
1075 ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
1077 } while (timeout--);
1078 ptr1 <<= ichdev->pos_shift;
1079 ptr = ichdev->fragsize1 - ptr1;
1081 spin_unlock(&chip->reg_lock);
1082 if (ptr >= ichdev->size)
1084 return bytes_to_frames(substream->runtime, ptr);
1087 static snd_pcm_hardware_t snd_intel8x0_stream =
1089 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1090 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1091 SNDRV_PCM_INFO_MMAP_VALID |
1092 SNDRV_PCM_INFO_PAUSE |
1093 SNDRV_PCM_INFO_RESUME),
1094 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1095 .rates = SNDRV_PCM_RATE_48000,
1100 .buffer_bytes_max = 128 * 1024,
1101 .period_bytes_min = 32,
1102 .period_bytes_max = 128 * 1024,
1104 .periods_max = 1024,
1108 static unsigned int channels4[] = {
1112 static snd_pcm_hw_constraint_list_t hw_constraints_channels4 = {
1113 .count = ARRAY_SIZE(channels4),
1118 static unsigned int channels6[] = {
1122 static snd_pcm_hw_constraint_list_t hw_constraints_channels6 = {
1123 .count = ARRAY_SIZE(channels6),
1128 static int snd_intel8x0_pcm_open(snd_pcm_substream_t * substream, ichdev_t *ichdev)
1130 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1131 snd_pcm_runtime_t *runtime = substream->runtime;
1134 ichdev->substream = substream;
1135 runtime->hw = snd_intel8x0_stream;
1136 runtime->hw.rates = ichdev->pcm->rates;
1137 snd_pcm_limit_hw_rates(runtime);
1138 if (chip->device_type == DEVICE_SIS) {
1139 runtime->hw.buffer_bytes_max = 64*1024;
1140 runtime->hw.period_bytes_max = 64*1024;
1142 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
1144 runtime->private_data = ichdev;
1148 static int snd_intel8x0_playback_open(snd_pcm_substream_t * substream)
1150 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1151 snd_pcm_runtime_t *runtime = substream->runtime;
1154 err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
1159 runtime->hw.channels_max = 6;
1160 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels6);
1161 } else if (chip->multi4) {
1162 runtime->hw.channels_max = 4;
1163 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels4);
1166 snd_ac97_pcm_double_rate_rules(runtime);
1168 if (chip->smp20bit) {
1169 runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
1170 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
1175 static int snd_intel8x0_playback_close(snd_pcm_substream_t * substream)
1177 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1179 chip->ichd[ICHD_PCMOUT].substream = NULL;
1183 static int snd_intel8x0_capture_open(snd_pcm_substream_t * substream)
1185 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1187 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMIN]);
1190 static int snd_intel8x0_capture_close(snd_pcm_substream_t * substream)
1192 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1194 chip->ichd[ICHD_PCMIN].substream = NULL;
1198 static int snd_intel8x0_mic_open(snd_pcm_substream_t * substream)
1200 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1202 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC]);
1205 static int snd_intel8x0_mic_close(snd_pcm_substream_t * substream)
1207 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1209 chip->ichd[ICHD_MIC].substream = NULL;
1213 static int snd_intel8x0_mic2_open(snd_pcm_substream_t * substream)
1215 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1217 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_MIC2]);
1220 static int snd_intel8x0_mic2_close(snd_pcm_substream_t * substream)
1222 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1224 chip->ichd[ICHD_MIC2].substream = NULL;
1228 static int snd_intel8x0_capture2_open(snd_pcm_substream_t * substream)
1230 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1232 return snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCM2IN]);
1235 static int snd_intel8x0_capture2_close(snd_pcm_substream_t * substream)
1237 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1239 chip->ichd[ICHD_PCM2IN].substream = NULL;
1243 static int snd_intel8x0_spdif_open(snd_pcm_substream_t * substream)
1245 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1246 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1248 return snd_intel8x0_pcm_open(substream, &chip->ichd[idx]);
1251 static int snd_intel8x0_spdif_close(snd_pcm_substream_t * substream)
1253 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1254 int idx = chip->device_type == DEVICE_NFORCE ? NVD_SPBAR : ICHD_SPBAR;
1256 chip->ichd[idx].substream = NULL;
1260 static int snd_intel8x0_ali_ac97spdifout_open(snd_pcm_substream_t * substream)
1262 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1265 spin_lock_irq(&chip->reg_lock);
1266 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1267 val |= ICH_ALI_IF_AC97SP;
1268 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1269 /* also needs to set ALI_SC_CODEC_SPDF correctly */
1270 spin_unlock_irq(&chip->reg_lock);
1272 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_AC97SPDIFOUT]);
1275 static int snd_intel8x0_ali_ac97spdifout_close(snd_pcm_substream_t * substream)
1277 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1280 chip->ichd[ALID_AC97SPDIFOUT].substream = NULL;
1281 spin_lock_irq(&chip->reg_lock);
1282 val = igetdword(chip, ICHREG(ALI_INTERFACECR));
1283 val &= ~ICH_ALI_IF_AC97SP;
1284 iputdword(chip, ICHREG(ALI_INTERFACECR), val);
1285 spin_unlock_irq(&chip->reg_lock);
1290 static int snd_intel8x0_ali_spdifin_open(snd_pcm_substream_t * substream)
1292 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1294 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFIN]);
1297 static int snd_intel8x0_ali_spdifin_close(snd_pcm_substream_t * substream)
1299 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1301 chip->ichd[ALID_SPDIFIN].substream = NULL;
1306 static int snd_intel8x0_ali_spdifout_open(snd_pcm_substream_t * substream)
1308 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1310 return snd_intel8x0_pcm_open(substream, &chip->ichd[ALID_SPDIFOUT]);
1313 static int snd_intel8x0_ali_spdifout_close(snd_pcm_substream_t * substream)
1315 intel8x0_t *chip = snd_pcm_substream_chip(substream);
1317 chip->ichd[ALID_SPDIFOUT].substream = NULL;
1322 static snd_pcm_ops_t snd_intel8x0_playback_ops = {
1323 .open = snd_intel8x0_playback_open,
1324 .close = snd_intel8x0_playback_close,
1325 .ioctl = snd_pcm_lib_ioctl,
1326 .hw_params = snd_intel8x0_hw_params,
1327 .hw_free = snd_intel8x0_hw_free,
1328 .prepare = snd_intel8x0_pcm_prepare,
1329 .trigger = snd_intel8x0_pcm_trigger,
1330 .pointer = snd_intel8x0_pcm_pointer,
1333 static snd_pcm_ops_t snd_intel8x0_capture_ops = {
1334 .open = snd_intel8x0_capture_open,
1335 .close = snd_intel8x0_capture_close,
1336 .ioctl = snd_pcm_lib_ioctl,
1337 .hw_params = snd_intel8x0_hw_params,
1338 .hw_free = snd_intel8x0_hw_free,
1339 .prepare = snd_intel8x0_pcm_prepare,
1340 .trigger = snd_intel8x0_pcm_trigger,
1341 .pointer = snd_intel8x0_pcm_pointer,
1344 static snd_pcm_ops_t snd_intel8x0_capture_mic_ops = {
1345 .open = snd_intel8x0_mic_open,
1346 .close = snd_intel8x0_mic_close,
1347 .ioctl = snd_pcm_lib_ioctl,
1348 .hw_params = snd_intel8x0_hw_params,
1349 .hw_free = snd_intel8x0_hw_free,
1350 .prepare = snd_intel8x0_pcm_prepare,
1351 .trigger = snd_intel8x0_pcm_trigger,
1352 .pointer = snd_intel8x0_pcm_pointer,
1355 static snd_pcm_ops_t snd_intel8x0_capture_mic2_ops = {
1356 .open = snd_intel8x0_mic2_open,
1357 .close = snd_intel8x0_mic2_close,
1358 .ioctl = snd_pcm_lib_ioctl,
1359 .hw_params = snd_intel8x0_hw_params,
1360 .hw_free = snd_intel8x0_hw_free,
1361 .prepare = snd_intel8x0_pcm_prepare,
1362 .trigger = snd_intel8x0_pcm_trigger,
1363 .pointer = snd_intel8x0_pcm_pointer,
1366 static snd_pcm_ops_t snd_intel8x0_capture2_ops = {
1367 .open = snd_intel8x0_capture2_open,
1368 .close = snd_intel8x0_capture2_close,
1369 .ioctl = snd_pcm_lib_ioctl,
1370 .hw_params = snd_intel8x0_hw_params,
1371 .hw_free = snd_intel8x0_hw_free,
1372 .prepare = snd_intel8x0_pcm_prepare,
1373 .trigger = snd_intel8x0_pcm_trigger,
1374 .pointer = snd_intel8x0_pcm_pointer,
1377 static snd_pcm_ops_t snd_intel8x0_spdif_ops = {
1378 .open = snd_intel8x0_spdif_open,
1379 .close = snd_intel8x0_spdif_close,
1380 .ioctl = snd_pcm_lib_ioctl,
1381 .hw_params = snd_intel8x0_hw_params,
1382 .hw_free = snd_intel8x0_hw_free,
1383 .prepare = snd_intel8x0_pcm_prepare,
1384 .trigger = snd_intel8x0_pcm_trigger,
1385 .pointer = snd_intel8x0_pcm_pointer,
1388 static snd_pcm_ops_t snd_intel8x0_ali_playback_ops = {
1389 .open = snd_intel8x0_playback_open,
1390 .close = snd_intel8x0_playback_close,
1391 .ioctl = snd_pcm_lib_ioctl,
1392 .hw_params = snd_intel8x0_hw_params,
1393 .hw_free = snd_intel8x0_hw_free,
1394 .prepare = snd_intel8x0_pcm_prepare,
1395 .trigger = snd_intel8x0_ali_trigger,
1396 .pointer = snd_intel8x0_pcm_pointer,
1399 static snd_pcm_ops_t snd_intel8x0_ali_capture_ops = {
1400 .open = snd_intel8x0_capture_open,
1401 .close = snd_intel8x0_capture_close,
1402 .ioctl = snd_pcm_lib_ioctl,
1403 .hw_params = snd_intel8x0_hw_params,
1404 .hw_free = snd_intel8x0_hw_free,
1405 .prepare = snd_intel8x0_pcm_prepare,
1406 .trigger = snd_intel8x0_ali_trigger,
1407 .pointer = snd_intel8x0_pcm_pointer,
1410 static snd_pcm_ops_t snd_intel8x0_ali_capture_mic_ops = {
1411 .open = snd_intel8x0_mic_open,
1412 .close = snd_intel8x0_mic_close,
1413 .ioctl = snd_pcm_lib_ioctl,
1414 .hw_params = snd_intel8x0_hw_params,
1415 .hw_free = snd_intel8x0_hw_free,
1416 .prepare = snd_intel8x0_pcm_prepare,
1417 .trigger = snd_intel8x0_ali_trigger,
1418 .pointer = snd_intel8x0_pcm_pointer,
1421 static snd_pcm_ops_t snd_intel8x0_ali_ac97spdifout_ops = {
1422 .open = snd_intel8x0_ali_ac97spdifout_open,
1423 .close = snd_intel8x0_ali_ac97spdifout_close,
1424 .ioctl = snd_pcm_lib_ioctl,
1425 .hw_params = snd_intel8x0_hw_params,
1426 .hw_free = snd_intel8x0_hw_free,
1427 .prepare = snd_intel8x0_pcm_prepare,
1428 .trigger = snd_intel8x0_ali_trigger,
1429 .pointer = snd_intel8x0_pcm_pointer,
1432 static snd_pcm_ops_t snd_intel8x0_ali_spdifin_ops = {
1433 .open = snd_intel8x0_ali_spdifin_open,
1434 .close = snd_intel8x0_ali_spdifin_close,
1435 .ioctl = snd_pcm_lib_ioctl,
1436 .hw_params = snd_intel8x0_hw_params,
1437 .hw_free = snd_intel8x0_hw_free,
1438 .prepare = snd_intel8x0_pcm_prepare,
1439 .trigger = snd_intel8x0_pcm_trigger,
1440 .pointer = snd_intel8x0_pcm_pointer,
1444 static snd_pcm_ops_t snd_intel8x0_ali_spdifout_ops = {
1445 .open = snd_intel8x0_ali_spdifout_open,
1446 .close = snd_intel8x0_ali_spdifout_close,
1447 .ioctl = snd_pcm_lib_ioctl,
1448 .hw_params = snd_intel8x0_hw_params,
1449 .hw_free = snd_intel8x0_hw_free,
1450 .prepare = snd_intel8x0_pcm_prepare,
1451 .trigger = snd_intel8x0_pcm_trigger,
1452 .pointer = snd_intel8x0_pcm_pointer,
1456 struct ich_pcm_table {
1458 snd_pcm_ops_t *playback_ops;
1459 snd_pcm_ops_t *capture_ops;
1460 size_t prealloc_size;
1461 size_t prealloc_max_size;
1465 static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_pcm_table *rec)
1472 sprintf(name, "Intel ICH - %s", rec->suffix);
1474 strcpy(name, "Intel ICH");
1475 err = snd_pcm_new(chip->card, name, device,
1476 rec->playback_ops ? 1 : 0,
1477 rec->capture_ops ? 1 : 0, &pcm);
1481 if (rec->playback_ops)
1482 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
1483 if (rec->capture_ops)
1484 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
1486 pcm->private_data = chip;
1487 pcm->info_flags = 0;
1489 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
1491 strcpy(pcm->name, chip->card->shortname);
1492 chip->pcm[device] = pcm;
1494 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
1495 rec->prealloc_size, rec->prealloc_max_size);
1500 static struct ich_pcm_table intel_pcms[] __devinitdata = {
1502 .playback_ops = &snd_intel8x0_playback_ops,
1503 .capture_ops = &snd_intel8x0_capture_ops,
1504 .prealloc_size = 64 * 1024,
1505 .prealloc_max_size = 128 * 1024,
1508 .suffix = "MIC ADC",
1509 .capture_ops = &snd_intel8x0_capture_mic_ops,
1511 .prealloc_max_size = 128 * 1024,
1512 .ac97_idx = ICHD_MIC,
1515 .suffix = "MIC2 ADC",
1516 .capture_ops = &snd_intel8x0_capture_mic2_ops,
1518 .prealloc_max_size = 128 * 1024,
1519 .ac97_idx = ICHD_MIC2,
1523 .capture_ops = &snd_intel8x0_capture2_ops,
1525 .prealloc_max_size = 128 * 1024,
1526 .ac97_idx = ICHD_PCM2IN,
1530 .playback_ops = &snd_intel8x0_spdif_ops,
1531 .prealloc_size = 64 * 1024,
1532 .prealloc_max_size = 128 * 1024,
1533 .ac97_idx = ICHD_SPBAR,
1537 static struct ich_pcm_table nforce_pcms[] __devinitdata = {
1539 .playback_ops = &snd_intel8x0_playback_ops,
1540 .capture_ops = &snd_intel8x0_capture_ops,
1541 .prealloc_size = 64 * 1024,
1542 .prealloc_max_size = 128 * 1024,
1545 .suffix = "MIC ADC",
1546 .capture_ops = &snd_intel8x0_capture_mic_ops,
1548 .prealloc_max_size = 128 * 1024,
1549 .ac97_idx = NVD_MIC,
1553 .playback_ops = &snd_intel8x0_spdif_ops,
1554 .prealloc_size = 64 * 1024,
1555 .prealloc_max_size = 128 * 1024,
1556 .ac97_idx = NVD_SPBAR,
1560 static struct ich_pcm_table ali_pcms[] __devinitdata = {
1562 .playback_ops = &snd_intel8x0_ali_playback_ops,
1563 .capture_ops = &snd_intel8x0_ali_capture_ops,
1564 .prealloc_size = 64 * 1024,
1565 .prealloc_max_size = 128 * 1024,
1568 .suffix = "MIC ADC",
1569 .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
1571 .prealloc_max_size = 128 * 1024,
1572 .ac97_idx = ALID_MIC,
1576 .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
1577 .capture_ops = &snd_intel8x0_ali_spdifin_ops,
1578 .prealloc_size = 64 * 1024,
1579 .prealloc_max_size = 128 * 1024,
1580 .ac97_idx = ALID_AC97SPDIFOUT,
1584 .suffix = "HW IEC958",
1585 .playback_ops = &snd_intel8x0_ali_spdifout_ops,
1586 .prealloc_size = 64 * 1024,
1587 .prealloc_max_size = 128 * 1024,
1592 static int __devinit snd_intel8x0_pcm(intel8x0_t *chip)
1594 int i, tblsize, device, err;
1595 struct ich_pcm_table *tbl, *rec;
1597 switch (chip->device_type) {
1598 case DEVICE_INTEL_ICH4:
1600 tblsize = ARRAY_SIZE(intel_pcms);
1604 tblsize = ARRAY_SIZE(nforce_pcms);
1608 tblsize = ARRAY_SIZE(ali_pcms);
1617 for (i = 0; i < tblsize; i++) {
1619 if (i > 0 && rec->ac97_idx) {
1620 /* activate PCM only when associated AC'97 codec */
1621 if (! chip->ichd[rec->ac97_idx].pcm)
1624 err = snd_intel8x0_pcm1(chip, device, rec);
1630 chip->pcm_devs = device;
1639 static void snd_intel8x0_mixer_free_ac97_bus(ac97_bus_t *bus)
1641 intel8x0_t *chip = bus->private_data;
1642 chip->ac97_bus = NULL;
1645 static void snd_intel8x0_mixer_free_ac97(ac97_t *ac97)
1647 intel8x0_t *chip = ac97->private_data;
1648 chip->ac97[ac97->num] = NULL;
1651 static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
1656 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1657 (1 << AC97_SLOT_PCM_RIGHT) |
1658 (1 << AC97_SLOT_PCM_CENTER) |
1659 (1 << AC97_SLOT_PCM_SLEFT) |
1660 (1 << AC97_SLOT_PCM_SRIGHT) |
1661 (1 << AC97_SLOT_LFE)
1664 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1665 (1 << AC97_SLOT_PCM_RIGHT) |
1666 (1 << AC97_SLOT_PCM_LEFT_0) |
1667 (1 << AC97_SLOT_PCM_RIGHT_0)
1676 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1677 (1 << AC97_SLOT_PCM_RIGHT)
1686 .slots = (1 << AC97_SLOT_MIC)
1695 .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
1696 (1 << AC97_SLOT_SPDIF_RIGHT2)
1705 .slots = (1 << AC97_SLOT_PCM_LEFT) |
1706 (1 << AC97_SLOT_PCM_RIGHT)
1715 .slots = (1 << AC97_SLOT_MIC)
1721 static struct ac97_quirk ac97_quirks[] __devinitdata = {
1725 .name = "Compaq Evo W4000", /* AD1885 */
1726 .type = AC97_TUNE_HP_ONLY
1731 .name = "Compaq Evo D510C",
1732 .type = AC97_TUNE_HP_ONLY
1737 .name = "HP/Compaq nx7010",
1738 .type = AC97_TUNE_MUTE_LED
1744 .type = AC97_TUNE_ALC_JACK
1749 .name = "Dell Precision 530", /* AD1885 */
1750 .type = AC97_TUNE_HP_ONLY
1755 .name = "Dell", /* which model? AD1885 */
1756 .type = AC97_TUNE_HP_ONLY
1761 .name = "Dell Optiplex GX260", /* AD1981A */
1762 .type = AC97_TUNE_HP_ONLY
1767 .name = "Dell Precision 650", /* AD1981A */
1768 .type = AC97_TUNE_HP_ONLY
1773 .name = "Dell Precision 450", /* AD1981B*/
1774 .type = AC97_TUNE_HP_ONLY
1779 .name = "Dell", /* which model? AD1981B*/
1780 .type = AC97_TUNE_HP_ONLY
1785 .name = "Dell Unknown", /* STAC9750/51 */
1786 .type = AC97_TUNE_HP_ONLY
1791 .name = "HP zv5000",
1792 .type = AC97_TUNE_MUTE_LED /*AD1981B*/
1794 { /* FIXME: which codec? */
1797 .name = "HP xw6000",
1798 .type = AC97_TUNE_HP_ONLY
1803 .name = "HP nc8000",
1804 .type = AC97_TUNE_MUTE_LED
1809 .name = "HP nc6000",
1810 .type = AC97_TUNE_MUTE_LED
1815 .name = "HP xw8000",
1816 .type = AC97_TUNE_HP_ONLY
1821 .name = "HP xw8200", /* AD1981B*/
1822 .type = AC97_TUNE_HP_ONLY
1827 .name = "HP xw6200",
1828 .type = AC97_TUNE_HP_ONLY
1833 .name = "HP xw4200", /* AD1981B*/
1834 .type = AC97_TUNE_HP_ONLY
1839 .name = "Sony S1XP",
1840 .type = AC97_TUNE_INV_EAPD
1845 .name = "ASUS ICH5/AD1985",
1846 .type = AC97_TUNE_AD_SHARING
1851 .name = "Fujitsu-Siemens E4010",
1852 .type = AC97_TUNE_HP_ONLY
1857 .name = "Fujitsu S6210", /* STAC9750/51 */
1858 .type = AC97_TUNE_HP_ONLY
1863 .name = "Fujitsu-Siemens Celsius", /* AD1981? */
1864 .type = AC97_TUNE_HP_ONLY
1869 .name = "AMD64 Mobo", /* ALC650 */
1870 .type = AC97_TUNE_HP_ONLY
1875 .name = "Fujitsu-Siemens Scenic", /* AD1981? */
1876 .type = AC97_TUNE_HP_ONLY
1881 .name = "ADI AD1985 (discrete)",
1882 .type = AC97_TUNE_HP_ONLY
1887 .name = "MSI P4 ATX 645 Ultra",
1888 .type = AC97_TUNE_HP_ONLY
1893 .name = "Fujitsu-Siemens D1522", /* AD1981 */
1894 .type = AC97_TUNE_HP_ONLY
1900 .name = "Intel ICH5/AD1985",
1901 .type = AC97_TUNE_AD_SHARING
1907 .name = "Intel ICH5/AD1985",
1908 .type = AC97_TUNE_AD_SHARING
1913 .name = "Intel D845WN (82801BA)",
1914 .type = AC97_TUNE_SWAP_HP
1919 .name = "Intel D850EMV2", /* AD1885 */
1920 .type = AC97_TUNE_HP_ONLY
1925 .name = "Intel ICH/AD1885",
1926 .type = AC97_TUNE_HP_ONLY
1932 .name = "Intel ICH5/AD1985",
1933 .type = AC97_TUNE_AD_SHARING
1939 .name = "Intel ICH5/AD1985",
1940 .type = AC97_TUNE_AD_SHARING
1942 #if 0 /* FIXME: this seems wrong on most boards */
1947 .name = "Intel ICH5/AD1985",
1948 .type = AC97_TUNE_HP_ONLY
1951 { } /* terminator */
1954 static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock, const char *quirk_override)
1957 ac97_template_t ac97;
1959 unsigned int i, codecs;
1960 unsigned int glob_sta = 0;
1961 ac97_bus_ops_t *ops;
1962 static ac97_bus_ops_t standard_bus_ops = {
1963 .write = snd_intel8x0_codec_write,
1964 .read = snd_intel8x0_codec_read,
1966 static ac97_bus_ops_t ali_bus_ops = {
1967 .write = snd_intel8x0_ali_codec_write,
1968 .read = snd_intel8x0_ali_codec_read,
1971 chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
1972 switch (chip->device_type) {
1974 chip->spdif_idx = NVD_SPBAR;
1977 chip->spdif_idx = ALID_AC97SPDIFOUT;
1979 case DEVICE_INTEL_ICH4:
1980 chip->spdif_idx = ICHD_SPBAR;
1984 chip->in_ac97_init = 1;
1986 memset(&ac97, 0, sizeof(ac97));
1987 ac97.private_data = chip;
1988 ac97.private_free = snd_intel8x0_mixer_free_ac97;
1989 ac97.scaps = AC97_SCAP_SKIP_MODEM;
1991 ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
1992 if (chip->device_type != DEVICE_ALI) {
1993 glob_sta = igetdword(chip, ICHREG(GLOB_STA));
1994 ops = &standard_bus_ops;
1995 if (chip->device_type == DEVICE_INTEL_ICH4) {
1997 if (glob_sta & ICH_PCR)
1999 if (glob_sta & ICH_SCR)
2001 if (glob_sta & ICH_TCR)
2003 chip->in_sdin_init = 1;
2004 for (i = 0; i < codecs; i++) {
2005 snd_intel8x0_codec_read_test(chip, i);
2006 chip->ac97_sdin[i] = igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
2008 chip->in_sdin_init = 0;
2010 codecs = glob_sta & ICH_SCR ? 2 : 1;
2015 /* detect the secondary codec */
2016 for (i = 0; i < 100; i++) {
2017 unsigned int reg = igetdword(chip, ICHREG(ALI_RTSR));
2022 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x40);
2026 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
2028 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
2029 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with modem driver */
2030 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2031 pbus->clock = ac97_clock;
2032 /* FIXME: my test board doesn't work well with VRA... */
2033 if (chip->device_type == DEVICE_ALI)
2037 chip->ac97_bus = pbus;
2039 ac97.pci = chip->pci;
2040 for (i = 0; i < codecs; i++) {
2042 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
2044 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
2050 /* tune up the primary codec */
2051 snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
2052 /* enable separate SDINs for ICH4 */
2053 if (chip->device_type == DEVICE_INTEL_ICH4)
2055 /* find the available PCM streams */
2056 i = ARRAY_SIZE(ac97_pcm_defs);
2057 if (chip->device_type != DEVICE_INTEL_ICH4)
2058 i -= 2; /* do not allocate PCM2IN and MIC2 */
2059 if (chip->spdif_idx < 0)
2060 i--; /* do not allocate S/PDIF */
2061 err = snd_ac97_pcm_assign(pbus, i, ac97_pcm_defs);
2064 chip->ichd[ICHD_PCMOUT].pcm = &pbus->pcms[0];
2065 chip->ichd[ICHD_PCMIN].pcm = &pbus->pcms[1];
2066 chip->ichd[ICHD_MIC].pcm = &pbus->pcms[2];
2067 if (chip->spdif_idx >= 0)
2068 chip->ichd[chip->spdif_idx].pcm = &pbus->pcms[3];
2069 if (chip->device_type == DEVICE_INTEL_ICH4) {
2070 chip->ichd[ICHD_PCM2IN].pcm = &pbus->pcms[4];
2071 chip->ichd[ICHD_MIC2].pcm = &pbus->pcms[5];
2073 /* enable separate SDINs for ICH4 */
2074 if (chip->device_type == DEVICE_INTEL_ICH4) {
2075 struct ac97_pcm *pcm = chip->ichd[ICHD_PCM2IN].pcm;
2076 u8 tmp = igetbyte(chip, ICHREG(SDM));
2077 tmp &= ~(ICH_DI2L_MASK|ICH_DI1L_MASK);
2079 tmp |= ICH_SE; /* steer enable for multiple SDINs */
2080 tmp |= chip->ac97_sdin[0] << ICH_DI1L_SHIFT;
2081 for (i = 1; i < 4; i++) {
2082 if (pcm->r[0].codec[i]) {
2083 tmp |= chip->ac97_sdin[pcm->r[0].codec[1]->num] << ICH_DI2L_SHIFT;
2088 tmp &= ~ICH_SE; /* steer disable */
2090 iputbyte(chip, ICHREG(SDM), tmp);
2092 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2094 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE))
2097 if (pbus->pcms[0].r[1].rslots[0]) {
2100 if (chip->device_type == DEVICE_INTEL_ICH4) {
2101 if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
2104 if (chip->device_type == DEVICE_NFORCE) {
2106 chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
2108 if (chip->device_type == DEVICE_INTEL_ICH4) {
2109 /* use slot 10/11 for SPDIF */
2111 val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
2112 val |= ICH_PCM_SPDIF_1011;
2113 iputdword(chip, ICHREG(GLOB_CNT), val);
2114 snd_ac97_update_bits(chip->ac97[0], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
2116 chip->in_ac97_init = 0;
2120 /* clear the cold-reset bit for the next chance */
2121 if (chip->device_type != DEVICE_ALI)
2122 iputdword(chip, ICHREG(GLOB_CNT), igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
2131 static void do_ali_reset(intel8x0_t *chip)
2133 iputdword(chip, ICHREG(ALI_SCR), ICH_ALI_SC_RESET);
2134 iputdword(chip, ICHREG(ALI_FIFOCR1), 0x83838383);
2135 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
2136 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
2137 iputdword(chip, ICHREG(ALI_INTERFACECR),
2138 ICH_ALI_IF_MC|ICH_ALI_IF_PI|ICH_ALI_IF_PO);
2139 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
2140 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2143 #define do_delay(chip) do {\
2144 set_current_state(TASK_UNINTERRUPTIBLE);\
2145 schedule_timeout(1);\
2148 static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
2150 unsigned long end_time;
2151 unsigned int cnt, status, nstatus;
2153 /* put logic to right state */
2154 /* first clear status bits */
2155 status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
2156 if (chip->device_type == DEVICE_NFORCE)
2157 status |= ICH_NVSPINT;
2158 cnt = igetdword(chip, ICHREG(GLOB_STA));
2159 iputdword(chip, ICHREG(GLOB_STA), cnt & status);
2161 /* ACLink on, 2 channels */
2162 cnt = igetdword(chip, ICHREG(GLOB_CNT));
2163 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
2164 /* finish cold or do warm reset */
2165 cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
2166 iputdword(chip, ICHREG(GLOB_CNT), cnt);
2167 end_time = (jiffies + (HZ / 4)) + 1;
2169 if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
2172 } while (time_after_eq(end_time, jiffies));
2173 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
2178 /* wait for any codec ready status.
2179 * Once it becomes ready it should remain ready
2180 * as long as we do not disable the ac97 link.
2182 end_time = jiffies + HZ;
2184 status = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2188 } while (time_after_eq(end_time, jiffies));
2190 /* no codec is found */
2191 snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", igetdword(chip, ICHREG(GLOB_STA)));
2195 if (chip->device_type == DEVICE_INTEL_ICH4)
2196 /* ICH4 can have three codecs */
2197 nstatus = ICH_PCR | ICH_SCR | ICH_TCR;
2199 /* others up to two codecs */
2200 nstatus = ICH_PCR | ICH_SCR;
2202 /* wait for other codecs ready status. */
2203 end_time = jiffies + HZ / 4;
2204 while (status != nstatus && time_after_eq(end_time, jiffies)) {
2206 status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
2213 for (i = 0; i < 3; i++)
2215 status |= get_ich_codec_bit(chip, i);
2216 /* wait until all the probed codecs are ready */
2217 end_time = jiffies + HZ;
2219 nstatus = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
2220 if (status == nstatus)
2223 } while (time_after_eq(end_time, jiffies));
2226 if (chip->device_type == DEVICE_SIS) {
2227 /* unmute the output on SIS7012 */
2228 iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
2230 if (chip->device_type == DEVICE_NFORCE) {
2231 /* enable SPDIF interrupt */
2233 pci_read_config_dword(chip->pci, 0x4c, &val);
2235 pci_write_config_dword(chip->pci, 0x4c, val);
2240 static int snd_intel8x0_ali_chip_init(intel8x0_t *chip, int probing)
2245 reg = igetdword(chip, ICHREG(ALI_SCR));
2246 if ((reg & 2) == 0) /* Cold required */
2249 reg |= 1; /* Warm */
2250 reg &= ~0x80000000; /* ACLink on */
2251 iputdword(chip, ICHREG(ALI_SCR), reg);
2253 for (i = 0; i < HZ / 2; i++) {
2254 if (! (igetdword(chip, ICHREG(ALI_INTERRUPTSR)) & ALI_INT_GPIO))
2258 snd_printk(KERN_ERR "AC'97 reset failed.\n");
2263 for (i = 0; i < HZ / 2; i++) {
2264 reg = igetdword(chip, ICHREG(ALI_RTSR));
2265 if (reg & 0x80) /* primary codec */
2267 iputdword(chip, ICHREG(ALI_RTSR), reg | 0x80);
2275 static int snd_intel8x0_chip_init(intel8x0_t *chip, int probing)
2280 if (chip->device_type != DEVICE_ALI) {
2281 if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
2283 iagetword(chip, 0); /* clear semaphore flag */
2285 if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
2289 /* disable interrupts */
2290 for (i = 0; i < chip->bdbars_count; i++)
2291 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2292 /* reset channels */
2293 for (i = 0; i < chip->bdbars_count; i++)
2294 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2295 /* initialize Buffer Descriptor Lists */
2296 for (i = 0; i < chip->bdbars_count; i++)
2297 iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
2301 static int snd_intel8x0_free(intel8x0_t *chip)
2307 /* disable interrupts */
2308 for (i = 0; i < chip->bdbars_count; i++)
2309 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
2310 /* reset channels */
2311 for (i = 0; i < chip->bdbars_count; i++)
2312 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
2313 if (chip->device_type == DEVICE_NFORCE) {
2314 /* stop the spdif interrupt */
2316 pci_read_config_dword(chip->pci, 0x4c, &val);
2318 pci_write_config_dword(chip->pci, 0x4c, val);
2321 synchronize_irq(chip->irq);
2324 free_irq(chip->irq, (void *)chip);
2325 if (chip->bdbars.area) {
2326 if (chip->fix_nocache)
2327 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
2328 snd_dma_free_pages(&chip->bdbars);
2330 if (chip->remap_addr)
2331 iounmap(chip->remap_addr);
2332 if (chip->remap_bmaddr)
2333 iounmap(chip->remap_bmaddr);
2334 pci_release_regions(chip->pci);
2335 pci_disable_device(chip->pci);
2344 static int intel8x0_suspend(snd_card_t *card, pm_message_t state)
2346 intel8x0_t *chip = card->pm_private_data;
2349 for (i = 0; i < chip->pcm_devs; i++)
2350 snd_pcm_suspend_all(chip->pcm[i]);
2352 if (chip->fix_nocache) {
2353 for (i = 0; i < chip->bdbars_count; i++) {
2354 ichdev_t *ichdev = &chip->ichd[i];
2355 if (ichdev->substream && ichdev->page_attr_changed) {
2356 snd_pcm_runtime_t *runtime = ichdev->substream->runtime;
2357 if (runtime->dma_area)
2358 fill_nocache(runtime->dma_area, runtime->dma_bytes, 0);
2362 for (i = 0; i < 3; i++)
2364 snd_ac97_suspend(chip->ac97[i]);
2365 pci_disable_device(chip->pci);
2369 static int intel8x0_resume(snd_card_t *card)
2371 intel8x0_t *chip = card->pm_private_data;
2374 pci_enable_device(chip->pci);
2375 pci_set_master(chip->pci);
2376 snd_intel8x0_chip_init(chip, 0);
2378 /* refill nocache */
2379 if (chip->fix_nocache)
2380 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2382 for (i = 0; i < 3; i++)
2384 snd_ac97_resume(chip->ac97[i]);
2386 /* refill nocache */
2387 if (chip->fix_nocache) {
2388 for (i = 0; i < chip->bdbars_count; i++) {
2389 ichdev_t *ichdev = &chip->ichd[i];
2390 if (ichdev->substream && ichdev->page_attr_changed) {
2391 snd_pcm_runtime_t *runtime = ichdev->substream->runtime;
2392 if (runtime->dma_area)
2393 fill_nocache(runtime->dma_area, runtime->dma_bytes, 1);
2400 #endif /* CONFIG_PM */
2402 #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
2404 static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2406 snd_pcm_substream_t *subs;
2409 unsigned long pos, t;
2410 struct timeval start_time, stop_time;
2412 if (chip->ac97_bus->clock != 48000)
2413 return; /* specified in module option */
2415 subs = chip->pcm[0]->streams[0].substream;
2416 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2417 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n");
2420 ichdev = &chip->ichd[ICHD_PCMOUT];
2421 ichdev->physbuf = subs->dma_buffer.addr;
2422 ichdev->size = chip->ichd[ICHD_PCMOUT].fragsize = INTEL8X0_TESTBUF_SIZE;
2423 ichdev->substream = NULL; /* don't process interrupts */
2426 if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
2427 snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock);
2430 snd_intel8x0_setup_periods(chip, ichdev);
2431 port = ichdev->reg_offset;
2432 spin_lock_irq(&chip->reg_lock);
2433 chip->in_measurement = 1;
2435 if (chip->device_type != DEVICE_ALI)
2436 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE | ICH_STARTBM);
2438 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
2439 iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
2441 do_gettimeofday(&start_time);
2442 spin_unlock_irq(&chip->reg_lock);
2443 set_current_state(TASK_UNINTERRUPTIBLE);
2444 schedule_timeout(HZ / 20);
2445 spin_lock_irq(&chip->reg_lock);
2446 /* check the position */
2447 pos = ichdev->fragsize1;
2448 pos -= igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << ichdev->pos_shift;
2449 pos += ichdev->position;
2450 chip->in_measurement = 0;
2451 do_gettimeofday(&stop_time);
2453 if (chip->device_type == DEVICE_ALI) {
2454 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 8));
2455 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2456 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2459 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2460 while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH))
2463 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
2464 spin_unlock_irq(&chip->reg_lock);
2466 t = stop_time.tv_sec - start_time.tv_sec;
2468 t += stop_time.tv_usec - start_time.tv_usec;
2469 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t);
2471 snd_printk(KERN_ERR "?? calculation error..\n");
2474 pos = (pos / 4) * 1000;
2475 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2476 if (pos < 40000 || pos >= 60000)
2477 /* abnormal value. hw problem? */
2478 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
2479 else if (pos < 47500 || pos > 48500)
2480 /* not 48000Hz, tuning the clock.. */
2481 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
2482 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
2485 static void snd_intel8x0_proc_read(snd_info_entry_t * entry,
2486 snd_info_buffer_t * buffer)
2488 intel8x0_t *chip = entry->private_data;
2491 snd_iprintf(buffer, "Intel8x0\n\n");
2492 if (chip->device_type == DEVICE_ALI)
2494 tmp = igetdword(chip, ICHREG(GLOB_STA));
2495 snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
2496 snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
2497 if (chip->device_type == DEVICE_INTEL_ICH4)
2498 snd_iprintf(buffer, "SDM : 0x%08x\n", igetdword(chip, ICHREG(SDM)));
2499 snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
2500 tmp & ICH_PCR ? " primary" : "",
2501 tmp & ICH_SCR ? " secondary" : "",
2502 tmp & ICH_TCR ? " tertiary" : "",
2503 (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
2504 if (chip->device_type == DEVICE_INTEL_ICH4)
2505 snd_iprintf(buffer, "AC'97 codecs SDIN : %i %i %i\n",
2508 chip->ac97_sdin[2]);
2511 static void __devinit snd_intel8x0_proc_init(intel8x0_t * chip)
2513 snd_info_entry_t *entry;
2515 if (! snd_card_proc_new(chip->card, "intel8x0", &entry))
2516 snd_info_set_text_ops(entry, chip, 1024, snd_intel8x0_proc_read);
2519 static int snd_intel8x0_dev_free(snd_device_t *device)
2521 intel8x0_t *chip = device->device_data;
2522 return snd_intel8x0_free(chip);
2525 struct ich_reg_info {
2526 unsigned int int_sta_mask;
2527 unsigned int offset;
2530 static int __devinit snd_intel8x0_create(snd_card_t * card,
2531 struct pci_dev *pci,
2532 unsigned long device_type,
2533 intel8x0_t ** r_intel8x0)
2538 unsigned int int_sta_masks;
2540 static snd_device_ops_t ops = {
2541 .dev_free = snd_intel8x0_dev_free,
2544 static unsigned int bdbars[] = {
2545 3, /* DEVICE_INTEL */
2546 6, /* DEVICE_INTEL_ICH4 */
2549 4, /* DEVICE_NFORCE */
2551 static struct ich_reg_info intel_regs[6] = {
2553 { ICH_POINT, 0x10 },
2554 { ICH_MCINT, 0x20 },
2555 { ICH_M2INT, 0x40 },
2556 { ICH_P2INT, 0x50 },
2557 { ICH_SPINT, 0x60 },
2559 static struct ich_reg_info nforce_regs[4] = {
2561 { ICH_POINT, 0x10 },
2562 { ICH_MCINT, 0x20 },
2563 { ICH_NVSPINT, 0x70 },
2565 static struct ich_reg_info ali_regs[6] = {
2566 { ALI_INT_PCMIN, 0x40 },
2567 { ALI_INT_PCMOUT, 0x50 },
2568 { ALI_INT_MICIN, 0x60 },
2569 { ALI_INT_CODECSPDIFOUT, 0x70 },
2570 { ALI_INT_SPDIFIN, 0xa0 },
2571 { ALI_INT_SPDIFOUT, 0xb0 },
2573 struct ich_reg_info *tbl;
2577 if ((err = pci_enable_device(pci)) < 0)
2580 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
2582 pci_disable_device(pci);
2585 spin_lock_init(&chip->reg_lock);
2586 chip->device_type = device_type;
2591 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2592 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2593 chip->fix_nocache = 1; /* enable workaround */
2595 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2596 * Needs to return IRQ_HANDLED for unknown irqs.
2598 if (device_type == DEVICE_NFORCE)
2599 chip->buggy_irq = 1;
2601 if ((err = pci_request_regions(pci, card->shortname)) < 0) {
2603 pci_disable_device(pci);
2607 if (device_type == DEVICE_ALI) {
2608 /* ALI5455 has no ac97 region */
2609 chip->bmaddr = pci_resource_start(pci, 0);
2613 if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */
2615 chip->addr = pci_resource_start(pci, 2);
2616 chip->remap_addr = ioremap_nocache(chip->addr,
2617 pci_resource_len(pci, 2));
2618 if (chip->remap_addr == NULL) {
2619 snd_printk("AC'97 space ioremap problem\n");
2620 snd_intel8x0_free(chip);
2624 chip->addr = pci_resource_start(pci, 0);
2626 if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */
2628 chip->bmaddr = pci_resource_start(pci, 3);
2629 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
2630 pci_resource_len(pci, 3));
2631 if (chip->remap_bmaddr == NULL) {
2632 snd_printk("Controller space ioremap problem\n");
2633 snd_intel8x0_free(chip);
2637 chip->bmaddr = pci_resource_start(pci, 1);
2641 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2642 snd_printk("unable to grab IRQ %d\n", pci->irq);
2643 snd_intel8x0_free(chip);
2646 chip->irq = pci->irq;
2647 pci_set_master(pci);
2648 synchronize_irq(chip->irq);
2650 chip->bdbars_count = bdbars[device_type];
2652 /* initialize offsets */
2653 switch (device_type) {
2664 for (i = 0; i < chip->bdbars_count; i++) {
2665 ichdev = &chip->ichd[i];
2667 ichdev->reg_offset = tbl[i].offset;
2668 ichdev->int_sta_mask = tbl[i].int_sta_mask;
2669 if (device_type == DEVICE_SIS) {
2670 /* SiS 7012 swaps the registers */
2671 ichdev->roff_sr = ICH_REG_OFF_PICB;
2672 ichdev->roff_picb = ICH_REG_OFF_SR;
2674 ichdev->roff_sr = ICH_REG_OFF_SR;
2675 ichdev->roff_picb = ICH_REG_OFF_PICB;
2677 if (device_type == DEVICE_ALI)
2678 ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
2679 /* SIS7012 handles the pcm data in bytes, others are in samples */
2680 ichdev->pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
2683 /* allocate buffer descriptor lists */
2684 /* the start of each lists must be aligned to 8 bytes */
2685 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
2686 chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
2687 &chip->bdbars) < 0) {
2688 snd_intel8x0_free(chip);
2689 snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n");
2692 /* tables must be aligned to 8 bytes here, but the kernel pages
2693 are much bigger, so we don't care (on i386) */
2694 /* workaround for 440MX */
2695 if (chip->fix_nocache)
2696 fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 1);
2698 for (i = 0; i < chip->bdbars_count; i++) {
2699 ichdev = &chip->ichd[i];
2700 ichdev->bdbar = ((u32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2);
2701 ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
2702 int_sta_masks |= ichdev->int_sta_mask;
2704 chip->int_sta_reg = device_type == DEVICE_ALI ? ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
2705 chip->int_sta_mask = int_sta_masks;
2707 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
2708 snd_intel8x0_free(chip);
2712 snd_card_set_pm_callback(card, intel8x0_suspend, intel8x0_resume, chip);
2714 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2715 snd_intel8x0_free(chip);
2719 snd_card_set_dev(card, &pci->dev);
2725 static struct shortname_table {
2728 } shortnames[] __devinitdata = {
2729 { PCI_DEVICE_ID_INTEL_82801, "Intel 82801AA-ICH" },
2730 { PCI_DEVICE_ID_INTEL_82901, "Intel 82901AB-ICH0" },
2731 { PCI_DEVICE_ID_INTEL_82801BA, "Intel 82801BA-ICH2" },
2732 { PCI_DEVICE_ID_INTEL_440MX, "Intel 440MX" },
2733 { PCI_DEVICE_ID_INTEL_ICH3, "Intel 82801CA-ICH3" },
2734 { PCI_DEVICE_ID_INTEL_ICH4, "Intel 82801DB-ICH4" },
2735 { PCI_DEVICE_ID_INTEL_ICH5, "Intel ICH5" },
2736 { PCI_DEVICE_ID_INTEL_ESB_5, "Intel 6300ESB" },
2737 { PCI_DEVICE_ID_INTEL_ICH6_18, "Intel ICH6" },
2738 { PCI_DEVICE_ID_INTEL_ICH7_20, "Intel ICH7" },
2739 { PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
2740 { PCI_DEVICE_ID_NVIDIA_MCP_AUDIO, "NVidia nForce" },
2741 { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
2742 { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
2743 { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO, "NVidia CK8S" },
2744 { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO, "NVidia CK804" },
2745 { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO, "NVidia CK8" },
2746 { 0x003a, "NVidia MCP04" },
2747 { 0x746d, "AMD AMD8111" },
2748 { 0x7445, "AMD AMD768" },
2749 { 0x5455, "ALi M5455" },
2753 static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2754 const struct pci_device_id *pci_id)
2760 struct shortname_table *name;
2762 if (dev >= SNDRV_CARDS)
2769 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2773 switch (pci_id->driver_data) {
2775 strcpy(card->driver, "NFORCE");
2777 case DEVICE_INTEL_ICH4:
2778 strcpy(card->driver, "ICH4");
2781 strcpy(card->driver, "ICH");
2785 strcpy(card->shortname, "Intel ICH");
2786 for (name = shortnames; name->id; name++) {
2787 if (pci->device == name->id) {
2788 strcpy(card->shortname, name->s);
2793 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip)) < 0) {
2794 snd_card_free(card);
2798 chip->buggy_irq = 1;
2802 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) {
2803 snd_card_free(card);
2806 if ((err = snd_intel8x0_pcm(chip)) < 0) {
2807 snd_card_free(card);
2811 snd_intel8x0_proc_init(chip);
2813 snprintf(card->longname, sizeof(card->longname),
2814 "%s with %s at %#lx, irq %i", card->shortname,
2815 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
2817 if (! ac97_clock[dev])
2818 intel8x0_measure_ac97_clock(chip);
2820 if ((err = snd_card_register(card)) < 0) {
2821 snd_card_free(card);
2824 pci_set_drvdata(pci, card);
2829 static void __devexit snd_intel8x0_remove(struct pci_dev *pci)
2831 snd_card_free(pci_get_drvdata(pci));
2832 pci_set_drvdata(pci, NULL);
2835 static struct pci_driver driver = {
2836 .name = "Intel ICH",
2837 .id_table = snd_intel8x0_ids,
2838 .probe = snd_intel8x0_probe,
2839 .remove = __devexit_p(snd_intel8x0_remove),
2840 SND_PCI_PM_CALLBACKS
2844 static int __init alsa_card_intel8x0_init(void)
2846 return pci_module_init(&driver);
2849 static void __exit alsa_card_intel8x0_exit(void)
2851 pci_unregister_driver(&driver);
2854 module_init(alsa_card_intel8x0_init)
2855 module_exit(alsa_card_intel8x0_exit)