33 #include <linux/pci.h>
34 #include <linux/slab.h>
35 #include <linux/module.h>
42 #include <asm/pgtable.h>
43 #include <asm/cacheflush.h>
45 #ifdef CONFIG_KVM_GUEST
46 #include <linux/kvm_para.h>
48 #define kvm_para_available() (0)
52 MODULE_DESCRIPTION(
"Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
55 "{Intel,82901AB-ICH0},"
56 "{Intel,82801BA-ICH2},"
57 "{Intel,82801CA-ICH3},"
58 "{Intel,82801DB-ICH4},"
66 "{NVidia,nForce Audio},"
67 "{NVidia,nForce2 Audio},"
68 "{NVidia,nForce3 Audio},"
80 static int ac97_clock;
82 static bool buggy_semaphore;
83 static int buggy_irq = -1;
85 static int spdif_aclink = -1;
86 static int inside_vm = -1;
93 MODULE_PARM_DESC(ac97_clock,
"AC'97 codec clock (0 = whitelist + auto-detect, 1 = force autodetect).");
97 MODULE_PARM_DESC(buggy_semaphore,
"Enable workaround for hardwares with problematic codec semaphores.");
99 MODULE_PARM_DESC(buggy_irq,
"Enable workaround for buggy interrupts on some motherboards.");
101 MODULE_PARM_DESC(xbox,
"Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
118 #define ICHREG(x) ICH_REG_##x
120 #define DEFINE_REGSET(name,base) \
122 ICH_REG_##name##_BDBAR = base + 0x0, \
123 ICH_REG_##name##_CIV = base + 0x04, \
124 ICH_REG_##name##_LVI = base + 0x05, \
125 ICH_REG_##name##_SR = base + 0x06, \
126 ICH_REG_##name##_PICB = base + 0x08, \
127 ICH_REG_##name##_PIV = base + 0x0a, \
128 ICH_REG_##name##_CR = base + 0x0b, \
145 #define ICH_REG_LVI_MASK 0x1f
148 #define ICH_FIFOE 0x10
149 #define ICH_BCIS 0x08
150 #define ICH_LVBCI 0x04
151 #define ICH_CELV 0x02
155 #define ICH_REG_PIV_MASK 0x1f
158 #define ICH_IOCE 0x10
159 #define ICH_FEIE 0x08
160 #define ICH_LVBIE 0x04
161 #define ICH_RESETREGS 0x02
162 #define ICH_STARTBM 0x01
166 #define ICH_REG_GLOB_CNT 0x2c
167 #define ICH_PCM_SPDIF_MASK 0xc0000000
168 #define ICH_PCM_SPDIF_NONE 0x00000000
169 #define ICH_PCM_SPDIF_78 0x40000000
170 #define ICH_PCM_SPDIF_69 0x80000000
171 #define ICH_PCM_SPDIF_1011 0xc0000000
172 #define ICH_PCM_20BIT 0x00400000
173 #define ICH_PCM_246_MASK 0x00300000
174 #define ICH_PCM_8 0x00300000
175 #define ICH_PCM_6 0x00200000
176 #define ICH_PCM_4 0x00100000
177 #define ICH_PCM_2 0x00000000
178 #define ICH_SIS_PCM_246_MASK 0x000000c0
179 #define ICH_SIS_PCM_6 0x00000080
180 #define ICH_SIS_PCM_4 0x00000040
181 #define ICH_SIS_PCM_2 0x00000000
182 #define ICH_TRIE 0x00000040
183 #define ICH_SRIE 0x00000020
184 #define ICH_PRIE 0x00000010
185 #define ICH_ACLINK 0x00000008
186 #define ICH_AC97WARM 0x00000004
187 #define ICH_AC97COLD 0x00000002
188 #define ICH_GIE 0x00000001
189 #define ICH_REG_GLOB_STA 0x30
190 #define ICH_TRI 0x20000000
191 #define ICH_TCR 0x10000000
192 #define ICH_BCS 0x08000000
193 #define ICH_SPINT 0x04000000
194 #define ICH_P2INT 0x02000000
195 #define ICH_M2INT 0x01000000
196 #define ICH_SAMPLE_CAP 0x00c00000
197 #define ICH_SAMPLE_16_20 0x00400000
198 #define ICH_MULTICHAN_CAP 0x00300000
199 #define ICH_SIS_TRI 0x00080000
200 #define ICH_SIS_TCR 0x00040000
201 #define ICH_MD3 0x00020000
202 #define ICH_AD3 0x00010000
203 #define ICH_RCS 0x00008000
204 #define ICH_BIT3 0x00004000
205 #define ICH_BIT2 0x00002000
206 #define ICH_BIT1 0x00001000
207 #define ICH_SRI 0x00000800
208 #define ICH_PRI 0x00000400
209 #define ICH_SCR 0x00000200
210 #define ICH_PCR 0x00000100
211 #define ICH_MCINT 0x00000080
212 #define ICH_POINT 0x00000040
213 #define ICH_PIINT 0x00000020
214 #define ICH_NVSPINT 0x00000010
215 #define ICH_MOINT 0x00000004
216 #define ICH_MIINT 0x00000002
217 #define ICH_GSCI 0x00000001
218 #define ICH_REG_ACC_SEMA 0x34
220 #define ICH_REG_SDM 0x80
221 #define ICH_DI2L_MASK 0x000000c0
222 #define ICH_DI2L_SHIFT 6
223 #define ICH_DI1L_MASK 0x00000030
224 #define ICH_DI1L_SHIFT 4
225 #define ICH_SE 0x00000008
226 #define ICH_LDI_MASK 0x00000003
228 #define ICH_MAX_FRAGS 32
272 #define ALI_CAS_SEM_BUSY 0x80000000
273 #define ALI_CPR_ADDR_SECONDARY 0x100
274 #define ALI_CPR_ADDR_READ 0x80
275 #define ALI_CSPSR_CODEC_READY 0x08
276 #define ALI_CSPSR_READ_OK 0x02
277 #define ALI_CSPSR_WRITE_OK 0x01
281 #define ALI_INT_MICIN2 (1<<26)
282 #define ALI_INT_PCMIN2 (1<<25)
283 #define ALI_INT_I2SIN (1<<24)
284 #define ALI_INT_SPDIFOUT (1<<23)
285 #define ALI_INT_SPDIFIN (1<<22)
286 #define ALI_INT_LFEOUT (1<<21)
287 #define ALI_INT_CENTEROUT (1<<20)
288 #define ALI_INT_CODECSPDIFOUT (1<<19)
289 #define ALI_INT_MICIN (1<<18)
290 #define ALI_INT_PCMOUT (1<<17)
291 #define ALI_INT_PCMIN (1<<16)
292 #define ALI_INT_CPRAIS (1<<7)
293 #define ALI_INT_SPRAIS (1<<5)
294 #define ALI_INT_GPIO (1<<1)
295 #define ALI_INT_MASK (ALI_INT_SPDIFOUT|ALI_INT_CODECSPDIFOUT|\
296 ALI_INT_MICIN|ALI_INT_PCMOUT|ALI_INT_PCMIN)
298 #define ICH_ALI_SC_RESET (1<<31)
299 #define ICH_ALI_SC_AC97_DBL (1<<30)
300 #define ICH_ALI_SC_CODEC_SPDF (3<<20)
301 #define ICH_ALI_SC_IN_BITS (3<<18)
302 #define ICH_ALI_SC_OUT_BITS (3<<16)
303 #define ICH_ALI_SC_6CH_CFG (3<<14)
304 #define ICH_ALI_SC_PCM_4 (1<<8)
305 #define ICH_ALI_SC_PCM_6 (2<<8)
306 #define ICH_ALI_SC_PCM_246_MASK (3<<8)
308 #define ICH_ALI_SS_SEC_ID (3<<5)
309 #define ICH_ALI_SS_PRI_ID (3<<3)
311 #define ICH_ALI_IF_AC97SP (1<<21)
312 #define ICH_ALI_IF_MC (1<<20)
313 #define ICH_ALI_IF_PI (1<<19)
314 #define ICH_ALI_IF_MC2 (1<<18)
315 #define ICH_ALI_IF_PI2 (1<<17)
316 #define ICH_ALI_IF_LINE_SRC (1<<15)
317 #define ICH_ALI_IF_MIC_SRC (1<<14)
318 #define ICH_ALI_IF_SPDF_SRC (3<<12)
319 #define ICH_ALI_IF_AC97_OUT (3<<8)
320 #define ICH_ALI_IF_PO_SPDF (1<<3)
321 #define ICH_ALI_IF_PO (1<<1)
353 #define get_ichdev(substream) (substream->runtime->private_data)
518 static int snd_intel8x0_codec_semaphore(
struct intel8x0 *
chip,
unsigned int codec)
533 if ((igetdword(chip,
ICHREG(GLOB_STA)) & codec) == 0)
551 igetbyte(chip,
ICHREG(ACC_SEMA)), igetdword(chip,
ICHREG(GLOB_STA)));
557 static void snd_intel8x0_codec_write(
struct snd_ac97 *ac97,
563 if (snd_intel8x0_codec_semaphore(chip, ac97->
num) < 0) {
567 iaputword(chip, reg + ac97->
num * 0x80, val);
570 static unsigned short snd_intel8x0_codec_read(
struct snd_ac97 *ac97,
577 if (snd_intel8x0_codec_semaphore(chip, ac97->
num) < 0) {
582 res = iagetword(chip, reg + ac97->
num * 0x80);
585 iputdword(chip,
ICHREG(GLOB_STA), tmp &
600 if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) {
601 iagetword(chip, codec * 0x80);
602 if ((tmp = igetdword(chip,
ICHREG(GLOB_STA))) & ICH_RCS) {
604 iputdword(chip,
ICHREG(GLOB_STA), tmp &
613 static int snd_intel8x0_ali_codec_ready(
struct intel8x0 *chip,
int mask)
616 for (count = 0; count < 0x7f; count++) {
617 int val = igetbyte(chip,
ICHREG(ALI_CSPSR));
626 static int snd_intel8x0_ali_codec_semaphore(
struct intel8x0 *chip)
638 static unsigned short snd_intel8x0_ali_codec_read(
struct snd_ac97 *ac97,
unsigned short reg)
641 unsigned short data = 0xffff;
643 if (snd_intel8x0_ali_codec_semaphore(chip))
648 iputword(chip,
ICHREG(ALI_CPR_ADDR), reg);
651 data = igetword(chip,
ICHREG(ALI_SPR));
656 static void snd_intel8x0_ali_codec_write(
struct snd_ac97 *ac97,
unsigned short reg,
661 if (snd_intel8x0_ali_codec_semaphore(chip))
663 iputword(chip,
ICHREG(ALI_CPR), val);
666 iputword(chip,
ICHREG(ALI_CPR_ADDR), reg);
680 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->
bdbar_addr);
704 idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
711 iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
716 "period_size1 = 0x%x\n",
740 #define fill_nocache(buf, size, nocache) do { ; } while (0)
747 static inline void snd_intel8x0_update(
struct intel8x0 *chip,
struct ichdev *ichdev)
755 status = igetbyte(chip, port + ichdev->
roff_sr);
756 civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
759 }
else if (civ == ichdev->
civ) {
765 step = civ - ichdev->
civ;
778 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->
lvi);
779 for (i = 0; i <
step; i++) {
785 "all = 0x%x, 0x%x\n",
787 ichdev->
bdbar[ichdev->
lvi * 2 + 1],
inb(ICH_REG_OFF_PIV + port),
788 inl(port + 4),
inb(port + ICH_REG_OFF_CR));
790 if (--ichdev->
ack == 0) {
795 spin_unlock_irqrestore(&chip->
reg_lock, flags);
799 iputbyte(chip, port + ichdev->
roff_sr,
806 struct ichdev *ichdev;
811 if (status == 0xffffffff)
825 ichdev = &chip->
ichd[
i];
827 snd_intel8x0_update(chip, ichdev);
843 struct ichdev *ichdev =
get_ichdev(substream);
844 unsigned char val = 0;
868 iputbyte(chip, port + ICH_REG_OFF_CR, val);
878 static int snd_intel8x0_ali_trigger(
struct snd_pcm_substream *substream,
int cmd)
881 struct ichdev *ichdev =
get_ichdev(substream);
883 static int fiforeg[] = {
888 val = igetdword(chip,
ICHREG(ALI_DMACR));
897 fifo = igetdword(chip, fiforeg[ichdev->
ali_slot / 4]);
898 fifo &= ~(0xff << (ichdev->
ali_slot % 4));
899 fifo |= 0x83 << (ichdev->
ali_slot % 4);
900 iputdword(chip, fiforeg[ichdev->
ali_slot / 4], fifo);
902 iputbyte(chip, port + ICH_REG_OFF_CR,
ICH_IOCE);
903 val &= ~(1 << (ichdev->
ali_slot + 16));
905 iputdword(chip,
ICHREG(ALI_DMACR), val | (1 << ichdev->
ali_slot));
913 iputdword(chip,
ICHREG(ALI_DMACR), val | (1 << (ichdev->
ali_slot + 16)));
914 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
915 while (igetbyte(chip, port + ICH_REG_OFF_CR))
922 iputbyte(chip, port + ICH_REG_OFF_SR,
923 igetbyte(chip, port + ICH_REG_OFF_SR) | 0x1e);
924 iputdword(chip,
ICHREG(ALI_INTERRUPTSR),
937 struct ichdev *ichdev =
get_ichdev(substream);
961 ichdev->
pcm->r[dbl].slots);
975 struct ichdev *ichdev =
get_ichdev(substream);
988 static void snd_intel8x0_setup_pcm_out(
struct intel8x0 *chip,
992 int dbl = runtime->
rate > 48000;
997 cnt = igetdword(chip,
ICHREG(ALI_SCR));
1003 iputdword(chip,
ICHREG(ALI_SCR), cnt);
1006 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
1012 iputdword(chip,
ICHREG(GLOB_CNT), cnt);
1015 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
1028 iputdword(chip,
ICHREG(GLOB_CNT), cnt & ~ICH_PCM_246_MASK);
1037 iputdword(chip,
ICHREG(GLOB_CNT), cnt);
1047 struct ichdev *ichdev =
get_ichdev(substream);
1050 ichdev->
size = snd_pcm_lib_buffer_bytes(substream);
1051 ichdev->
fragsize = snd_pcm_lib_period_bytes(substream);
1053 snd_intel8x0_setup_pcm_out(chip, runtime);
1057 snd_intel8x0_setup_periods(chip, ichdev);
1064 struct ichdev *ichdev =
get_ichdev(substream);
1071 civ = igetbyte(chip, ichdev->
reg_offset + ICH_REG_OFF_CIV);
1078 if (civ != igetbyte(chip, ichdev->
reg_offset + ICH_REG_OFF_CIV))
1091 }
while (timeout--);
1098 unsigned int pos_base, last_base;
1099 pos_base = position / ichdev->
fragsize1;
1104 if (pos_base == last_base)
1110 if (ptr >= ichdev->
size)
1112 return bytes_to_frames(substream->
runtime, ptr);
1136 static unsigned int channels4[] = {
1146 static unsigned int channels6[] = {
1156 static unsigned int channels8[] = {
1166 static int snd_intel8x0_pcm_open(
struct snd_pcm_substream *substream,
struct ichdev *ichdev)
1173 runtime->
hw = snd_intel8x0_stream;
1174 runtime->
hw.rates = ichdev->
pcm->rates;
1177 runtime->
hw.buffer_bytes_max = 64*1024;
1178 runtime->
hw.period_bytes_max = 64*1024;
1197 runtime->
hw.channels_max = 8;
1200 &hw_constraints_channels8);
1201 }
else if (chip->
multi6) {
1202 runtime->
hw.channels_max = 6;
1204 &hw_constraints_channels6);
1205 }
else if (chip->
multi4) {
1206 runtime->
hw.channels_max = 4;
1208 &hw_constraints_channels4);
1232 return snd_intel8x0_pcm_open(substream, &chip->
ichd[
ICHD_PCMIN]);
1247 return snd_intel8x0_pcm_open(substream, &chip->
ichd[
ICHD_MIC]);
1262 return snd_intel8x0_pcm_open(substream, &chip->
ichd[
ICHD_MIC2]);
1293 return snd_intel8x0_pcm_open(substream, &chip->
ichd[idx]);
1305 static int snd_intel8x0_ali_ac97spdifout_open(
struct snd_pcm_substream *substream)
1311 val = igetdword(chip,
ICHREG(ALI_INTERFACECR));
1313 iputdword(chip,
ICHREG(ALI_INTERFACECR), val);
1320 static int snd_intel8x0_ali_ac97spdifout_close(
struct snd_pcm_substream *substream)
1327 val = igetdword(chip,
ICHREG(ALI_INTERFACECR));
1329 iputdword(chip,
ICHREG(ALI_INTERFACECR), val);
1367 static struct snd_pcm_ops snd_intel8x0_playback_ops = {
1368 .open = snd_intel8x0_playback_open,
1369 .close = snd_intel8x0_playback_close,
1371 .hw_params = snd_intel8x0_hw_params,
1372 .hw_free = snd_intel8x0_hw_free,
1373 .prepare = snd_intel8x0_pcm_prepare,
1374 .trigger = snd_intel8x0_pcm_trigger,
1375 .pointer = snd_intel8x0_pcm_pointer,
1378 static struct snd_pcm_ops snd_intel8x0_capture_ops = {
1379 .open = snd_intel8x0_capture_open,
1380 .close = snd_intel8x0_capture_close,
1382 .hw_params = snd_intel8x0_hw_params,
1383 .hw_free = snd_intel8x0_hw_free,
1384 .prepare = snd_intel8x0_pcm_prepare,
1385 .trigger = snd_intel8x0_pcm_trigger,
1386 .pointer = snd_intel8x0_pcm_pointer,
1389 static struct snd_pcm_ops snd_intel8x0_capture_mic_ops = {
1390 .open = snd_intel8x0_mic_open,
1391 .close = snd_intel8x0_mic_close,
1393 .hw_params = snd_intel8x0_hw_params,
1394 .hw_free = snd_intel8x0_hw_free,
1395 .prepare = snd_intel8x0_pcm_prepare,
1396 .trigger = snd_intel8x0_pcm_trigger,
1397 .pointer = snd_intel8x0_pcm_pointer,
1400 static struct snd_pcm_ops snd_intel8x0_capture_mic2_ops = {
1401 .open = snd_intel8x0_mic2_open,
1402 .close = snd_intel8x0_mic2_close,
1404 .hw_params = snd_intel8x0_hw_params,
1405 .hw_free = snd_intel8x0_hw_free,
1406 .prepare = snd_intel8x0_pcm_prepare,
1407 .trigger = snd_intel8x0_pcm_trigger,
1408 .pointer = snd_intel8x0_pcm_pointer,
1411 static struct snd_pcm_ops snd_intel8x0_capture2_ops = {
1412 .open = snd_intel8x0_capture2_open,
1413 .close = snd_intel8x0_capture2_close,
1415 .hw_params = snd_intel8x0_hw_params,
1416 .hw_free = snd_intel8x0_hw_free,
1417 .prepare = snd_intel8x0_pcm_prepare,
1418 .trigger = snd_intel8x0_pcm_trigger,
1419 .pointer = snd_intel8x0_pcm_pointer,
1422 static struct snd_pcm_ops snd_intel8x0_spdif_ops = {
1423 .open = snd_intel8x0_spdif_open,
1424 .close = snd_intel8x0_spdif_close,
1426 .hw_params = snd_intel8x0_hw_params,
1427 .hw_free = snd_intel8x0_hw_free,
1428 .prepare = snd_intel8x0_pcm_prepare,
1429 .trigger = snd_intel8x0_pcm_trigger,
1430 .pointer = snd_intel8x0_pcm_pointer,
1433 static struct snd_pcm_ops snd_intel8x0_ali_playback_ops = {
1434 .open = snd_intel8x0_playback_open,
1435 .close = snd_intel8x0_playback_close,
1437 .hw_params = snd_intel8x0_hw_params,
1438 .hw_free = snd_intel8x0_hw_free,
1439 .prepare = snd_intel8x0_pcm_prepare,
1440 .trigger = snd_intel8x0_ali_trigger,
1441 .pointer = snd_intel8x0_pcm_pointer,
1444 static struct snd_pcm_ops snd_intel8x0_ali_capture_ops = {
1445 .open = snd_intel8x0_capture_open,
1446 .close = snd_intel8x0_capture_close,
1448 .hw_params = snd_intel8x0_hw_params,
1449 .hw_free = snd_intel8x0_hw_free,
1450 .prepare = snd_intel8x0_pcm_prepare,
1451 .trigger = snd_intel8x0_ali_trigger,
1452 .pointer = snd_intel8x0_pcm_pointer,
1455 static struct snd_pcm_ops snd_intel8x0_ali_capture_mic_ops = {
1456 .open = snd_intel8x0_mic_open,
1457 .close = snd_intel8x0_mic_close,
1459 .hw_params = snd_intel8x0_hw_params,
1460 .hw_free = snd_intel8x0_hw_free,
1461 .prepare = snd_intel8x0_pcm_prepare,
1462 .trigger = snd_intel8x0_ali_trigger,
1463 .pointer = snd_intel8x0_pcm_pointer,
1466 static struct snd_pcm_ops snd_intel8x0_ali_ac97spdifout_ops = {
1467 .open = snd_intel8x0_ali_ac97spdifout_open,
1468 .close = snd_intel8x0_ali_ac97spdifout_close,
1470 .hw_params = snd_intel8x0_hw_params,
1471 .hw_free = snd_intel8x0_hw_free,
1472 .prepare = snd_intel8x0_pcm_prepare,
1473 .trigger = snd_intel8x0_ali_trigger,
1474 .pointer = snd_intel8x0_pcm_pointer,
1478 static struct snd_pcm_ops snd_intel8x0_ali_spdifin_ops = {
1479 .
open = snd_intel8x0_ali_spdifin_open,
1480 .close = snd_intel8x0_ali_spdifin_close,
1482 .hw_params = snd_intel8x0_hw_params,
1483 .hw_free = snd_intel8x0_hw_free,
1484 .prepare = snd_intel8x0_pcm_prepare,
1485 .trigger = snd_intel8x0_pcm_trigger,
1486 .pointer = snd_intel8x0_pcm_pointer,
1489 static struct snd_pcm_ops snd_intel8x0_ali_spdifout_ops = {
1490 .
open = snd_intel8x0_ali_spdifout_open,
1491 .close = snd_intel8x0_ali_spdifout_close,
1493 .hw_params = snd_intel8x0_hw_params,
1494 .hw_free = snd_intel8x0_hw_free,
1495 .prepare = snd_intel8x0_pcm_prepare,
1496 .trigger = snd_intel8x0_pcm_trigger,
1497 .pointer = snd_intel8x0_pcm_pointer,
1520 strcpy(name,
"Intel ICH");
1569 .playback_ops = &snd_intel8x0_playback_ops,
1570 .capture_ops = &snd_intel8x0_capture_ops,
1571 .prealloc_size = 64 * 1024,
1572 .prealloc_max_size = 128 * 1024,
1575 .suffix =
"MIC ADC",
1576 .capture_ops = &snd_intel8x0_capture_mic_ops,
1578 .prealloc_max_size = 128 * 1024,
1582 .suffix =
"MIC2 ADC",
1583 .capture_ops = &snd_intel8x0_capture_mic2_ops,
1585 .prealloc_max_size = 128 * 1024,
1590 .capture_ops = &snd_intel8x0_capture2_ops,
1592 .prealloc_max_size = 128 * 1024,
1597 .playback_ops = &snd_intel8x0_spdif_ops,
1598 .prealloc_size = 64 * 1024,
1599 .prealloc_max_size = 128 * 1024,
1607 .capture_ops = &snd_intel8x0_capture_ops,
1608 .prealloc_size = 64 * 1024,
1609 .prealloc_max_size = 128 * 1024,
1612 .suffix =
"MIC ADC",
1613 .capture_ops = &snd_intel8x0_capture_mic_ops,
1615 .prealloc_max_size = 128 * 1024,
1620 .playback_ops = &snd_intel8x0_spdif_ops,
1621 .prealloc_size = 64 * 1024,
1622 .prealloc_max_size = 128 * 1024,
1630 .capture_ops = &snd_intel8x0_ali_capture_ops,
1631 .prealloc_size = 64 * 1024,
1632 .prealloc_max_size = 128 * 1024,
1635 .suffix =
"MIC ADC",
1636 .capture_ops = &snd_intel8x0_ali_capture_mic_ops,
1638 .prealloc_max_size = 128 * 1024,
1643 .playback_ops = &snd_intel8x0_ali_ac97spdifout_ops,
1645 .prealloc_size = 64 * 1024,
1646 .prealloc_max_size = 128 * 1024,
1651 .suffix =
"HW IEC958",
1652 .playback_ops = &snd_intel8x0_ali_spdifout_ops,
1653 .prealloc_size = 64 * 1024,
1654 .prealloc_max_size = 128 * 1024,
1688 for (i = 0; i < tblsize; i++) {
1695 err = snd_intel8x0_pcm1(chip, device, rec);
1710 static void snd_intel8x0_mixer_free_ac97_bus(
struct snd_ac97_bus *
bus)
1716 static void snd_intel8x0_mixer_free_ac97(
struct snd_ac97 *ac97)
1722 static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
1792 static struct ac97_quirk ac97_quirks[] __devinitdata = {
1794 .subvendor = 0x0e11,
1795 .subdevice = 0x000e,
1796 .name =
"Compaq Deskpro EN",
1800 .subvendor = 0x0e11,
1801 .subdevice = 0x008a,
1802 .name =
"Compaq Evo W4000",
1806 .subvendor = 0x0e11,
1807 .subdevice = 0x00b8,
1808 .name =
"Compaq Evo D510C",
1812 .subvendor = 0x0e11,
1813 .subdevice = 0x0860,
1814 .name =
"HP/Compaq nx7010",
1818 .subvendor = 0x1014,
1819 .subdevice = 0x0534,
1820 .name =
"ThinkPad X31",
1824 .subvendor = 0x1014,
1825 .subdevice = 0x1f00,
1830 .subvendor = 0x1014,
1831 .subdevice = 0x0267,
1832 .name =
"IBM NetVista A30p",
1836 .subvendor = 0x1025,
1837 .subdevice = 0x0082,
1838 .name =
"Acer Travelmate 2310",
1842 .subvendor = 0x1025,
1843 .subdevice = 0x0083,
1844 .name =
"Acer Aspire 3003LCi",
1848 .subvendor = 0x1028,
1849 .subdevice = 0x00d8,
1850 .name =
"Dell Precision 530",
1854 .subvendor = 0x1028,
1855 .subdevice = 0x010d,
1860 .subvendor = 0x1028,
1861 .subdevice = 0x0126,
1862 .name =
"Dell Optiplex GX260",
1866 .subvendor = 0x1028,
1867 .subdevice = 0x012c,
1868 .name =
"Dell Precision 650",
1872 .subvendor = 0x1028,
1873 .subdevice = 0x012d,
1874 .name =
"Dell Precision 450",
1878 .subvendor = 0x1028,
1879 .subdevice = 0x0147,
1884 .subvendor = 0x1028,
1885 .subdevice = 0x0151,
1886 .name =
"Dell Optiplex GX270",
1890 .subvendor = 0x1028,
1891 .subdevice = 0x014e,
1892 .name =
"Dell D800",
1896 .subvendor = 0x1028,
1897 .subdevice = 0x0163,
1898 .name =
"Dell Unknown",
1902 .subvendor = 0x1028,
1903 .subdevice = 0x016a,
1904 .name =
"Dell Inspiron 8600",
1908 .subvendor = 0x1028,
1909 .subdevice = 0x0182,
1910 .name =
"Dell Latitude D610",
1914 .subvendor = 0x1028,
1915 .subdevice = 0x0186,
1916 .name =
"Dell Latitude D810",
1920 .subvendor = 0x1028,
1921 .subdevice = 0x0188,
1922 .name =
"Dell Inspiron 6000",
1926 .subvendor = 0x1028,
1927 .subdevice = 0x0189,
1928 .name =
"Dell Inspiron 9300",
1932 .subvendor = 0x1028,
1933 .subdevice = 0x0191,
1934 .name =
"Dell Inspiron 8600",
1938 .subvendor = 0x103c,
1939 .subdevice = 0x006d,
1940 .name =
"HP zv5000",
1944 .subvendor = 0x103c,
1945 .subdevice = 0x00c3,
1946 .name =
"HP xw6000",
1950 .subvendor = 0x103c,
1951 .subdevice = 0x088c,
1952 .name =
"HP nc8000",
1956 .subvendor = 0x103c,
1957 .subdevice = 0x0890,
1958 .name =
"HP nc6000",
1962 .subvendor = 0x103c,
1963 .subdevice = 0x129d,
1964 .name =
"HP xw8000",
1968 .subvendor = 0x103c,
1969 .subdevice = 0x0938,
1970 .name =
"HP nc4200",
1974 .subvendor = 0x103c,
1975 .subdevice = 0x099c,
1976 .name =
"HP nx6110/nc6120",
1980 .subvendor = 0x103c,
1981 .subdevice = 0x0944,
1982 .name =
"HP nc6220",
1986 .subvendor = 0x103c,
1987 .subdevice = 0x0934,
1988 .name =
"HP nc8220",
1992 .subvendor = 0x103c,
1993 .subdevice = 0x12f1,
1994 .name =
"HP xw8200",
1998 .subvendor = 0x103c,
1999 .subdevice = 0x12f2,
2000 .name =
"HP xw6200",
2004 .subvendor = 0x103c,
2005 .subdevice = 0x3008,
2006 .name =
"HP xw4200",
2010 .subvendor = 0x104d,
2011 .subdevice = 0x8144,
2016 .subvendor = 0x104d,
2017 .subdevice = 0x8197,
2018 .name =
"Sony S1XP",
2022 .subvendor = 0x104d,
2023 .subdevice = 0x81c0,
2024 .name =
"Sony VAIO VGN-T350P",
2028 .subvendor = 0x104d,
2029 .subdevice = 0x81c5,
2030 .name =
"Sony VAIO VGN-B1VP",
2034 .subvendor = 0x1043,
2035 .subdevice = 0x80f3,
2036 .name =
"ASUS ICH5/AD1985",
2040 .subvendor = 0x10cf,
2041 .subdevice = 0x11c3,
2042 .name =
"Fujitsu-Siemens E4010",
2046 .subvendor = 0x10cf,
2047 .subdevice = 0x1225,
2048 .name =
"Fujitsu-Siemens T3010",
2052 .subvendor = 0x10cf,
2053 .subdevice = 0x1253,
2054 .name =
"Fujitsu S6210",
2058 .subvendor = 0x10cf,
2059 .subdevice = 0x127d,
2060 .name =
"Fujitsu Lifebook P7010",
2064 .subvendor = 0x10cf,
2065 .subdevice = 0x127e,
2066 .name =
"Fujitsu Lifebook C1211D",
2070 .subvendor = 0x10cf,
2071 .subdevice = 0x12ec,
2072 .name =
"Fujitsu-Siemens 4010",
2076 .subvendor = 0x10cf,
2077 .subdevice = 0x12f2,
2078 .name =
"Fujitsu-Siemens Celsius H320",
2082 .subvendor = 0x10f1,
2083 .subdevice = 0x2665,
2084 .name =
"Fujitsu-Siemens Celsius",
2088 .subvendor = 0x10f1,
2089 .subdevice = 0x2885,
2090 .name =
"AMD64 Mobo",
2094 .subvendor = 0x10f1,
2095 .subdevice = 0x2895,
2096 .name =
"Tyan Thunder K8WE",
2100 .subvendor = 0x10f7,
2101 .subdevice = 0x834c,
2102 .name =
"Panasonic CF-R4",
2106 .subvendor = 0x110a,
2107 .subdevice = 0x0056,
2108 .name =
"Fujitsu-Siemens Scenic",
2112 .subvendor = 0x11d4,
2113 .subdevice = 0x5375,
2114 .name =
"ADI AD1985 (discrete)",
2118 .subvendor = 0x1462,
2119 .subdevice = 0x5470,
2120 .name =
"MSI P4 ATX 645 Ultra",
2124 .subvendor = 0x161f,
2125 .subdevice = 0x202f,
2126 .name =
"Gateway M520",
2130 .subvendor = 0x161f,
2131 .subdevice = 0x203a,
2132 .name =
"Gateway 4525GZ",
2136 .subvendor = 0x1734,
2137 .subdevice = 0x0088,
2138 .name =
"Fujitsu-Siemens D1522",
2142 .subvendor = 0x8086,
2143 .subdevice = 0x2000,
2145 .name =
"Intel ICH5/AD1985",
2149 .subvendor = 0x8086,
2150 .subdevice = 0x4000,
2152 .name =
"Intel ICH5/AD1985",
2156 .subvendor = 0x8086,
2157 .subdevice = 0x4856,
2158 .name =
"Intel D845WN (82801BA)",
2162 .subvendor = 0x8086,
2163 .subdevice = 0x4d44,
2164 .name =
"Intel D850EMV2",
2168 .subvendor = 0x8086,
2169 .subdevice = 0x4d56,
2170 .name =
"Intel ICH/AD1885",
2174 .subvendor = 0x8086,
2175 .subdevice = 0x6000,
2177 .name =
"Intel ICH5/AD1985",
2181 .subvendor = 0x8086,
2182 .subdevice = 0xe000,
2184 .name =
"Intel ICH5/AD1985",
2189 .subvendor = 0x8086,
2190 .subdevice = 0xa000,
2192 .name =
"Intel ICH5/AD1985",
2200 const char *quirk_override)
2205 unsigned int i, codecs;
2206 unsigned int glob_sta = 0;
2209 .
write = snd_intel8x0_codec_write,
2210 .read = snd_intel8x0_codec_read,
2213 .
write = snd_intel8x0_ali_codec_write,
2214 .read = snd_intel8x0_ali_codec_read,
2218 if (!spdif_aclink) {
2234 memset(&ac97, 0,
sizeof(ac97));
2241 glob_sta = igetdword(chip,
ICHREG(GLOB_STA));
2242 ops = &standard_bus_ops;
2249 snd_intel8x0_codec_read_test(chip, codecs);
2265 for (i = 0; i < 100; i++) {
2266 unsigned int reg = igetdword(chip,
ICHREG(ALI_RTSR));
2271 iputdword(chip,
ICHREG(ALI_RTSR), reg | 0x40);
2278 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2279 pbus->
clock = ac97_clock;
2289 for (i = 0; i < codecs; i++) {
2324 u8 tmp = igetbyte(chip,
ICHREG(SDM));
2329 for (i = 1; i < 4; i++) {
2330 if (pcm->
r[0].codec[i]) {
2338 iputbyte(chip,
ICHREG(SDM), tmp);
2348 if (pbus->
pcms[0].r[1].rslots[0]) {
2364 iputdword(chip,
ICHREG(GLOB_CNT), val);
2373 iputdword(chip,
ICHREG(GLOB_CNT),
2383 static void do_ali_reset(
struct intel8x0 *chip)
2386 iputdword(chip,
ICHREG(ALI_FIFOCR1), 0x83838383);
2387 iputdword(chip,
ICHREG(ALI_FIFOCR2), 0x83838383);
2388 iputdword(chip,
ICHREG(ALI_FIFOCR3), 0x83838383);
2389 iputdword(chip,
ICHREG(ALI_INTERFACECR),
2391 iputdword(chip,
ICHREG(ALI_INTERRUPTCR), 0x00000000);
2392 iputdword(chip,
ICHREG(ALI_INTERRUPTSR), 0x00000000);
2395 #ifdef CONFIG_SND_AC97_POWER_SAVE
2396 static struct snd_pci_quirk ich_chip_reset_mode[] = {
2397 SND_PCI_QUIRK(0x1014, 0x051f,
"Thinkpad R32", 1),
2406 if (snd_pci_quirk_lookup(chip->
pci, ich_chip_reset_mode))
2409 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
2416 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
2422 #define snd_intel8x0_ich_chip_can_cold_reset(chip) \
2423 (!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
2425 #define snd_intel8x0_ich_chip_cold_reset(chip) 0
2426 #define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
2429 static int snd_intel8x0_ich_chip_reset(
struct intel8x0 *chip)
2431 unsigned long end_time;
2434 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
2438 iputdword(chip,
ICHREG(GLOB_CNT), cnt);
2446 igetdword(chip,
ICHREG(GLOB_CNT)));
2450 static int snd_intel8x0_ich_chip_init(
struct intel8x0 *chip,
int probing)
2452 unsigned long end_time;
2453 unsigned int status, nstatus;
2462 cnt = igetdword(chip,
ICHREG(GLOB_STA));
2463 iputdword(chip,
ICHREG(GLOB_STA), cnt & status);
2468 err = snd_intel8x0_ich_chip_reset(chip);
2479 status = igetdword(chip,
ICHREG(GLOB_STA)) &
2488 igetdword(chip,
ICHREG(GLOB_STA)));
2497 status |= igetdword(chip,
ICHREG(GLOB_STA)) &
2505 for (i = 0; i < chip->
ncodecs; i++)
2511 nstatus = igetdword(chip,
ICHREG(GLOB_STA)) &
2513 if (status == nstatus)
2521 iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
2526 pci_read_config_dword(chip->
pci, 0x4c, &val);
2528 pci_write_config_dword(chip->
pci, 0x4c, val);
2533 static int snd_intel8x0_ali_chip_init(
struct intel8x0 *chip,
int probing)
2538 reg = igetdword(chip,
ICHREG(ALI_SCR));
2544 iputdword(chip,
ICHREG(ALI_SCR), reg);
2546 for (i = 0; i < HZ / 2; i++) {
2556 for (i = 0; i < HZ / 2; i++) {
2557 reg = igetdword(chip,
ICHREG(ALI_RTSR));
2560 iputdword(chip,
ICHREG(ALI_RTSR), reg | 0x80);
2568 static int snd_intel8x0_chip_init(
struct intel8x0 *chip,
int probing)
2570 unsigned int i, timeout;
2574 if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0)
2578 if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0)
2584 iputbyte(chip, ICH_REG_OFF_CR + chip->
ichd[i].reg_offset, 0x00);
2590 while (--timeout != 0) {
2591 if ((igetbyte(chip, ICH_REG_OFF_CR + chip->
ichd[i].reg_offset) &
ICH_RESETREGS) == 0)
2599 iputdword(chip, ICH_REG_OFF_BDBAR + chip->
ichd[i].reg_offset,
2600 chip->
ichd[i].bdbar_addr);
2604 static int snd_intel8x0_free(
struct intel8x0 *chip)
2612 iputbyte(chip, ICH_REG_OFF_CR + chip->
ichd[i].reg_offset, 0x00);
2619 pci_read_config_dword(chip->
pci, 0x4c, &val);
2621 pci_write_config_dword(chip->
pci, 0x4c, val);
2643 #ifdef CONFIG_PM_SLEEP
2647 static int intel8x0_suspend(
struct device *
dev)
2655 for (i = 0; i < chip->
pcm_devs; i++)
2656 snd_pcm_suspend_all(chip->
pcm[i]);
2660 struct ichdev *ichdev = &chip->
ichd[
i];
2668 for (i = 0; i < chip->
ncodecs; i++)
2669 snd_ac97_suspend(chip->
ac97[i]);
2673 if (chip->
irq >= 0) {
2686 static int intel8x0_resume(
struct device *dev)
2697 "disabling device\n");
2702 snd_intel8x0_chip_init(chip, 0);
2706 "disabling device\n", pci->
irq);
2718 iputdword(chip,
ICHREG(GLOB_CNT),
2727 for (i = 0; i < chip->
ncodecs; i++)
2728 snd_ac97_resume(chip->
ac97[i]);
2733 struct ichdev *ichdev = &chip->
ichd[
i];
2744 struct ichdev *ichdev = &chip->
ichd[
i];
2749 snd_intel8x0_setup_pcm_out(chip, ichdev->
substream->runtime);
2750 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->
bdbar_addr);
2751 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->
lvi);
2752 iputbyte(chip, port + ICH_REG_OFF_CIV, ichdev->
civ);
2761 #define INTEL8X0_PM_OPS &intel8x0_pm
2763 #define INTEL8X0_PM_OPS NULL
2766 #define INTEL8X0_TESTBUF_SIZE 32768
2771 struct ichdev *ichdev;
2773 unsigned long pos, pos1,
t;
2774 int civ, timeout = 1000, attempt = 1;
2775 struct timespec start_time, stop_time;
2777 if (chip->
ac97_bus->clock != 48000)
2781 subs = chip->
pcm[0]->streams[0].substream;
2796 snd_intel8x0_setup_periods(chip, ichdev);
2804 iputbyte(chip, port + ICH_REG_OFF_CR,
ICH_IOCE);
2813 civ = igetbyte(chip, ichdev->
reg_offset + ICH_REG_OFF_CIV);
2819 if (civ == igetbyte(chip, ichdev->
reg_offset + ICH_REG_OFF_CIV) &&
2822 }
while (timeout--);
2834 iputdword(chip,
ICHREG(ALI_DMACR), 1 << (ichdev->
ali_slot + 16));
2835 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2836 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2839 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2861 printk(
KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
2867 pos = (pos /
t) * 1000 + ((pos % t) * 1000) / t;
2868 if (pos < 40000 || pos >= 60000) {
2872 }
else if (pos > 40500 && pos < 41500)
2875 else if (pos > 43600 && pos < 44600)
2878 else if (pos < 47500 || pos > 48500)
2886 static struct snd_pci_quirk intel8x0_clock_list[] __devinitdata = {
2887 SND_PCI_QUIRK(0x0e11, 0x008a,
"AD1885", 41000),
2888 SND_PCI_QUIRK(0x1028, 0x00be,
"AD1885", 44100),
2889 SND_PCI_QUIRK(0x1028, 0x0177,
"AD1980", 48000),
2890 SND_PCI_QUIRK(0x1028, 0x01ad,
"AD1981B", 48000),
2891 SND_PCI_QUIRK(0x1043, 0x80f3,
"AD1985", 48000),
2898 const struct snd_pci_quirk *wl;
2900 wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
2909 #ifdef CONFIG_PROC_FS
2916 snd_iprintf(buffer,
"Intel8x0\n\n");
2919 tmp = igetdword(chip,
ICHREG(GLOB_STA));
2920 snd_iprintf(buffer,
"Global control : 0x%08x\n", igetdword(chip,
ICHREG(GLOB_CNT)));
2921 snd_iprintf(buffer,
"Global status : 0x%08x\n", tmp);
2923 snd_iprintf(buffer,
"SDM : 0x%08x\n", igetdword(chip,
ICHREG(SDM)));
2924 snd_iprintf(buffer,
"AC'97 codecs ready :");
2927 static const char *codecs[3] = {
2928 "primary",
"secondary",
"tertiary"
2932 snd_iprintf(buffer,
" %s", codecs[i]);
2934 snd_iprintf(buffer,
" none");
2935 snd_iprintf(buffer,
"\n");
2938 snd_iprintf(buffer,
"AC'97 codecs SDIN : %i %i %i\n",
2948 if (! snd_card_proc_new(chip->
card,
"intel8x0", &entry))
2949 snd_info_set_text_ops(entry, chip, snd_intel8x0_proc_read);
2952 #define snd_intel8x0_proc_init(x)
2955 static int snd_intel8x0_dev_free(
struct snd_device *device)
2958 return snd_intel8x0_free(chip);
2966 static unsigned int ich_codec_bits[3] = {
2969 static unsigned int sis_codec_bits[3] = {
2980 msg = result ?
"enable (forced) VM" :
"disable (forced) VM";
2986 #ifdef X86_FEATURE_HYPERVISOR
2999 msg =
"enable Parallels VM";
3001 msg =
"disable (unknown or VT-d) VM";
3020 unsigned int int_sta_masks;
3021 struct ichdev *ichdev;
3023 .dev_free = snd_intel8x0_dev_free,
3026 static unsigned int bdbars[] = {
3079 chip->
inside_vm = snd_intel8x0_inside_vm(pci);
3093 chip->
bmaddr = pci_iomap(pci, 0, 0);
3098 chip->
addr = pci_iomap(pci, 2, 0);
3100 chip->
addr = pci_iomap(pci, 0, 0);
3103 snd_intel8x0_free(chip);
3107 chip->
bmaddr = pci_iomap(pci, 3, 0);
3109 chip->
bmaddr = pci_iomap(pci, 1, 0);
3112 snd_intel8x0_free(chip);
3120 switch (device_type) {
3132 ichdev = &chip->
ichd[
i];
3138 ichdev->
roff_sr = ICH_REG_OFF_PICB;
3141 ichdev->
roff_sr = ICH_REG_OFF_SR;
3155 snd_intel8x0_free(chip);
3166 ichdev = &chip->
ichd[
i];
3202 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
3203 snd_intel8x0_free(chip);
3211 snd_intel8x0_free(chip);
3217 snd_intel8x0_free(chip);
3227 static struct shortname_table {
3230 } shortnames[] __devinitdata = {
3249 { 0x003a,
"NVidia MCP04" },
3250 { 0x746d,
"AMD AMD8111" },
3251 { 0x7445,
"AMD AMD768" },
3252 { 0x5455,
"ALi M5455" },
3256 static struct snd_pci_quirk spdif_aclink_defaults[] __devinitdata = {
3257 SND_PCI_QUIRK(0x147b, 0x1c1a,
"ASUS KN8", 1),
3264 const struct snd_pci_quirk *
w;
3266 w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
3270 "AC-Link for %s\n", w->name);
3273 "SPDIF DMA for %s\n", w->name);
3285 struct shortname_table *
name;
3291 if (spdif_aclink < 0)
3292 spdif_aclink = check_default_spdif_aclink(pci);
3295 if (!spdif_aclink) {
3306 for (name = shortnames; name->id; name++) {
3307 if (pci->
device == name->id) {
3313 if (buggy_irq < 0) {
3323 if ((err = snd_intel8x0_create(card, pci, pci_id->
driver_data,
3330 if ((err = snd_intel8x0_mixer(chip, ac97_clock,
ac97_quirk)) < 0) {
3334 if ((err = snd_intel8x0_pcm(chip)) < 0) {
3342 "%s with %s at irq %i", card->
shortname,
3345 if (ac97_clock == 0 || ac97_clock == 1) {
3346 if (ac97_clock == 0) {
3347 if (intel8x0_in_clock_list(chip) == 0)
3348 intel8x0_measure_ac97_clock(chip);
3350 intel8x0_measure_ac97_clock(chip);
3358 pci_set_drvdata(pci, card);
3365 pci_set_drvdata(pci,
NULL);
3369 .name = KBUILD_MODNAME,
3370 .id_table = snd_intel8x0_ids,
3371 .probe = snd_intel8x0_probe,