162306a36Sopenharmony_ci================================================= 262306a36Sopenharmony_ciBrief Notes on C-Media 8338/8738/8768/8770 Driver 362306a36Sopenharmony_ci================================================= 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciTakashi Iwai <tiwai@suse.de> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciFront/Rear Multi-channel Playback 962306a36Sopenharmony_ci--------------------------------- 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciCM8x38 chip can use ADC as the second DAC so that two different stereo 1262306a36Sopenharmony_cichannels can be used for front/rear playbacks. Since there are two 1362306a36Sopenharmony_ciDACs, both streams are handled independently unlike the 4/6ch multi- 1462306a36Sopenharmony_cichannel playbacks in the section below. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciAs default, ALSA driver assigns the first PCM device (i.e. hw:0,0 for 1762306a36Sopenharmony_cicard#0) for front and 4/6ch playbacks, while the second PCM device 1862306a36Sopenharmony_ci(hw:0,1) is assigned to the second DAC for rear playback. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciThere are slight differences between the two DACs: 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci- The first DAC supports U8 and S16LE formats, while the second DAC 2362306a36Sopenharmony_ci supports only S16LE. 2462306a36Sopenharmony_ci- The second DAC supports only two channel stereo. 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciPlease note that the CM8x38 DAC doesn't support continuous playback 2762306a36Sopenharmony_cirate but only fixed rates: 5512, 8000, 11025, 16000, 22050, 32000, 2862306a36Sopenharmony_ci44100 and 48000 Hz. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciThe rear output can be heard only when "Four Channel Mode" switch is 3162306a36Sopenharmony_cidisabled. Otherwise no signal will be routed to the rear speakers. 3262306a36Sopenharmony_ciAs default it's turned on. 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci.. WARNING:: 3562306a36Sopenharmony_ci When "Four Channel Mode" switch is off, the output from rear speakers 3662306a36Sopenharmony_ci will be FULL VOLUME regardless of Master and PCM volumes [#]_. 3762306a36Sopenharmony_ci This might damage your audio equipment. Please disconnect speakers 3862306a36Sopenharmony_ci before your turn off this switch. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci.. [#] 4262306a36Sopenharmony_ci Well.. I once got the output with correct volume (i.e. same with the 4362306a36Sopenharmony_ci front one) and was so excited. It was even with "Four Channel" bit 4462306a36Sopenharmony_ci on and "double DAC" mode. Actually I could hear separate 4 channels 4562306a36Sopenharmony_ci from front and rear speakers! But.. after reboot, all was gone. 4662306a36Sopenharmony_ci It's a very pity that I didn't save the register dump at that 4762306a36Sopenharmony_ci time.. Maybe there is an unknown register to achieve this... 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciIf your card has an extra output jack for the rear output, the rear 5062306a36Sopenharmony_ciplayback should be routed there as default. If not, there is a 5162306a36Sopenharmony_cicontrol switch in the driver "Line-In As Rear", which you can change 5262306a36Sopenharmony_civia alsamixer or somewhat else. When this switch is on, line-in jack 5362306a36Sopenharmony_ciis used as rear output. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciThere are two more controls regarding to the rear output. 5662306a36Sopenharmony_ciThe "Exchange DAC" switch is used to exchange front and rear playback 5762306a36Sopenharmony_ciroutes, i.e. the 2nd DAC is output from front output. 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci4/6 Multi-Channel Playback 6162306a36Sopenharmony_ci-------------------------- 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ciThe recent CM8738 chips support for the 4/6 multi-channel playback 6462306a36Sopenharmony_cifunction. This is useful especially for AC3 decoding. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciWhen the multi-channel is supported, the driver name has a suffix 6762306a36Sopenharmony_ci"-MC" such like "CMI8738-MC6". You can check this name from 6862306a36Sopenharmony_ci/proc/asound/cards. 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciWhen the 4/6-ch output is enabled, the second DAC accepts up to 6 (or 7162306a36Sopenharmony_ci4) channels. While the dual DAC supports two different rates or 7262306a36Sopenharmony_ciformats, the 4/6-ch playback supports only the same condition for all 7362306a36Sopenharmony_cichannels. Since the multi-channel playback mode uses both DACs, you 7462306a36Sopenharmony_cicannot operate with full-duplex. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciThe 4.0 and 5.1 modes are defined as the pcm "surround40" and "surround51" 7762306a36Sopenharmony_ciin alsa-lib. For example, you can play a WAV file with 6 channels like 7862306a36Sopenharmony_ci:: 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci % aplay -Dsurround51 sixchannels.wav 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciFor programming the 4/6 channel playback, you need to specify the PCM 8362306a36Sopenharmony_cichannels as you like and set the format S16LE. For example, for playback 8462306a36Sopenharmony_ciwith 4 channels, 8562306a36Sopenharmony_ci:: 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci snd_pcm_hw_params_set_access(pcm, hw, SND_PCM_ACCESS_RW_INTERLEAVED); 8862306a36Sopenharmony_ci // or mmap if you like 8962306a36Sopenharmony_ci snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE); 9062306a36Sopenharmony_ci snd_pcm_hw_params_set_channels(pcm, hw, 4); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciand use the interleaved 4 channel data. 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ciThere are some control switches affecting to the speaker connections: 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ciLine-In Mode 9762306a36Sopenharmony_ci an enum control to change the behavior of line-in 9862306a36Sopenharmony_ci jack. Either "Line-In", "Rear Output" or "Bass Output" can 9962306a36Sopenharmony_ci be selected. The last item is available only with model 039 10062306a36Sopenharmony_ci or newer. 10162306a36Sopenharmony_ci When "Rear Output" is chosen, the surround channels 3 and 4 10262306a36Sopenharmony_ci are output to line-in jack. 10362306a36Sopenharmony_ciMic-In Mode 10462306a36Sopenharmony_ci an enum control to change the behavior of mic-in 10562306a36Sopenharmony_ci jack. Either "Mic-In" or "Center/LFE Output" can be 10662306a36Sopenharmony_ci selected. 10762306a36Sopenharmony_ci When "Center/LFE Output" is chosen, the center and bass 10862306a36Sopenharmony_ci channels (channels 5 and 6) are output to mic-in jack. 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciDigital I/O 11162306a36Sopenharmony_ci----------- 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciThe CM8x38 provides the excellent SPDIF capability with very cheap 11462306a36Sopenharmony_ciprice (yes, that's the reason I bought the card :) 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciThe SPDIF playback and capture are done via the third PCM device 11762306a36Sopenharmony_ci(hw:0,2). Usually this is assigned to the PCM device "spdif". 11862306a36Sopenharmony_ciThe available rates are 44100 and 48000 Hz. 11962306a36Sopenharmony_ciFor playback with aplay, you can run like below: 12062306a36Sopenharmony_ci:: 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci % aplay -Dhw:0,2 foo.wav 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_cior 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci:: 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci % aplay -Dspdif foo.wav 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci24bit format is also supported experimentally. 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciThe playback and capture over SPDIF use normal DAC and ADC, 13362306a36Sopenharmony_cirespectively, so you cannot playback both analog and digital streams 13462306a36Sopenharmony_cisimultaneously. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ciTo enable SPDIF output, you need to turn on "IEC958 Output Switch" 13762306a36Sopenharmony_cicontrol via mixer or alsactl ("IEC958" is the official name of 13862306a36Sopenharmony_ciso-called S/PDIF). Then you'll see the red light on from the card so 13962306a36Sopenharmony_ciyou know that's working obviously :) 14062306a36Sopenharmony_ciThe SPDIF input is always enabled, so you can hear SPDIF input data 14162306a36Sopenharmony_cifrom line-out with "IEC958 In Monitor" switch at any time (see 14262306a36Sopenharmony_cibelow). 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciYou can play via SPDIF even with the first device (hw:0,0), 14562306a36Sopenharmony_cibut SPDIF is enabled only when the proper format (S16LE), sample rate 14662306a36Sopenharmony_ci(441100 or 48000) and channels (2) are used. Otherwise it's turned 14762306a36Sopenharmony_cioff. (Also don't forget to turn on "IEC958 Output Switch", too.) 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciAdditionally there are relevant control switches: 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ciIEC958 Mix Analog 15362306a36Sopenharmony_ci Mix analog PCM playback and FM-OPL/3 streams and 15462306a36Sopenharmony_ci output through SPDIF. This switch appears only on old chip 15562306a36Sopenharmony_ci models (CM8738 033 and 037). 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci Note: without this control you can output PCM to SPDIF. 15862306a36Sopenharmony_ci This is "mixing" of streams, so e.g. it's not for AC3 output 15962306a36Sopenharmony_ci (see the next section). 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciIEC958 In Select 16262306a36Sopenharmony_ci Select SPDIF input, the internal CD-in (false) 16362306a36Sopenharmony_ci and the external input (true). 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ciIEC958 Loop 16662306a36Sopenharmony_ci SPDIF input data is loop back into SPDIF 16762306a36Sopenharmony_ci output (aka bypass) 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciIEC958 Copyright 17062306a36Sopenharmony_ci Set the copyright bit. 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciIEC958 5V 17362306a36Sopenharmony_ci Select 0.5V (coax) or 5V (optical) interface. 17462306a36Sopenharmony_ci On some cards this doesn't work and you need to change the 17562306a36Sopenharmony_ci configuration with hardware dip-switch. 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ciIEC958 In Monitor 17862306a36Sopenharmony_ci SPDIF input is routed to DAC. 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ciIEC958 In Phase Inverse 18162306a36Sopenharmony_ci Set SPDIF input format as inverse. 18262306a36Sopenharmony_ci [FIXME: this doesn't work on all chips..] 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ciIEC958 In Valid 18562306a36Sopenharmony_ci Set input validity flag detection. 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciNote: When "PCM Playback Switch" is on, you'll hear the digital output 18862306a36Sopenharmony_cistream through analog line-out. 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ciThe AC3 (RAW DIGITAL) OUTPUT 19262306a36Sopenharmony_ci---------------------------- 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ciThe driver supports raw digital (typically AC3) i/o over SPDIF. This 19562306a36Sopenharmony_cican be toggled via IEC958 playback control, but usually you need to 19662306a36Sopenharmony_ciaccess it via alsa-lib. See alsa-lib documents for more details. 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ciOn the raw digital mode, the "PCM Playback Switch" is automatically 19962306a36Sopenharmony_citurned off so that non-audio data is heard from the analog line-out. 20062306a36Sopenharmony_ciSimilarly the following switches are off: "IEC958 Mix Analog" and 20162306a36Sopenharmony_ci"IEC958 Loop". The switches are resumed after closing the SPDIF PCM 20262306a36Sopenharmony_cidevice automatically to the previous state. 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ciOn the model 033, AC3 is implemented by the software conversion in 20562306a36Sopenharmony_cithe alsa-lib. If you need to bypass the software conversion of IEC958 20662306a36Sopenharmony_cisubframes, pass the "soft_ac3=0" module option. This doesn't matter 20762306a36Sopenharmony_cion the newer models. 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ciANALOG MIXER INTERFACE 21162306a36Sopenharmony_ci---------------------- 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciThe mixer interface on CM8x38 is similar to SB16. 21462306a36Sopenharmony_ciThere are Master, PCM, Synth, CD, Line, Mic and PC Speaker playback 21562306a36Sopenharmony_civolumes. Synth, CD, Line and Mic have playback and capture switches, 21662306a36Sopenharmony_citoo, as well as SB16. 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciIn addition to the standard SB mixer, CM8x38 provides more functions. 21962306a36Sopenharmony_ci- PCM playback switch 22062306a36Sopenharmony_ci- PCM capture switch (to capture the data sent to DAC) 22162306a36Sopenharmony_ci- Mic Boost switch 22262306a36Sopenharmony_ci- Mic capture volume 22362306a36Sopenharmony_ci- Aux playback volume/switch and capture switch 22462306a36Sopenharmony_ci- 3D control switch 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciMIDI CONTROLLER 22862306a36Sopenharmony_ci--------------- 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ciWith CMI8338 chips, the MPU401-UART interface is disabled as default. 23162306a36Sopenharmony_ciYou need to set the module option "mpu_port" to a valid I/O port address 23262306a36Sopenharmony_cito enable MIDI support. Valid I/O ports are 0x300, 0x310, 0x320 and 23362306a36Sopenharmony_ci0x330. Choose a value that doesn't conflict with other cards. 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ciWith CMI8738 and newer chips, the MIDI interface is enabled by default 23662306a36Sopenharmony_ciand the driver automatically chooses a port address. 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ciThere is *no* hardware wavetable function on this chip (except for 23962306a36Sopenharmony_ciOPL3 synth below). 24062306a36Sopenharmony_ciWhat's said as MIDI synth on Windows is a software synthesizer 24162306a36Sopenharmony_ciemulation. On Linux use TiMidity or other softsynth program for 24262306a36Sopenharmony_ciplaying MIDI music. 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ciFM OPL/3 Synth 24662306a36Sopenharmony_ci-------------- 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ciThe FM OPL/3 is also enabled as default only for the first card. 24962306a36Sopenharmony_ciSet "fm_port" module option for more cards. 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ciThe output quality of FM OPL/3 is, however, very weird. 25262306a36Sopenharmony_ciI don't know why.. 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ciCMI8768 and newer chips do not have the FM synth. 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ciJoystick and Modem 25862306a36Sopenharmony_ci------------------ 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ciThe legacy joystick is supported. To enable the joystick support, pass 26162306a36Sopenharmony_cijoystick_port=1 module option. The value 1 means the auto-detection. 26262306a36Sopenharmony_ciIf the auto-detection fails, try to pass the exact I/O address. 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ciThe modem is enabled dynamically via a card control switch "Modem". 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ciDebugging Information 26862306a36Sopenharmony_ci--------------------- 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ciThe registers are shown in /proc/asound/cardX/cmipci. If you have any 27162306a36Sopenharmony_ciproblem (especially unexpected behavior of mixer), please attach the 27262306a36Sopenharmony_cioutput of this proc file together with the bug report. 273