Matrix:Module-sun4i-codec

From AlsaProject
Revision as of 07:41, 31 December 2016 by Caysho (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Contents

Specific information about the sun4i-codec

This module is used on the Allwinner series of ARM SoC.

The alsa-info.sh script output below is from running debian on a Lemaker Banana Pi, an Allwinner A20 device, in its base configuration.

There is a single 1/8" stereo out jack.

It seems the same module is used across the series.

Take note of the Alsactl output (asound.state).

Some channels need to be muted to ensure the sound is sent to left / right correctly.

       upload=true&script=true&cardinfo=
       !!################################
       !!ALSA Information Script v 0.4.64
       !!################################
       !!Script ran on: Fri Dec 16 14:42:41 UTC 2016
       
       !!Linux Distribution
       !!------------------
       
       Debian GNU/Linux stretch/sid \n \l PRETTY_NAME="Debian GNU/Linux stretch/sid" NAME="Debian GNU/Linux" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
       
       
       !!DMI Information
       !!---------------
       
       Manufacturer:      
       Product Name:      
       Product Version:   
       Firmware Version:  
       
       
       !!Kernel Information
       !!------------------
       
       Kernel release:    4.8.0-1-armmp-lpae
       Operating System:  GNU/Linux
       Architecture:      armv7l
       Processor:         unknown
       SMP Enabled:       Yes
       
       
       !!ALSA Version
       !!------------
       
       Driver version:     k4.8.0-1-armmp-lpae
       Library version:    1.1.2
       Utilities version:  1.1.2
       
       
       !!Loaded ALSA modules
       !!-------------------
       
       (null)
       
       
       !!Sound Servers on this system
       !!----------------------------
       
       No sound servers found.
       
       
       !!Soundcards recognised by ALSA
       !!-----------------------------
       
        0 [sun4icodec     ]: sun4i-codec - sun4i-codec
                             sun4i-codec
       
       
       !!PCI Soundcards installed in the system
       !!--------------------------------------
       
       
       
       !!Advanced information - PCI Vendor/Device/Subsystem ID's
       !!-------------------------------------------------------
       
       
       
       !!Modprobe options (Sound related)
       !!--------------------------------
       
       snd_pcsp: index=-2
       snd_usb_audio: index=-2
       snd_atiixp_modem: index=-2
       snd_intel8x0m: index=-2
       snd_via82xx_modem: index=-2
       
       
       !!Loaded sound module options
       !!---------------------------
       
       !!Module: (null)
       	* : 
       
       
       !!Aplay/Arecord output
       !!--------------------
       
       APLAY
       
       **** List of PLAYBACK Hardware Devices ****
       card 0: sun4icodec [sun4i-codec], device 0: CDC PCM Codec-0 []
         Subdevices: 0/1
         Subdevice #0: subdevice #0
       
       ARECORD
       
       **** List of CAPTURE Hardware Devices ****
       card 0: sun4icodec [sun4i-codec], device 0: CDC PCM Codec-0 []
         Subdevices: 1/1
         Subdevice #0: subdevice #0
       
       !!Amixer output
       !!-------------
       
       !!-------Mixer controls for card 0 [sun4icodec]
       
       Card hw:0 'sun4icodec'/'sun4i-codec'
         Mixer name	: 
         Components	: 
         Controls      : 7
         Simple ctrls  : 7
       Simple mixer control 'Left Mixer Left DAC',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [off]
       Simple mixer control 'Power Amplifier',0
         Capabilities: volume volume-joined
         Playback channels: Mono
         Capture channels: Mono
         Limits: 0 - 63
         Mono: 63 [100%] [0.00dB]
       Simple mixer control 'Power Amplifier DAC',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [on]
       Simple mixer control 'Power Amplifier Mixer',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [off]
       Simple mixer control 'Power Amplifier Mute',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [on]
       Simple mixer control 'Right Mixer Left DAC',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [off]
       Simple mixer control 'Right Mixer Right DAC',0
         Capabilities: pswitch pswitch-joined
         Playback channels: Mono
         Mono: Playback [off]
       
       
       !!Alsactl output
       !!--------------
       
       state.sun4icodec {
       	control.1 {
       		iface MIXER
       		name 'Power Amplifier Volume'
       		value 63
       		comment {
       			access 'read write'
       			type INTEGER
       			count 1
       			range '0 - 63'
       			dbmin -9999999
       			dbmax 0
       			dbvalue.0 0
       		}
       	}
       	control.2 {
       		iface MIXER
       		name 'Left Mixer Left DAC Playback Switch'
       		value false
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       	control.3 {
       		iface MIXER
       		name 'Right Mixer Right DAC Playback Switch'
       		value false
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       	control.4 {
       		iface MIXER
       		name 'Right Mixer Left DAC Playback Switch'
       		value false
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       	control.5 {
       		iface MIXER
       		name 'Power Amplifier DAC Playback Switch'
       		value true
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       	control.6 {
       		iface MIXER
       		name 'Power Amplifier Mixer Playback Switch'
       		value false
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       	control.7 {
       		iface MIXER
       		name 'Power Amplifier Mute Switch'
       		value true
       		comment {
       			access 'read write'
       			type BOOLEAN
       			count 1
       		}
       	}
       }
       
       
       !!ALSA Device nodes
       !!-----------------
       
       crw-rw---- 1 root audio 116,  2 Nov  4 01:16 /dev/snd/controlC0
       crw-rw---- 1 root audio 116,  4 Nov  4 01:16 /dev/snd/pcmC0D0c
       crw-rw---- 1 root audio 116,  3 Nov  4 01:16 /dev/snd/pcmC0D0p
       crw-rw---- 1 root audio 116,  1 Nov  4 01:16 /dev/snd/seq
       crw-rw---- 1 root audio 116, 33 Nov  4 01:16 /dev/snd/timer
       
       /dev/snd/by-path:
       total 0
       drwxr-xr-x 2 root root  60 Nov  4 01:16 .
       drwxr-xr-x 3 root root 160 Nov  4 01:16 ..
       lrwxrwxrwx 1 root root  12 Nov  4 01:16 platform-1c22c00.codec -> ../controlC0
       
       
       !!ALSA/HDA dmesg
       !!--------------

The module options for snd-sun4i-codec (actual module name is sun41-codec)

description:  Allwinner A10 codec driver
author:  author unknown
license: GPL

Introduction for sun4i-a10-codec soundcard

There are two ways of getting Linux drivers to work, you can either compile them into the kernel or build them separately as modules. Read the Kernel-HOWTO for details of how to compile a kernel.

You must turn on the sound support soundcore module. This is in the kernel. Look in the sound drivers directory and it should be the first option. Most people enable the module setting. That way you can load and unload the module manually if you have multiple soundcards/​devices or if you intend to debug or use cutting edge software which may cause your drivers to halt sometimes. Of course it also means you have more control of your system.

Most modern distros come with soundcore compiled as a module. You can check this in numerous ways. The easiest way is to type:

       modinfo soundcore

If this command returns that you have this module, then you don't need to recompile your kernel.

Quick installation

This explains how to build from source tarballs. See GIT_Server for instructions on getting and using the latest source from git repositories.

Type the following commands in the shell of your choice.

Make a directory to store the alsa source code in:

       cd /usr/src
       mkdir alsa
       cd alsa
       cp /downloads/alsa-* .

Now unzip and install the alsa-driver package:

       bunzip2 alsa-driver-xxx
       tar -xf alsa-driver-xxx
       cd alsa-driver-xxx
       ./configure --with-cards=sun4i-codec --with-sequencer=yes ; make ; make install

Now unzip and install the alsa-lib package:

       cd ..
       bunzip2 alsa-lib-xxx
       tar -xf alsa-lib-xxx
       cd alsa-lib-xxx
       ./configure ; make ; make install

Now unzip and install the alsa-firmware package:

       cd ..
       bunzip2 alsa-firmware-xxx
       tar -xf alsa-firmware-xxx
       cd alsa-firmware-xxx
       ./configure ; make ; make install

Now unzip and install the alsa-utils package:

       cd ..
       bunzip2 alsa-utils-xxx
       tar -xf alsa-utils-xxx
       cd alsa-utils-xxx
       ./configure ; make ; make install

Now insert the modules into the kernel:

       modprobe snd-sun4i-codec ; modprobe snd-pcm-oss ; modprobe snd-mixer-oss ; modprobe snd-seq-oss

Now adjust your soundcard's volume levels. All mixer channels are muted by default. You must use a native mixer program to unmute appropriate channels, for example alsamixer from the alsa-utils package. Note that some usb-audio devices do not have internal mixer controls. Run:

       alsamixer

You can also look at the utils/​alsasound file. This script is designed for the RedHat Linux distribution, but it can also be used with other distributions which use System V style rc init scripts. This will allow you to load your modules at boot time. If you don't want to do this you can of course compile them into the kernel instead and save yourself the hassle of coming to terms with the rc init scripts.

Setting up modprobe and kmod support

Before you send a mail complaining that "I don't have /etc/​modules.conf, where do I find it ……" ‒ the /etc/​conf.modules has been deprecated with a few distro's, but in your case it may still be /etc/​conf.modules. Basically they are both the same, but recent version of modutils use /etc/​modules.conf instead. Nothing to worry about as such, optionally please update to the latest version of modutils. This should solve your problem.

Here's the example for this card. Copy and paste this to the bottom of your /etc/​modules.conf file.

Note: 

Debian GNU/Linux users need to save this information into a file in the /etc/​modutils/ directory (eg. /etc/​modutils/​alsa) and run update-modules.

Note also that the kernel module soundcore has been renamed in Debian kernels >2.6.23 into snd. A workaround is to put a symlink at /lib/modules/x.x.xx/kernel/sound/soundcore.ko pointing to snd.ko


Note: 

Systemd users need to save this information into a file in the /etc/​modprobe.d/ directory terminating with .conf (eg. /etc/​modprobe.d/​alsa.conf).

In case of modules auto-loading instead, the module name must be inserted in a file in the/etc/​modules-load.d/ directory terminating with .conf (eg. /etc/​modules-load.d/​alsa.conf).


       # ALSA portion
       alias char-major-116 snd
       alias snd-card-0 snd-sun4i-codec
       # module options should go here
       
       # OSS/Free portion
       alias char-major-14 soundcore
       alias sound-slot-0 snd-card-0
       
       # card #1
       alias sound-service-0-0 snd-mixer-oss
       alias sound-service-0-1 snd-seq-oss
       alias sound-service-0-3 snd-pcm-oss
       alias sound-service-0-8 snd-seq-oss
       alias sound-service-0-12 snd-pcm-oss

To copy and paste the above to your /etc/​modules.conf file follow these instructions.

modules.conf

This is a short explanation of what happens in the /etc/​modules.conf file.

Native devices

After the main multiplexer is loaded, its code automatically requests the top level sound card module. String snd-card-%i is requested for native devices where %i is the sound card number, counted from zero (the first sound card) to seven (the eighth sound card). String sound-slot-%i is requested for native devices where %i is slot number for the corresponding ALSA owner (which is basically the sound card number). The options line allows you to set various configuration options before the module is loaded. String id (or snd_id) lets you set the name of the card which is then returned in the /proc/​asound/​cards file, i.e. to user space applications. Other options may be available depending on the specific card. Options for these cards are found in the INSTALL file or above.

       username@hostname# pico /etc/modules.conf
       
       # ALSA portion
       alias snd-card-0 snd-hda-intel
       alias snd-card-1 snd-cmipci
       options snd-cmipci id="first" mpu_port=0x330
       
       # OSS/Free portion
       alias sound-slot-0 snd-card-0
       alias sound-slot-1 snd-card-1
NB: 

For drivers older than 0.9.0rc5 use:

       options snd-cmipci snd_id="first" snd_mpu_port=0x330


NB: 

The "snd_" prefix has been removed from the module options to fit with the kernel standard.


Autoloading OSS/free emulation

At this point we are finished with the configuration for ALSA native devices, but you may also need autoloading for the OSS/Free emulation modules, an ALSA add-on. At this time only one module does not depend on any others, thus must be loaded separately: snd-pcm1-oss. String sound-service-%i-%i is required for OSS/Free service where the first %i is the slot number/​sound card number and the second %i is the service number.

       username@hostname# pico /etc/modules.conf
       
       # OSS/Free portion - card #1
       alias sound-slot-0 snd-card-0
       alias sound-service-0-0 snd-mixer-oss
       alias sound-service-0-1 snd-seq-oss
       alias sound-service-0-3 snd-pcm-oss
       alias sound-service-0-8 snd-seq-oss
       alias sound-service-0-12 snd-pcm-oss
       
       # OSS/Free portion - card #2 (cmipci)
       alias sound-slot-1 snd-card-1
       alias sound-service-1-0 snd-mixer-oss
       alias sound-service-1-3 snd-pcm-oss
       alias sound-service-1-12 snd-pcm-oss

The alias for snd-seq-oss is not necessary on the second device, because there is only one /dev/​sequencer regardless how many devices you have.

The .asoundrc file

This file allows you to have more advanced control over your card/​device. For most setups the default, system-wide configuration is sufficient. You may change this file only for special setup. The .asoundrc file consists of definitions for the various sound devices available in your system. It also provides access to the pcm plugins in alsa-lib. These allow you to do tricky things like combine your cards into one or access multiple I/O streams on your multi-channel card.

Below is the most basic definition (only example - not required to define at all).

Make a file called .asoundrc in your home and/​or root directory:

       vi ~/.asoundrc

Copy and paste the following into the file, then save it:

       pcm.sun4i-codec {
          type hw
          card 0
       }
       
       ctl.sun4i-codec {
          type hw
          card 0
       }

Software volume control

If your card doesn't have hardware volume control (e. g. Asus Xonar XD/XDG), you might want to create software Master control. Edit .asoundrc as follows.

       pcm.softvol {
          type softvol
          slave {
             pcm "dmix"
          }
          control {
             name "Master"
             card 0
          }
       }
       
       pcm.!default {
         type plug
         slave.pcm "softvol"
       }

Restart alsa, then open a music player, play a file and close the player. Then check alsamixer, as you should have a Master volume control. Note that this control doesn't have a mute option.

Links

Generic

Specific

Custom Search
Personal tools
Namespaces

Variants
Actions
Navigation
wiki
Toolbox