Skip to contentSkip to conversation

PATCH] SPDIF out clock sync for via8235 / ALC650

PATCH Antonin ENFRUN 3 participants 7 messages Nov 26, 2002 – Feb 3, 2003 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

I'm using alsa-driver 0.9.0rc6 on an Asus A7V8X (via8235 southbridge and ALC650 -ac97 compatible- codec).

PCM output is fine on the main analog channel, but SPDIF out is not working for any FS != 48khz. Looking at the source, the SPDIF out is initialised at 48Khz on startup, and there is no way to change it. But the ALC650 disable SPDIF out if SPDIF clock is not the same as the clock used on the corresponding ac-link channel (I don't know if it's a standard AC97 behaviour ?)

The patch included tracks clock change on the main DAC channel, and updates the SPDIF clock accordingly : it allows SPDIF out to output the main PCM channel, when the sample rate is 32K, 44.1K or 48K.

If there is a better solution, let me know !

TODO:
* Test for the codec used (if other codecs don't need this ?)
* Check the channel/slot on AC97-SPSA to track the corresponding clock.

On a side note, how can I send PCM to the other channels (rear, lfe/front and spdif) ? And is there already an API to get/set the SPDIF clock ?

Thanks for any feedback / suggestions !

Signature · 1 line
Antonin ENFRUN <[email protected]>
alsa-kernel/pci/ac97/ac97_codec.c +52 -1
@@ -1946,6 +1946,51 @@
  *  PCM support
  */
 
+
+// AE: Updating SPDIF Clock
+static void ae_set_spdif(ac97_t *ac97, unsigned short rate)
+{  
+	unsigned short old, new;
+	
+	// Get new SPDIF Rate
+	switch(rate) {
+	case 48000:
+		rate = AC97_SC_SPSR_48K;
+		break;
+		
+	case 44100:
+		rate = AC97_SC_SPSR_44K;
+		break;
+		
+	case 32000:
+		rate = AC97_SC_SPSR_32K;
+		break;
+		
+	default:
+		rate = AC97_SC_SPSR_48K;
+		break;
+	}
+	
+	
+	// Do we need to change SR ?
+	old = ac97->regs[AC97_SPDIF];
+	new = (old & ~  AC97_SC_SPSR_MASK) | rate;
+	if (old != new) {
+		
+		// Disable SPDIF
+		snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+		
+		
+		// Set SPDIF out RATE
+		snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, rate);
+		
+		
+		// Re-Enable SPDIF
+		snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
+  }
+}
+
+
 int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned short rate)
 {
 	unsigned short mask;
@@ -1978,7 +2023,13 @@
 	if (tmp > 65535)
 		return -EINVAL;
 	snd_ac97_update(ac97, reg, tmp & 0xffff);
-	snd_ac97_read(ac97, reg);
+	rate = snd_ac97_read(ac97, reg);
+	
+	// AE: Set SPDIF out RATE  
+	if (reg == AC97_PCM_FRONT_DAC_RATE) {
+	  ae_set_spdif(ac97, rate);
+	}
+
 	return 0;
 }
 
#1 lore raw

Hi,

At 26 Nov 2002 12:42:12 +0100,

Quoted 11 lines · Antonin ENFRUN

I'm using alsa-driver 0.9.0rc6 on an Asus A7V8X (via8235 southbridge and ALC650 -ac97 compatible- codec).

PCM output is fine on the main analog channel, but SPDIF out is not working for any FS != 48khz. Looking at the source, the SPDIF out is initialised at 48Khz on startup, and there is no way to change it. But the ALC650 disable SPDIF out if SPDIF clock is not the same as the clock used on the corresponding ac-link channel (I don't know if it's a standard AC97 behaviour ?)

Quoted 3 lines

The patch included tracks clock change on the main DAC channel, and updates the SPDIF clock accordingly : it allows SPDIF out to output the main PCM channel, when the sample rate is 32K, 44.1K or 48K.

thanks for your patch!

we have already a method to change the spdif rate:

	snd_ac97_set_rate(ac97, AC97_SPDIF, rate);

but it didn't work properly. so i fixed the relevant part based on your patch.

to via82xx.c, the above call was just added, so that the spdif rate is automatically changed.

Quoted 9 lines

If there is a better solution, let me know !

TODO:
* Test for the codec used (if other codecs don't need this ?)
* Check the channel/slot on AC97-SPSA to track the corresponding clock.

On a side note, how can I send PCM to the other channels (rear, lfe/front and spdif) ?

you can use 4 or 6 channel interleaved samples.

Quoted 1 line

And is there already an API to get/set the SPDIF clock ?

it's possible also to use a control "IEC958 Playback Default" and set iec958 status bits.

ciao,

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en

#2 lore raw
Quoted 7 lines · Takashi Iwai

we have already a method to change the spdif rate:

	snd_ac97_set_rate(ac97, AC97_SPDIF, rate);

but it didn't work properly. so i fixed the relevant part based on your patch.

to via82xx.c, the above call was just added, so that the spdif rate is automatically changed.

I have produced a minimal patch based upon your work in CVS to get the SPDIF port going on A7V8X motherboards with 0.9.0rc6 until 0.9.0rc7 is released:

alsa-kernel/pci/via82xx.c renamed from alsa-kernel/pci/via82xx.c.orig +3 -0
@@ -613,6 +613,9 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 
 	snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
 	if (chip->chip_type == TYPE_VIA8233 &&
 	    chip->playback.reg_offset != VIA_REG_MULTPLAY_STATUS) {
 		unsigned int tmp;
alsa-kernel/pci/ac97/ac97_codec.c renamed from alsa-kernel/pci/ac97/ac97_codec.c.orig +42 -2

56 lines not on this page · raw message

Signature · 7 lines
John GOTTS <[email protected]>  http://linuxsavvy.com/staff/jgotts


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
#3 lore raw

In message <[email protected]>, [email protected]

Quoted 2 lines · om

I have produced a minimal patch based upon your work in CVS to get the SPDIF port going on A7V8X motherboards with 0.9.0rc6 until 0.9.0rc7 is released:

I'm not sure what went wrong with 0.9.0rc7, but SPDIF output still doesn't work with my chipset. The patch only had cosmetic changes in the 0.9.0rc7 release, so something must have been broken between the CVS tree as of December 30th and the 0.9.0rc7 release.

The line out does work...

John

Signature · 7 lines
John GOTTS <[email protected]>  http://linuxsavvy.com/staff/jgotts


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
#4 lore raw

At Sun, 02 Feb 2003 07:03:02 -0500,

Quoted 11 lines · [email protected] wrote:

In message <[email protected]>, [email protected]

Quoted 2 lines · om

I have produced a minimal patch based upon your work in CVS to get the SPDIF port going on A7V8X motherboards with 0.9.0rc6 until 0.9.0rc7 is released:

I'm not sure what went wrong with 0.9.0rc7, but SPDIF output still doesn't work with my chipset. The patch only had cosmetic changes in the 0.9.0rc7 release, so something must have been broken between the CVS tree as of December 30th and the 0.9.0rc7 release.

on rc7, you don't need a patch. try to use "spdif" pcm for the spdif output. it uses the SDX3 channel as described in the data sheet.

playing through the spdif-out on the multi-channel is still posstible, too. but you need to reset "IEC958 AC97-SPSA" to 0, which corresponds to the slot 3/4, while the slot 10/11 is used as default on via823x.

ciao,

Takashi

-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

#6 lore raw
In reply to a message not in the archive

At Mon, 03 Feb 2003 11:36:30 +0100,

Quoted 24 lines · David Björkevik
Quoted 15 lines · Takashi Iwai

At Sun, 02 Feb 2003 07:03:02 -0500,

Quoted 11 lines · [email protected] wrote:

In message <[email protected]>, [email protected]

Quoted 2 lines · om

I have produced a minimal patch based upon your work in CVS to get the SPDIF port going on A7V8X motherboards with 0.9.0rc6 until 0.9.0rc7 is released:

I'm not sure what went wrong with 0.9.0rc7, but SPDIF output still doesn't work with my chipset. The patch only had cosmetic changes in the 0.9.0rc7 release, so something must have been broken between the CVS tree as of December 30th and the 0.9.0rc7 release.

Quoted 6 lines

on rc7, you don't need a patch. try to use "spdif" pcm for the spdif output. it uses the SDX3 channel as described in the data sheet.

playing through the spdif-out on the multi-channel is still posstible, too. but you need to reset "IEC958 AC97-SPSA" to 0, which corresponds to the slot 3/4, while the slot 10/11 is used as default on via823x.

Quoted 6 lines

This did not work for me. Using rc7 my DAC does not lock to a signal using any combination of spdif/default output or AC97-SPSA setting.

When applying jgotts patch to rc6 I managed to get lock on some combinations, but the signal still seemed strange and my DAC did not produce any sound.

hmm.

the behavior of via82xx driver depends on the chip model. hence, first, please check your chip model listed on /proc/asound/cards.

if it's a VIA8233A, you need to set

- "IEC958 Output" to true
- "IEC958 Playback" to true
- "IEC958 SPSA" to 0

i'm not sure whether "IEC958 Output" can be false. this register bit controls the DSX3 channel spdif output.

the playback on the DSX3 channel is implemented as hw:1 but i don't know whether this channel is available on VIA8233A.

if you have VIA8233A, please check whether playback on hw:1 does work (regardless whether the sound comes out or not).

% aplay -Dhw:1 foo.wav

if you have another VIA823x, namely, 8233, 8233C and 8235 chips, you must have valid DSX channels.

Takashi

-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

#8 lore raw
In reply to a message not in the archive

At Mon, 03 Feb 2003 12:07:15 +0100,

Quoted 17 lines · David Björkevik

Thank you for trying to help me fix this.

Quoted 7 lines · Takashi Iwai
Quoted 6 lines

This did not work for me. Using rc7 my DAC does not lock to a signal using any combination of spdif/default output or AC97-SPSA setting.

When applying jgotts patch to rc6 I managed to get lock on some combinations, but the signal still seemed strange and my DAC did not produce any sound.

Quoted 5 lines

hmm.

the behavior of via82xx driver depends on the chip model. hence, first, please check your chip model listed on /proc/asound/cards.

Quoted 7 lines

This gives me

0 [VIA ]: VIA8233 - VIA 823x rev80

                     VIA 823x rev80 at 0xd800, irq 22

This would indicate a 8235-chip (according to the defines in via82xx.c)...

yep, there was a bug in the driver. already fixed on cvs. but it doesn't matter for the behavior of the driver. the audio part of 8235 is identical with 8233.

Quoted 5 lines
Quoted 2 lines

if you have another VIA823x, namely, 8233, 8233C and 8235 chips, you must have valid DSX channels.

I guess this will make me sound stupid, but I don't know what a DSX channel is or how to get valid ones =)

the 8233 (and 8235) chip has two different paths for playback. one is called DSX (direct sound) and 8233 has 4 channels. by using these channels, you can do up to 4 playbacks simultaneously. the spdif is output from the DSX3 channel usually with ac97 slot 10/11.

another is the "multi-channel" playback, which supports the 4 or 6 channels outputs. this is supported on every 823x chip.

it seems these two outputs are exclusive. if DSX is used, multi-chanenl cannot be used, and vice versa.

Takashi

-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com