1. 程式人生 > >新路程------imx6q aplay設定引數路徑驗證

新路程------imx6q aplay設定引數路徑驗證

aplay先是open了pcm一個節點,然後用ioctl來設定引數,這個節點是

在sound/aoa/soundbus/i2sbus/core.c中的i2sbus_probe函式中的i2sbus_add_dev中生成的,

這個裝置節點初始化的時候dev->sound.attach_codec = i2sbus_attach_codec;

在這個attach,位置在sound/aoa/soundbus/i2sbus/pcm.c中

主要是err = snd_pcm_new(card, dev->pcmname, dev->pcmid, 0, 0,

 &dev->pcm);

在pcm.c中if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0)這裡的ops裡

static struct snd_device_ops ops = {
.dev_free = snd_pcm_dev_free,
.dev_register = snd_pcm_dev_register,
.dev_disconnect = snd_pcm_dev_disconnect,

}; 

在sound/core/pcm.c中static int snd_pcm_dev_register(struct snd_device *device)中

err = snd_register_device_for_dev(devtype, pcm->card,
 pcm->device,
 &snd_pcm_f_ops[cidx],
 pcm, str, dev);

這裡的snd_pcm_f_ops裡有個ioctl

const struct file_operations snd_pcm_f_ops[2] = {
{
.owner = THIS_MODULE,
.write = snd_pcm_write,
.aio_write = snd_pcm_aio_write,
.open =

snd_pcm_playback_open,
.release = snd_pcm_release,
.llseek = no_llseek,
.poll = snd_pcm_playback_poll,
.unlocked_ioctl = snd_pcm_playback_ioctl, //這個就是真實的上層設定路徑的時候的呼叫
.compat_ioctl = snd_pcm_ioctl_compat,
.mmap = snd_pcm_mmap,
.fasync = snd_pcm_fasync,
.get_unmapped_area = snd_pcm_get_unmapped_area,
},
{
.owner = THIS_MODULE,
.read = snd_pcm_read,
.aio_read = snd_pcm_aio_read,
.open = snd_pcm_capture_open,//這個就是真實的上層設定路徑的時候的呼叫
.release = snd_pcm_release,
.llseek = no_llseek,
.poll = snd_pcm_capture_poll,
.unlocked_ioctl = snd_pcm_capture_ioctl,
.compat_ioctl = snd_pcm_ioctl_compat,
.mmap = snd_pcm_mmap,
.fasync = snd_pcm_fasync,
.get_unmapped_area = snd_pcm_get_unmapped_area,
}

};

真正的設定引數的函式是sound/pcm_native.c中的

static int snd_pcm_common_ioctl1(struct file *file,
struct snd_pcm_substream *substream,

unsigned int cmd, void __user *arg)裡

case SNDRV_PCM_IOCTL_HW_PARAMS:

return snd_pcm_s

hw_params_user(substream, arg);

然後呼叫到了

err = substream->ops->hw_params(substream, params);這裡的ops->hw_params就是我們的驅動中的

static struct snd_soc_ops imx_hifi_ops = {
.startup = imx_hifi_startup,
.shutdown = imx_hifi_shutdown,
.hw_params = imx_hifi_hw_params,
.hw_free = imx_hifi_hw_free,
.trigger = imx_hifi_trigger,
};完成了硬體裝置的設定