struct snd_soc_dai_ops接口介紹


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 *);
};
  1. DAI 時鍾配置函數,通常由snd_card驅動即machine驅動的 hw_params函數調用
    set_sysclk 設置dai的主時鍾
    set_pll 設置codec內PLL參數
    set_clkdiv 設置分頻系數

  2. 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並聯使用同一引腳時需要使用該回調

  3. 標准的snd_soc_ops回調 通常由asoc core在進行PCM操作時調用
    startup
    shutdown
    hw_params
    hw_free
    prepare
    trigger

  4. 降低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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM