All of lore.kernel.org
 help / color / mirror / Atom feed
* PATCH] SPDIF out clock sync for via8235 / ALC650
@ 2002-11-26 11:42 Antonin ENFRUN
  2002-11-28 15:32 ` Takashi Iwai
  0 siblings, 1 reply; 7+ messages in thread
From: Antonin ENFRUN @ 2002-11-26 11:42 UTC (permalink / raw)
  To: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 1095 bytes --]


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 !

-- 
Antonin ENFRUN <ae.tech@noos.fr>

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1471 bytes --]

--- alsa-driver-0.9.0rc6/alsa-kernel/pci/ac97/ac97_codec.c	2002-10-30 15:20:08.000000000 +0100
+++ alsa-driver-0.9.0rc6-ae/alsa-kernel/pci/ac97/ac97_codec.c	2002-11-26 10:21:13.000000000 +0100
@@ -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;
 }
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
  2002-11-26 11:42 PATCH] SPDIF out clock sync for via8235 / ALC650 Antonin ENFRUN
@ 2002-11-28 15:32 ` Takashi Iwai
  2002-12-30 21:30   ` jgotts
  0 siblings, 1 reply; 7+ messages in thread
From: Takashi Iwai @ 2002-11-28 15:32 UTC (permalink / raw)
  To: Antonin ENFRUN; +Cc: alsa-devel

Hi,

At 26 Nov 2002 12:42:12 +0100,
Antonin ENFRUN wrote:
> 
> 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.

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.


> 
> 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.

> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
  2002-11-28 15:32 ` Takashi Iwai
@ 2002-12-30 21:30   ` jgotts
  2003-02-02 12:03     ` jgotts
  0 siblings, 1 reply; 7+ messages in thread
From: jgotts @ 2002-12-30 21:30 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: ae.tech, alsa-devel

In message <s5hznrtzp3z.wl@alsa2.suse.de>, Takashi Iwai writes:

>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-driver-0.9.0rc6/alsa-kernel/pci/via82xx.c.orig	2002-12-27 17:25:29.000000000 -0500
+++ alsa-driver-0.9.0rc6/alsa-kernel/pci/via82xx.c	2002-12-27 17:27:22.000000000 -0500
@@ -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-driver-0.9.0rc6/alsa-kernel/pci/ac97/ac97_codec.c.orig	2002-12-27 17:29:08.000000000 -0500
+++ alsa-driver-0.9.0rc6/alsa-kernel/pci/ac97/ac97_codec.c	2002-12-27 17:43:43.000000000 -0500
@@ -1942,6 +1942,45 @@
 	}
 }
 
+static int set_spdif_rate(ac97_t *ac97, unsigned short rate)
+{
+	unsigned short old, bits, reg;
+
+	if (! (ac97->ext_id & AC97_EI_SPDIF))
+		return -ENODEV;
+
+	if (ac97->flags & AC97_CS_SPDIF) {
+		switch (rate) {
+		case 48000: bits = 0; break;
+		case 44100: bits = 1 << AC97_SC_SPSR_SHIFT; break;
+		default: /* invalid - disable output */
+			snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+			return -EINVAL;
+		}
+		reg = AC97_CSR_SPDIF;
+	} else {
+		switch (rate) {
+		case 44100: bits = AC97_SC_SPSR_44K; break;
+		case 48000: bits = AC97_SC_SPSR_48K; break;
+		case 32000: bits = AC97_SC_SPSR_32K; break;
+		default: /* invalid - disable output */
+			snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+			return -EINVAL;
+		}
+		reg = AC97_SPDIF;
+	}
+
+	spin_lock(&ac97->reg_lock);
+	old = ac97->regs[reg] & ~AC97_SC_SPSR_MASK;
+	if (old != bits) {
+		snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+		snd_ac97_update_bits_nolock(ac97, reg, AC97_SC_SPSR_MASK, bits);
+	}
+	snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
+	spin_unlock(&ac97->reg_lock);
+	return 0;
+}
+
 /*
  *  PCM support
  */
@@ -1971,8 +2010,9 @@
 				return -EINVAL;
 		break;
 	case AC97_SPDIF:
-		return 0;
-	default: return -EINVAL;
+		return set_spdif_rate(ac97, rate);
+	default:
+		return -EINVAL;
 	}
 	tmp = ((unsigned int)rate * ac97->clock) / 48000;
 	if (tmp > 65535)

-- 
John GOTTS <jgotts@linuxsavvy.com>  http://linuxsavvy.com/staff/jgotts


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
  2002-12-30 21:30   ` jgotts
@ 2003-02-02 12:03     ` jgotts
  2003-02-03  9:45       ` Takashi Iwai
  0 siblings, 1 reply; 7+ messages in thread
From: jgotts @ 2003-02-02 12:03 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: ae.tech, alsa-devel

In message <200212302130.gBULUVp24791@ann-arbor.fmfts.com>, jgotts@linuxsavvy.c
om writes:

>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

-- 
John GOTTS <jgotts@linuxsavvy.com>  http://linuxsavvy.com/staff/jgotts


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
  2003-02-02 12:03     ` jgotts
@ 2003-02-03  9:45       ` Takashi Iwai
       [not found]         ` <3E3E462E.B2EDC7D8@lysator.liu.se>
  0 siblings, 1 reply; 7+ messages in thread
From: Takashi Iwai @ 2003-02-03  9:45 UTC (permalink / raw)
  To: jgotts; +Cc: alsa-devel

At Sun, 02 Feb 2003 07:03:02 -0500,
jgotts@linuxsavvy.com wrote:
> 
> In message <200212302130.gBULUVp24791@ann-arbor.fmfts.com>, jgotts@linuxsavvy.c
> om writes:
> 
> >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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
       [not found]         ` <3E3E462E.B2EDC7D8@lysator.liu.se>
@ 2003-02-03 10:45           ` Takashi Iwai
       [not found]             ` <3E3E4D63.8BFEC97F@lysator.liu.se>
  0 siblings, 1 reply; 7+ messages in thread
From: Takashi Iwai @ 2003-02-03 10:45 UTC (permalink / raw)
  To: David Björkevik; +Cc: jgotts, alsa-devel

At Mon, 03 Feb 2003 11:36:30 +0100,
David Björkevik wrote:
> 
> Takashi Iwai wrote:
> > 
> > At Sun, 02 Feb 2003 07:03:02 -0500,
> > jgotts@linuxsavvy.com wrote:
> > >
> > > In message <200212302130.gBULUVp24791@ann-arbor.fmfts.com>, jgotts@linuxsavvy.c
> > > om writes:
> > >
> > > >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.
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH] SPDIF out clock sync for via8235 / ALC650
       [not found]             ` <3E3E4D63.8BFEC97F@lysator.liu.se>
@ 2003-02-03 11:26               ` Takashi Iwai
  0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2003-02-03 11:26 UTC (permalink / raw)
  To: David Björkevik; +Cc: alsa-devel

At Mon, 03 Feb 2003 12:07:15 +0100,
David Björkevik wrote:
> 
> Thank you for trying to help me fix this.
> 
> Takashi Iwai wrote:
> > > 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.
> 
> 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.
 
> > 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-02-03 11:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-26 11:42 PATCH] SPDIF out clock sync for via8235 / ALC650 Antonin ENFRUN
2002-11-28 15:32 ` Takashi Iwai
2002-12-30 21:30   ` jgotts
2003-02-02 12:03     ` jgotts
2003-02-03  9:45       ` Takashi Iwai
     [not found]         ` <3E3E462E.B2EDC7D8@lysator.liu.se>
2003-02-03 10:45           ` Takashi Iwai
     [not found]             ` <3E3E4D63.8BFEC97F@lysator.liu.se>
2003-02-03 11:26               ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.