Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ec775e7 authored by Jaroslav Kysela's avatar Jaroslav Kysela
Browse files

[ALSA] intel8x0: add one retry to the ac97_clock measurement routine



It seems that on some hardware platforms, the first measurement is wrong.
This patch adds second measurement to this case.

Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 29dab4fd
Loading
Loading
Loading
Loading
+11 −4
Original line number Original line Diff line number Diff line
@@ -2676,12 +2676,13 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
	struct ichdev *ichdev;
	struct ichdev *ichdev;
	unsigned long port;
	unsigned long port;
	unsigned long pos, pos1, t;
	unsigned long pos, pos1, t;
	int civ, timeout = 1000;
	int civ, timeout = 1000, attempt = 1;
	struct timespec start_time, stop_time;
	struct timespec start_time, stop_time;


	if (chip->ac97_bus->clock != 48000)
	if (chip->ac97_bus->clock != 48000)
		return; /* specified in module option */
		return; /* specified in module option */


      __again:
	subs = chip->pcm[0]->streams[0].substream;
	subs = chip->pcm[0]->streams[0].substream;
	if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
	if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
		snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
		snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
@@ -2749,6 +2750,11 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)


	if (pos == 0) {
	if (pos == 0) {
		snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n");
		snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n");
	      __retry:
		if (attempt < 2) {
			attempt++;
			goto __again;
		}
		return;
		return;
	}
	}


@@ -2759,14 +2765,15 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
	printk(KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
	printk(KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
	if (t == 0) {
	if (t == 0) {
		snd_printk(KERN_ERR "intel8x0: ?? calculation error..\n");
		snd_printk(KERN_ERR "intel8x0: ?? calculation error..\n");
		return;
		goto __retry;
	}
	}
	pos *= 1000;
	pos *= 1000;
	pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
	pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
	if (pos < 40000 || pos >= 60000) 
	if (pos < 40000 || pos >= 60000) {
		/* abnormal value. hw problem? */
		/* abnormal value. hw problem? */
		printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
		printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
	else if (pos > 40500 && pos < 41500)
		goto __retry;
	} else if (pos > 40500 && pos < 41500)
		/* first exception - 41000Hz reference clock */
		/* first exception - 41000Hz reference clock */
		chip->ac97_bus->clock = 41000;
		chip->ac97_bus->clock = 41000;
	else if (pos > 43600 && pos < 44600)
	else if (pos > 43600 && pos < 44600)