1*4882a593Smuzhiyun================================================= 2*4882a593SmuzhiyunBrief Notes on C-Media 8338/8738/8768/8770 Driver 3*4882a593Smuzhiyun================================================= 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunTakashi Iwai <tiwai@suse.de> 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunFront/Rear Multi-channel Playback 9*4882a593Smuzhiyun--------------------------------- 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunCM8x38 chip can use ADC as the second DAC so that two different stereo 12*4882a593Smuzhiyunchannels can be used for front/rear playbacks. Since there are two 13*4882a593SmuzhiyunDACs, both streams are handled independently unlike the 4/6ch multi- 14*4882a593Smuzhiyunchannel playbacks in the section below. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunAs default, ALSA driver assigns the first PCM device (i.e. hw:0,0 for 17*4882a593Smuzhiyuncard#0) for front and 4/6ch playbacks, while the second PCM device 18*4882a593Smuzhiyun(hw:0,1) is assigned to the second DAC for rear playback. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunThere are slight differences between the two DACs: 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun- The first DAC supports U8 and S16LE formats, while the second DAC 23*4882a593Smuzhiyun supports only S16LE. 24*4882a593Smuzhiyun- The second DAC supports only two channel stereo. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunPlease note that the CM8x38 DAC doesn't support continuous playback 27*4882a593Smuzhiyunrate but only fixed rates: 5512, 8000, 11025, 16000, 22050, 32000, 28*4882a593Smuzhiyun44100 and 48000 Hz. 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunThe rear output can be heard only when "Four Channel Mode" switch is 31*4882a593Smuzhiyundisabled. Otherwise no signal will be routed to the rear speakers. 32*4882a593SmuzhiyunAs default it's turned on. 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun.. WARNING:: 35*4882a593Smuzhiyun When "Four Channel Mode" switch is off, the output from rear speakers 36*4882a593Smuzhiyun will be FULL VOLUME regardless of Master and PCM volumes [#]_. 37*4882a593Smuzhiyun This might damage your audio equipment. Please disconnect speakers 38*4882a593Smuzhiyun before your turn off this switch. 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun.. [#] 42*4882a593Smuzhiyun Well.. I once got the output with correct volume (i.e. same with the 43*4882a593Smuzhiyun front one) and was so excited. It was even with "Four Channel" bit 44*4882a593Smuzhiyun on and "double DAC" mode. Actually I could hear separate 4 channels 45*4882a593Smuzhiyun from front and rear speakers! But.. after reboot, all was gone. 46*4882a593Smuzhiyun It's a very pity that I didn't save the register dump at that 47*4882a593Smuzhiyun time.. Maybe there is an unknown register to achieve this... 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunIf your card has an extra output jack for the rear output, the rear 50*4882a593Smuzhiyunplayback should be routed there as default. If not, there is a 51*4882a593Smuzhiyuncontrol switch in the driver "Line-In As Rear", which you can change 52*4882a593Smuzhiyunvia alsamixer or somewhat else. When this switch is on, line-in jack 53*4882a593Smuzhiyunis used as rear output. 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunThere are two more controls regarding to the rear output. 56*4882a593SmuzhiyunThe "Exchange DAC" switch is used to exchange front and rear playback 57*4882a593Smuzhiyunroutes, i.e. the 2nd DAC is output from front output. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun4/6 Multi-Channel Playback 61*4882a593Smuzhiyun-------------------------- 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunThe recent CM8738 chips support for the 4/6 multi-channel playback 64*4882a593Smuzhiyunfunction. This is useful especially for AC3 decoding. 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunWhen the multi-channel is supported, the driver name has a suffix 67*4882a593Smuzhiyun"-MC" such like "CMI8738-MC6". You can check this name from 68*4882a593Smuzhiyun/proc/asound/cards. 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunWhen the 4/6-ch output is enabled, the second DAC accepts up to 6 (or 71*4882a593Smuzhiyun4) channels. While the dual DAC supports two different rates or 72*4882a593Smuzhiyunformats, the 4/6-ch playback supports only the same condition for all 73*4882a593Smuzhiyunchannels. Since the multi-channel playback mode uses both DACs, you 74*4882a593Smuzhiyuncannot operate with full-duplex. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunThe 4.0 and 5.1 modes are defined as the pcm "surround40" and "surround51" 77*4882a593Smuzhiyunin alsa-lib. For example, you can play a WAV file with 6 channels like 78*4882a593Smuzhiyun:: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun % aplay -Dsurround51 sixchannels.wav 81*4882a593Smuzhiyun 82*4882a593SmuzhiyunFor programming the 4/6 channel playback, you need to specify the PCM 83*4882a593Smuzhiyunchannels as you like and set the format S16LE. For example, for playback 84*4882a593Smuzhiyunwith 4 channels, 85*4882a593Smuzhiyun:: 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun snd_pcm_hw_params_set_access(pcm, hw, SND_PCM_ACCESS_RW_INTERLEAVED); 88*4882a593Smuzhiyun // or mmap if you like 89*4882a593Smuzhiyun snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE); 90*4882a593Smuzhiyun snd_pcm_hw_params_set_channels(pcm, hw, 4); 91*4882a593Smuzhiyun 92*4882a593Smuzhiyunand use the interleaved 4 channel data. 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunThere are some control switches affecting to the speaker connections: 95*4882a593Smuzhiyun 96*4882a593SmuzhiyunLine-In Mode 97*4882a593Smuzhiyun an enum control to change the behavior of line-in 98*4882a593Smuzhiyun jack. Either "Line-In", "Rear Output" or "Bass Output" can 99*4882a593Smuzhiyun be selected. The last item is available only with model 039 100*4882a593Smuzhiyun or newer. 101*4882a593Smuzhiyun When "Rear Output" is chosen, the surround channels 3 and 4 102*4882a593Smuzhiyun are output to line-in jack. 103*4882a593SmuzhiyunMic-In Mode 104*4882a593Smuzhiyun an enum control to change the behavior of mic-in 105*4882a593Smuzhiyun jack. Either "Mic-In" or "Center/LFE Output" can be 106*4882a593Smuzhiyun selected. 107*4882a593Smuzhiyun When "Center/LFE Output" is chosen, the center and bass 108*4882a593Smuzhiyun channels (channels 5 and 6) are output to mic-in jack. 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunDigital I/O 111*4882a593Smuzhiyun----------- 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunThe CM8x38 provides the excellent SPDIF capability with very cheap 114*4882a593Smuzhiyunprice (yes, that's the reason I bought the card :) 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunThe SPDIF playback and capture are done via the third PCM device 117*4882a593Smuzhiyun(hw:0,2). Usually this is assigned to the PCM device "spdif". 118*4882a593SmuzhiyunThe available rates are 44100 and 48000 Hz. 119*4882a593SmuzhiyunFor playback with aplay, you can run like below: 120*4882a593Smuzhiyun:: 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun % aplay -Dhw:0,2 foo.wav 123*4882a593Smuzhiyun 124*4882a593Smuzhiyunor 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun:: 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun % aplay -Dspdif foo.wav 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun24bit format is also supported experimentally. 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunThe playback and capture over SPDIF use normal DAC and ADC, 133*4882a593Smuzhiyunrespectively, so you cannot playback both analog and digital streams 134*4882a593Smuzhiyunsimultaneously. 135*4882a593Smuzhiyun 136*4882a593SmuzhiyunTo enable SPDIF output, you need to turn on "IEC958 Output Switch" 137*4882a593Smuzhiyuncontrol via mixer or alsactl ("IEC958" is the official name of 138*4882a593Smuzhiyunso-called S/PDIF). Then you'll see the red light on from the card so 139*4882a593Smuzhiyunyou know that's working obviously :) 140*4882a593SmuzhiyunThe SPDIF input is always enabled, so you can hear SPDIF input data 141*4882a593Smuzhiyunfrom line-out with "IEC958 In Monitor" switch at any time (see 142*4882a593Smuzhiyunbelow). 143*4882a593Smuzhiyun 144*4882a593SmuzhiyunYou can play via SPDIF even with the first device (hw:0,0), 145*4882a593Smuzhiyunbut SPDIF is enabled only when the proper format (S16LE), sample rate 146*4882a593Smuzhiyun(441100 or 48000) and channels (2) are used. Otherwise it's turned 147*4882a593Smuzhiyunoff. (Also don't forget to turn on "IEC958 Output Switch", too.) 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunAdditionally there are relevant control switches: 151*4882a593Smuzhiyun 152*4882a593SmuzhiyunIEC958 Mix Analog 153*4882a593Smuzhiyun Mix analog PCM playback and FM-OPL/3 streams and 154*4882a593Smuzhiyun output through SPDIF. This switch appears only on old chip 155*4882a593Smuzhiyun models (CM8738 033 and 037). 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun Note: without this control you can output PCM to SPDIF. 158*4882a593Smuzhiyun This is "mixing" of streams, so e.g. it's not for AC3 output 159*4882a593Smuzhiyun (see the next section). 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunIEC958 In Select 162*4882a593Smuzhiyun Select SPDIF input, the internal CD-in (false) 163*4882a593Smuzhiyun and the external input (true). 164*4882a593Smuzhiyun 165*4882a593SmuzhiyunIEC958 Loop 166*4882a593Smuzhiyun SPDIF input data is loop back into SPDIF 167*4882a593Smuzhiyun output (aka bypass) 168*4882a593Smuzhiyun 169*4882a593SmuzhiyunIEC958 Copyright 170*4882a593Smuzhiyun Set the copyright bit. 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunIEC958 5V 173*4882a593Smuzhiyun Select 0.5V (coax) or 5V (optical) interface. 174*4882a593Smuzhiyun On some cards this doesn't work and you need to change the 175*4882a593Smuzhiyun configuration with hardware dip-switch. 176*4882a593Smuzhiyun 177*4882a593SmuzhiyunIEC958 In Monitor 178*4882a593Smuzhiyun SPDIF input is routed to DAC. 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunIEC958 In Phase Inverse 181*4882a593Smuzhiyun Set SPDIF input format as inverse. 182*4882a593Smuzhiyun [FIXME: this doesn't work on all chips..] 183*4882a593Smuzhiyun 184*4882a593SmuzhiyunIEC958 In Valid 185*4882a593Smuzhiyun Set input validity flag detection. 186*4882a593Smuzhiyun 187*4882a593SmuzhiyunNote: When "PCM Playback Switch" is on, you'll hear the digital output 188*4882a593Smuzhiyunstream through analog line-out. 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun 191*4882a593SmuzhiyunThe AC3 (RAW DIGITAL) OUTPUT 192*4882a593Smuzhiyun---------------------------- 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunThe driver supports raw digital (typically AC3) i/o over SPDIF. This 195*4882a593Smuzhiyuncan be toggled via IEC958 playback control, but usually you need to 196*4882a593Smuzhiyunaccess it via alsa-lib. See alsa-lib documents for more details. 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunOn the raw digital mode, the "PCM Playback Switch" is automatically 199*4882a593Smuzhiyunturned off so that non-audio data is heard from the analog line-out. 200*4882a593SmuzhiyunSimilarly the following switches are off: "IEC958 Mix Analog" and 201*4882a593Smuzhiyun"IEC958 Loop". The switches are resumed after closing the SPDIF PCM 202*4882a593Smuzhiyundevice automatically to the previous state. 203*4882a593Smuzhiyun 204*4882a593SmuzhiyunOn the model 033, AC3 is implemented by the software conversion in 205*4882a593Smuzhiyunthe alsa-lib. If you need to bypass the software conversion of IEC958 206*4882a593Smuzhiyunsubframes, pass the "soft_ac3=0" module option. This doesn't matter 207*4882a593Smuzhiyunon the newer models. 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun 210*4882a593SmuzhiyunANALOG MIXER INTERFACE 211*4882a593Smuzhiyun---------------------- 212*4882a593Smuzhiyun 213*4882a593SmuzhiyunThe mixer interface on CM8x38 is similar to SB16. 214*4882a593SmuzhiyunThere are Master, PCM, Synth, CD, Line, Mic and PC Speaker playback 215*4882a593Smuzhiyunvolumes. Synth, CD, Line and Mic have playback and capture switches, 216*4882a593Smuzhiyuntoo, as well as SB16. 217*4882a593Smuzhiyun 218*4882a593SmuzhiyunIn addition to the standard SB mixer, CM8x38 provides more functions. 219*4882a593Smuzhiyun- PCM playback switch 220*4882a593Smuzhiyun- PCM capture switch (to capture the data sent to DAC) 221*4882a593Smuzhiyun- Mic Boost switch 222*4882a593Smuzhiyun- Mic capture volume 223*4882a593Smuzhiyun- Aux playback volume/switch and capture switch 224*4882a593Smuzhiyun- 3D control switch 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun 227*4882a593SmuzhiyunMIDI CONTROLLER 228*4882a593Smuzhiyun--------------- 229*4882a593Smuzhiyun 230*4882a593SmuzhiyunWith CMI8338 chips, the MPU401-UART interface is disabled as default. 231*4882a593SmuzhiyunYou need to set the module option "mpu_port" to a valid I/O port address 232*4882a593Smuzhiyunto enable MIDI support. Valid I/O ports are 0x300, 0x310, 0x320 and 233*4882a593Smuzhiyun0x330. Choose a value that doesn't conflict with other cards. 234*4882a593Smuzhiyun 235*4882a593SmuzhiyunWith CMI8738 and newer chips, the MIDI interface is enabled by default 236*4882a593Smuzhiyunand the driver automatically chooses a port address. 237*4882a593Smuzhiyun 238*4882a593SmuzhiyunThere is *no* hardware wavetable function on this chip (except for 239*4882a593SmuzhiyunOPL3 synth below). 240*4882a593SmuzhiyunWhat's said as MIDI synth on Windows is a software synthesizer 241*4882a593Smuzhiyunemulation. On Linux use TiMidity or other softsynth program for 242*4882a593Smuzhiyunplaying MIDI music. 243*4882a593Smuzhiyun 244*4882a593Smuzhiyun 245*4882a593SmuzhiyunFM OPL/3 Synth 246*4882a593Smuzhiyun-------------- 247*4882a593Smuzhiyun 248*4882a593SmuzhiyunThe FM OPL/3 is also enabled as default only for the first card. 249*4882a593SmuzhiyunSet "fm_port" module option for more cards. 250*4882a593Smuzhiyun 251*4882a593SmuzhiyunThe output quality of FM OPL/3 is, however, very weird. 252*4882a593SmuzhiyunI don't know why.. 253*4882a593Smuzhiyun 254*4882a593SmuzhiyunCMI8768 and newer chips do not have the FM synth. 255*4882a593Smuzhiyun 256*4882a593Smuzhiyun 257*4882a593SmuzhiyunJoystick and Modem 258*4882a593Smuzhiyun------------------ 259*4882a593Smuzhiyun 260*4882a593SmuzhiyunThe legacy joystick is supported. To enable the joystick support, pass 261*4882a593Smuzhiyunjoystick_port=1 module option. The value 1 means the auto-detection. 262*4882a593SmuzhiyunIf the auto-detection fails, try to pass the exact I/O address. 263*4882a593Smuzhiyun 264*4882a593SmuzhiyunThe modem is enabled dynamically via a card control switch "Modem". 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun 267*4882a593SmuzhiyunDebugging Information 268*4882a593Smuzhiyun--------------------- 269*4882a593Smuzhiyun 270*4882a593SmuzhiyunThe registers are shown in /proc/asound/cardX/cmipci. If you have any 271*4882a593Smuzhiyunproblem (especially unexpected behavior of mixer), please attach the 272*4882a593Smuzhiyunoutput of this proc file together with the bug report. 273