aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_intel.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda/hda_intel.c')
-rw-r--r--sound/pci/hda/hda_intel.c306
1 files changed, 237 insertions, 69 deletions
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index b3a618eb42cd..16715a68ba5e 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -55,6 +55,7 @@ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
55static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 55static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
56static char *model[SNDRV_CARDS]; 56static char *model[SNDRV_CARDS];
57static int position_fix[SNDRV_CARDS]; 57static int position_fix[SNDRV_CARDS];
58static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
58static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 59static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
59static int single_cmd; 60static int single_cmd;
60static int enable_msi; 61static int enable_msi;
@@ -69,7 +70,9 @@ module_param_array(model, charp, NULL, 0444);
69MODULE_PARM_DESC(model, "Use the given board model."); 70MODULE_PARM_DESC(model, "Use the given board model.");
70module_param_array(position_fix, int, NULL, 0444); 71module_param_array(position_fix, int, NULL, 0444);
71MODULE_PARM_DESC(position_fix, "Fix DMA pointer " 72MODULE_PARM_DESC(position_fix, "Fix DMA pointer "
72 "(0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size)."); 73 "(0 = auto, 1 = none, 2 = POSBUF).");
74module_param_array(bdl_pos_adj, int, NULL, 0644);
75MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
73module_param_array(probe_mask, int, NULL, 0444); 76module_param_array(probe_mask, int, NULL, 0444);
74MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); 77MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
75module_param(single_cmd, bool, 0444); 78module_param(single_cmd, bool, 0444);
@@ -197,6 +200,10 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
197#define ATIHDMI_NUM_CAPTURE 0 200#define ATIHDMI_NUM_CAPTURE 0
198#define ATIHDMI_NUM_PLAYBACK 1 201#define ATIHDMI_NUM_PLAYBACK 1
199 202
203/* TERA has 4 playback and 3 capture */
204#define TERA_NUM_CAPTURE 3
205#define TERA_NUM_PLAYBACK 4
206
200/* this number is statically defined for simplicity */ 207/* this number is statically defined for simplicity */
201#define MAX_AZX_DEV 16 208#define MAX_AZX_DEV 16
202 209
@@ -259,9 +266,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
259/* position fix mode */ 266/* position fix mode */
260enum { 267enum {
261 POS_FIX_AUTO, 268 POS_FIX_AUTO,
262 POS_FIX_NONE, 269 POS_FIX_LPIB,
263 POS_FIX_POSBUF, 270 POS_FIX_POSBUF,
264 POS_FIX_FIFO,
265}; 271};
266 272
267/* Defines for ATI HD Audio support in SB450 south bridge */ 273/* Defines for ATI HD Audio support in SB450 south bridge */
@@ -285,6 +291,7 @@ struct azx_dev {
285 u32 *posbuf; /* position buffer pointer */ 291 u32 *posbuf; /* position buffer pointer */
286 292
287 unsigned int bufsize; /* size of the play buffer in bytes */ 293 unsigned int bufsize; /* size of the play buffer in bytes */
294 unsigned int period_bytes; /* size of the period in bytes */
288 unsigned int frags; /* number for period in the play buffer */ 295 unsigned int frags; /* number for period in the play buffer */
289 unsigned int fifo_size; /* FIFO size */ 296 unsigned int fifo_size; /* FIFO size */
290 297
@@ -301,11 +308,11 @@ struct azx_dev {
301 */ 308 */
302 unsigned char stream_tag; /* assigned stream */ 309 unsigned char stream_tag; /* assigned stream */
303 unsigned char index; /* stream index */ 310 unsigned char index; /* stream index */
304 /* for sanity check of position buffer */
305 unsigned int period_intr;
306 311
307 unsigned int opened :1; 312 unsigned int opened :1;
308 unsigned int running :1; 313 unsigned int running :1;
314 unsigned int irq_pending :1;
315 unsigned int irq_ignore :1;
309}; 316};
310 317
311/* CORB/RIRB */ 318/* CORB/RIRB */
@@ -323,6 +330,7 @@ struct azx_rb {
323struct azx { 330struct azx {
324 struct snd_card *card; 331 struct snd_card *card;
325 struct pci_dev *pci; 332 struct pci_dev *pci;
333 int dev_index;
326 334
327 /* chip type specific */ 335 /* chip type specific */
328 int driver_type; 336 int driver_type;
@@ -366,9 +374,13 @@ struct azx {
366 unsigned int single_cmd :1; 374 unsigned int single_cmd :1;
367 unsigned int polling_mode :1; 375 unsigned int polling_mode :1;
368 unsigned int msi :1; 376 unsigned int msi :1;
377 unsigned int irq_pending_warned :1;
369 378
370 /* for debugging */ 379 /* for debugging */
371 unsigned int last_cmd; /* last issued command (to sync) */ 380 unsigned int last_cmd; /* last issued command (to sync) */
381
382 /* for pending irqs */
383 struct work_struct irq_pending_work;
372}; 384};
373 385
374/* driver types */ 386/* driver types */
@@ -381,6 +393,7 @@ enum {
381 AZX_DRIVER_SIS, 393 AZX_DRIVER_SIS,
382 AZX_DRIVER_ULI, 394 AZX_DRIVER_ULI,
383 AZX_DRIVER_NVIDIA, 395 AZX_DRIVER_NVIDIA,
396 AZX_DRIVER_TERA,
384}; 397};
385 398
386static char *driver_short_names[] __devinitdata = { 399static char *driver_short_names[] __devinitdata = {
@@ -392,6 +405,7 @@ static char *driver_short_names[] __devinitdata = {
392 [AZX_DRIVER_SIS] = "HDA SIS966", 405 [AZX_DRIVER_SIS] = "HDA SIS966",
393 [AZX_DRIVER_ULI] = "HDA ULI M5461", 406 [AZX_DRIVER_ULI] = "HDA ULI M5461",
394 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 407 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
408 [AZX_DRIVER_TERA] = "HDA Teradici",
395}; 409};
396 410
397/* 411/*
@@ -426,11 +440,6 @@ static char *driver_short_names[] __devinitdata = {
426/* for pcm support */ 440/* for pcm support */
427#define get_azx_dev(substream) (substream->runtime->private_data) 441#define get_azx_dev(substream) (substream->runtime->private_data)
428 442
429/* Get the upper 32bit of the given dma_addr_t
430 * Compiler should optimize and eliminate the code if dma_addr_t is 32bit
431 */
432#define upper_32bit(addr) (sizeof(addr) > 4 ? (u32)((addr) >> 32) : (u32)0)
433
434static int azx_acquire_irq(struct azx *chip, int do_disconnect); 443static int azx_acquire_irq(struct azx *chip, int do_disconnect);
435 444
436/* 445/*
@@ -461,7 +470,7 @@ static void azx_init_cmd_io(struct azx *chip)
461 chip->corb.addr = chip->rb.addr; 470 chip->corb.addr = chip->rb.addr;
462 chip->corb.buf = (u32 *)chip->rb.area; 471 chip->corb.buf = (u32 *)chip->rb.area;
463 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr); 472 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
464 azx_writel(chip, CORBUBASE, upper_32bit(chip->corb.addr)); 473 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
465 474
466 /* set the corb size to 256 entries (ULI requires explicitly) */ 475 /* set the corb size to 256 entries (ULI requires explicitly) */
467 azx_writeb(chip, CORBSIZE, 0x02); 476 azx_writeb(chip, CORBSIZE, 0x02);
@@ -476,7 +485,7 @@ static void azx_init_cmd_io(struct azx *chip)
476 chip->rirb.addr = chip->rb.addr + 2048; 485 chip->rirb.addr = chip->rb.addr + 2048;
477 chip->rirb.buf = (u32 *)(chip->rb.area + 2048); 486 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
478 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); 487 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
479 azx_writel(chip, RIRBUBASE, upper_32bit(chip->rirb.addr)); 488 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
480 489
481 /* set the rirb size to 256 entries (ULI requires explicitly) */ 490 /* set the rirb size to 256 entries (ULI requires explicitly) */
482 azx_writeb(chip, RIRBSIZE, 0x02); 491 azx_writeb(chip, RIRBSIZE, 0x02);
@@ -847,7 +856,7 @@ static void azx_init_chip(struct azx *chip)
847 856
848 /* program the position buffer */ 857 /* program the position buffer */
849 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); 858 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
850 azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr)); 859 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
851 860
852 chip->initialized = 1; 861 chip->initialized = 1;
853} 862}
@@ -908,6 +917,8 @@ static void azx_init_pci(struct azx *chip)
908} 917}
909 918
910 919
920static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
921
911/* 922/*
912 * interrupt handler 923 * interrupt handler
913 */ 924 */
@@ -930,11 +941,23 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
930 azx_dev = &chip->azx_dev[i]; 941 azx_dev = &chip->azx_dev[i];
931 if (status & azx_dev->sd_int_sta_mask) { 942 if (status & azx_dev->sd_int_sta_mask) {
932 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); 943 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
933 if (azx_dev->substream && azx_dev->running) { 944 if (!azx_dev->substream || !azx_dev->running)
934 azx_dev->period_intr++; 945 continue;
946 /* ignore the first dummy IRQ (due to pos_adj) */
947 if (azx_dev->irq_ignore) {
948 azx_dev->irq_ignore = 0;
949 continue;
950 }
951 /* check whether this IRQ is really acceptable */
952 if (azx_position_ok(chip, azx_dev)) {
953 azx_dev->irq_pending = 0;
935 spin_unlock(&chip->reg_lock); 954 spin_unlock(&chip->reg_lock);
936 snd_pcm_period_elapsed(azx_dev->substream); 955 snd_pcm_period_elapsed(azx_dev->substream);
937 spin_lock(&chip->reg_lock); 956 spin_lock(&chip->reg_lock);
957 } else {
958 /* bogus IRQ, process it later */
959 azx_dev->irq_pending = 1;
960 schedule_work(&chip->irq_pending_work);
938 } 961 }
939 } 962 }
940 } 963 }
@@ -959,59 +982,107 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
959 982
960 983
961/* 984/*
985 * set up a BDL entry
986 */
987static int setup_bdle(struct snd_pcm_substream *substream,
988 struct azx_dev *azx_dev, u32 **bdlp,
989 int ofs, int size, int with_ioc)
990{
991 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
992 u32 *bdl = *bdlp;
993
994 while (size > 0) {
995 dma_addr_t addr;
996 int chunk;
997
998 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
999 return -EINVAL;
1000
1001 addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
1002 /* program the address field of the BDL entry */
1003 bdl[0] = cpu_to_le32((u32)addr);
1004 bdl[1] = cpu_to_le32(upper_32_bits(addr));
1005 /* program the size field of the BDL entry */
1006 chunk = PAGE_SIZE - (ofs % PAGE_SIZE);
1007 if (size < chunk)
1008 chunk = size;
1009 bdl[2] = cpu_to_le32(chunk);
1010 /* program the IOC to enable interrupt
1011 * only when the whole fragment is processed
1012 */
1013 size -= chunk;
1014 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
1015 bdl += 4;
1016 azx_dev->frags++;
1017 ofs += chunk;
1018 }
1019 *bdlp = bdl;
1020 return ofs;
1021}
1022
1023/*
962 * set up BDL entries 1024 * set up BDL entries
963 */ 1025 */
964static int azx_setup_periods(struct snd_pcm_substream *substream, 1026static int azx_setup_periods(struct azx *chip,
1027 struct snd_pcm_substream *substream,
965 struct azx_dev *azx_dev) 1028 struct azx_dev *azx_dev)
966{ 1029{
967 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
968 u32 *bdl; 1030 u32 *bdl;
969 int i, ofs, periods, period_bytes; 1031 int i, ofs, periods, period_bytes;
1032 int pos_adj;
970 1033
971 /* reset BDL address */ 1034 /* reset BDL address */
972 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1035 azx_sd_writel(azx_dev, SD_BDLPL, 0);
973 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1036 azx_sd_writel(azx_dev, SD_BDLPU, 0);
974 1037
975 period_bytes = snd_pcm_lib_period_bytes(substream); 1038 period_bytes = snd_pcm_lib_period_bytes(substream);
1039 azx_dev->period_bytes = period_bytes;
976 periods = azx_dev->bufsize / period_bytes; 1040 periods = azx_dev->bufsize / period_bytes;
977 1041
978 /* program the initial BDL entries */ 1042 /* program the initial BDL entries */
979 bdl = (u32 *)azx_dev->bdl.area; 1043 bdl = (u32 *)azx_dev->bdl.area;
980 ofs = 0; 1044 ofs = 0;
981 azx_dev->frags = 0; 1045 azx_dev->frags = 0;
982 for (i = 0; i < periods; i++) { 1046 azx_dev->irq_ignore = 0;
983 int size, rest; 1047 pos_adj = bdl_pos_adj[chip->dev_index];
984 if (i >= AZX_MAX_BDL_ENTRIES) { 1048 if (pos_adj > 0) {
985 snd_printk(KERN_ERR "Too many BDL entries: " 1049 struct snd_pcm_runtime *runtime = substream->runtime;
986 "buffer=%d, period=%d\n", 1050 pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
987 azx_dev->bufsize, period_bytes); 1051 if (!pos_adj)
988 /* reset */ 1052 pos_adj = 1;
989 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1053 pos_adj = frames_to_bytes(runtime, pos_adj);
990 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1054 if (pos_adj >= period_bytes) {
991 return -EINVAL; 1055 snd_printk(KERN_WARNING "Too big adjustment %d\n",
1056 bdl_pos_adj[chip->dev_index]);
1057 pos_adj = 0;
1058 } else {
1059 ofs = setup_bdle(substream, azx_dev,
1060 &bdl, ofs, pos_adj, 1);
1061 if (ofs < 0)
1062 goto error;
1063 azx_dev->irq_ignore = 1;
992 } 1064 }
993 rest = period_bytes; 1065 } else
994 do { 1066 pos_adj = 0;
995 dma_addr_t addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs); 1067 for (i = 0; i < periods; i++) {
996 /* program the address field of the BDL entry */ 1068 if (i == periods - 1 && pos_adj)
997 bdl[0] = cpu_to_le32((u32)addr); 1069 ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
998 bdl[1] = cpu_to_le32(upper_32bit(addr)); 1070 period_bytes - pos_adj, 0);
999 /* program the size field of the BDL entry */ 1071 else
1000 size = PAGE_SIZE - (ofs % PAGE_SIZE); 1072 ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
1001 if (rest < size) 1073 period_bytes, 1);
1002 size = rest; 1074 if (ofs < 0)
1003 bdl[2] = cpu_to_le32(size); 1075 goto error;
1004 /* program the IOC to enable interrupt
1005 * only when the whole fragment is processed
1006 */
1007 rest -= size;
1008 bdl[3] = rest ? 0 : cpu_to_le32(0x01);
1009 bdl += 4;
1010 azx_dev->frags++;
1011 ofs += size;
1012 } while (rest > 0);
1013 } 1076 }
1014 return 0; 1077 return 0;
1078
1079 error:
1080 snd_printk(KERN_ERR "Too many BDL entries: buffer=%d, period=%d\n",
1081 azx_dev->bufsize, period_bytes);
1082 /* reset */
1083 azx_sd_writel(azx_dev, SD_BDLPL, 0);
1084 azx_sd_writel(azx_dev, SD_BDLPU, 0);
1085 return -EINVAL;
1015} 1086}
1016 1087
1017/* 1088/*
@@ -1062,7 +1133,7 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1062 /* lower BDL address */ 1133 /* lower BDL address */
1063 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr); 1134 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
1064 /* upper BDL address */ 1135 /* upper BDL address */
1065 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl.addr)); 1136 azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
1066 1137
1067 /* enable the position buffer */ 1138 /* enable the position buffer */
1068 if (chip->position_fix == POS_FIX_POSBUF || 1139 if (chip->position_fix == POS_FIX_POSBUF ||
@@ -1085,7 +1156,7 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1085 */ 1156 */
1086 1157
1087static unsigned int azx_max_codecs[] __devinitdata = { 1158static unsigned int azx_max_codecs[] __devinitdata = {
1088 [AZX_DRIVER_ICH] = 3, 1159 [AZX_DRIVER_ICH] = 4, /* Some ICH9 boards use SD3 */
1089 [AZX_DRIVER_SCH] = 3, 1160 [AZX_DRIVER_SCH] = 3,
1090 [AZX_DRIVER_ATI] = 4, 1161 [AZX_DRIVER_ATI] = 4,
1091 [AZX_DRIVER_ATIHDMI] = 4, 1162 [AZX_DRIVER_ATIHDMI] = 4,
@@ -1093,6 +1164,7 @@ static unsigned int azx_max_codecs[] __devinitdata = {
1093 [AZX_DRIVER_SIS] = 3, /* FIXME: correct? */ 1164 [AZX_DRIVER_SIS] = 3, /* FIXME: correct? */
1094 [AZX_DRIVER_ULI] = 3, /* FIXME: correct? */ 1165 [AZX_DRIVER_ULI] = 3, /* FIXME: correct? */
1095 [AZX_DRIVER_NVIDIA] = 3, /* FIXME: correct? */ 1166 [AZX_DRIVER_NVIDIA] = 3, /* FIXME: correct? */
1167 [AZX_DRIVER_TERA] = 1,
1096}; 1168};
1097 1169
1098static int __devinit azx_codec_create(struct azx *chip, const char *model, 1170static int __devinit azx_codec_create(struct azx *chip, const char *model,
@@ -1316,7 +1388,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1316 1388
1317 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n", 1389 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
1318 azx_dev->bufsize, azx_dev->format_val); 1390 azx_dev->bufsize, azx_dev->format_val);
1319 if (azx_setup_periods(substream, azx_dev) < 0) 1391 if (azx_setup_periods(chip, substream, azx_dev) < 0)
1320 return -EINVAL; 1392 return -EINVAL;
1321 azx_setup_controller(chip, azx_dev); 1393 azx_setup_controller(chip, azx_dev);
1322 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1394 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1421,35 +1493,113 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1421 return 0; 1493 return 0;
1422} 1494}
1423 1495
1424static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) 1496static unsigned int azx_get_position(struct azx *chip,
1497 struct azx_dev *azx_dev)
1425{ 1498{
1426 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1427 struct azx *chip = apcm->chip;
1428 struct azx_dev *azx_dev = get_azx_dev(substream);
1429 unsigned int pos; 1499 unsigned int pos;
1430 1500
1431 if (chip->position_fix == POS_FIX_POSBUF || 1501 if (chip->position_fix == POS_FIX_POSBUF ||
1432 chip->position_fix == POS_FIX_AUTO) { 1502 chip->position_fix == POS_FIX_AUTO) {
1433 /* use the position buffer */ 1503 /* use the position buffer */
1434 pos = le32_to_cpu(*azx_dev->posbuf); 1504 pos = le32_to_cpu(*azx_dev->posbuf);
1435 if (chip->position_fix == POS_FIX_AUTO &&
1436 azx_dev->period_intr == 1 && !pos) {
1437 printk(KERN_WARNING
1438 "hda-intel: Invalid position buffer, "
1439 "using LPIB read method instead.\n");
1440 chip->position_fix = POS_FIX_NONE;
1441 goto read_lpib;
1442 }
1443 } else { 1505 } else {
1444 read_lpib:
1445 /* read LPIB */ 1506 /* read LPIB */
1446 pos = azx_sd_readl(azx_dev, SD_LPIB); 1507 pos = azx_sd_readl(azx_dev, SD_LPIB);
1447 if (chip->position_fix == POS_FIX_FIFO)
1448 pos += azx_dev->fifo_size;
1449 } 1508 }
1450 if (pos >= azx_dev->bufsize) 1509 if (pos >= azx_dev->bufsize)
1451 pos = 0; 1510 pos = 0;
1452 return bytes_to_frames(substream->runtime, pos); 1511 return pos;
1512}
1513
1514static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
1515{
1516 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1517 struct azx *chip = apcm->chip;
1518 struct azx_dev *azx_dev = get_azx_dev(substream);
1519 return bytes_to_frames(substream->runtime,
1520 azx_get_position(chip, azx_dev));
1521}
1522
1523/*
1524 * Check whether the current DMA position is acceptable for updating
1525 * periods. Returns non-zero if it's OK.
1526 *
1527 * Many HD-audio controllers appear pretty inaccurate about
1528 * the update-IRQ timing. The IRQ is issued before actually the
1529 * data is processed. So, we need to process it afterwords in a
1530 * workqueue.
1531 */
1532static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1533{
1534 unsigned int pos;
1535
1536 pos = azx_get_position(chip, azx_dev);
1537 if (chip->position_fix == POS_FIX_AUTO) {
1538 if (!pos) {
1539 printk(KERN_WARNING
1540 "hda-intel: Invalid position buffer, "
1541 "using LPIB read method instead.\n");
1542 chip->position_fix = POS_FIX_LPIB;
1543 pos = azx_get_position(chip, azx_dev);
1544 } else
1545 chip->position_fix = POS_FIX_POSBUF;
1546 }
1547
1548 if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
1549 return 0; /* NG - it's below the period boundary */
1550 return 1; /* OK, it's fine */
1551}
1552
1553/*
1554 * The work for pending PCM period updates.
1555 */
1556static void azx_irq_pending_work(struct work_struct *work)
1557{
1558 struct azx *chip = container_of(work, struct azx, irq_pending_work);
1559 int i, pending;
1560
1561 if (!chip->irq_pending_warned) {
1562 printk(KERN_WARNING
1563 "hda-intel: IRQ timing workaround is activated "
1564 "for card #%d. Suggest a bigger bdl_pos_adj.\n",
1565 chip->card->number);
1566 chip->irq_pending_warned = 1;
1567 }
1568
1569 for (;;) {
1570 pending = 0;
1571 spin_lock_irq(&chip->reg_lock);
1572 for (i = 0; i < chip->num_streams; i++) {
1573 struct azx_dev *azx_dev = &chip->azx_dev[i];
1574 if (!azx_dev->irq_pending ||
1575 !azx_dev->substream ||
1576 !azx_dev->running)
1577 continue;
1578 if (azx_position_ok(chip, azx_dev)) {
1579 azx_dev->irq_pending = 0;
1580 spin_unlock(&chip->reg_lock);
1581 snd_pcm_period_elapsed(azx_dev->substream);
1582 spin_lock(&chip->reg_lock);
1583 } else
1584 pending++;
1585 }
1586 spin_unlock_irq(&chip->reg_lock);
1587 if (!pending)
1588 return;
1589 cond_resched();
1590 }
1591}
1592
1593/* clear irq_pending flags and assure no on-going workq */
1594static void azx_clear_irq_pending(struct azx *chip)
1595{
1596 int i;
1597
1598 spin_lock_irq(&chip->reg_lock);
1599 for (i = 0; i < chip->num_streams; i++)
1600 chip->azx_dev[i].irq_pending = 0;
1601 spin_unlock_irq(&chip->reg_lock);
1602 flush_scheduled_work();
1453} 1603}
1454 1604
1455static struct snd_pcm_ops azx_pcm_ops = { 1605static struct snd_pcm_ops azx_pcm_ops = {
@@ -1676,6 +1826,7 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1676 int i; 1826 int i;
1677 1827
1678 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1828 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1829 azx_clear_irq_pending(chip);
1679 for (i = 0; i < AZX_MAX_PCMS; i++) 1830 for (i = 0; i < AZX_MAX_PCMS; i++)
1680 snd_pcm_suspend_all(chip->pcm[i]); 1831 snd_pcm_suspend_all(chip->pcm[i]);
1681 if (chip->initialized) 1832 if (chip->initialized)
@@ -1732,6 +1883,7 @@ static int azx_free(struct azx *chip)
1732 int i; 1883 int i;
1733 1884
1734 if (chip->initialized) { 1885 if (chip->initialized) {
1886 azx_clear_irq_pending(chip);
1735 for (i = 0; i < chip->num_streams; i++) 1887 for (i = 0; i < chip->num_streams; i++)
1736 azx_stream_stop(chip, &chip->azx_dev[i]); 1888 azx_stream_stop(chip, &chip->azx_dev[i]);
1737 azx_stop_chip(chip); 1889 azx_stop_chip(chip);
@@ -1770,9 +1922,9 @@ static int azx_dev_free(struct snd_device *device)
1770 * white/black-listing for position_fix 1922 * white/black-listing for position_fix
1771 */ 1923 */
1772static struct snd_pci_quirk position_fix_list[] __devinitdata = { 1924static struct snd_pci_quirk position_fix_list[] __devinitdata = {
1773 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE), 1925 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
1774 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE), 1926 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
1775 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_NONE), 1927 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
1776 {} 1928 {}
1777}; 1929};
1778 1930
@@ -1857,12 +2009,25 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1857 chip->irq = -1; 2009 chip->irq = -1;
1858 chip->driver_type = driver_type; 2010 chip->driver_type = driver_type;
1859 chip->msi = enable_msi; 2011 chip->msi = enable_msi;
2012 chip->dev_index = dev;
2013 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
1860 2014
1861 chip->position_fix = check_position_fix(chip, position_fix[dev]); 2015 chip->position_fix = check_position_fix(chip, position_fix[dev]);
1862 check_probe_mask(chip, dev); 2016 check_probe_mask(chip, dev);
1863 2017
1864 chip->single_cmd = single_cmd; 2018 chip->single_cmd = single_cmd;
1865 2019
2020 if (bdl_pos_adj[dev] < 0) {
2021 switch (chip->driver_type) {
2022 case AZX_DRIVER_ICH:
2023 bdl_pos_adj[dev] = 1;
2024 break;
2025 default:
2026 bdl_pos_adj[dev] = 32;
2027 break;
2028 }
2029 }
2030
1866#if BITS_PER_LONG != 64 2031#if BITS_PER_LONG != 64
1867 /* Fix up base address on ULI M5461 */ 2032 /* Fix up base address on ULI M5461 */
1868 if (chip->driver_type == AZX_DRIVER_ULI) { 2033 if (chip->driver_type == AZX_DRIVER_ULI) {
@@ -2089,6 +2254,7 @@ static struct pci_device_id azx_ids[] = {
2089 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH }, 2254 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
2090 { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH }, 2255 { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
2091 { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH }, 2256 { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
2257 { PCI_DEVICE(0x8086, 0x2911), .driver_data = AZX_DRIVER_ICH },
2092 { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH }, 2258 { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
2093 { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH }, 2259 { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
2094 { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH }, 2260 { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
@@ -2141,6 +2307,8 @@ static struct pci_device_id azx_ids[] = {
2141 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA }, 2307 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
2142 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA }, 2308 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
2143 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA }, 2309 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
2310 /* Teradici */
2311 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
2144 { 0, } 2312 { 0, }
2145}; 2313};
2146MODULE_DEVICE_TABLE(pci, azx_ids); 2314MODULE_DEVICE_TABLE(pci, azx_ids);