当前位置:网站首页>Codec of ASoC framework driven by alsa

Codec of ASoC framework driven by alsa

2022-06-12 05:02:00 Facing the sea 0902

One 、Nau8810 Chip system frame diagram

 System description
As can be seen from the system framework diagram , The input is differential MIC Input , The output can be MOUT or Speaker.Codec The external hardware interface passes through Audio I/O and Digital I/O, among Audio I/O Generally, the audio signal transmitted is I2S or PCM,Digital I/O The control signal is generally I2C.
The chip pin distribution is as follows :
 Insert picture description here

Two 、Codec register

static struct i2c_driver nau8810_i2c_driver = {
    
	.driver = {
    
		.name = "nau8810",
		.of_match_table = of_match_ptr(nau8810_of_match),
	},
	.probe =    nau8810_i2c_probe,
	.remove =   nau8810_i2c_remove,
	.id_table = nau8810_i2c_id,
};

We talked about it earlier nau8810 The control signal is I2C The bus is connected to the main chip of the platform , After the main system is started, it will detect I2C Whether the device registered on the bus exists , If the device exists and matches the corresponding drive , Then drive probe function Called , as follows :

static int nau8810_i2c_probe(struct i2c_client *i2c,
			    const struct i2c_device_id *id)
{
    
	struct device *dev = &i2c->dev;
	struct nau8810 *nau8810 = dev_get_platdata(dev);

	if (!nau8810) {
    
		nau8810 = devm_kzalloc(dev, sizeof(*nau8810), GFP_KERNEL);
		if (!nau8810)
			return -ENOMEM;
	}
	i2c_set_clientdata(i2c, nau8810);
	nau8810->dev = dev;
	nau8810->control_data = i2c;

	return snd_soc_register_codec(dev,
		&nau8810_codec_driver, &nau8810_dai, 1);
}

Probe function :
1、 adopt dev_get_platdata obtain dev->platform_data;
2、 Call standard snd_soc_register_codec register Codec.

3、 ... and 、 initialization Codec And dai

The focus here is on the registration above Codec Of snd_soc_register_codec(dev, &nau8810_codec_driver, &nau8810_dai, 1) Medium snd_soc_codec_driver and snd_soc_dai_driver Structure .
snd_soc_codec_driver nau8810_codec_driver as follows :

static struct snd_soc_codec_driver nau8810_codec_driver = {
    
	.probe			= nau8810_codec_probe,
	.remove 		= nau8810_codec_remove, 
	.set_bias_level = nau8810_set_bias_level,

	.read 			= nau8810_read,
	.write 			= nau8810_write,

	.reg_cache_size = ARRAY_SIZE(nau8810_reg_defaults),
	.reg_word_size = sizeof(u16),
	.reg_cache_default = nau8810_reg_defaults,
	.reg_cache_step = 1,
	
	.controls = nau8810_snd_controls,
	.num_controls = ARRAY_SIZE(nau8810_snd_controls),
	.dapm_widgets = nau8810_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(nau8810_dapm_widgets),
	.dapm_routes = nau8810_dapm_routes,
	.num_dapm_routes = ARRAY_SIZE(nau8810_dapm_routes),
	
};

Such as ALSA drive asoc Framework machine( One ) As described in : adopt 3 A global linked list , Match by name , Match the codec,dai and platform The instance is assigned to each pair of sound cards dai Of snd_soc_pcm_runtime variable . Once the binding is successful , Will make codec and dai Driven probe Callback called ,codec The initialization of is completed in this callback .
stay nau8810_codec_driver In the structure .read/write It's reading and writing Codec Register interface ,probe The main function is to initialize Codec,set_bias_level Function is used to change the working state of the chip ,dapm_widgets and dapm_routes involves DAPM It's very complicated. I'll talk about it separately later .

snd_soc_dai_driver nau8810_dai, as follows :


static struct snd_soc_dai_driver nau8810_dai = {
    
	.name = "nau8810-hifi",
	.playback = {
    
		.stream_name = "Playback",
		.channels_min = 1,
		.channels_max = 2,   /* Only 1 channel of data */
		.rates = NAU8810_RATES,
		.formats = NAU8810_FORMATS,
	},
	.capture = {
    
		.stream_name = "Capture",
		.channels_min = 1,
		.channels_max = 2,   /* Only 1 channel of data */
		.rates = NAU8810_RATES,
		.formats = NAU8810_FORMATS,
	},
	.ops = &nau8810_ops,
	.symmetric_rates = 1,
};

snd_soc_dai_driver The name structure corresponds to snd_soc_card Inside the structure dai_link The name of the member in , It has the function of recording and playing , One more operation Structure , That is to say .ops Field , It points to codec_dai The set of operation functions of , Defined dai The clock configuration of 、 Format configuration 、 Hardware parameter configuration and other callbacks , as follows :

static const struct snd_soc_dai_ops nau8810_ops = {
    
	.hw_params = nau8810_pcm_hw_params,
	.set_fmt = nau8810_set_dai_fmt,
	.set_sysclk = nau8810_set_sysclk,
	.set_pll = nau8810_set_pll,	
};

On the whole Codec The driver is almost finished , But more specifically, for example kcontrol 、widget、path And further study Codec The driver will find
snd_soc_dapm_widget,snd_soc_dapm_path,snd_soc_dapm_route, What are these and how to use them , Later we will say .

原网站

版权声明
本文为[Facing the sea 0902]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010621524559.html