Wiki

This version is outdated by a newer approved version.DiffThis version (08 Jun 2016 20:14) was approved by Lars-Peter Clausen.The Previously approved version (20 Nov 2015 17:07) is available.Diff

This is an old revision of the document!


SSM4329 Sound CODEC Linux Driver

Supported Devices

Source Code

Status

Source Mainlined?
git WIP

Files

Example device initialization

For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.

For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.

21 Oct 2010 16:10

Declaring I2C devices

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: Documentation/i2c/instantiating-devices.rst

21 Oct 2010 16:10

The I2C address of the SSM4329 depends on the setting of the ADDR0 and ADDR1 pins

ADDR0 ADDR1 I2C Address
0 0 0x34
1 0 0x35
0 1 0x36
1 1 0x37
static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
 
	[--snip--]
	{
		I2C_BOARD_INFO("ssm4329", 0x34),
	},
	[--snip--]
}
static int __init stamp_init(void)
{
	[--snip--]
	i2c_register_board_info(0, bfin_i2c_board_info,
				ARRAY_SIZE(bfin_i2c_board_info));
	[--snip--]
 
	return 0;
}
arch_initcall(board_init);

Devicetree

i2s: i2c@41600000 {
	compatible = "...;
	...

	#size-cells = <0>;
	#address-cells = <1>;
            
	ssm4329: ssm4329@34 {
		compatible = "adi,ssm4329";
		reg = <0x34>;
		gpios = <&gpio 5 0>;
	};
};

ASoC DAPM Widgets

Name Description
OUT Class-D Amplifier Output
AIN Mono ADC Input

ALSA Controls

Name Description
DAC Playback Switch Mutes/Unmutes the DAC path
DAC Playback Volume Configures the digital Volume of the DAC
DAC Clip Point Volume Configures the cliping point of the DAC
Interpolator Playback Volume Configures the digital Volume of the Interpolator
Interpolator Clip Point Volume Configures the cliping point of the DAC
ADC Playback Switch Mutes/Unmutes the ADC path
ADC Capture Volume Configures the digital Volume of the ADC
DAC High Pass Filter Switch Enables/Disables the High Pass Filter for the DAC
DAC Low-power Switch Enables/Disables Low-power mode for the DAC
ADC High Pass Filter Switch Enables/Disables the High Pass Filter for the ADC
ADC Low-power Switch Enables/Disables Low-power mode for the DAC
Interpolator Playback Switch Mute/Unmutes the Interpolator path
Low-EMI Mode Playback Switch Enables/Disables Low-EMI mode for the Class-D stage
Amplifier Boost Switch Enables/Disables the boost of of the Class-D stage
DAC Playback Mux Selects the audio source for the DAC. Possible values: “Serial Port 1”, “Serial Port 2”, “DSP”, “ADC”.
Interpolator Playback Mux Selects the audio source for the Interpolator path. Possible values: “Serial Port 1”, “Serial Port 2”, “DSP”, “ADC”.
Serial Port 1 Channel 1 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 1 Channel 2 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 1 Channel 3 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 1 Channel 4 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 2 Channel 1 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 2 Channel 2 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 2 Channel 3 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Serial Port 2 Channel 4 Output Mux Selects the audio source for serial port 1 channel 1. Possible values: “ADC”, “AEC”, “DSP”, “SRC”, “Voltage Sense”, “Current Sense”, “VBAT”, “Voltage Sense/VBAT”, “Current Sense/VBAT”, “Interpolator”
Input SRC Channel 1 Mux Select the audio source for the sample-rate-converter channel 1. Possible values: “Serial Port 1 Channel 1”, “Serial Port 1 Channel 3”, “Serial Port 2 Channel 1”, “Serial Port 2 Channel 3”, “ADC”, “DSP”.
Input SRC Channel 2 Mux Select the audio source for the input sample-rate-converter channel 2. Possible values: “Serial Port 1 Channel 2”, “Serial Port 1 Channel 4”, “Serial Port 2 Channel 2”, “Serial Port 2 Channel 4”, “ADC”, “DSP”.
Output SRC Channel 1 Mux Selects the audio source for the output sample-rate converter channel 1. Possible values: “DSP”, “AEC”, “Input SRC”, “ADC”.
Output SRC Channel 2 Mux Selects the audio source for the output sample-rate converter channel 2. Possible values: “DSP”, “AEC”, “Input SRC”, “ADC”.

SigmaDSP Firmware

In order to use the SigmaDSP core of the SSM4329 you need to provide a firmware file. Please refer to the SigmaDSP Firmware Utility for Linux page on how to generate a firmware file. The firmware file for SSM4329 driver has to be named ssm4329.bin.

PLL configuration

To configure the PLL of the device the snd_soc_codec_set_pll() function can be used. It should be used to configure the internal PLL correctly depending on the external clock source and the desired sampling rate. The clk_id parameter must always be SSM4329_PLL. The source parameter must be one of the input clock source constants listed below. The freq_in parameter must be in the range of 8000 to 2700000, this needs to match the frequency of the selected input clock source. The freq_out parameter should typically be 98304000.

#define SSM4329_PLL 0
 
#define SSM4329_PLL_SRC_MCLKIN  0
#define SSM4329_PLL_SRC_FSYNC1  1
#define SSM4329_PLL_SRC_BCLK1   2
#define SSM4329_PLL_SRC_FSYNC2  3
#define SSM4329_PLL_SRC_BCLK2   4

DAI configuration

The codec driver registers two DAIs, one for each serial port. The DAIs are named “ssm4329-sp0” and “ssm4329-sp1”.

Supported DAI formats

Name Supported by driver Description
SND_SOC_DAIFMT_I2S yes I2S mode
SND_SOC_DAIFMT_RIGHT_J yes Right Justified mode
SND_SOC_DAIFMT_LEFT_J yes Left Justified mode
SND_SOC_DAIFMT_DSP_A yes data MSB after FRM LRC
SND_SOC_DAIFMT_DSP_B yes data MSB during FRM LRC
SND_SOC_DAIFMT_AC97 no AC97 mode
SND_SOC_DAIFMT_PDM no Pulse density modulation
SND_SOC_DAIFMT_NB_NF yes Normal bit- and frameclock
SND_SOC_DAIFMT_NB_IF yes Normal bitclock, inverted frameclock
SND_SOC_DAIFMT_IB_NF yes Inverted frameclock, normal bitclock
SND_SOC_DAIFMT_IB_IF yes Inverted bit- and frameclock
SND_SOC_DAIFMT_CBM_CFM yes Codec bit- and frameclock master
SND_SOC_DAIFMT_CBS_CFM yes Codec bitclock slave, frameclock master
SND_SOC_DAIFMT_CBM_CFS yes Codec bitclock master, frameclock slave
SND_SOC_DAIFMT_CBS_CFS yes Codec bit- and frameclock slave

TDM configuration

If you want to use the SSM4329 in TDM mode you can configure it using snd_soc_dai_set_tdm_slot() from you ASoC board driver.

The following restrictions apply to the parameters of snd_soc_dai_set_tdm_slot().

  • tx_mask specifies the output channel mapping for the serial port. The first set bit specifies the slot for the first channel, the second set bit the slot for the second channel and so on.
  • rx_mask specifies the input channel mapping for the serial port. The first set bit specifies the slot for the first channel, the second set bit the slot for the second channel and so on.
  • slots must be between 1 and 16
  • width must be either 16, 24, 32

Example:

static int ssm4329_link_init(struct snd_soc_pcm_runtime *rtd)
{
    int ret;
 
    ret = snd_soc_dai_set_tdm_slot(rtd->codec_dai, 0x0c, 0x0c, 8, 32);
    if (ret < 0)
        return ret;
 
    return 0;
}
 
static struct snd_soc_dai_link ssm4329_dai_link = {
    ...,
    .init = ssm4329_link_init,
};

Example DAI configuration

#include "../codecs/ssm4329.h"
 
static int ssm4329_zed_init(struct snd_soc_pcm_runtime *rtd)
{
    return snd_soc_codec_set_pll(rtd->codec_dai->codec, SSM4329_PLL,
                SSM4329_PLL_SRC_MCLKIN, 12288000, 2048 * 48000);
}
 
static const struct snd_soc_dapm_widget ssm4329_zed_widgets[] = {
	SND_SOC_DAPM_SPK("Speaker Out", NULL),
	SND_SOC_DAPM_LINEIN("Line In", NULL),
};
 
static const struct snd_soc_dapm_route ssm4329_zed_routes[] = {
	{ "Speaker Out", NULL, "OUT" },
	{ "AIN", NULL,  "Line In" }
};
 
static struct snd_soc_dai_link ssm4329_zed_dai_link = {
    .name = "ssm4329",
    .stream_name = "ssm4329",
    .codec_dai_name = "ssm4329-sp1",
    .dai_fmt = SND_SOC_DAIFMT_I2S |
            SND_SOC_DAIFMT_NB_NF |
            SND_SOC_DAIFMT_CBS_CFS,
    .init = ssm4329_zed_init,
};
 
static struct snd_soc_card ssm4329_zed_card = {
    .name = "ZED SSM4329",
    .owner = THIS_MODULE,
    .dai_link = &zed_ssm4329_dai_link,
    .num_links = 1,
    .dapm_widgets = zed_ssm4329_widgets,
    .num_dapm_widgets = ARRAY_SIZE(zed_ssm4329_widgets),
    .dapm_routes = zed_ssm4329_routes,
    .num_dapm_routes = ARRAY_SIZE(zed_ssm4329_routes),
    .fully_routed = true,
};

More information

resources/tools-software/linux-drivers/sound/ssm4329.1465409658.txt.gz · Last modified: 08 Jun 2016 20:14 by Lars-Peter Clausen