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 */
428 ac97_bus_t
*ac97_bus
;
430 unsigned int ac97_sdin
[3];
435 struct snd_dma_buffer bdbars
;
436 u32 int_sta_reg
; /* interrupt status register */
437 u32 int_sta_mask
; /* interrupt status mask */
440 static struct pci_device_id snd_intel8x0_ids
[] = {
441 { 0x8086, 0x2415, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* 82801AA */
442 { 0x8086, 0x2425, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* 82901AB */
443 { 0x8086, 0x2445, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* 82801BA */
444 { 0x8086, 0x2485, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* ICH3 */
445 { 0x8086, 0x24c5, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ICH4 */
446 { 0x8086, 0x24d5, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ICH5 */
447 { 0x8086, 0x25a6, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ESB */
448 { 0x8086, 0x266e, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ICH6 */
449 { 0x8086, 0x27de, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ICH7 */
450 { 0x8086, 0x2698, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL_ICH4
}, /* ESB2 */
451 { 0x8086, 0x7195, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* 440MX */
452 { 0x1039, 0x7012, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_SIS
}, /* SI7012 */
453 { 0x10de, 0x01b1, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* NFORCE */
454 { 0x10de, 0x003a, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* MCP04 */
455 { 0x10de, 0x006a, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* NFORCE2 */
456 { 0x10de, 0x0059, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* CK804 */
457 { 0x10de, 0x008a, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* CK8 */
458 { 0x10de, 0x00da, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* NFORCE3 */
459 { 0x10de, 0x00ea, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_NFORCE
}, /* CK8S */
460 { 0x1022, 0x746d, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* AMD8111 */
461 { 0x1022, 0x7445, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_INTEL
}, /* AMD768 */
462 { 0x10b9, 0x5455, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_ALI
}, /* Ali5455 */
466 MODULE_DEVICE_TABLE(pci
, snd_intel8x0_ids
);
469 * Lowlevel I/O - busmaster
472 static u8
igetbyte(intel8x0_t
*chip
, u32 offset
)
475 return readb(chip
->remap_bmaddr
+ offset
);
477 return inb(chip
->bmaddr
+ offset
);
480 static u16
igetword(intel8x0_t
*chip
, u32 offset
)
483 return readw(chip
->remap_bmaddr
+ offset
);
485 return inw(chip
->bmaddr
+ offset
);
488 static u32
igetdword(intel8x0_t
*chip
, u32 offset
)
491 return readl(chip
->remap_bmaddr
+ offset
);
493 return inl(chip
->bmaddr
+ offset
);
496 static void iputbyte(intel8x0_t
*chip
, u32 offset
, u8 val
)
499 writeb(val
, chip
->remap_bmaddr
+ offset
);
501 outb(val
, chip
->bmaddr
+ offset
);
504 static void iputword(intel8x0_t
*chip
, u32 offset
, u16 val
)
507 writew(val
, chip
->remap_bmaddr
+ offset
);
509 outw(val
, chip
->bmaddr
+ offset
);
512 static void iputdword(intel8x0_t
*chip
, u32 offset
, u32 val
)
515 writel(val
, chip
->remap_bmaddr
+ offset
);
517 outl(val
, chip
->bmaddr
+ offset
);
521 * Lowlevel I/O - AC'97 registers
524 static u16
iagetword(intel8x0_t
*chip
, u32 offset
)
527 return readw(chip
->remap_addr
+ offset
);
529 return inw(chip
->addr
+ offset
);
532 static void iaputword(intel8x0_t
*chip
, u32 offset
, u16 val
)
535 writew(val
, chip
->remap_addr
+ offset
);
537 outw(val
, chip
->addr
+ offset
);
545 * access to AC97 codec via normal i/o (for ICH and SIS7012)
548 /* return the GLOB_STA bit for the corresponding codec */
549 static unsigned int get_ich_codec_bit(intel8x0_t
*chip
, unsigned int codec
)
551 static unsigned int codec_bit
[3] = {
552 ICH_PCR
, ICH_SCR
, ICH_TCR
554 snd_assert(codec
< 3, return ICH_PCR
);
555 if (chip
->device_type
== DEVICE_INTEL_ICH4
)
556 codec
= chip
->ac97_sdin
[codec
];
557 return codec_bit
[codec
];
560 static int snd_intel8x0_codec_semaphore(intel8x0_t
*chip
, unsigned int codec
)
566 if (chip
->in_sdin_init
) {
567 /* we don't know the ready bit assignment at the moment */
568 /* so we check any */
569 codec
= ICH_PCR
| ICH_SCR
| ICH_TCR
;
571 codec
= get_ich_codec_bit(chip
, codec
);
575 if ((igetdword(chip
, ICHREG(GLOB_STA
)) & codec
) == 0)
578 /* Anyone holding a semaphore for 1 msec should be shot... */
581 if (!(igetbyte(chip
, ICHREG(ACC_SEMA
)) & ICH_CAS
))
586 /* access to some forbidden (non existant) ac97 registers will not
587 * reset the semaphore. So even if you don't get the semaphore, still
588 * continue the access. We don't need the semaphore anyway. */
589 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
590 igetbyte(chip
, ICHREG(ACC_SEMA
)), igetdword(chip
, ICHREG(GLOB_STA
)));
591 iagetword(chip
, 0); /* clear semaphore flag */
592 /* I don't care about the semaphore */
596 static void snd_intel8x0_codec_write(ac97_t
*ac97
,
600 intel8x0_t
*chip
= ac97
->private_data
;
602 if (snd_intel8x0_codec_semaphore(chip
, ac97
->num
) < 0) {
603 if (! chip
->in_ac97_init
)
604 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97
->num
, reg
);
606 iaputword(chip
, reg
+ ac97
->num
* 0x80, val
);
609 static unsigned short snd_intel8x0_codec_read(ac97_t
*ac97
,
612 intel8x0_t
*chip
= ac97
->private_data
;
616 if (snd_intel8x0_codec_semaphore(chip
, ac97
->num
) < 0) {
617 if (! chip
->in_ac97_init
)
618 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97
->num
, reg
);
621 res
= iagetword(chip
, reg
+ ac97
->num
* 0x80);
622 if ((tmp
= igetdword(chip
, ICHREG(GLOB_STA
))) & ICH_RCS
) {
623 /* reset RCS and preserve other R/WC bits */
624 iputdword(chip
, ICHREG(GLOB_STA
), tmp
& ~(ICH_SRI
|ICH_PRI
|ICH_TRI
|ICH_GSCI
));
625 if (! chip
->in_ac97_init
)
626 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97
->num
, reg
);
633 static void snd_intel8x0_codec_read_test(intel8x0_t
*chip
, unsigned int codec
)
637 if (snd_intel8x0_codec_semaphore(chip
, codec
) >= 0) {
638 iagetword(chip
, codec
* 0x80);
639 if ((tmp
= igetdword(chip
, ICHREG(GLOB_STA
))) & ICH_RCS
) {
640 /* reset RCS and preserve other R/WC bits */
641 iputdword(chip
, ICHREG(GLOB_STA
), tmp
& ~(ICH_SRI
|ICH_PRI
|ICH_TRI
|ICH_GSCI
));
647 * access to AC97 for Ali5455
649 static int snd_intel8x0_ali_codec_ready(intel8x0_t
*chip
, int mask
)
652 for (count
= 0; count
< 0x7f; count
++) {
653 int val
= igetbyte(chip
, ICHREG(ALI_CSPSR
));
657 snd_printd(KERN_WARNING
"intel8x0: AC97 codec ready timeout.\n");
661 static int snd_intel8x0_ali_codec_semaphore(intel8x0_t
*chip
)
664 while (time
-- && (igetdword(chip
, ICHREG(ALI_CAS
)) & ALI_CAS_SEM_BUSY
))
667 snd_printk(KERN_WARNING
"ali_codec_semaphore timeout\n");
668 return snd_intel8x0_ali_codec_ready(chip
, ALI_CSPSR_CODEC_READY
);
671 static unsigned short snd_intel8x0_ali_codec_read(ac97_t
*ac97
, unsigned short reg
)
673 intel8x0_t
*chip
= ac97
->private_data
;
674 unsigned short data
= 0xffff;
676 if (snd_intel8x0_ali_codec_semaphore(chip
))
678 reg
|= ALI_CPR_ADDR_READ
;
680 reg
|= ALI_CPR_ADDR_SECONDARY
;
681 iputword(chip
, ICHREG(ALI_CPR_ADDR
), reg
);
682 if (snd_intel8x0_ali_codec_ready(chip
, ALI_CSPSR_READ_OK
))
684 data
= igetword(chip
, ICHREG(ALI_SPR
));
689 static void snd_intel8x0_ali_codec_write(ac97_t
*ac97
, unsigned short reg
, unsigned short val
)
691 intel8x0_t
*chip
= ac97
->private_data
;
693 if (snd_intel8x0_ali_codec_semaphore(chip
))
695 iputword(chip
, ICHREG(ALI_CPR
), val
);
697 reg
|= ALI_CPR_ADDR_SECONDARY
;
698 iputword(chip
, ICHREG(ALI_CPR_ADDR
), reg
);
699 snd_intel8x0_ali_codec_ready(chip
, ALI_CSPSR_WRITE_OK
);
706 static void snd_intel8x0_setup_periods(intel8x0_t
*chip
, ichdev_t
*ichdev
)
709 u32
*bdbar
= ichdev
->bdbar
;
710 unsigned long port
= ichdev
->reg_offset
;
712 iputdword(chip
, port
+ ICH_REG_OFF_BDBAR
, ichdev
->bdbar_addr
);
713 if (ichdev
->size
== ichdev
->fragsize
) {
714 ichdev
->ack_reload
= ichdev
->ack
= 2;
715 ichdev
->fragsize1
= ichdev
->fragsize
>> 1;
716 for (idx
= 0; idx
< (ICH_REG_LVI_MASK
+ 1) * 2; idx
+= 4) {
717 bdbar
[idx
+ 0] = cpu_to_le32(ichdev
->physbuf
);
718 bdbar
[idx
+ 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
719 ichdev
->fragsize1
>> ichdev
->pos_shift
);
720 bdbar
[idx
+ 2] = cpu_to_le32(ichdev
->physbuf
+ (ichdev
->size
>> 1));
721 bdbar
[idx
+ 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
722 ichdev
->fragsize1
>> ichdev
->pos_shift
);
726 ichdev
->ack_reload
= ichdev
->ack
= 1;
727 ichdev
->fragsize1
= ichdev
->fragsize
;
728 for (idx
= 0; idx
< (ICH_REG_LVI_MASK
+ 1) * 2; idx
+= 2) {
729 bdbar
[idx
+ 0] = cpu_to_le32(ichdev
->physbuf
+ (((idx
>> 1) * ichdev
->fragsize
) % ichdev
->size
));
730 bdbar
[idx
+ 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
731 ichdev
->fragsize
>> ichdev
->pos_shift
);
732 // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
734 ichdev
->frags
= ichdev
->size
/ ichdev
->fragsize
;
736 iputbyte(chip
, port
+ ICH_REG_OFF_LVI
, ichdev
->lvi
= ICH_REG_LVI_MASK
);
738 iputbyte(chip
, port
+ ICH_REG_OFF_CIV
, 0);
739 ichdev
->lvi_frag
= ICH_REG_LVI_MASK
% ichdev
->frags
;
740 ichdev
->position
= 0;
742 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
743 ichdev
->lvi_frag
, ichdev
->frags
, ichdev
->fragsize
, ichdev
->fragsize1
);
745 /* clear interrupts */
746 iputbyte(chip
, port
+ ichdev
->roff_sr
, ICH_FIFOE
| ICH_BCIS
| ICH_LVBCI
);
751 * Intel 82443MX running a 100MHz processor system bus has a hardware bug,
752 * which aborts PCI busmaster for audio transfer. A workaround is to set
753 * the pages as non-cached. For details, see the errata in
754 * http://www.intel.com/design/chipsets/specupdt/245051.htm
756 static void fill_nocache(void *buf
, int size
, int nocache
)
758 size
= (size
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
759 change_page_attr(virt_to_page(buf
), size
, nocache
? PAGE_KERNEL_NOCACHE
: PAGE_KERNEL
);
763 #define fill_nocache(buf,size,nocache)
770 static inline void snd_intel8x0_update(intel8x0_t
*chip
, ichdev_t
*ichdev
)
772 unsigned long port
= ichdev
->reg_offset
;
773 int status
, civ
, i
, step
;
776 spin_lock(&chip
->reg_lock
);
777 status
= igetbyte(chip
, port
+ ichdev
->roff_sr
);
778 civ
= igetbyte(chip
, port
+ ICH_REG_OFF_CIV
);
779 if (!(status
& ICH_BCIS
)) {
781 } else if (civ
== ichdev
->civ
) {
782 // snd_printd("civ same %d\n", civ);
785 ichdev
->civ
&= ICH_REG_LVI_MASK
;
787 step
= civ
- ichdev
->civ
;
789 step
+= ICH_REG_LVI_MASK
+ 1;
791 // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
795 ichdev
->position
+= step
* ichdev
->fragsize1
;
796 if (! chip
->in_measurement
)
797 ichdev
->position
%= ichdev
->size
;
799 ichdev
->lvi
&= ICH_REG_LVI_MASK
;
800 iputbyte(chip
, port
+ ICH_REG_OFF_LVI
, ichdev
->lvi
);
801 for (i
= 0; i
< step
; i
++) {
803 ichdev
->lvi_frag
%= ichdev
->frags
;
804 ichdev
->bdbar
[ichdev
->lvi
* 2] = cpu_to_le32(ichdev
->physbuf
+ ichdev
->lvi_frag
* ichdev
->fragsize1
);
805 // 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));
806 if (--ichdev
->ack
== 0) {
807 ichdev
->ack
= ichdev
->ack_reload
;
811 spin_unlock(&chip
->reg_lock
);
812 if (ack
&& ichdev
->substream
) {
813 snd_pcm_period_elapsed(ichdev
->substream
);
815 iputbyte(chip
, port
+ ichdev
->roff_sr
,
816 status
& (ICH_FIFOE
| ICH_BCIS
| ICH_LVBCI
));
819 static irqreturn_t
snd_intel8x0_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
821 intel8x0_t
*chip
= dev_id
;
826 status
= igetdword(chip
, chip
->int_sta_reg
);
827 if (status
== 0xffffffff) /* we are not yet resumed */
830 if ((status
& chip
->int_sta_mask
) == 0) {
833 iputdword(chip
, chip
->int_sta_reg
, status
);
834 if (! chip
->buggy_irq
)
837 return IRQ_RETVAL(status
);
840 for (i
= 0; i
< chip
->bdbars_count
; i
++) {
841 ichdev
= &chip
->ichd
[i
];
842 if (status
& ichdev
->int_sta_mask
)
843 snd_intel8x0_update(chip
, ichdev
);
847 iputdword(chip
, chip
->int_sta_reg
, status
& chip
->int_sta_mask
);
856 static int snd_intel8x0_pcm_trigger(snd_pcm_substream_t
*substream
, int cmd
)
858 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
859 ichdev_t
*ichdev
= get_ichdev(substream
);
860 unsigned char val
= 0;
861 unsigned long port
= ichdev
->reg_offset
;
864 case SNDRV_PCM_TRIGGER_START
:
865 case SNDRV_PCM_TRIGGER_RESUME
:
866 val
= ICH_IOCE
| ICH_STARTBM
;
868 case SNDRV_PCM_TRIGGER_STOP
:
869 case SNDRV_PCM_TRIGGER_SUSPEND
:
872 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
875 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
876 val
= ICH_IOCE
| ICH_STARTBM
;
881 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, val
);
882 if (cmd
== SNDRV_PCM_TRIGGER_STOP
) {
883 /* wait until DMA stopped */
884 while (!(igetbyte(chip
, port
+ ichdev
->roff_sr
) & ICH_DCH
)) ;
885 /* reset whole DMA things */
886 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_RESETREGS
);
891 static int snd_intel8x0_ali_trigger(snd_pcm_substream_t
*substream
, int cmd
)
893 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
894 ichdev_t
*ichdev
= get_ichdev(substream
);
895 unsigned long port
= ichdev
->reg_offset
;
896 static int fiforeg
[] = { ICHREG(ALI_FIFOCR1
), ICHREG(ALI_FIFOCR2
), ICHREG(ALI_FIFOCR3
) };
897 unsigned int val
, fifo
;
899 val
= igetdword(chip
, ICHREG(ALI_DMACR
));
901 case SNDRV_PCM_TRIGGER_START
:
902 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
903 case SNDRV_PCM_TRIGGER_RESUME
:
904 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
905 /* clear FIFO for synchronization of channels */
906 fifo
= igetdword(chip
, fiforeg
[ichdev
->ali_slot
/ 4]);
907 fifo
&= ~(0xff << (ichdev
->ali_slot
% 4));
908 fifo
|= 0x83 << (ichdev
->ali_slot
% 4);
909 iputdword(chip
, fiforeg
[ichdev
->ali_slot
/ 4], fifo
);
911 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_IOCE
);
912 val
&= ~(1 << (ichdev
->ali_slot
+ 16)); /* clear PAUSE flag */
913 iputdword(chip
, ICHREG(ALI_DMACR
), val
| (1 << ichdev
->ali_slot
)); /* start DMA */
915 case SNDRV_PCM_TRIGGER_STOP
:
916 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
917 case SNDRV_PCM_TRIGGER_SUSPEND
:
918 iputdword(chip
, ICHREG(ALI_DMACR
), val
| (1 << (ichdev
->ali_slot
+ 16))); /* pause */
919 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, 0);
920 while (igetbyte(chip
, port
+ ICH_REG_OFF_CR
))
922 if (cmd
== SNDRV_PCM_TRIGGER_PAUSE_PUSH
)
924 /* reset whole DMA things */
925 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_RESETREGS
);
926 /* clear interrupts */
927 iputbyte(chip
, port
+ ICH_REG_OFF_SR
, igetbyte(chip
, port
+ ICH_REG_OFF_SR
) | 0x1e);
928 iputdword(chip
, ICHREG(ALI_INTERRUPTSR
),
929 igetdword(chip
, ICHREG(ALI_INTERRUPTSR
)) & ichdev
->int_sta_mask
);
937 static int snd_intel8x0_hw_params(snd_pcm_substream_t
* substream
,
938 snd_pcm_hw_params_t
* hw_params
)
940 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
941 ichdev_t
*ichdev
= get_ichdev(substream
);
942 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
943 int dbl
= params_rate(hw_params
) > 48000;
946 if (chip
->fix_nocache
&& ichdev
->page_attr_changed
) {
947 fill_nocache(runtime
->dma_area
, runtime
->dma_bytes
, 0); /* clear */
948 ichdev
->page_attr_changed
= 0;
950 err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
953 if (chip
->fix_nocache
) {
954 if (runtime
->dma_area
&& ! ichdev
->page_attr_changed
) {
955 fill_nocache(runtime
->dma_area
, runtime
->dma_bytes
, 1);
956 ichdev
->page_attr_changed
= 1;
959 if (ichdev
->pcm_open_flag
) {
960 snd_ac97_pcm_close(ichdev
->pcm
);
961 ichdev
->pcm_open_flag
= 0;
963 err
= snd_ac97_pcm_open(ichdev
->pcm
, params_rate(hw_params
),
964 params_channels(hw_params
),
965 ichdev
->pcm
->r
[dbl
].slots
);
967 ichdev
->pcm_open_flag
= 1;
968 /* Force SPDIF setting */
969 if (ichdev
->ichd
== ICHD_PCMOUT
&& chip
->spdif_idx
< 0)
970 snd_ac97_set_rate(ichdev
->pcm
->r
[0].codec
[0], AC97_SPDIF
, params_rate(hw_params
));
975 static int snd_intel8x0_hw_free(snd_pcm_substream_t
* substream
)
977 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
978 ichdev_t
*ichdev
= get_ichdev(substream
);
980 if (ichdev
->pcm_open_flag
) {
981 snd_ac97_pcm_close(ichdev
->pcm
);
982 ichdev
->pcm_open_flag
= 0;
984 if (chip
->fix_nocache
&& ichdev
->page_attr_changed
) {
985 fill_nocache(substream
->runtime
->dma_area
, substream
->runtime
->dma_bytes
, 0);
986 ichdev
->page_attr_changed
= 0;
988 return snd_pcm_lib_free_pages(substream
);
991 static void snd_intel8x0_setup_pcm_out(intel8x0_t
*chip
,
992 snd_pcm_runtime_t
*runtime
)
995 int dbl
= runtime
->rate
> 48000;
996 switch (chip
->device_type
) {
998 cnt
= igetdword(chip
, ICHREG(ALI_SCR
));
999 cnt
&= ~ICH_ALI_SC_PCM_246_MASK
;
1000 if (runtime
->channels
== 4 || dbl
)
1001 cnt
|= ICH_ALI_SC_PCM_4
;
1002 else if (runtime
->channels
== 6)
1003 cnt
|= ICH_ALI_SC_PCM_6
;
1004 iputdword(chip
, ICHREG(ALI_SCR
), cnt
);
1007 cnt
= igetdword(chip
, ICHREG(GLOB_CNT
));
1008 cnt
&= ~ICH_SIS_PCM_246_MASK
;
1009 if (runtime
->channels
== 4 || dbl
)
1010 cnt
|= ICH_SIS_PCM_4
;
1011 else if (runtime
->channels
== 6)
1012 cnt
|= ICH_SIS_PCM_6
;
1013 iputdword(chip
, ICHREG(GLOB_CNT
), cnt
);
1016 cnt
= igetdword(chip
, ICHREG(GLOB_CNT
));
1017 cnt
&= ~(ICH_PCM_246_MASK
| ICH_PCM_20BIT
);
1018 if (runtime
->channels
== 4 || dbl
)
1020 else if (runtime
->channels
== 6)
1022 if (chip
->device_type
== DEVICE_NFORCE
) {
1023 /* reset to 2ch once to keep the 6 channel data in alignment,
1024 * to start from Front Left always
1026 if (cnt
& ICH_PCM_246_MASK
) {
1027 iputdword(chip
, ICHREG(GLOB_CNT
), cnt
& ~ICH_PCM_246_MASK
);
1028 spin_unlock_irq(&chip
->reg_lock
);
1029 msleep(50); /* grrr... */
1030 spin_lock_irq(&chip
->reg_lock
);
1032 } else if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
1033 if (runtime
->sample_bits
> 16)
1034 cnt
|= ICH_PCM_20BIT
;
1036 iputdword(chip
, ICHREG(GLOB_CNT
), cnt
);
1041 static int snd_intel8x0_pcm_prepare(snd_pcm_substream_t
* substream
)
1043 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1044 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1045 ichdev_t
*ichdev
= get_ichdev(substream
);
1047 ichdev
->physbuf
= runtime
->dma_addr
;
1048 ichdev
->size
= snd_pcm_lib_buffer_bytes(substream
);
1049 ichdev
->fragsize
= snd_pcm_lib_period_bytes(substream
);
1050 spin_lock_irq(&chip
->reg_lock
);
1051 if (ichdev
->ichd
== ICHD_PCMOUT
) {
1052 snd_intel8x0_setup_pcm_out(chip
, runtime
);
1053 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
1054 ichdev
->pos_shift
= (runtime
->sample_bits
> 16) ? 2 : 1;
1057 snd_intel8x0_setup_periods(chip
, ichdev
);
1058 spin_unlock_irq(&chip
->reg_lock
);
1062 static snd_pcm_uframes_t
snd_intel8x0_pcm_pointer(snd_pcm_substream_t
* substream
)
1064 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1065 ichdev_t
*ichdev
= get_ichdev(substream
);
1067 int civ
, timeout
= 100;
1068 unsigned int position
;
1070 spin_lock(&chip
->reg_lock
);
1072 civ
= igetbyte(chip
, ichdev
->reg_offset
+ ICH_REG_OFF_CIV
);
1073 ptr1
= igetword(chip
, ichdev
->reg_offset
+ ichdev
->roff_picb
);
1074 position
= ichdev
->position
;
1079 if (civ
== igetbyte(chip
, ichdev
->reg_offset
+ ICH_REG_OFF_CIV
) &&
1080 ptr1
== igetword(chip
, ichdev
->reg_offset
+ ichdev
->roff_picb
))
1082 } while (timeout
--);
1083 ptr1
<<= ichdev
->pos_shift
;
1084 ptr
= ichdev
->fragsize1
- ptr1
;
1086 spin_unlock(&chip
->reg_lock
);
1087 if (ptr
>= ichdev
->size
)
1089 return bytes_to_frames(substream
->runtime
, ptr
);
1092 static snd_pcm_hardware_t snd_intel8x0_stream
=
1094 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1095 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1096 SNDRV_PCM_INFO_MMAP_VALID
|
1097 SNDRV_PCM_INFO_PAUSE
|
1098 SNDRV_PCM_INFO_RESUME
),
1099 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1100 .rates
= SNDRV_PCM_RATE_48000
,
1105 .buffer_bytes_max
= 128 * 1024,
1106 .period_bytes_min
= 32,
1107 .period_bytes_max
= 128 * 1024,
1109 .periods_max
= 1024,
1113 static unsigned int channels4
[] = {
1117 static snd_pcm_hw_constraint_list_t hw_constraints_channels4
= {
1118 .count
= ARRAY_SIZE(channels4
),
1123 static unsigned int channels6
[] = {
1127 static snd_pcm_hw_constraint_list_t hw_constraints_channels6
= {
1128 .count
= ARRAY_SIZE(channels6
),
1133 static int snd_intel8x0_pcm_open(snd_pcm_substream_t
* substream
, ichdev_t
*ichdev
)
1135 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1136 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1139 ichdev
->substream
= substream
;
1140 runtime
->hw
= snd_intel8x0_stream
;
1141 runtime
->hw
.rates
= ichdev
->pcm
->rates
;
1142 snd_pcm_limit_hw_rates(runtime
);
1143 if (chip
->device_type
== DEVICE_SIS
) {
1144 runtime
->hw
.buffer_bytes_max
= 64*1024;
1145 runtime
->hw
.period_bytes_max
= 64*1024;
1147 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
1149 runtime
->private_data
= ichdev
;
1153 static int snd_intel8x0_playback_open(snd_pcm_substream_t
* substream
)
1155 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1156 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
1159 err
= snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ICHD_PCMOUT
]);
1164 runtime
->hw
.channels_max
= 6;
1165 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
, &hw_constraints_channels6
);
1166 } else if (chip
->multi4
) {
1167 runtime
->hw
.channels_max
= 4;
1168 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
, &hw_constraints_channels4
);
1171 snd_ac97_pcm_double_rate_rules(runtime
);
1173 if (chip
->smp20bit
) {
1174 runtime
->hw
.formats
|= SNDRV_PCM_FMTBIT_S32_LE
;
1175 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 20);
1180 static int snd_intel8x0_playback_close(snd_pcm_substream_t
* substream
)
1182 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1184 chip
->ichd
[ICHD_PCMOUT
].substream
= NULL
;
1188 static int snd_intel8x0_capture_open(snd_pcm_substream_t
* substream
)
1190 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1192 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ICHD_PCMIN
]);
1195 static int snd_intel8x0_capture_close(snd_pcm_substream_t
* substream
)
1197 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1199 chip
->ichd
[ICHD_PCMIN
].substream
= NULL
;
1203 static int snd_intel8x0_mic_open(snd_pcm_substream_t
* substream
)
1205 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1207 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ICHD_MIC
]);
1210 static int snd_intel8x0_mic_close(snd_pcm_substream_t
* substream
)
1212 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1214 chip
->ichd
[ICHD_MIC
].substream
= NULL
;
1218 static int snd_intel8x0_mic2_open(snd_pcm_substream_t
* substream
)
1220 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1222 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ICHD_MIC2
]);
1225 static int snd_intel8x0_mic2_close(snd_pcm_substream_t
* substream
)
1227 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1229 chip
->ichd
[ICHD_MIC2
].substream
= NULL
;
1233 static int snd_intel8x0_capture2_open(snd_pcm_substream_t
* substream
)
1235 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1237 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ICHD_PCM2IN
]);
1240 static int snd_intel8x0_capture2_close(snd_pcm_substream_t
* substream
)
1242 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1244 chip
->ichd
[ICHD_PCM2IN
].substream
= NULL
;
1248 static int snd_intel8x0_spdif_open(snd_pcm_substream_t
* substream
)
1250 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1251 int idx
= chip
->device_type
== DEVICE_NFORCE
? NVD_SPBAR
: ICHD_SPBAR
;
1253 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[idx
]);
1256 static int snd_intel8x0_spdif_close(snd_pcm_substream_t
* substream
)
1258 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1259 int idx
= chip
->device_type
== DEVICE_NFORCE
? NVD_SPBAR
: ICHD_SPBAR
;
1261 chip
->ichd
[idx
].substream
= NULL
;
1265 static int snd_intel8x0_ali_ac97spdifout_open(snd_pcm_substream_t
* substream
)
1267 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1270 spin_lock_irq(&chip
->reg_lock
);
1271 val
= igetdword(chip
, ICHREG(ALI_INTERFACECR
));
1272 val
|= ICH_ALI_IF_AC97SP
;
1273 iputdword(chip
, ICHREG(ALI_INTERFACECR
), val
);
1274 /* also needs to set ALI_SC_CODEC_SPDF correctly */
1275 spin_unlock_irq(&chip
->reg_lock
);
1277 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ALID_AC97SPDIFOUT
]);
1280 static int snd_intel8x0_ali_ac97spdifout_close(snd_pcm_substream_t
* substream
)
1282 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1285 chip
->ichd
[ALID_AC97SPDIFOUT
].substream
= NULL
;
1286 spin_lock_irq(&chip
->reg_lock
);
1287 val
= igetdword(chip
, ICHREG(ALI_INTERFACECR
));
1288 val
&= ~ICH_ALI_IF_AC97SP
;
1289 iputdword(chip
, ICHREG(ALI_INTERFACECR
), val
);
1290 spin_unlock_irq(&chip
->reg_lock
);
1295 static int snd_intel8x0_ali_spdifin_open(snd_pcm_substream_t
* substream
)
1297 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1299 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ALID_SPDIFIN
]);
1302 static int snd_intel8x0_ali_spdifin_close(snd_pcm_substream_t
* substream
)
1304 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1306 chip
->ichd
[ALID_SPDIFIN
].substream
= NULL
;
1311 static int snd_intel8x0_ali_spdifout_open(snd_pcm_substream_t
* substream
)
1313 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1315 return snd_intel8x0_pcm_open(substream
, &chip
->ichd
[ALID_SPDIFOUT
]);
1318 static int snd_intel8x0_ali_spdifout_close(snd_pcm_substream_t
* substream
)
1320 intel8x0_t
*chip
= snd_pcm_substream_chip(substream
);
1322 chip
->ichd
[ALID_SPDIFOUT
].substream
= NULL
;
1327 static snd_pcm_ops_t snd_intel8x0_playback_ops
= {
1328 .open
= snd_intel8x0_playback_open
,
1329 .close
= snd_intel8x0_playback_close
,
1330 .ioctl
= snd_pcm_lib_ioctl
,
1331 .hw_params
= snd_intel8x0_hw_params
,
1332 .hw_free
= snd_intel8x0_hw_free
,
1333 .prepare
= snd_intel8x0_pcm_prepare
,
1334 .trigger
= snd_intel8x0_pcm_trigger
,
1335 .pointer
= snd_intel8x0_pcm_pointer
,
1338 static snd_pcm_ops_t snd_intel8x0_capture_ops
= {
1339 .open
= snd_intel8x0_capture_open
,
1340 .close
= snd_intel8x0_capture_close
,
1341 .ioctl
= snd_pcm_lib_ioctl
,
1342 .hw_params
= snd_intel8x0_hw_params
,
1343 .hw_free
= snd_intel8x0_hw_free
,
1344 .prepare
= snd_intel8x0_pcm_prepare
,
1345 .trigger
= snd_intel8x0_pcm_trigger
,
1346 .pointer
= snd_intel8x0_pcm_pointer
,
1349 static snd_pcm_ops_t snd_intel8x0_capture_mic_ops
= {
1350 .open
= snd_intel8x0_mic_open
,
1351 .close
= snd_intel8x0_mic_close
,
1352 .ioctl
= snd_pcm_lib_ioctl
,
1353 .hw_params
= snd_intel8x0_hw_params
,
1354 .hw_free
= snd_intel8x0_hw_free
,
1355 .prepare
= snd_intel8x0_pcm_prepare
,
1356 .trigger
= snd_intel8x0_pcm_trigger
,
1357 .pointer
= snd_intel8x0_pcm_pointer
,
1360 static snd_pcm_ops_t snd_intel8x0_capture_mic2_ops
= {
1361 .open
= snd_intel8x0_mic2_open
,
1362 .close
= snd_intel8x0_mic2_close
,
1363 .ioctl
= snd_pcm_lib_ioctl
,
1364 .hw_params
= snd_intel8x0_hw_params
,
1365 .hw_free
= snd_intel8x0_hw_free
,
1366 .prepare
= snd_intel8x0_pcm_prepare
,
1367 .trigger
= snd_intel8x0_pcm_trigger
,
1368 .pointer
= snd_intel8x0_pcm_pointer
,
1371 static snd_pcm_ops_t snd_intel8x0_capture2_ops
= {
1372 .open
= snd_intel8x0_capture2_open
,
1373 .close
= snd_intel8x0_capture2_close
,
1374 .ioctl
= snd_pcm_lib_ioctl
,
1375 .hw_params
= snd_intel8x0_hw_params
,
1376 .hw_free
= snd_intel8x0_hw_free
,
1377 .prepare
= snd_intel8x0_pcm_prepare
,
1378 .trigger
= snd_intel8x0_pcm_trigger
,
1379 .pointer
= snd_intel8x0_pcm_pointer
,
1382 static snd_pcm_ops_t snd_intel8x0_spdif_ops
= {
1383 .open
= snd_intel8x0_spdif_open
,
1384 .close
= snd_intel8x0_spdif_close
,
1385 .ioctl
= snd_pcm_lib_ioctl
,
1386 .hw_params
= snd_intel8x0_hw_params
,
1387 .hw_free
= snd_intel8x0_hw_free
,
1388 .prepare
= snd_intel8x0_pcm_prepare
,
1389 .trigger
= snd_intel8x0_pcm_trigger
,
1390 .pointer
= snd_intel8x0_pcm_pointer
,
1393 static snd_pcm_ops_t snd_intel8x0_ali_playback_ops
= {
1394 .open
= snd_intel8x0_playback_open
,
1395 .close
= snd_intel8x0_playback_close
,
1396 .ioctl
= snd_pcm_lib_ioctl
,
1397 .hw_params
= snd_intel8x0_hw_params
,
1398 .hw_free
= snd_intel8x0_hw_free
,
1399 .prepare
= snd_intel8x0_pcm_prepare
,
1400 .trigger
= snd_intel8x0_ali_trigger
,
1401 .pointer
= snd_intel8x0_pcm_pointer
,
1404 static snd_pcm_ops_t snd_intel8x0_ali_capture_ops
= {
1405 .open
= snd_intel8x0_capture_open
,
1406 .close
= snd_intel8x0_capture_close
,
1407 .ioctl
= snd_pcm_lib_ioctl
,
1408 .hw_params
= snd_intel8x0_hw_params
,
1409 .hw_free
= snd_intel8x0_hw_free
,
1410 .prepare
= snd_intel8x0_pcm_prepare
,
1411 .trigger
= snd_intel8x0_ali_trigger
,
1412 .pointer
= snd_intel8x0_pcm_pointer
,
1415 static snd_pcm_ops_t snd_intel8x0_ali_capture_mic_ops
= {
1416 .open
= snd_intel8x0_mic_open
,
1417 .close
= snd_intel8x0_mic_close
,
1418 .ioctl
= snd_pcm_lib_ioctl
,
1419 .hw_params
= snd_intel8x0_hw_params
,
1420 .hw_free
= snd_intel8x0_hw_free
,
1421 .prepare
= snd_intel8x0_pcm_prepare
,
1422 .trigger
= snd_intel8x0_ali_trigger
,
1423 .pointer
= snd_intel8x0_pcm_pointer
,
1426 static snd_pcm_ops_t snd_intel8x0_ali_ac97spdifout_ops
= {
1427 .open
= snd_intel8x0_ali_ac97spdifout_open
,
1428 .close
= snd_intel8x0_ali_ac97spdifout_close
,
1429 .ioctl
= snd_pcm_lib_ioctl
,
1430 .hw_params
= snd_intel8x0_hw_params
,
1431 .hw_free
= snd_intel8x0_hw_free
,
1432 .prepare
= snd_intel8x0_pcm_prepare
,
1433 .trigger
= snd_intel8x0_ali_trigger
,
1434 .pointer
= snd_intel8x0_pcm_pointer
,
1437 static snd_pcm_ops_t snd_intel8x0_ali_spdifin_ops
= {
1438 .open
= snd_intel8x0_ali_spdifin_open
,
1439 .close
= snd_intel8x0_ali_spdifin_close
,
1440 .ioctl
= snd_pcm_lib_ioctl
,
1441 .hw_params
= snd_intel8x0_hw_params
,
1442 .hw_free
= snd_intel8x0_hw_free
,
1443 .prepare
= snd_intel8x0_pcm_prepare
,
1444 .trigger
= snd_intel8x0_pcm_trigger
,
1445 .pointer
= snd_intel8x0_pcm_pointer
,
1449 static snd_pcm_ops_t snd_intel8x0_ali_spdifout_ops
= {
1450 .open
= snd_intel8x0_ali_spdifout_open
,
1451 .close
= snd_intel8x0_ali_spdifout_close
,
1452 .ioctl
= snd_pcm_lib_ioctl
,
1453 .hw_params
= snd_intel8x0_hw_params
,
1454 .hw_free
= snd_intel8x0_hw_free
,
1455 .prepare
= snd_intel8x0_pcm_prepare
,
1456 .trigger
= snd_intel8x0_pcm_trigger
,
1457 .pointer
= snd_intel8x0_pcm_pointer
,
1461 struct ich_pcm_table
{
1463 snd_pcm_ops_t
*playback_ops
;
1464 snd_pcm_ops_t
*capture_ops
;
1465 size_t prealloc_size
;
1466 size_t prealloc_max_size
;
1470 static int __devinit
snd_intel8x0_pcm1(intel8x0_t
*chip
, int device
, struct ich_pcm_table
*rec
)
1477 sprintf(name
, "Intel ICH - %s", rec
->suffix
);
1479 strcpy(name
, "Intel ICH");
1480 err
= snd_pcm_new(chip
->card
, name
, device
,
1481 rec
->playback_ops
? 1 : 0,
1482 rec
->capture_ops
? 1 : 0, &pcm
);
1486 if (rec
->playback_ops
)
1487 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, rec
->playback_ops
);
1488 if (rec
->capture_ops
)
1489 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, rec
->capture_ops
);
1491 pcm
->private_data
= chip
;
1492 pcm
->info_flags
= 0;
1494 sprintf(pcm
->name
, "%s - %s", chip
->card
->shortname
, rec
->suffix
);
1496 strcpy(pcm
->name
, chip
->card
->shortname
);
1497 chip
->pcm
[device
] = pcm
;
1499 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(chip
->pci
),
1500 rec
->prealloc_size
, rec
->prealloc_max_size
);
1505 static struct ich_pcm_table intel_pcms
[] __devinitdata
= {
1507 .playback_ops
= &snd_intel8x0_playback_ops
,
1508 .capture_ops
= &snd_intel8x0_capture_ops
,
1509 .prealloc_size
= 64 * 1024,
1510 .prealloc_max_size
= 128 * 1024,
1513 .suffix
= "MIC ADC",
1514 .capture_ops
= &snd_intel8x0_capture_mic_ops
,
1516 .prealloc_max_size
= 128 * 1024,
1517 .ac97_idx
= ICHD_MIC
,
1520 .suffix
= "MIC2 ADC",
1521 .capture_ops
= &snd_intel8x0_capture_mic2_ops
,
1523 .prealloc_max_size
= 128 * 1024,
1524 .ac97_idx
= ICHD_MIC2
,
1528 .capture_ops
= &snd_intel8x0_capture2_ops
,
1530 .prealloc_max_size
= 128 * 1024,
1531 .ac97_idx
= ICHD_PCM2IN
,
1535 .playback_ops
= &snd_intel8x0_spdif_ops
,
1536 .prealloc_size
= 64 * 1024,
1537 .prealloc_max_size
= 128 * 1024,
1538 .ac97_idx
= ICHD_SPBAR
,
1542 static struct ich_pcm_table nforce_pcms
[] __devinitdata
= {
1544 .playback_ops
= &snd_intel8x0_playback_ops
,
1545 .capture_ops
= &snd_intel8x0_capture_ops
,
1546 .prealloc_size
= 64 * 1024,
1547 .prealloc_max_size
= 128 * 1024,
1550 .suffix
= "MIC ADC",
1551 .capture_ops
= &snd_intel8x0_capture_mic_ops
,
1553 .prealloc_max_size
= 128 * 1024,
1554 .ac97_idx
= NVD_MIC
,
1558 .playback_ops
= &snd_intel8x0_spdif_ops
,
1559 .prealloc_size
= 64 * 1024,
1560 .prealloc_max_size
= 128 * 1024,
1561 .ac97_idx
= NVD_SPBAR
,
1565 static struct ich_pcm_table ali_pcms
[] __devinitdata
= {
1567 .playback_ops
= &snd_intel8x0_ali_playback_ops
,
1568 .capture_ops
= &snd_intel8x0_ali_capture_ops
,
1569 .prealloc_size
= 64 * 1024,
1570 .prealloc_max_size
= 128 * 1024,
1573 .suffix
= "MIC ADC",
1574 .capture_ops
= &snd_intel8x0_ali_capture_mic_ops
,
1576 .prealloc_max_size
= 128 * 1024,
1577 .ac97_idx
= ALID_MIC
,
1581 .playback_ops
= &snd_intel8x0_ali_ac97spdifout_ops
,
1582 .capture_ops
= &snd_intel8x0_ali_spdifin_ops
,
1583 .prealloc_size
= 64 * 1024,
1584 .prealloc_max_size
= 128 * 1024,
1585 .ac97_idx
= ALID_AC97SPDIFOUT
,
1589 .suffix
= "HW IEC958",
1590 .playback_ops
= &snd_intel8x0_ali_spdifout_ops
,
1591 .prealloc_size
= 64 * 1024,
1592 .prealloc_max_size
= 128 * 1024,
1597 static int __devinit
snd_intel8x0_pcm(intel8x0_t
*chip
)
1599 int i
, tblsize
, device
, err
;
1600 struct ich_pcm_table
*tbl
, *rec
;
1602 switch (chip
->device_type
) {
1603 case DEVICE_INTEL_ICH4
:
1605 tblsize
= ARRAY_SIZE(intel_pcms
);
1609 tblsize
= ARRAY_SIZE(nforce_pcms
);
1613 tblsize
= ARRAY_SIZE(ali_pcms
);
1622 for (i
= 0; i
< tblsize
; i
++) {
1624 if (i
> 0 && rec
->ac97_idx
) {
1625 /* activate PCM only when associated AC'97 codec */
1626 if (! chip
->ichd
[rec
->ac97_idx
].pcm
)
1629 err
= snd_intel8x0_pcm1(chip
, device
, rec
);
1635 chip
->pcm_devs
= device
;
1644 static void snd_intel8x0_mixer_free_ac97_bus(ac97_bus_t
*bus
)
1646 intel8x0_t
*chip
= bus
->private_data
;
1647 chip
->ac97_bus
= NULL
;
1650 static void snd_intel8x0_mixer_free_ac97(ac97_t
*ac97
)
1652 intel8x0_t
*chip
= ac97
->private_data
;
1653 chip
->ac97
[ac97
->num
] = NULL
;
1656 static struct ac97_pcm ac97_pcm_defs
[] __devinitdata
= {
1661 .slots
= (1 << AC97_SLOT_PCM_LEFT
) |
1662 (1 << AC97_SLOT_PCM_RIGHT
) |
1663 (1 << AC97_SLOT_PCM_CENTER
) |
1664 (1 << AC97_SLOT_PCM_SLEFT
) |
1665 (1 << AC97_SLOT_PCM_SRIGHT
) |
1666 (1 << AC97_SLOT_LFE
)
1669 .slots
= (1 << AC97_SLOT_PCM_LEFT
) |
1670 (1 << AC97_SLOT_PCM_RIGHT
) |
1671 (1 << AC97_SLOT_PCM_LEFT_0
) |
1672 (1 << AC97_SLOT_PCM_RIGHT_0
)
1681 .slots
= (1 << AC97_SLOT_PCM_LEFT
) |
1682 (1 << AC97_SLOT_PCM_RIGHT
)
1691 .slots
= (1 << AC97_SLOT_MIC
)
1700 .slots
= (1 << AC97_SLOT_SPDIF_LEFT2
) |
1701 (1 << AC97_SLOT_SPDIF_RIGHT2
)
1710 .slots
= (1 << AC97_SLOT_PCM_LEFT
) |
1711 (1 << AC97_SLOT_PCM_RIGHT
)
1720 .slots
= (1 << AC97_SLOT_MIC
)
1726 static struct ac97_quirk ac97_quirks
[] __devinitdata
= {
1730 .name
= "Compaq Evo W4000", /* AD1885 */
1731 .type
= AC97_TUNE_HP_ONLY
1736 .name
= "Compaq Evo D510C",
1737 .type
= AC97_TUNE_HP_ONLY
1742 .name
= "HP/Compaq nx7010",
1743 .type
= AC97_TUNE_MUTE_LED
1749 .type
= AC97_TUNE_ALC_JACK
1754 .name
= "Dell Precision 530", /* AD1885 */
1755 .type
= AC97_TUNE_HP_ONLY
1760 .name
= "Dell", /* which model? AD1885 */
1761 .type
= AC97_TUNE_HP_ONLY
1766 .name
= "Dell Optiplex GX260", /* AD1981A */
1767 .type
= AC97_TUNE_HP_ONLY
1772 .name
= "Dell Precision 650", /* AD1981A */
1773 .type
= AC97_TUNE_HP_ONLY
1778 .name
= "Dell Precision 450", /* AD1981B*/
1779 .type
= AC97_TUNE_HP_ONLY
1784 .name
= "Dell", /* which model? AD1981B*/
1785 .type
= AC97_TUNE_HP_ONLY
1790 .name
= "Dell Unknown", /* STAC9750/51 */
1791 .type
= AC97_TUNE_HP_ONLY
1796 .name
= "HP zv5000",
1797 .type
= AC97_TUNE_MUTE_LED
/*AD1981B*/
1799 { /* FIXME: which codec? */
1802 .name
= "HP xw6000",
1803 .type
= AC97_TUNE_HP_ONLY
1808 .name
= "HP nc8000",
1809 .type
= AC97_TUNE_MUTE_LED
1814 .name
= "HP nc6000",
1815 .type
= AC97_TUNE_MUTE_LED
1820 .name
= "HP xw8000",
1821 .type
= AC97_TUNE_HP_ONLY
1826 .name
= "HP xw8200", /* AD1981B*/
1827 .type
= AC97_TUNE_HP_ONLY
1832 .name
= "HP xw6200",
1833 .type
= AC97_TUNE_HP_ONLY
1838 .name
= "HP xw4200", /* AD1981B*/
1839 .type
= AC97_TUNE_HP_ONLY
1844 .name
= "Sony S1XP",
1845 .type
= AC97_TUNE_INV_EAPD
1850 .name
= "ASUS ICH5/AD1985",
1851 .type
= AC97_TUNE_AD_SHARING
1856 .name
= "Fujitsu-Siemens E4010",
1857 .type
= AC97_TUNE_HP_ONLY
1862 .name
= "Fujitsu S6210", /* STAC9750/51 */
1863 .type
= AC97_TUNE_HP_ONLY
1868 .name
= "Fujitsu-Siemens Celsius", /* AD1981? */
1869 .type
= AC97_TUNE_HP_ONLY
1874 .name
= "AMD64 Mobo", /* ALC650 */
1875 .type
= AC97_TUNE_HP_ONLY
1880 .name
= "Fujitsu-Siemens Scenic", /* AD1981? */
1881 .type
= AC97_TUNE_HP_ONLY
1886 .name
= "ADI AD1985 (discrete)",
1887 .type
= AC97_TUNE_HP_ONLY
1892 .name
= "MSI P4 ATX 645 Ultra",
1893 .type
= AC97_TUNE_HP_ONLY
1898 .name
= "Fujitsu-Siemens D1522", /* AD1981 */
1899 .type
= AC97_TUNE_HP_ONLY
1905 .name
= "Intel ICH5/AD1985",
1906 .type
= AC97_TUNE_AD_SHARING
1912 .name
= "Intel ICH5/AD1985",
1913 .type
= AC97_TUNE_AD_SHARING
1918 .name
= "Intel D845WN (82801BA)",
1919 .type
= AC97_TUNE_SWAP_HP
1924 .name
= "Intel D850EMV2", /* AD1885 */
1925 .type
= AC97_TUNE_HP_ONLY
1930 .name
= "Intel ICH/AD1885",
1931 .type
= AC97_TUNE_HP_ONLY
1937 .name
= "Intel ICH5/AD1985",
1938 .type
= AC97_TUNE_AD_SHARING
1944 .name
= "Intel ICH5/AD1985",
1945 .type
= AC97_TUNE_AD_SHARING
1947 #if 0 /* FIXME: this seems wrong on most boards */
1952 .name
= "Intel ICH5/AD1985",
1953 .type
= AC97_TUNE_HP_ONLY
1956 { } /* terminator */
1959 static int __devinit
snd_intel8x0_mixer(intel8x0_t
*chip
, int ac97_clock
, const char *quirk_override
)
1962 ac97_template_t ac97
;
1964 unsigned int i
, codecs
;
1965 unsigned int glob_sta
= 0;
1966 ac97_bus_ops_t
*ops
;
1967 static ac97_bus_ops_t standard_bus_ops
= {
1968 .write
= snd_intel8x0_codec_write
,
1969 .read
= snd_intel8x0_codec_read
,
1971 static ac97_bus_ops_t ali_bus_ops
= {
1972 .write
= snd_intel8x0_ali_codec_write
,
1973 .read
= snd_intel8x0_ali_codec_read
,
1976 chip
->spdif_idx
= -1; /* use PCMOUT (or disabled) */
1977 switch (chip
->device_type
) {
1979 chip
->spdif_idx
= NVD_SPBAR
;
1982 chip
->spdif_idx
= ALID_AC97SPDIFOUT
;
1984 case DEVICE_INTEL_ICH4
:
1985 chip
->spdif_idx
= ICHD_SPBAR
;
1989 chip
->in_ac97_init
= 1;
1991 memset(&ac97
, 0, sizeof(ac97
));
1992 ac97
.private_data
= chip
;
1993 ac97
.private_free
= snd_intel8x0_mixer_free_ac97
;
1994 ac97
.scaps
= AC97_SCAP_SKIP_MODEM
;
1996 ac97
.scaps
|= AC97_SCAP_DETECT_BY_VENDOR
;
1997 if (chip
->device_type
!= DEVICE_ALI
) {
1998 glob_sta
= igetdword(chip
, ICHREG(GLOB_STA
));
1999 ops
= &standard_bus_ops
;
2000 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
2002 if (glob_sta
& ICH_PCR
)
2004 if (glob_sta
& ICH_SCR
)
2006 if (glob_sta
& ICH_TCR
)
2008 chip
->in_sdin_init
= 1;
2009 for (i
= 0; i
< codecs
; i
++) {
2010 snd_intel8x0_codec_read_test(chip
, i
);
2011 chip
->ac97_sdin
[i
] = igetbyte(chip
, ICHREG(SDM
)) & ICH_LDI_MASK
;
2013 chip
->in_sdin_init
= 0;
2015 codecs
= glob_sta
& ICH_SCR
? 2 : 1;
2020 /* detect the secondary codec */
2021 for (i
= 0; i
< 100; i
++) {
2022 unsigned int reg
= igetdword(chip
, ICHREG(ALI_RTSR
));
2027 iputdword(chip
, ICHREG(ALI_RTSR
), reg
| 0x40);
2031 if ((err
= snd_ac97_bus(chip
->card
, 0, ops
, chip
, &pbus
)) < 0)
2033 pbus
->private_free
= snd_intel8x0_mixer_free_ac97_bus
;
2034 pbus
->shared_type
= AC97_SHARED_TYPE_ICH
; /* shared with modem driver */
2035 if (ac97_clock
>= 8000 && ac97_clock
<= 48000)
2036 pbus
->clock
= ac97_clock
;
2037 /* FIXME: my test board doesn't work well with VRA... */
2038 if (chip
->device_type
== DEVICE_ALI
)
2042 chip
->ac97_bus
= pbus
;
2044 ac97
.pci
= chip
->pci
;
2045 for (i
= 0; i
< codecs
; i
++) {
2047 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &chip
->ac97
[i
])) < 0) {
2049 snd_printk(KERN_ERR
"Unable to initialize codec #%d\n", i
);
2055 /* tune up the primary codec */
2056 snd_ac97_tune_hardware(chip
->ac97
[0], ac97_quirks
, quirk_override
);
2057 /* enable separate SDINs for ICH4 */
2058 if (chip
->device_type
== DEVICE_INTEL_ICH4
)
2060 /* find the available PCM streams */
2061 i
= ARRAY_SIZE(ac97_pcm_defs
);
2062 if (chip
->device_type
!= DEVICE_INTEL_ICH4
)
2063 i
-= 2; /* do not allocate PCM2IN and MIC2 */
2064 if (chip
->spdif_idx
< 0)
2065 i
--; /* do not allocate S/PDIF */
2066 err
= snd_ac97_pcm_assign(pbus
, i
, ac97_pcm_defs
);
2069 chip
->ichd
[ICHD_PCMOUT
].pcm
= &pbus
->pcms
[0];
2070 chip
->ichd
[ICHD_PCMIN
].pcm
= &pbus
->pcms
[1];
2071 chip
->ichd
[ICHD_MIC
].pcm
= &pbus
->pcms
[2];
2072 if (chip
->spdif_idx
>= 0)
2073 chip
->ichd
[chip
->spdif_idx
].pcm
= &pbus
->pcms
[3];
2074 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
2075 chip
->ichd
[ICHD_PCM2IN
].pcm
= &pbus
->pcms
[4];
2076 chip
->ichd
[ICHD_MIC2
].pcm
= &pbus
->pcms
[5];
2078 /* enable separate SDINs for ICH4 */
2079 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
2080 struct ac97_pcm
*pcm
= chip
->ichd
[ICHD_PCM2IN
].pcm
;
2081 u8 tmp
= igetbyte(chip
, ICHREG(SDM
));
2082 tmp
&= ~(ICH_DI2L_MASK
|ICH_DI1L_MASK
);
2084 tmp
|= ICH_SE
; /* steer enable for multiple SDINs */
2085 tmp
|= chip
->ac97_sdin
[0] << ICH_DI1L_SHIFT
;
2086 for (i
= 1; i
< 4; i
++) {
2087 if (pcm
->r
[0].codec
[i
]) {
2088 tmp
|= chip
->ac97_sdin
[pcm
->r
[0].codec
[1]->num
] << ICH_DI2L_SHIFT
;
2093 tmp
&= ~ICH_SE
; /* steer disable */
2095 iputbyte(chip
, ICHREG(SDM
), tmp
);
2097 if (pbus
->pcms
[0].r
[0].slots
& (1 << AC97_SLOT_PCM_SLEFT
)) {
2099 if (pbus
->pcms
[0].r
[0].slots
& (1 << AC97_SLOT_LFE
))
2102 if (pbus
->pcms
[0].r
[1].rslots
[0]) {
2105 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
2106 if ((igetdword(chip
, ICHREG(GLOB_STA
)) & ICH_SAMPLE_CAP
) == ICH_SAMPLE_16_20
)
2109 if (chip
->device_type
== DEVICE_NFORCE
) {
2111 chip
->ichd
[chip
->spdif_idx
].pcm
->rates
= SNDRV_PCM_RATE_48000
;
2113 if (chip
->device_type
== DEVICE_INTEL_ICH4
) {
2114 /* use slot 10/11 for SPDIF */
2116 val
= igetdword(chip
, ICHREG(GLOB_CNT
)) & ~ICH_PCM_SPDIF_MASK
;
2117 val
|= ICH_PCM_SPDIF_1011
;
2118 iputdword(chip
, ICHREG(GLOB_CNT
), val
);
2119 snd_ac97_update_bits(chip
->ac97
[0], AC97_EXTENDED_STATUS
, 0x03 << 4, 0x03 << 4);
2121 chip
->in_ac97_init
= 0;
2125 /* clear the cold-reset bit for the next chance */
2126 if (chip
->device_type
!= DEVICE_ALI
)
2127 iputdword(chip
, ICHREG(GLOB_CNT
), igetdword(chip
, ICHREG(GLOB_CNT
)) & ~ICH_AC97COLD
);
2136 static void do_ali_reset(intel8x0_t
*chip
)
2138 iputdword(chip
, ICHREG(ALI_SCR
), ICH_ALI_SC_RESET
);
2139 iputdword(chip
, ICHREG(ALI_FIFOCR1
), 0x83838383);
2140 iputdword(chip
, ICHREG(ALI_FIFOCR2
), 0x83838383);
2141 iputdword(chip
, ICHREG(ALI_FIFOCR3
), 0x83838383);
2142 iputdword(chip
, ICHREG(ALI_INTERFACECR
),
2143 ICH_ALI_IF_MC
|ICH_ALI_IF_PI
|ICH_ALI_IF_PO
);
2144 iputdword(chip
, ICHREG(ALI_INTERRUPTCR
), 0x00000000);
2145 iputdword(chip
, ICHREG(ALI_INTERRUPTSR
), 0x00000000);
2148 #define do_delay(chip) do {\
2149 set_current_state(TASK_UNINTERRUPTIBLE);\
2150 schedule_timeout(1);\
2153 static int snd_intel8x0_ich_chip_init(intel8x0_t
*chip
, int probing
)
2155 unsigned long end_time
;
2156 unsigned int cnt
, status
, nstatus
;
2158 /* put logic to right state */
2159 /* first clear status bits */
2160 status
= ICH_RCS
| ICH_MCINT
| ICH_POINT
| ICH_PIINT
;
2161 if (chip
->device_type
== DEVICE_NFORCE
)
2162 status
|= ICH_NVSPINT
;
2163 cnt
= igetdword(chip
, ICHREG(GLOB_STA
));
2164 iputdword(chip
, ICHREG(GLOB_STA
), cnt
& status
);
2166 /* ACLink on, 2 channels */
2167 cnt
= igetdword(chip
, ICHREG(GLOB_CNT
));
2168 cnt
&= ~(ICH_ACLINK
| ICH_PCM_246_MASK
);
2169 /* finish cold or do warm reset */
2170 cnt
|= (cnt
& ICH_AC97COLD
) == 0 ? ICH_AC97COLD
: ICH_AC97WARM
;
2171 iputdword(chip
, ICHREG(GLOB_CNT
), cnt
);
2172 end_time
= (jiffies
+ (HZ
/ 4)) + 1;
2174 if ((igetdword(chip
, ICHREG(GLOB_CNT
)) & ICH_AC97WARM
) == 0)
2177 } while (time_after_eq(end_time
, jiffies
));
2178 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip
, ICHREG(GLOB_CNT
)));
2183 /* wait for any codec ready status.
2184 * Once it becomes ready it should remain ready
2185 * as long as we do not disable the ac97 link.
2187 end_time
= jiffies
+ HZ
;
2189 status
= igetdword(chip
, ICHREG(GLOB_STA
)) & (ICH_PCR
| ICH_SCR
| ICH_TCR
);
2193 } while (time_after_eq(end_time
, jiffies
));
2195 /* no codec is found */
2196 snd_printk(KERN_ERR
"codec_ready: codec is not ready [0x%x]\n", igetdword(chip
, ICHREG(GLOB_STA
)));
2200 if (chip
->device_type
== DEVICE_INTEL_ICH4
)
2201 /* ICH4 can have three codecs */
2202 nstatus
= ICH_PCR
| ICH_SCR
| ICH_TCR
;
2204 /* others up to two codecs */
2205 nstatus
= ICH_PCR
| ICH_SCR
;
2207 /* wait for other codecs ready status. */
2208 end_time
= jiffies
+ HZ
/ 4;
2209 while (status
!= nstatus
&& time_after_eq(end_time
, jiffies
)) {
2211 status
|= igetdword(chip
, ICHREG(GLOB_STA
)) & nstatus
;
2218 for (i
= 0; i
< 3; i
++)
2220 status
|= get_ich_codec_bit(chip
, i
);
2221 /* wait until all the probed codecs are ready */
2222 end_time
= jiffies
+ HZ
;
2224 nstatus
= igetdword(chip
, ICHREG(GLOB_STA
)) & (ICH_PCR
| ICH_SCR
| ICH_TCR
);
2225 if (status
== nstatus
)
2228 } while (time_after_eq(end_time
, jiffies
));
2231 if (chip
->device_type
== DEVICE_SIS
) {
2232 /* unmute the output on SIS7012 */
2233 iputword(chip
, 0x4c, igetword(chip
, 0x4c) | 1);
2235 if (chip
->device_type
== DEVICE_NFORCE
) {
2236 /* enable SPDIF interrupt */
2238 pci_read_config_dword(chip
->pci
, 0x4c, &val
);
2240 pci_write_config_dword(chip
->pci
, 0x4c, val
);
2245 static int snd_intel8x0_ali_chip_init(intel8x0_t
*chip
, int probing
)
2250 reg
= igetdword(chip
, ICHREG(ALI_SCR
));
2251 if ((reg
& 2) == 0) /* Cold required */
2254 reg
|= 1; /* Warm */
2255 reg
&= ~0x80000000; /* ACLink on */
2256 iputdword(chip
, ICHREG(ALI_SCR
), reg
);
2258 for (i
= 0; i
< HZ
/ 2; i
++) {
2259 if (! (igetdword(chip
, ICHREG(ALI_INTERRUPTSR
)) & ALI_INT_GPIO
))
2263 snd_printk(KERN_ERR
"AC'97 reset failed.\n");
2268 for (i
= 0; i
< HZ
/ 2; i
++) {
2269 reg
= igetdword(chip
, ICHREG(ALI_RTSR
));
2270 if (reg
& 0x80) /* primary codec */
2272 iputdword(chip
, ICHREG(ALI_RTSR
), reg
| 0x80);
2280 static int snd_intel8x0_chip_init(intel8x0_t
*chip
, int probing
)
2285 if (chip
->device_type
!= DEVICE_ALI
) {
2286 if ((err
= snd_intel8x0_ich_chip_init(chip
, probing
)) < 0)
2288 iagetword(chip
, 0); /* clear semaphore flag */
2290 if ((err
= snd_intel8x0_ali_chip_init(chip
, probing
)) < 0)
2294 /* disable interrupts */
2295 for (i
= 0; i
< chip
->bdbars_count
; i
++)
2296 iputbyte(chip
, ICH_REG_OFF_CR
+ chip
->ichd
[i
].reg_offset
, 0x00);
2297 /* reset channels */
2298 for (i
= 0; i
< chip
->bdbars_count
; i
++)
2299 iputbyte(chip
, ICH_REG_OFF_CR
+ chip
->ichd
[i
].reg_offset
, ICH_RESETREGS
);
2300 /* initialize Buffer Descriptor Lists */
2301 for (i
= 0; i
< chip
->bdbars_count
; i
++)
2302 iputdword(chip
, ICH_REG_OFF_BDBAR
+ chip
->ichd
[i
].reg_offset
, chip
->ichd
[i
].bdbar_addr
);
2306 static int snd_intel8x0_free(intel8x0_t
*chip
)
2312 /* disable interrupts */
2313 for (i
= 0; i
< chip
->bdbars_count
; i
++)
2314 iputbyte(chip
, ICH_REG_OFF_CR
+ chip
->ichd
[i
].reg_offset
, 0x00);
2315 /* reset channels */
2316 for (i
= 0; i
< chip
->bdbars_count
; i
++)
2317 iputbyte(chip
, ICH_REG_OFF_CR
+ chip
->ichd
[i
].reg_offset
, ICH_RESETREGS
);
2318 if (chip
->device_type
== DEVICE_NFORCE
) {
2319 /* stop the spdif interrupt */
2321 pci_read_config_dword(chip
->pci
, 0x4c, &val
);
2323 pci_write_config_dword(chip
->pci
, 0x4c, val
);
2326 synchronize_irq(chip
->irq
);
2329 free_irq(chip
->irq
, (void *)chip
);
2330 if (chip
->bdbars
.area
) {
2331 if (chip
->fix_nocache
)
2332 fill_nocache(chip
->bdbars
.area
, chip
->bdbars
.bytes
, 0);
2333 snd_dma_free_pages(&chip
->bdbars
);
2335 if (chip
->remap_addr
)
2336 iounmap(chip
->remap_addr
);
2337 if (chip
->remap_bmaddr
)
2338 iounmap(chip
->remap_bmaddr
);
2339 pci_release_regions(chip
->pci
);
2340 pci_disable_device(chip
->pci
);
2349 static int intel8x0_suspend(snd_card_t
*card
, pm_message_t state
)
2351 intel8x0_t
*chip
= card
->pm_private_data
;
2354 for (i
= 0; i
< chip
->pcm_devs
; i
++)
2355 snd_pcm_suspend_all(chip
->pcm
[i
]);
2357 if (chip
->fix_nocache
) {
2358 for (i
= 0; i
< chip
->bdbars_count
; i
++) {
2359 ichdev_t
*ichdev
= &chip
->ichd
[i
];
2360 if (ichdev
->substream
&& ichdev
->page_attr_changed
) {
2361 snd_pcm_runtime_t
*runtime
= ichdev
->substream
->runtime
;
2362 if (runtime
->dma_area
)
2363 fill_nocache(runtime
->dma_area
, runtime
->dma_bytes
, 0);
2367 for (i
= 0; i
< 3; i
++)
2369 snd_ac97_suspend(chip
->ac97
[i
]);
2370 pci_disable_device(chip
->pci
);
2374 static int intel8x0_resume(snd_card_t
*card
)
2376 intel8x0_t
*chip
= card
->pm_private_data
;
2379 pci_enable_device(chip
->pci
);
2380 pci_set_master(chip
->pci
);
2381 snd_intel8x0_chip_init(chip
, 0);
2383 /* refill nocache */
2384 if (chip
->fix_nocache
)
2385 fill_nocache(chip
->bdbars
.area
, chip
->bdbars
.bytes
, 1);
2387 for (i
= 0; i
< 3; i
++)
2389 snd_ac97_resume(chip
->ac97
[i
]);
2391 /* refill nocache */
2392 if (chip
->fix_nocache
) {
2393 for (i
= 0; i
< chip
->bdbars_count
; i
++) {
2394 ichdev_t
*ichdev
= &chip
->ichd
[i
];
2395 if (ichdev
->substream
&& ichdev
->page_attr_changed
) {
2396 snd_pcm_runtime_t
*runtime
= ichdev
->substream
->runtime
;
2397 if (runtime
->dma_area
)
2398 fill_nocache(runtime
->dma_area
, runtime
->dma_bytes
, 1);
2405 #endif /* CONFIG_PM */
2407 #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */
2409 static void __devinit
intel8x0_measure_ac97_clock(intel8x0_t
*chip
)
2411 snd_pcm_substream_t
*subs
;
2414 unsigned long pos
, t
;
2415 struct timeval start_time
, stop_time
;
2417 if (chip
->ac97_bus
->clock
!= 48000)
2418 return; /* specified in module option */
2420 subs
= chip
->pcm
[0]->streams
[0].substream
;
2421 if (! subs
|| subs
->dma_buffer
.bytes
< INTEL8X0_TESTBUF_SIZE
) {
2422 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n");
2425 ichdev
= &chip
->ichd
[ICHD_PCMOUT
];
2426 ichdev
->physbuf
= subs
->dma_buffer
.addr
;
2427 ichdev
->size
= chip
->ichd
[ICHD_PCMOUT
].fragsize
= INTEL8X0_TESTBUF_SIZE
;
2428 ichdev
->substream
= NULL
; /* don't process interrupts */
2431 if (snd_ac97_set_rate(chip
->ac97
[0], AC97_PCM_FRONT_DAC_RATE
, 48000) < 0) {
2432 snd_printk(KERN_ERR
"cannot set ac97 rate: clock = %d\n", chip
->ac97_bus
->clock
);
2435 snd_intel8x0_setup_periods(chip
, ichdev
);
2436 port
= ichdev
->reg_offset
;
2437 spin_lock_irq(&chip
->reg_lock
);
2438 chip
->in_measurement
= 1;
2440 if (chip
->device_type
!= DEVICE_ALI
)
2441 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_IOCE
| ICH_STARTBM
);
2443 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_IOCE
);
2444 iputdword(chip
, ICHREG(ALI_DMACR
), 1 << ichdev
->ali_slot
);
2446 do_gettimeofday(&start_time
);
2447 spin_unlock_irq(&chip
->reg_lock
);
2448 set_current_state(TASK_UNINTERRUPTIBLE
);
2449 schedule_timeout(HZ
/ 20);
2450 spin_lock_irq(&chip
->reg_lock
);
2451 /* check the position */
2452 pos
= ichdev
->fragsize1
;
2453 pos
-= igetword(chip
, ichdev
->reg_offset
+ ichdev
->roff_picb
) << ichdev
->pos_shift
;
2454 pos
+= ichdev
->position
;
2455 chip
->in_measurement
= 0;
2456 do_gettimeofday(&stop_time
);
2458 if (chip
->device_type
== DEVICE_ALI
) {
2459 iputdword(chip
, ICHREG(ALI_DMACR
), 1 << (ichdev
->ali_slot
+ 8));
2460 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, 0);
2461 while (igetbyte(chip
, port
+ ICH_REG_OFF_CR
))
2464 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, 0);
2465 while (!(igetbyte(chip
, port
+ ichdev
->roff_sr
) & ICH_DCH
))
2468 iputbyte(chip
, port
+ ICH_REG_OFF_CR
, ICH_RESETREGS
);
2469 spin_unlock_irq(&chip
->reg_lock
);
2471 t
= stop_time
.tv_sec
- start_time
.tv_sec
;
2473 t
+= stop_time
.tv_usec
- start_time
.tv_usec
;
2474 printk(KERN_INFO
"%s: measured %lu usecs\n", __FUNCTION__
, t
);
2476 snd_printk(KERN_ERR
"?? calculation error..\n");
2479 pos
= (pos
/ 4) * 1000;
2480 pos
= (pos
/ t
) * 1000 + ((pos
% t
) * 1000) / t
;
2481 if (pos
< 40000 || pos
>= 60000)
2482 /* abnormal value. hw problem? */
2483 printk(KERN_INFO
"intel8x0: measured clock %ld rejected\n", pos
);
2484 else if (pos
< 47500 || pos
> 48500)
2485 /* not 48000Hz, tuning the clock.. */
2486 chip
->ac97_bus
->clock
= (chip
->ac97_bus
->clock
* 48000) / pos
;
2487 printk(KERN_INFO
"intel8x0: clocking to %d\n", chip
->ac97_bus
->clock
);
2490 static void snd_intel8x0_proc_read(snd_info_entry_t
* entry
,
2491 snd_info_buffer_t
* buffer
)
2493 intel8x0_t
*chip
= entry
->private_data
;
2496 snd_iprintf(buffer
, "Intel8x0\n\n");
2497 if (chip
->device_type
== DEVICE_ALI
)
2499 tmp
= igetdword(chip
, ICHREG(GLOB_STA
));
2500 snd_iprintf(buffer
, "Global control : 0x%08x\n", igetdword(chip
, ICHREG(GLOB_CNT
)));
2501 snd_iprintf(buffer
, "Global status : 0x%08x\n", tmp
);
2502 if (chip
->device_type
== DEVICE_INTEL_ICH4
)
2503 snd_iprintf(buffer
, "SDM : 0x%08x\n", igetdword(chip
, ICHREG(SDM
)));
2504 snd_iprintf(buffer
, "AC'97 codecs ready :%s%s%s%s\n",
2505 tmp
& ICH_PCR
? " primary" : "",
2506 tmp
& ICH_SCR
? " secondary" : "",
2507 tmp
& ICH_TCR
? " tertiary" : "",
2508 (tmp
& (ICH_PCR
| ICH_SCR
| ICH_TCR
)) == 0 ? " none" : "");
2509 if (chip
->device_type
== DEVICE_INTEL_ICH4
)
2510 snd_iprintf(buffer
, "AC'97 codecs SDIN : %i %i %i\n",
2513 chip
->ac97_sdin
[2]);
2516 static void __devinit
snd_intel8x0_proc_init(intel8x0_t
* chip
)
2518 snd_info_entry_t
*entry
;
2520 if (! snd_card_proc_new(chip
->card
, "intel8x0", &entry
))
2521 snd_info_set_text_ops(entry
, chip
, 1024, snd_intel8x0_proc_read
);
2524 static int snd_intel8x0_dev_free(snd_device_t
*device
)
2526 intel8x0_t
*chip
= device
->device_data
;
2527 return snd_intel8x0_free(chip
);
2530 struct ich_reg_info
{
2531 unsigned int int_sta_mask
;
2532 unsigned int offset
;
2535 static int __devinit
snd_intel8x0_create(snd_card_t
* card
,
2536 struct pci_dev
*pci
,
2537 unsigned long device_type
,
2538 intel8x0_t
** r_intel8x0
)
2543 unsigned int int_sta_masks
;
2545 static snd_device_ops_t ops
= {
2546 .dev_free
= snd_intel8x0_dev_free
,
2549 static unsigned int bdbars
[] = {
2550 3, /* DEVICE_INTEL */
2551 6, /* DEVICE_INTEL_ICH4 */
2554 4, /* DEVICE_NFORCE */
2556 static struct ich_reg_info intel_regs
[6] = {
2558 { ICH_POINT
, 0x10 },
2559 { ICH_MCINT
, 0x20 },
2560 { ICH_M2INT
, 0x40 },
2561 { ICH_P2INT
, 0x50 },
2562 { ICH_SPINT
, 0x60 },
2564 static struct ich_reg_info nforce_regs
[4] = {
2566 { ICH_POINT
, 0x10 },
2567 { ICH_MCINT
, 0x20 },
2568 { ICH_NVSPINT
, 0x70 },
2570 static struct ich_reg_info ali_regs
[6] = {
2571 { ALI_INT_PCMIN
, 0x40 },
2572 { ALI_INT_PCMOUT
, 0x50 },
2573 { ALI_INT_MICIN
, 0x60 },
2574 { ALI_INT_CODECSPDIFOUT
, 0x70 },
2575 { ALI_INT_SPDIFIN
, 0xa0 },
2576 { ALI_INT_SPDIFOUT
, 0xb0 },
2578 struct ich_reg_info
*tbl
;
2582 if ((err
= pci_enable_device(pci
)) < 0)
2585 chip
= kcalloc(1, sizeof(*chip
), GFP_KERNEL
);
2587 pci_disable_device(pci
);
2590 spin_lock_init(&chip
->reg_lock
);
2591 chip
->device_type
= device_type
;
2596 if (pci
->vendor
== PCI_VENDOR_ID_INTEL
&&
2597 pci
->device
== PCI_DEVICE_ID_INTEL_440MX
)
2598 chip
->fix_nocache
= 1; /* enable workaround */
2600 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2601 * Needs to return IRQ_HANDLED for unknown irqs.
2603 if (device_type
== DEVICE_NFORCE
)
2604 chip
->buggy_irq
= 1;
2606 if ((err
= pci_request_regions(pci
, card
->shortname
)) < 0) {
2608 pci_disable_device(pci
);
2612 if (device_type
== DEVICE_ALI
) {
2613 /* ALI5455 has no ac97 region */
2614 chip
->bmaddr
= pci_resource_start(pci
, 0);
2618 if (pci_resource_flags(pci
, 2) & IORESOURCE_MEM
) { /* ICH4 and Nforce */
2620 chip
->addr
= pci_resource_start(pci
, 2);
2621 chip
->remap_addr
= ioremap_nocache(chip
->addr
,
2622 pci_resource_len(pci
, 2));
2623 if (chip
->remap_addr
== NULL
) {
2624 snd_printk("AC'97 space ioremap problem\n");
2625 snd_intel8x0_free(chip
);
2629 chip
->addr
= pci_resource_start(pci
, 0);
2631 if (pci_resource_flags(pci
, 3) & IORESOURCE_MEM
) { /* ICH4 */
2633 chip
->bmaddr
= pci_resource_start(pci
, 3);
2634 chip
->remap_bmaddr
= ioremap_nocache(chip
->bmaddr
,
2635 pci_resource_len(pci
, 3));
2636 if (chip
->remap_bmaddr
== NULL
) {
2637 snd_printk("Controller space ioremap problem\n");
2638 snd_intel8x0_free(chip
);
2642 chip
->bmaddr
= pci_resource_start(pci
, 1);
2646 if (request_irq(pci
->irq
, snd_intel8x0_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, card
->shortname
, (void *)chip
)) {
2647 snd_printk("unable to grab IRQ %d\n", pci
->irq
);
2648 snd_intel8x0_free(chip
);
2651 chip
->irq
= pci
->irq
;
2652 pci_set_master(pci
);
2653 synchronize_irq(chip
->irq
);
2655 chip
->bdbars_count
= bdbars
[device_type
];
2657 /* initialize offsets */
2658 switch (device_type
) {
2669 for (i
= 0; i
< chip
->bdbars_count
; i
++) {
2670 ichdev
= &chip
->ichd
[i
];
2672 ichdev
->reg_offset
= tbl
[i
].offset
;
2673 ichdev
->int_sta_mask
= tbl
[i
].int_sta_mask
;
2674 if (device_type
== DEVICE_SIS
) {
2675 /* SiS 7012 swaps the registers */
2676 ichdev
->roff_sr
= ICH_REG_OFF_PICB
;
2677 ichdev
->roff_picb
= ICH_REG_OFF_SR
;
2679 ichdev
->roff_sr
= ICH_REG_OFF_SR
;
2680 ichdev
->roff_picb
= ICH_REG_OFF_PICB
;
2682 if (device_type
== DEVICE_ALI
)
2683 ichdev
->ali_slot
= (ichdev
->reg_offset
- 0x40) / 0x10;
2684 /* SIS7012 handles the pcm data in bytes, others are in samples */
2685 ichdev
->pos_shift
= (device_type
== DEVICE_SIS
) ? 0 : 1;
2688 /* allocate buffer descriptor lists */
2689 /* the start of each lists must be aligned to 8 bytes */
2690 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
2691 chip
->bdbars_count
* sizeof(u32
) * ICH_MAX_FRAGS
* 2,
2692 &chip
->bdbars
) < 0) {
2693 snd_intel8x0_free(chip
);
2694 snd_printk(KERN_ERR
"intel8x0: cannot allocate buffer descriptors\n");
2697 /* tables must be aligned to 8 bytes here, but the kernel pages
2698 are much bigger, so we don't care (on i386) */
2699 /* workaround for 440MX */
2700 if (chip
->fix_nocache
)
2701 fill_nocache(chip
->bdbars
.area
, chip
->bdbars
.bytes
, 1);
2703 for (i
= 0; i
< chip
->bdbars_count
; i
++) {
2704 ichdev
= &chip
->ichd
[i
];
2705 ichdev
->bdbar
= ((u32
*)chip
->bdbars
.area
) + (i
* ICH_MAX_FRAGS
* 2);
2706 ichdev
->bdbar_addr
= chip
->bdbars
.addr
+ (i
* sizeof(u32
) * ICH_MAX_FRAGS
* 2);
2707 int_sta_masks
|= ichdev
->int_sta_mask
;
2709 chip
->int_sta_reg
= device_type
== DEVICE_ALI
? ICH_REG_ALI_INTERRUPTSR
: ICH_REG_GLOB_STA
;
2710 chip
->int_sta_mask
= int_sta_masks
;
2712 if ((err
= snd_intel8x0_chip_init(chip
, 1)) < 0) {
2713 snd_intel8x0_free(chip
);
2717 snd_card_set_pm_callback(card
, intel8x0_suspend
, intel8x0_resume
, chip
);
2719 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
2720 snd_intel8x0_free(chip
);
2724 snd_card_set_dev(card
, &pci
->dev
);
2730 static struct shortname_table
{
2733 } shortnames
[] __devinitdata
= {
2734 { PCI_DEVICE_ID_INTEL_82801
, "Intel 82801AA-ICH" },
2735 { PCI_DEVICE_ID_INTEL_82901
, "Intel 82901AB-ICH0" },
2736 { PCI_DEVICE_ID_INTEL_82801BA
, "Intel 82801BA-ICH2" },
2737 { PCI_DEVICE_ID_INTEL_440MX
, "Intel 440MX" },
2738 { PCI_DEVICE_ID_INTEL_ICH3
, "Intel 82801CA-ICH3" },
2739 { PCI_DEVICE_ID_INTEL_ICH4
, "Intel 82801DB-ICH4" },
2740 { PCI_DEVICE_ID_INTEL_ICH5
, "Intel ICH5" },
2741 { PCI_DEVICE_ID_INTEL_ESB_5
, "Intel 6300ESB" },
2742 { PCI_DEVICE_ID_INTEL_ICH6_18
, "Intel ICH6" },
2743 { PCI_DEVICE_ID_INTEL_ICH7_20
, "Intel ICH7" },
2744 { PCI_DEVICE_ID_INTEL_ESB2_14
, "Intel ESB2" },
2745 { PCI_DEVICE_ID_SI_7012
, "SiS SI7012" },
2746 { PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
, "NVidia nForce" },
2747 { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
, "NVidia nForce2" },
2748 { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO
, "NVidia nForce3" },
2749 { PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO
, "NVidia CK8S" },
2750 { PCI_DEVICE_ID_NVIDIA_CK804_AUDIO
, "NVidia CK804" },
2751 { PCI_DEVICE_ID_NVIDIA_CK8_AUDIO
, "NVidia CK8" },
2752 { 0x003a, "NVidia MCP04" },
2753 { 0x746d, "AMD AMD8111" },
2754 { 0x7445, "AMD AMD768" },
2755 { 0x5455, "ALi M5455" },
2759 static int __devinit
snd_intel8x0_probe(struct pci_dev
*pci
,
2760 const struct pci_device_id
*pci_id
)
2766 struct shortname_table
*name
;
2768 if (dev
>= SNDRV_CARDS
)
2775 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
2779 switch (pci_id
->driver_data
) {
2781 strcpy(card
->driver
, "NFORCE");
2783 case DEVICE_INTEL_ICH4
:
2784 strcpy(card
->driver
, "ICH4");
2787 strcpy(card
->driver
, "ICH");
2791 strcpy(card
->shortname
, "Intel ICH");
2792 for (name
= shortnames
; name
->id
; name
++) {
2793 if (pci
->device
== name
->id
) {
2794 strcpy(card
->shortname
, name
->s
);
2799 if ((err
= snd_intel8x0_create(card
, pci
, pci_id
->driver_data
, &chip
)) < 0) {
2800 snd_card_free(card
);
2804 chip
->buggy_irq
= 1;
2808 if ((err
= snd_intel8x0_mixer(chip
, ac97_clock
[dev
], ac97_quirk
[dev
])) < 0) {
2809 snd_card_free(card
);
2812 if ((err
= snd_intel8x0_pcm(chip
)) < 0) {
2813 snd_card_free(card
);
2817 snd_intel8x0_proc_init(chip
);
2819 snprintf(card
->longname
, sizeof(card
->longname
),
2820 "%s with %s at %#lx, irq %i", card
->shortname
,
2821 snd_ac97_get_short_name(chip
->ac97
[0]), chip
->addr
, chip
->irq
);
2823 if (! ac97_clock
[dev
])
2824 intel8x0_measure_ac97_clock(chip
);
2826 if ((err
= snd_card_register(card
)) < 0) {
2827 snd_card_free(card
);
2830 pci_set_drvdata(pci
, card
);
2835 static void __devexit
snd_intel8x0_remove(struct pci_dev
*pci
)
2837 snd_card_free(pci_get_drvdata(pci
));
2838 pci_set_drvdata(pci
, NULL
);
2841 static struct pci_driver driver
= {
2842 .name
= "Intel ICH",
2843 .id_table
= snd_intel8x0_ids
,
2844 .probe
= snd_intel8x0_probe
,
2845 .remove
= __devexit_p(snd_intel8x0_remove
),
2846 SND_PCI_PM_CALLBACKS
2850 static int __init
alsa_card_intel8x0_init(void)
2852 return pci_module_init(&driver
);
2855 static void __exit
alsa_card_intel8x0_exit(void)
2857 pci_unregister_driver(&driver
);
2860 module_init(alsa_card_intel8x0_init
)
2861 module_exit(alsa_card_intel8x0_exit
)