Skip to contentSkip to conversation

2.4.18 - CMI9738 codec support in ac97_codec.c

PATCH In review Ed Clark 2 participants 2 messages Apr 27, 2002 Sound

lore
Share & tools
lore

Ed Clark

author
#0 lore raw

PATCH 1/1 2.4.18 - CMI9738 codec support in ac97_codec.c

hi all,

this patch was originally written to fix a problem with the on-board audio subsystem of a pcchips m810lmr, which involves the SiS7018 controller and C-Media CMI9738 AC97 codec. As such, the scope of this patch is any audio subsystem using the CMI9738, and requiring the trident.o module.

The CMI9738 is budget codec which appears to only provide limited support of the usual AC97 features. For example, the CD volume control resolution is 4 bits instead of the usual 5, and there is no support for PCM volume adjustment (presumably because an equivalent function would typically be available in the AC97 controller). This patch provides a work around for these problems. Instead of simply writing the codec registers, a mechanism is provided for making callbacks to either codec or controller specific routines which make amends for codec deficiencies.

later

linux/ac97_codec.h renamed from linux/ac97_codec.h.orig +9 -0
@@ -180,6 +180,9 @@
                                     (FOO < SOUND_MIXER_NRDEVICES) && \
                                     (CODEC)->supported_mixers & (1<<FOO) )
 
+struct ac97_codec; /* prevent compiler warnings */
+typedef void (*write_mixer_func_t)(struct ac97_codec*, int, unsigned int, unsigned int) ;
+
 struct ac97_codec {
 	/* AC97 controller connected with */
 	void *private_data;
@@ -218,6 +221,12 @@
 
 	/* Software Modem interface */
 	int  (*modem_ioctl)(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
+
+        /* callback hooks to complement functionally limited codecs */
+        struct {
+                write_mixer_func_t *controller_write_mixer_func;
+                write_mixer_func_t *codec_alt_write_mixer_func;
+        } misc_ops;
 };
 
 /*
sound/ac97_codec.c renamed from sound/ac97_codec.c.orig +64 -0

114 lines not on this page · raw message

sound/trident.c renamed from sound/trident.c.orig +37 -0
@@ -36,6 +36,10 @@
  *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  *  History
+ *  v0.14.9e
+ *	April 24 2002 Ed Clark <[email protected]>
+ *	Added controller callback mechanism to complement functionally
+ *	limited AC97 codecs. Included callback for PCM volume adjustment.
  *  v0.14.9d
  *  	October 8 2001 Arnaldo Carvalho de Melo <[email protected]>
  *	use set_current_state, properly release resources on failure in
@@ -413,6 +417,8 @@
 static int trident_open_mixdev(struct inode *inode, struct file *file);
 static int trident_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
 				unsigned long arg);
+static void trident_write_mixer_pcm(struct ac97_codec *codec, int oss_channel,
+                                    unsigned int left, unsigned int right);
 
 static void ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val);
 static u16 ali_ac97_get(struct trident_card *card, int secondary, u8 reg);
@@ -3785,6 +3791,34 @@
 	open:		trident_open_mixdev,
 };
 
+/* PCM volume adjustment (for AC97 codecs lacking this ability) */
+static void trident_write_mixer_pcm(struct ac97_codec *codec, int oss_channel,
+                                    unsigned int left, unsigned int right)
+{
+        struct trident_card *card = (struct trident_card *)codec->private_data;
+        unsigned int val;
+    
+        right = ((100 - right) * 32) / 100;
+        left = ((100 - left) * 32) / 100;
+        if (right >= 32)
+                right = 31;
+        if (left >= 32)
+                left = 31;
+        /* attenuation scaling,
+           AC97 codec : 1.5dB/step
+           controller : 0.5dB/step
+        */
+        right *= 3;
+        left *= 3;        
+        val = (right << 8) | left;
+        val = (val << 16) | val;
+        outl(val,TRID_REG(card, T4D_MUSICVOL_WAVEVOL));
+}
+
+static write_mixer_func_t controller_write_mixer_func[SOUND_MIXER_NRDEVICES] = {
+        [SOUND_MIXER_PCM] = trident_write_mixer_pcm,
+};
+
 static int ali_reset_5451(struct trident_card *card)
 {
 	struct pci_dev *pci_dev = NULL;
@@ -3910,6 +3944,9 @@
 			codec->codec_write = trident_ac97_set;
 		}
 	
+                /* set AC97 controller callbacks */
+                codec->misc_ops.controller_write_mixer_func = controller_write_mixer_func;
+                
 		if (ac97_probe_codec(codec) == 0)
 			break;
 
#1 lore raw

<original deleted - your mailer needs debugging so it wordwraps text/plain
as per the RFC's>

I'd rather keep the core AC97 code clean. It would be much nicer to have the driver handle this case, since for a partially implemented codec only the card driver really knows the right strategy.