CPU DAI和codec DAI 驱动用结构体 struct snd_soc_dai_driver描述,其字段ops的类型是 struct snd_soc_dai_ops,定义了DAI驱动的操作接口。
代码如下:
struct snd_soc_dai_ops {
/*
* DAI clocking configuration, all optional.
* Called by soc_card drivers, normally in their hw_params.
*/
int (*set_sysclk)(struct snd_soc_dai *dai,
int clk_id, unsigned int freq, int dir);
int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
unsigned int freq_in, unsigned int freq_out);
int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
/*
* DAI format configuration
* Called by soc_card drivers, normally in their hw_params.
*/
int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
int (*xlate_tdm_slot_mask)(unsigned int slots,
unsigned int *tx_mask, unsigned int *rx_mask);
int (*set_tdm_slot)(struct snd_soc_dai *dai,
unsigned int tx_mask, unsigned int rx_mask,
int slots, int slot_width);
int (*set_channel_map)(struct snd_soc_dai *dai,
unsigned int tx_num, unsigned int *tx_slot,
unsigned int rx_num, unsigned int *rx_slot);
int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
/*
* DAI digital mute - optional.
* Called by soc-core to minimise any pops.
*/
int (*digital_mute)(struct snd_soc_dai *dai, int mute);
int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
/*
* ALSA PCM audio operations - all optional.
* Called by soc-core during audio PCM operations.
*/
int (*startup)(struct snd_pcm_substream *,
struct snd_soc_dai *);
void (*shutdown)(struct snd_pcm_substream *,
struct snd_soc_dai *);
int (*hw_params)(struct snd_pcm_substream *,
struct snd_pcm_hw_params *, struct snd_soc_dai *);
int (*hw_free)(struct snd_pcm_substream *,
struct snd_soc_dai *);
int (*prepare)(struct snd_pcm_substream *,
struct snd_soc_dai *);
/*
* NOTE: Commands passed to the trigger function are not necessarily
* compatible with the current state of the dai. For example this
* sequence of commands is possible: START STOP STOP.
* So do not unconditionally use refcounting functions in the trigger
* function, e.g. clk_enable/disable.
*/
int (*trigger)(struct snd_pcm_substream *, int,
struct snd_soc_dai *);
int (*bespoke_trigger)(struct snd_pcm_substream *, int,
struct snd_soc_dai *);
/*
* For hardware based FIFO caused delay reporting.
* Optional.
*/
snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
struct snd_soc_dai *);
};
-
DAI 时钟配置函数,通常由snd_card驱动即machine驱动的 hw_params函数调用
set_sysclk 设置dai的主时钟
set_pll 设置codec内PLL参数
set_clkdiv 设置分频系数 -
DAI 格式配置函数,通常由snd_card驱动即machine驱动的 hw_params函数调用
set_fmt 设置dai的格式,例如主从模式、i2s或dsp模式等
set_tdm_slot 设置DAI支持tdm时分复用,用来设置时分复用的slot,codec设备在第几个slot上读取数据。
set_channel_map 声道的时分复用映射设置
set_tristate 设置dai引脚的状态,当与其他dai并联使用同一引脚时需要使用该回调 -
标准的snd_soc_ops回调 通常由asoc core在进行PCM操作时调用
startup
shutdown
hw_params
hw_free
prepare
trigger -
降低pop音,由asoc-core调用
digital_mute
soc-dai.h文件里定义的下面函数,通常在machine驱动 struct snd_soc_ops接口的hw_params()函数里 被调用,接收struct snd_soc_dai 实例参数。
参考文档:
https://blog.csdn.net/DroidPhone/article/details/7316061