18c2ecf20Sopenharmony_ci================================================= 28c2ecf20Sopenharmony_ciBrief Notes on C-Media 8338/8738/8768/8770 Driver 38c2ecf20Sopenharmony_ci================================================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciTakashi Iwai <tiwai@suse.de> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciFront/Rear Multi-channel Playback 98c2ecf20Sopenharmony_ci--------------------------------- 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciCM8x38 chip can use ADC as the second DAC so that two different stereo 128c2ecf20Sopenharmony_cichannels can be used for front/rear playbacks. Since there are two 138c2ecf20Sopenharmony_ciDACs, both streams are handled independently unlike the 4/6ch multi- 148c2ecf20Sopenharmony_cichannel playbacks in the section below. 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciAs default, ALSA driver assigns the first PCM device (i.e. hw:0,0 for 178c2ecf20Sopenharmony_cicard#0) for front and 4/6ch playbacks, while the second PCM device 188c2ecf20Sopenharmony_ci(hw:0,1) is assigned to the second DAC for rear playback. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciThere are slight differences between the two DACs: 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci- The first DAC supports U8 and S16LE formats, while the second DAC 238c2ecf20Sopenharmony_ci supports only S16LE. 248c2ecf20Sopenharmony_ci- The second DAC supports only two channel stereo. 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciPlease note that the CM8x38 DAC doesn't support continuous playback 278c2ecf20Sopenharmony_cirate but only fixed rates: 5512, 8000, 11025, 16000, 22050, 32000, 288c2ecf20Sopenharmony_ci44100 and 48000 Hz. 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciThe rear output can be heard only when "Four Channel Mode" switch is 318c2ecf20Sopenharmony_cidisabled. Otherwise no signal will be routed to the rear speakers. 328c2ecf20Sopenharmony_ciAs default it's turned on. 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci.. WARNING:: 358c2ecf20Sopenharmony_ci When "Four Channel Mode" switch is off, the output from rear speakers 368c2ecf20Sopenharmony_ci will be FULL VOLUME regardless of Master and PCM volumes [#]_. 378c2ecf20Sopenharmony_ci This might damage your audio equipment. Please disconnect speakers 388c2ecf20Sopenharmony_ci before your turn off this switch. 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci.. [#] 428c2ecf20Sopenharmony_ci Well.. I once got the output with correct volume (i.e. same with the 438c2ecf20Sopenharmony_ci front one) and was so excited. It was even with "Four Channel" bit 448c2ecf20Sopenharmony_ci on and "double DAC" mode. Actually I could hear separate 4 channels 458c2ecf20Sopenharmony_ci from front and rear speakers! But.. after reboot, all was gone. 468c2ecf20Sopenharmony_ci It's a very pity that I didn't save the register dump at that 478c2ecf20Sopenharmony_ci time.. Maybe there is an unknown register to achieve this... 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciIf your card has an extra output jack for the rear output, the rear 508c2ecf20Sopenharmony_ciplayback should be routed there as default. If not, there is a 518c2ecf20Sopenharmony_cicontrol switch in the driver "Line-In As Rear", which you can change 528c2ecf20Sopenharmony_civia alsamixer or somewhat else. When this switch is on, line-in jack 538c2ecf20Sopenharmony_ciis used as rear output. 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciThere are two more controls regarding to the rear output. 568c2ecf20Sopenharmony_ciThe "Exchange DAC" switch is used to exchange front and rear playback 578c2ecf20Sopenharmony_ciroutes, i.e. the 2nd DAC is output from front output. 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci4/6 Multi-Channel Playback 618c2ecf20Sopenharmony_ci-------------------------- 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciThe recent CM8738 chips support for the 4/6 multi-channel playback 648c2ecf20Sopenharmony_cifunction. This is useful especially for AC3 decoding. 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciWhen the multi-channel is supported, the driver name has a suffix 678c2ecf20Sopenharmony_ci"-MC" such like "CMI8738-MC6". You can check this name from 688c2ecf20Sopenharmony_ci/proc/asound/cards. 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciWhen the 4/6-ch output is enabled, the second DAC accepts up to 6 (or 718c2ecf20Sopenharmony_ci4) channels. While the dual DAC supports two different rates or 728c2ecf20Sopenharmony_ciformats, the 4/6-ch playback supports only the same condition for all 738c2ecf20Sopenharmony_cichannels. Since the multi-channel playback mode uses both DACs, you 748c2ecf20Sopenharmony_cicannot operate with full-duplex. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ciThe 4.0 and 5.1 modes are defined as the pcm "surround40" and "surround51" 778c2ecf20Sopenharmony_ciin alsa-lib. For example, you can play a WAV file with 6 channels like 788c2ecf20Sopenharmony_ci:: 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci % aplay -Dsurround51 sixchannels.wav 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciFor programming the 4/6 channel playback, you need to specify the PCM 838c2ecf20Sopenharmony_cichannels as you like and set the format S16LE. For example, for playback 848c2ecf20Sopenharmony_ciwith 4 channels, 858c2ecf20Sopenharmony_ci:: 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci snd_pcm_hw_params_set_access(pcm, hw, SND_PCM_ACCESS_RW_INTERLEAVED); 888c2ecf20Sopenharmony_ci // or mmap if you like 898c2ecf20Sopenharmony_ci snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE); 908c2ecf20Sopenharmony_ci snd_pcm_hw_params_set_channels(pcm, hw, 4); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciand use the interleaved 4 channel data. 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciThere are some control switches affecting to the speaker connections: 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciLine-In Mode 978c2ecf20Sopenharmony_ci an enum control to change the behavior of line-in 988c2ecf20Sopenharmony_ci jack. Either "Line-In", "Rear Output" or "Bass Output" can 998c2ecf20Sopenharmony_ci be selected. The last item is available only with model 039 1008c2ecf20Sopenharmony_ci or newer. 1018c2ecf20Sopenharmony_ci When "Rear Output" is chosen, the surround channels 3 and 4 1028c2ecf20Sopenharmony_ci are output to line-in jack. 1038c2ecf20Sopenharmony_ciMic-In Mode 1048c2ecf20Sopenharmony_ci an enum control to change the behavior of mic-in 1058c2ecf20Sopenharmony_ci jack. Either "Mic-In" or "Center/LFE Output" can be 1068c2ecf20Sopenharmony_ci selected. 1078c2ecf20Sopenharmony_ci When "Center/LFE Output" is chosen, the center and bass 1088c2ecf20Sopenharmony_ci channels (channels 5 and 6) are output to mic-in jack. 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciDigital I/O 1118c2ecf20Sopenharmony_ci----------- 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciThe CM8x38 provides the excellent SPDIF capability with very cheap 1148c2ecf20Sopenharmony_ciprice (yes, that's the reason I bought the card :) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ciThe SPDIF playback and capture are done via the third PCM device 1178c2ecf20Sopenharmony_ci(hw:0,2). Usually this is assigned to the PCM device "spdif". 1188c2ecf20Sopenharmony_ciThe available rates are 44100 and 48000 Hz. 1198c2ecf20Sopenharmony_ciFor playback with aplay, you can run like below: 1208c2ecf20Sopenharmony_ci:: 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci % aplay -Dhw:0,2 foo.wav 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cior 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci:: 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci % aplay -Dspdif foo.wav 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci24bit format is also supported experimentally. 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ciThe playback and capture over SPDIF use normal DAC and ADC, 1338c2ecf20Sopenharmony_cirespectively, so you cannot playback both analog and digital streams 1348c2ecf20Sopenharmony_cisimultaneously. 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciTo enable SPDIF output, you need to turn on "IEC958 Output Switch" 1378c2ecf20Sopenharmony_cicontrol via mixer or alsactl ("IEC958" is the official name of 1388c2ecf20Sopenharmony_ciso-called S/PDIF). Then you'll see the red light on from the card so 1398c2ecf20Sopenharmony_ciyou know that's working obviously :) 1408c2ecf20Sopenharmony_ciThe SPDIF input is always enabled, so you can hear SPDIF input data 1418c2ecf20Sopenharmony_cifrom line-out with "IEC958 In Monitor" switch at any time (see 1428c2ecf20Sopenharmony_cibelow). 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciYou can play via SPDIF even with the first device (hw:0,0), 1458c2ecf20Sopenharmony_cibut SPDIF is enabled only when the proper format (S16LE), sample rate 1468c2ecf20Sopenharmony_ci(441100 or 48000) and channels (2) are used. Otherwise it's turned 1478c2ecf20Sopenharmony_cioff. (Also don't forget to turn on "IEC958 Output Switch", too.) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ciAdditionally there are relevant control switches: 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciIEC958 Mix Analog 1538c2ecf20Sopenharmony_ci Mix analog PCM playback and FM-OPL/3 streams and 1548c2ecf20Sopenharmony_ci output through SPDIF. This switch appears only on old chip 1558c2ecf20Sopenharmony_ci models (CM8738 033 and 037). 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci Note: without this control you can output PCM to SPDIF. 1588c2ecf20Sopenharmony_ci This is "mixing" of streams, so e.g. it's not for AC3 output 1598c2ecf20Sopenharmony_ci (see the next section). 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciIEC958 In Select 1628c2ecf20Sopenharmony_ci Select SPDIF input, the internal CD-in (false) 1638c2ecf20Sopenharmony_ci and the external input (true). 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ciIEC958 Loop 1668c2ecf20Sopenharmony_ci SPDIF input data is loop back into SPDIF 1678c2ecf20Sopenharmony_ci output (aka bypass) 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ciIEC958 Copyright 1708c2ecf20Sopenharmony_ci Set the copyright bit. 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciIEC958 5V 1738c2ecf20Sopenharmony_ci Select 0.5V (coax) or 5V (optical) interface. 1748c2ecf20Sopenharmony_ci On some cards this doesn't work and you need to change the 1758c2ecf20Sopenharmony_ci configuration with hardware dip-switch. 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ciIEC958 In Monitor 1788c2ecf20Sopenharmony_ci SPDIF input is routed to DAC. 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ciIEC958 In Phase Inverse 1818c2ecf20Sopenharmony_ci Set SPDIF input format as inverse. 1828c2ecf20Sopenharmony_ci [FIXME: this doesn't work on all chips..] 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ciIEC958 In Valid 1858c2ecf20Sopenharmony_ci Set input validity flag detection. 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ciNote: When "PCM Playback Switch" is on, you'll hear the digital output 1888c2ecf20Sopenharmony_cistream through analog line-out. 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciThe AC3 (RAW DIGITAL) OUTPUT 1928c2ecf20Sopenharmony_ci---------------------------- 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ciThe driver supports raw digital (typically AC3) i/o over SPDIF. This 1958c2ecf20Sopenharmony_cican be toggled via IEC958 playback control, but usually you need to 1968c2ecf20Sopenharmony_ciaccess it via alsa-lib. See alsa-lib documents for more details. 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ciOn the raw digital mode, the "PCM Playback Switch" is automatically 1998c2ecf20Sopenharmony_citurned off so that non-audio data is heard from the analog line-out. 2008c2ecf20Sopenharmony_ciSimilarly the following switches are off: "IEC958 Mix Analog" and 2018c2ecf20Sopenharmony_ci"IEC958 Loop". The switches are resumed after closing the SPDIF PCM 2028c2ecf20Sopenharmony_cidevice automatically to the previous state. 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ciOn the model 033, AC3 is implemented by the software conversion in 2058c2ecf20Sopenharmony_cithe alsa-lib. If you need to bypass the software conversion of IEC958 2068c2ecf20Sopenharmony_cisubframes, pass the "soft_ac3=0" module option. This doesn't matter 2078c2ecf20Sopenharmony_cion the newer models. 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ciANALOG MIXER INTERFACE 2118c2ecf20Sopenharmony_ci---------------------- 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ciThe mixer interface on CM8x38 is similar to SB16. 2148c2ecf20Sopenharmony_ciThere are Master, PCM, Synth, CD, Line, Mic and PC Speaker playback 2158c2ecf20Sopenharmony_civolumes. Synth, CD, Line and Mic have playback and capture switches, 2168c2ecf20Sopenharmony_citoo, as well as SB16. 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ciIn addition to the standard SB mixer, CM8x38 provides more functions. 2198c2ecf20Sopenharmony_ci- PCM playback switch 2208c2ecf20Sopenharmony_ci- PCM capture switch (to capture the data sent to DAC) 2218c2ecf20Sopenharmony_ci- Mic Boost switch 2228c2ecf20Sopenharmony_ci- Mic capture volume 2238c2ecf20Sopenharmony_ci- Aux playback volume/switch and capture switch 2248c2ecf20Sopenharmony_ci- 3D control switch 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ciMIDI CONTROLLER 2288c2ecf20Sopenharmony_ci--------------- 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ciWith CMI8338 chips, the MPU401-UART interface is disabled as default. 2318c2ecf20Sopenharmony_ciYou need to set the module option "mpu_port" to a valid I/O port address 2328c2ecf20Sopenharmony_cito enable MIDI support. Valid I/O ports are 0x300, 0x310, 0x320 and 2338c2ecf20Sopenharmony_ci0x330. Choose a value that doesn't conflict with other cards. 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ciWith CMI8738 and newer chips, the MIDI interface is enabled by default 2368c2ecf20Sopenharmony_ciand the driver automatically chooses a port address. 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ciThere is *no* hardware wavetable function on this chip (except for 2398c2ecf20Sopenharmony_ciOPL3 synth below). 2408c2ecf20Sopenharmony_ciWhat's said as MIDI synth on Windows is a software synthesizer 2418c2ecf20Sopenharmony_ciemulation. On Linux use TiMidity or other softsynth program for 2428c2ecf20Sopenharmony_ciplaying MIDI music. 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ciFM OPL/3 Synth 2468c2ecf20Sopenharmony_ci-------------- 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ciThe FM OPL/3 is also enabled as default only for the first card. 2498c2ecf20Sopenharmony_ciSet "fm_port" module option for more cards. 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ciThe output quality of FM OPL/3 is, however, very weird. 2528c2ecf20Sopenharmony_ciI don't know why.. 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ciCMI8768 and newer chips do not have the FM synth. 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ciJoystick and Modem 2588c2ecf20Sopenharmony_ci------------------ 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ciThe legacy joystick is supported. To enable the joystick support, pass 2618c2ecf20Sopenharmony_cijoystick_port=1 module option. The value 1 means the auto-detection. 2628c2ecf20Sopenharmony_ciIf the auto-detection fails, try to pass the exact I/O address. 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ciThe modem is enabled dynamically via a card control switch "Modem". 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ciDebugging Information 2688c2ecf20Sopenharmony_ci--------------------- 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ciThe registers are shown in /proc/asound/cardX/cmipci. If you have any 2718c2ecf20Sopenharmony_ciproblem (especially unexpected behavior of mixer), please attach the 2728c2ecf20Sopenharmony_cioutput of this proc file together with the bug report. 273