strace分析: aplay Windows.wav
1. /dev/snd/controlC0 对应的file_operations是snd_ctl_f_ops
open : snd_ctl_open
SNDRV_CTL_IOCTL_PVERSION : snd_ctl_ioctl -> put_user(SNDRV_CTL_VERSION, ip)
SNDRV_CTL_IOCTL_CARD_INFO : snd_ctl_ioctl -> snd_ctl_card_info(card, ctl, cmd, argp);
copy_to_user
SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE : snd_ctl_ioctl -> snd_pcm_control_ioctl -> control->prefer_pcm_subdevice = val;
close
上述三个ioctl不涉及硬件操作
2. /dev/snd/pcmC0D0p 对应的file_operations是snd_pcm_f_ops[0]
open : snd_pcm_playback_open
snd_pcm_open
snd_pcm_open_file
struct snd_pcm_substream *substream;
snd_pcm_open_substream
err = snd_pcm_hw_constraints_init(substream);
err = substream->ops->open(substream) // substream->ops : snd_pcm_ops结构体
soc_pcm_open
依次调用cpu_dai, dma, codec_dai, machine的open或startup函数
pcm_file->substream = substream;
file->private_data = pcm_file;
注意:substream->ops = soc_new_pcm函数里的soc_pcm_ops
以下的ioctl入口都是:snd_pcm_playback_ioctl
SNDRV_PCM_IOCTL_INFO : snd_pcm_info_user(substream, arg);
substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_INFO, info);
snd_pcm_lib_ioctl
SNDRV_PCM_IOCTL_PVERSION : put_user(SNDRV_PCM_VERSION, (int __user *)arg)
SNDRV_PCM_IOCTL_TTSTAMP : snd_pcm_tstamp(substream, arg);
SNDRV_PCM_IOCTL_SYNC_PTR : snd_pcm_sync_ptr(substream, arg); 先不管
SNDRV_PCM_IOCTL_HW_REFINE .... : snd_pcm_hw_refine_user(substream, arg);
memdup_user
snd_pcm_hw_refine(substream, params); 先不管
copy_to_user
SNDRV_PCM_IOCTL_HW_PARAMS : snd_pcm_hw_params_user(substream, arg);
snd_pcm_hw_params
substream->ops->hw_params(substream, params);
soc_pcm_hw_params
依次调用machine,codec_dai,cpu_dai,platform(dma)的hw_params函数
SNDRV_PCM_IOCTL_SYNC_PTR
SNDRV_PCM_IOCTL_SW_PARAMS : snd_pcm_sw_params_user(substream, arg);
snd_pcm_sw_params 不涉及硬件操作
SNDRV_PCM_IOCTL_SYNC_PTR
SNDRV_PCM_IOCTL_PREPARE : snd_pcm_prepare(substream, file);
snd_power_wait // 电源管理相关,先不管
SNDRV_PCM_IOCTL_SYNC_PTR
SNDRV_PCM_IOCTL_SW_PARAMS
循环:
SNDRV_PCM_IOCTL_WRITEI_FRAMES : copy_from_user
snd_pcm_lib_write
snd_pcm_lib_write1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_write_transfer)
snd_pcm_lib_write_transfer
copy_from_user
snd_pcm_start(substream); // 启动传输
SNDRV_PCM_IOCTL_SYNC_PTR
SNDRV_PCM_IOCTL_DRAIN
SNDRV_PCM_IOCTL_DROP
SNDRV_PCM_IOCTL_HW_FREE
close
strace分析: amixer cset numid=1 30 (设置音量)
/dev/snd/controlC0
open
SNDRV_CTL_IOCTL_CARD_INFO
SNDRV_CTL_IOCTL_PVERSION
SNDRV_CTL_IOCTL_ELEM_INFO
SNDRV_CTL_IOCTL_ELEM_READ
SNDRV_CTL_IOCTL_ELEM_WRITE : snd_ctl_elem_write_user
snd_ctl_elem_write
result = kctl->put(kctl, control);
附:
static struct snd_soc_card snd_soc_s3c24xx_uda134x = {
.name = "S3C24XX_UDA134X",
.owner = THIS_MODULE,
.dai_link = &s3c24xx_uda134x_dai_link,
.num_links = 1,
};
static struct snd_soc_dai_link s3c24xx_uda134x_dai_link = {
.name = "UDA134X",
.stream_name = "UDA134X",
.codec_name = "uda134x-codec",
.codec_dai_name = "uda134x-hifi",
.cpu_dai_name = "s3c24xx-iis",
.ops = &s3c24xx_uda134x_ops,
.platform_name = "samsung-audio",
};