Commit da2436a2 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] intel8x0: do not use zero value from PICB register

It seems that the zero value from the PICB (position in current buffer)
register is not reliable. Use jiffies to correct returned value
from the ring buffer pointer callback.
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 920e4ae3
...@@ -355,6 +355,9 @@ struct ichdev { ...@@ -355,6 +355,9 @@ struct ichdev {
unsigned int fragsize1; unsigned int fragsize1;
unsigned int position; unsigned int position;
unsigned int pos_shift; unsigned int pos_shift;
unsigned int last_pos;
unsigned long last_pos_jiffies;
unsigned int jiffy_to_bytes;
int frags; int frags;
int lvi; int lvi;
int lvi_frag; int lvi_frag;
...@@ -838,7 +841,10 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd ...@@ -838,7 +841,10 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd
ichdev->suspended = 0; ichdev->suspended = 0;
/* fallthru */ /* fallthru */
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
val = ICH_IOCE | ICH_STARTBM; val = ICH_IOCE | ICH_STARTBM;
ichdev->last_pos = ichdev->position;
ichdev->last_pos_jiffies = jiffies;
break; break;
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
ichdev->suspended = 1; ichdev->suspended = 1;
...@@ -849,9 +855,6 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd ...@@ -849,9 +855,6 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
val = ICH_IOCE; val = ICH_IOCE;
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
val = ICH_IOCE | ICH_STARTBM;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -1045,6 +1048,7 @@ static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -1045,6 +1048,7 @@ static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1; ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
} }
snd_intel8x0_setup_periods(chip, ichdev); snd_intel8x0_setup_periods(chip, ichdev);
ichdev->jiffy_to_bytes = (runtime->rate * 4 * ichdev->pos_shift) / HZ;
return 0; return 0;
} }
...@@ -1053,7 +1057,7 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs ...@@ -1053,7 +1057,7 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs
struct intel8x0 *chip = snd_pcm_substream_chip(substream); struct intel8x0 *chip = snd_pcm_substream_chip(substream);
struct ichdev *ichdev = get_ichdev(substream); struct ichdev *ichdev = get_ichdev(substream);
size_t ptr1, ptr; size_t ptr1, ptr;
int civ, timeout = 100; int civ, timeout = 10;
unsigned int position; unsigned int position;
spin_lock(&chip->reg_lock); spin_lock(&chip->reg_lock);
...@@ -1069,9 +1073,19 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs ...@@ -1069,9 +1073,19 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs
ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb)) ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
break; break;
} while (timeout--); } while (timeout--);
ptr1 <<= ichdev->pos_shift; if (ptr1 != 0) {
ptr = ichdev->fragsize1 - ptr1; ptr1 <<= ichdev->pos_shift;
ptr += position; ptr = ichdev->fragsize1 - ptr1;
ptr += position;
ichdev->last_pos = ptr;
ichdev->last_pos_jiffies = jiffies;
} else {
ptr1 = jiffies - ichdev->last_pos_jiffies;
if (ptr1)
ptr1 -= 1;
ptr = ichdev->last_pos + ptr1 * ichdev->jiffy_to_bytes;
ptr %= ichdev->size;
}
spin_unlock(&chip->reg_lock); spin_unlock(&chip->reg_lock);
if (ptr >= ichdev->size) if (ptr >= ichdev->size)
return 0; return 0;
...@@ -2710,9 +2724,13 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip) ...@@ -2710,9 +2724,13 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb)) pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
break; break;
} while (timeout--); } while (timeout--);
pos = ichdev->fragsize1; if (pos1 == 0) { /* oops, this value is not reliable */
pos -= pos1 << ichdev->pos_shift; pos = 0;
pos += ichdev->position; } else {
pos = ichdev->fragsize1;
pos -= pos1 << ichdev->pos_shift;
pos += ichdev->position;
}
chip->in_measurement = 0; chip->in_measurement = 0;
do_posix_clock_monotonic_gettime(&stop_time); do_posix_clock_monotonic_gettime(&stop_time);
/* stop */ /* stop */
...@@ -2729,6 +2747,11 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip) ...@@ -2729,6 +2747,11 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS); iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
spin_unlock_irq(&chip->reg_lock); spin_unlock_irq(&chip->reg_lock);
if (pos == 0) {
snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n");
return;
}
pos /= 4; pos /= 4;
t = stop_time.tv_sec - start_time.tv_sec; t = stop_time.tv_sec - start_time.tv_sec;
t *= 1000000; t *= 1000000;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment