linux/include/sound/soc-dai.h

/* SPDX-License-Identifier: GPL-2.0
 *
 * linux/sound/soc-dai.h -- ALSA SoC Layer
 *
 * Copyright:	2005-2008 Wolfson Microelectronics. PLC.
 *
 * Digital Audio Interface (DAI) API.
 */

#ifndef __LINUX_SND_SOC_DAI_H
#define __LINUX_SND_SOC_DAI_H


#include <linux/list.h>
#include <sound/asoc.h>

struct snd_pcm_substream;
struct snd_soc_dapm_widget;
struct snd_compr_stream;

/*
 * DAI hardware audio formats.
 *
 * Describes the physical PCM data formating and clocking. Add new formats
 * to the end.
 */
#define SND_SOC_DAIFMT_I2S
#define SND_SOC_DAIFMT_RIGHT_J
#define SND_SOC_DAIFMT_LEFT_J
#define SND_SOC_DAIFMT_DSP_A
#define SND_SOC_DAIFMT_DSP_B
#define SND_SOC_DAIFMT_AC97
#define SND_SOC_DAIFMT_PDM

/* left and right justified also known as MSB and LSB respectively */
#define SND_SOC_DAIFMT_MSB
#define SND_SOC_DAIFMT_LSB

/* Describes the possible PCM format */
/*
 * use SND_SOC_DAI_FORMAT_xx as eash shift.
 * see
 *	snd_soc_runtime_get_dai_fmt()
 */
#define SND_SOC_POSSIBLE_DAIFMT_FORMAT_SHIFT
#define SND_SOC_POSSIBLE_DAIFMT_FORMAT_MASK
#define SND_SOC_POSSIBLE_DAIFMT_I2S
#define SND_SOC_POSSIBLE_DAIFMT_RIGHT_J
#define SND_SOC_POSSIBLE_DAIFMT_LEFT_J
#define SND_SOC_POSSIBLE_DAIFMT_DSP_A
#define SND_SOC_POSSIBLE_DAIFMT_DSP_B
#define SND_SOC_POSSIBLE_DAIFMT_AC97
#define SND_SOC_POSSIBLE_DAIFMT_PDM

/*
 * DAI Clock gating.
 *
 * DAI bit clocks can be gated (disabled) when the DAI is not
 * sending or receiving PCM data in a frame. This can be used to save power.
 */
#define SND_SOC_DAIFMT_CONT
#define SND_SOC_DAIFMT_GATED

/* Describes the possible PCM format */
/*
 * define GATED -> CONT. GATED will be selected if both are selected.
 * see
 *	snd_soc_runtime_get_dai_fmt()
 */
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_MASK
#define SND_SOC_POSSIBLE_DAIFMT_GATED
#define SND_SOC_POSSIBLE_DAIFMT_CONT

/*
 * DAI hardware signal polarity.
 *
 * Specifies whether the DAI can also support inverted clocks for the specified
 * format.
 *
 * BCLK:
 * - "normal" polarity means signal is available at rising edge of BCLK
 * - "inverted" polarity means signal is available at falling edge of BCLK
 *
 * FSYNC "normal" polarity depends on the frame format:
 * - I2S: frame consists of left then right channel data. Left channel starts
 *      with falling FSYNC edge, right channel starts with rising FSYNC edge.
 * - Left/Right Justified: frame consists of left then right channel data.
 *      Left channel starts with rising FSYNC edge, right channel starts with
 *      falling FSYNC edge.
 * - DSP A/B: Frame starts with rising FSYNC edge.
 * - AC97: Frame starts with rising FSYNC edge.
 *
 * "Negative" FSYNC polarity is the one opposite of "normal" polarity.
 */
#define SND_SOC_DAIFMT_NB_NF
#define SND_SOC_DAIFMT_NB_IF
#define SND_SOC_DAIFMT_IB_NF
#define SND_SOC_DAIFMT_IB_IF

/* Describes the possible PCM format */
#define SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT
#define SND_SOC_POSSIBLE_DAIFMT_INV_MASK
#define SND_SOC_POSSIBLE_DAIFMT_NB_NF
#define SND_SOC_POSSIBLE_DAIFMT_NB_IF
#define SND_SOC_POSSIBLE_DAIFMT_IB_NF
#define SND_SOC_POSSIBLE_DAIFMT_IB_IF

/*
 * DAI hardware clock providers/consumers
 *
 * This is wrt the codec, the inverse is true for the interface
 * i.e. if the codec is clk and FRM provider then the interface is
 * clk and frame consumer.
 */
#define SND_SOC_DAIFMT_CBP_CFP
#define SND_SOC_DAIFMT_CBC_CFP
#define SND_SOC_DAIFMT_CBP_CFC
#define SND_SOC_DAIFMT_CBC_CFC

/* previous definitions kept for backwards-compatibility, do not use in new contributions */
#define SND_SOC_DAIFMT_CBM_CFM
#define SND_SOC_DAIFMT_CBS_CFM
#define SND_SOC_DAIFMT_CBM_CFS
#define SND_SOC_DAIFMT_CBS_CFS

/* when passed to set_fmt directly indicate if the device is provider or consumer */
#define SND_SOC_DAIFMT_BP_FP
#define SND_SOC_DAIFMT_BC_FP
#define SND_SOC_DAIFMT_BP_FC
#define SND_SOC_DAIFMT_BC_FC

/* Describes the possible PCM format */
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_MASK
#define SND_SOC_POSSIBLE_DAIFMT_CBP_CFP
#define SND_SOC_POSSIBLE_DAIFMT_CBC_CFP
#define SND_SOC_POSSIBLE_DAIFMT_CBP_CFC
#define SND_SOC_POSSIBLE_DAIFMT_CBC_CFC

#define SND_SOC_DAIFMT_FORMAT_MASK
#define SND_SOC_DAIFMT_CLOCK_MASK
#define SND_SOC_DAIFMT_INV_MASK
#define SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK

#define SND_SOC_DAIFMT_MASTER_MASK

/*
 * Master Clock Directions
 */
#define SND_SOC_CLOCK_IN
#define SND_SOC_CLOCK_OUT

#define SND_SOC_STD_AC97_FMTS

struct snd_soc_dai_driver;
struct snd_soc_dai;
struct snd_ac97_bus_ops;

/* Digital Audio Interface clocking API.*/
int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
	unsigned int freq, int dir);

int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
	int div_id, int div);

int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
	int pll_id, int source, unsigned int freq_in, unsigned int freq_out);

int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);

/* Digital Audio interface formatting */
int snd_soc_dai_get_fmt_max_priority(const struct snd_soc_pcm_runtime *rtd);
u64 snd_soc_dai_get_fmt(const struct snd_soc_dai *dai, int priority);
int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);

int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
	unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);

int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
	unsigned int tx_num, const unsigned int *tx_slot,
	unsigned int rx_num, const unsigned int *rx_slot);

int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);

/* Digital Audio Interface mute */
int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
			     int direction);


int snd_soc_dai_get_channel_map(const struct snd_soc_dai *dai,
		unsigned int *tx_num, unsigned int *tx_slot,
		unsigned int *rx_num, unsigned int *rx_slot);

int snd_soc_dai_is_dummy(const struct snd_soc_dai *dai);

int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
			  struct snd_pcm_substream *substream,
			  struct snd_pcm_hw_params *params);
void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
			 struct snd_pcm_substream *substream,
			 int rollback);
int snd_soc_dai_startup(struct snd_soc_dai *dai,
			struct snd_pcm_substream *substream);
void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
			  struct snd_pcm_substream *substream, int rollback);
void snd_soc_dai_suspend(struct snd_soc_dai *dai);
void snd_soc_dai_resume(struct snd_soc_dai *dai);
int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
			     struct snd_soc_pcm_runtime *rtd, int num);
bool snd_soc_dai_stream_valid(const struct snd_soc_dai *dai, int stream);
void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link);
void snd_soc_dai_action(struct snd_soc_dai *dai,
			int stream, int action);
static inline void snd_soc_dai_activate(struct snd_soc_dai *dai,
					int stream)
{}
static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai,
					  int stream)
{}
int snd_soc_dai_active(const struct snd_soc_dai *dai);

int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order);
int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order);
int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd);
int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream);
int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
			    int rollback);
int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
				    int cmd);
void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
			   snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);

int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
			      struct snd_compr_stream *cstream);
void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
				struct snd_compr_stream *cstream,
				int rollback);
int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
			      struct snd_compr_stream *cstream, int cmd);
int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
				 struct snd_compr_stream *cstream,
				 struct snd_compr_params *params);
int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
				 struct snd_compr_stream *cstream,
				 struct snd_codec *params);
int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
			  struct snd_compr_stream *cstream,
			  size_t bytes);
int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
			      struct snd_compr_stream *cstream,
			      struct snd_compr_tstamp *tstamp);
int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
				   struct snd_compr_stream *cstream,
				   struct snd_compr_metadata *metadata);
int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
				   struct snd_compr_stream *cstream,
				   struct snd_compr_metadata *metadata);

const char *snd_soc_dai_name_get(const struct snd_soc_dai *dai);

struct snd_soc_dai_ops {};

struct snd_soc_cdai_ops {};

/*
 * Digital Audio Interface Driver.
 *
 * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
 * operations and capabilities. Codec and platform drivers will register this
 * structure for every DAI they have.
 *
 * This structure covers the clocking, formating and ALSA operations for each
 * interface.
 */
struct snd_soc_dai_driver {};

/* for Playback/Capture */
struct snd_soc_dai_stream {};

/*
 * Digital Audio Interface runtime data.
 *
 * Holds runtime data for a DAI.
 */
struct snd_soc_dai {};

static inline const struct snd_soc_pcm_stream *
snd_soc_dai_get_pcm_stream(const struct snd_soc_dai *dai, int stream)
{}

#define snd_soc_dai_get_widget_playback(dai)
#define snd_soc_dai_get_widget_capture(dai)
static inline
struct snd_soc_dapm_widget *snd_soc_dai_get_widget(struct snd_soc_dai *dai, int stream)
{}

#define snd_soc_dai_set_widget_playback(dai, widget)
#define snd_soc_dai_set_widget_capture(dai,  widget)
static inline
void snd_soc_dai_set_widget(struct snd_soc_dai *dai, int stream, struct snd_soc_dapm_widget *widget)
{}

#define snd_soc_dai_dma_data_get_playback(dai)
#define snd_soc_dai_dma_data_get_capture(dai)
#define snd_soc_dai_get_dma_data(dai, ss)
static inline void *snd_soc_dai_dma_data_get(const struct snd_soc_dai *dai, int stream)
{}

#define snd_soc_dai_dma_data_set_playback(dai, data)
#define snd_soc_dai_dma_data_set_capture(dai,  data)
#define snd_soc_dai_set_dma_data(dai, ss, data)
static inline void snd_soc_dai_dma_data_set(struct snd_soc_dai *dai, int stream, void *data)
{}

static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai, void *playback, void *capture)
{}

static inline unsigned int snd_soc_dai_tdm_mask_get(const struct snd_soc_dai *dai,
						    int stream)
{}

static inline void snd_soc_dai_tdm_mask_set(struct snd_soc_dai *dai, int stream,
					    unsigned int tdm_mask)
{}

static inline unsigned int snd_soc_dai_stream_active(const struct snd_soc_dai *dai,
						     int stream)
{}

static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
		void *data)
{}

static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
{}

/**
 * snd_soc_dai_set_stream() - Configures a DAI for stream operation
 * @dai: DAI
 * @stream: STREAM (opaque structure depending on DAI type)
 * @direction: Stream direction(Playback/Capture)
 * Some subsystems, such as SoundWire, don't have a notion of direction and we reuse
 * the ASoC stream direction to configure sink/source ports.
 * Playback maps to source ports and Capture for sink ports.
 *
 * This should be invoked with NULL to clear the stream set previously.
 * Returns 0 on success, a negative error code otherwise.
 */
static inline int snd_soc_dai_set_stream(struct snd_soc_dai *dai,
					 void *stream, int direction)
{}

/**
 * snd_soc_dai_get_stream() - Retrieves stream from DAI
 * @dai: DAI
 * @direction: Stream direction(Playback/Capture)
 *
 * This routine only retrieves that was previously configured
 * with snd_soc_dai_get_stream()
 *
 * Returns pointer to stream or an ERR_PTR value, e.g.
 * ERR_PTR(-ENOTSUPP) if callback is not supported;
 */
static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
					   int direction)
{}

#endif