Subject: CS4231 sound device driver fix
To: None <port-sparc64@netbsd.org>
From: Sung-Won Chung <swchung7@hotmail.com>
List: port-sparc64
Date: 08/22/2002 12:26:48
Today, when I played mp3 with Ultra1, I found a problem that
CS4231 volume control didn't work with mpg321 or amp.
The reason was that these software don't specify which mixer device
to be affected by volume control ioctl().
And it means master output mix device is used by default.
This behavior was set in sys/dev/audio.c.

However, unlike other sound device drivers,
cs4231 driver didn't specified audioNmaster.
So the volume control request in cs4231 was silently ignored.

I corrected cs4231.c to have master output as follows,
and volume control works now. However, default volume is zero,
you should explicitly specify volume (or gain) to audio program.


Index: cs4231.c
===================================================================
RCS file: /usr/local/cvsroot/nunbora/src/syssrc/sys/dev/ic/cs4231.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 cs4231.c
545c545
< 		strcpy(dip->label.name, AudioNoutput);
---
>		strcpy(dip->label.name, AudioNmaster);


Another interesting things is that cs4231 have a facility that can
specifies the volume of builtin speaker and heaphone, with
different value. It means, with a seperate ioctl(), you can
listen with both headphone and built-in speaker or with either one.
This is already implemented in ad1848 driver which is the core of cs4231.
But cs4231 driver support for it seems to be not complete.

So, if you want to listen with headphone only, apply the following fix.
If you specify non-zero volume, both built-in speaker and headphone turns 
on.
However, if you specify ZERO volume, built-in speaker turns off and
you will hear only from headphone with mid volume.
But, this is ad-hoc quick fix,  it may broke underlying mute state.

Sung-Won


Index: ad1848.c
===================================================================
RCS file: /usr/local/cvsroot/nunbora/src/syssrc/sys/dev/ic/ad1848.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ad1848.c
--- ad1848.c	2002/08/16 14:50:41	1.1.1.1
+++ ad1848.c	2002/08/22 02:48:18
@@ -529,6 +529,17 @@

	sc->gains[device] = *gp;

+	if (device == AD1848_DAC_CHANNEL && gp->left == 0) {
+		/* turn only headphone */
+		reg = ad_read(sc, CS_MONO_IO_CONTROL);
+		ad_write(sc, CS_MONO_IO_CONTROL, reg | MONO_OUTPUT_MUTE);
+		#define MID_GAIN 220
+		gp->left = gp->right = MID_GAIN;
+	} else {
+		reg = ad_read(sc, CS_MONO_IO_CONTROL);
+		ad_write(sc, CS_MONO_IO_CONTROL, reg & ~MONO_OUTPUT_MUTE);
+	}
+
	atten = (AUDIO_MAX_GAIN - gp->left) * (info->atten_bits + 1) /
		(AUDIO_MAX_GAIN + 1);




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com