linux/sound/soc/sof/sof-audio.h

/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/*
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * Copyright(c) 2019 Intel Corporation
 *
 * Author: Ranjani Sridharan <[email protected]>
 */

#ifndef __SOUND_SOC_SOF_AUDIO_H
#define __SOUND_SOC_SOF_AUDIO_H

#include <linux/workqueue.h>

#include <sound/soc.h>
#include <sound/control.h>
#include <sound/sof/stream.h> /* needs to be included before control.h */
#include <sound/sof/control.h>
#include <sound/sof/dai.h>
#include <sound/sof/topology.h>
#include "sof-priv.h"

#define SOF_AUDIO_PCM_DRV_NAME

/*
 * The ipc4 firmware only supports up to 8 sink or source pins
 * per widget, because only 3 bits are used for queue(pin) ID
 * in ipc4 protocol.
 */
#define SOF_WIDGET_MAX_NUM_PINS

/* Widget pin type */
#define SOF_PIN_TYPE_INPUT
#define SOF_PIN_TYPE_OUTPUT

/* max number of FE PCMs before BEs */
#define SOF_BE_PCM_BASE

#define DMA_CHAN_INVALID

#define WIDGET_IS_DAI(id)
#define WIDGET_IS_AIF(id)
#define WIDGET_IS_AIF_OR_DAI(id)
#define WIDGET_IS_COPIER(id)

#define SOF_DAI_PARAM_INTEL_SSP_MCLK
#define SOF_DAI_PARAM_INTEL_SSP_BCLK
#define SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS

enum sof_widget_op {};

/*
 * Volume fractional word length define to 16 sets
 * the volume linear gain value to use Qx.16 format
 */
#define VOLUME_FWL

#define SOF_TLV_ITEMS

static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
{}

static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
{}

struct snd_sof_widget;
struct snd_sof_route;
struct snd_sof_control;
struct snd_sof_dai;
struct snd_sof_pcm;

struct snd_sof_dai_config_data {};

/**
 * struct sof_ipc_pcm_ops - IPC-specific PCM ops
 * @hw_params: Function pointer for hw_params
 * @hw_free: Function pointer for hw_free
 * @trigger: Function pointer for trigger
 * @dai_link_fixup: Function pointer for DAI link fixup
 * @pcm_setup: Function pointer for IPC-specific PCM set up that can be used for allocating
 *	       additional memory in the SOF PCM stream structure
 * @pcm_free: Function pointer for PCM free that can be used for freeing any
 *	       additional memory in the SOF PCM stream structure
 * @pointer: Function pointer for pcm pointer
 *	     Note: the @pointer callback may return -EOPNOTSUPP which should be
 *		   handled in a same way as if the callback is not provided
 * @delay: Function pointer for pcm delay reporting
 * @reset_hw_params_during_stop: Flag indicating whether the hw_params should be reset during the
 *				 STOP pcm trigger
 * @ipc_first_on_start: Send IPC before invoking platform trigger during
 *				START/PAUSE_RELEASE triggers
 * @platform_stop_during_hw_free: Invoke the platform trigger during hw_free. This is needed for
 *				  IPC4 where a pipeline is only paused during stop/pause/suspend
 *				  triggers. The FW keeps the host DMA running in this case and
 *				  therefore the host must do the same and should stop the DMA during
 *				  hw_free.
 * @d0i3_supported_in_s0ix: Allow DSP D0I3 during S0iX
 */
struct sof_ipc_pcm_ops {};

/**
 * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
 */
struct sof_ipc_tplg_control_ops {};

/**
 * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
 * @ipc_setup: Function pointer for setting up widget IPC params
 * @ipc_free: Function pointer for freeing widget IPC params
 * @token_list: List of token ID's that should be parsed for the widget
 * @token_list_size: number of elements in token_list
 * @bind_event: Function pointer for binding events to the widget
 * @ipc_prepare: Optional op for preparing a widget for set up
 * @ipc_unprepare: Optional op for unpreparing a widget
 */
struct sof_ipc_tplg_widget_ops {};

/**
 * struct sof_ipc_tplg_ops - IPC-specific topology ops
 * @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
 *	    SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
 *	    initialized to 0.
 * @control: Pointer to the IPC-specific ops for topology kcontrol IO
 * @route_setup: Function pointer for setting up pipeline connections
 * @route_free: Function pointer for freeing pipeline connections.
 * @token_list: List of all tokens supported by the IPC version. The size of the token_list
 *		array should be SOF_TOKEN_COUNT. The unused elements in the array will be
 *		initialized to 0.
 * @control_setup: Function pointer for setting up kcontrol IPC-specific data
 * @control_free: Function pointer for freeing kcontrol IPC-specific data
 * @pipeline_complete: Function pointer for pipeline complete IPC
 * @widget_setup: Function pointer for setting up setup in the DSP
 * @widget_free: Function pointer for freeing widget in the DSP
 * @dai_config: Function pointer for sending DAI config IPC to the DSP
 * @dai_get_param: Function pointer for getting the DAI parameter
 * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
 * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
 * @parse_manifest: Function pointer for ipc4 specific parsing of topology manifest
 * @link_setup: Function pointer for IPC-specific DAI link set up
 *
 * Note: function pointers (ops) are optional
 */
struct sof_ipc_tplg_ops {};

/** struct snd_sof_tuple - Tuple info
 * @token:	Token ID
 * @value:	union of a string or a u32 values
 */
struct snd_sof_tuple {};

/*
 * List of SOF token ID's. The order of ID's does not matter as token arrays are looked up based on
 * the ID.
 */
enum sof_tokens {};

/**
 * struct sof_topology_token - SOF topology token definition
 * @token:		Token number
 * @type:		Token type
 * @get_token:		Function pointer to parse the token value and save it in a object
 * @offset:		Offset within an object to save the token value into
 */
struct sof_topology_token {};

struct sof_token_info {};

/**
 * struct snd_sof_pcm_stream_pipeline_list - List of pipelines associated with a PCM stream
 * @count: number of pipeline widgets in the @pipe_widgets array
 * @pipelines: array of pipelines
 */
struct snd_sof_pcm_stream_pipeline_list {};

/* PCM stream, mapped to FW component  */
struct snd_sof_pcm_stream {};

/* ALSA SOF PCM device */
struct snd_sof_pcm {};

struct snd_sof_led_control {};

/* ALSA SOF Kcontrol device */
struct snd_sof_control {};

/** struct snd_sof_dai_link - DAI link info
 * @tuples: array of parsed tuples
 * @num_tuples: number of tuples in the tuples array
 * @link: Pointer to snd_soc_dai_link
 * @hw_configs: Pointer to hw configs in topology
 * @num_hw_configs: Number of hw configs in topology
 * @default_hw_cfg_id: Default hw config ID
 * @type: DAI type
 * @list: item in snd_sof_dev dai_link list
 */
struct snd_sof_dai_link {};

/* ASoC SOF DAPM widget */
struct snd_sof_widget {};

/** struct snd_sof_pipeline - ASoC SOF pipeline
 * @pipe_widget: Pointer to the pipeline widget
 * @started_count: Count of number of PCM's that have started this pipeline
 * @paused_count: Count of number of PCM's that have started and have currently paused this
		  pipeline
 * @complete: flag used to indicate that pipeline set up is complete.
 * @core_mask: Mask containing target cores for all modules in the pipeline
 * @list: List item in sdev pipeline_list
 */
struct snd_sof_pipeline {};

/* ASoC SOF DAPM route */
struct snd_sof_route {};

/* ASoC DAI device */
struct snd_sof_dai {};

/*
 * Kcontrols.
 */

int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
		       struct snd_ctl_elem_value *ucontrol);
int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
		       struct snd_ctl_elem_value *ucontrol);
int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
			struct snd_ctl_elem_info *uinfo);
int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
		       struct snd_ctl_elem_value *ucontrol);
int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
		       struct snd_ctl_elem_value *ucontrol);
int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
		     struct snd_ctl_elem_value *ucontrol);
int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
		     struct snd_ctl_elem_value *ucontrol);
int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
		      struct snd_ctl_elem_value *ucontrol);
int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
		      struct snd_ctl_elem_value *ucontrol);
int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
			  const unsigned int __user *binary_data,
			  unsigned int size);
int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
			  unsigned int __user *binary_data,
			  unsigned int size);
int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
				   unsigned int size);
void snd_sof_control_notify(struct snd_sof_dev *sdev,
			    struct sof_ipc_ctrl_data *cdata);

/*
 * Topology.
 * There is no snd_sof_free_topology since topology components will
 * be freed by snd_soc_unregister_component,
 */
int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);

/*
 * Stream IPC
 */
int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
			    struct snd_sof_pcm *spcm, int direction,
			    struct sof_ipc_stream_posn *posn);

struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
					    const char *name);
struct snd_sof_widget *
snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
			   const char *pcm_name, int dir);
struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
				     const char *name);

static inline
struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
					  struct snd_soc_pcm_runtime *rtd)
{}

struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
					   const char *name);
struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
					   unsigned int comp_id,
					   int *direction);
void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
void snd_sof_pcm_init_elapsed_work(struct work_struct *work);

#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
void snd_sof_compr_init_elapsed_work(struct work_struct *work);
#else
static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
#endif

/* DAI link fixup */
int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);

/* PM */
bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);

/* Machine driver enumeration */
int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);

int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
		    struct snd_soc_dapm_widget *wsink);

/* PCM */
int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
			  struct snd_pcm_hw_params *fe_params,
			  struct snd_sof_platform_stream_params *platform_params,
			  int dir);
int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
			 struct snd_sof_pcm *spcm);
int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
			struct snd_sof_pcm *spcm, int dir, bool free_widget_list);
int get_token_u32(void *elem, void *object, u32 offset);
int get_token_u16(void *elem, void *object, u32 offset);
int get_token_comp_format(void *elem, void *object, u32 offset);
int get_token_dai_type(void *elem, void *object, u32 offset);
int get_token_uuid(void *elem, void *object, u32 offset);
int get_token_string(void *elem, void *object, u32 offset);
int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
			  struct snd_sof_tuple *tuples, int num_tuples,
			  size_t object_size, int token_instance_num);
u32 vol_compute_gain(u32 value, int *tlv);
#endif