linux/sound/soc/sof/topology.c

// 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) 2018 Intel Corporation
//
// Author: Liam Girdwood <[email protected]>
//

#include <linux/bits.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/firmware.h>
#include <linux/workqueue.h>
#include <sound/tlv.h>
#include <uapi/sound/sof/tokens.h>
#include "sof-priv.h"
#include "sof-audio.h"
#include "ops.h"

#define COMP_ID_UNASSIGNED
/*
 * Constants used in the computation of linear volume gain
 * from dB gain 20th root of 10 in Q1.16 fixed-point notation
 */
#define VOL_TWENTIETH_ROOT_OF_TEN
/* 40th root of 10 in Q1.16 fixed-point notation*/
#define VOL_FORTIETH_ROOT_OF_TEN

/* 0.5 dB step value in topology TLV */
#define VOL_HALF_DB_STEP

/* TLV data items */
#define TLV_MIN
#define TLV_STEP
#define TLV_MUTE

/**
 * sof_update_ipc_object - Parse multiple sets of tokens within the token array associated with the
 *			    token ID.
 * @scomp: pointer to SOC component
 * @object: target IPC struct to save the parsed values
 * @token_id: token ID for the token array to be searched
 * @tuples: pointer to the tuples array
 * @num_tuples: number of tuples in the tuples array
 * @object_size: size of the object
 * @token_instance_num: number of times the same @token_id needs to be parsed i.e. the function
 *			looks for @token_instance_num of each token in the token array associated
 *			with the @token_id
 */
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)
{}

static inline int get_tlv_data(const int *p, int tlv[SOF_TLV_ITEMS])
{}

/*
 * Function to truncate an unsigned 64-bit number
 * by x bits and return 32-bit unsigned number. This
 * function also takes care of rounding while truncating
 */
static inline u32 vol_shift_64(u64 i, u32 x)
{}

/*
 * Function to compute a ^ exp where,
 * a is a fractional number represented by a fixed-point
 * integer with a fractional world length of "fwl"
 * exp is an integer
 * fwl is the fractional word length
 * Return value is a fractional number represented by a
 * fixed-point integer with a fractional word length of "fwl"
 */
static u32 vol_pow32(u32 a, int exp, u32 fwl)
{}

/*
 * Function to calculate volume gain from TLV data.
 * This function can only handle gain steps that are multiples of 0.5 dB
 */
u32 vol_compute_gain(u32 value, int *tlv)
{}

/*
 * Set up volume table for kcontrols from tlv data
 * "size" specifies the number of entries in the table
 */
static int set_up_volume_table(struct snd_sof_control *scontrol,
			       int tlv[SOF_TLV_ITEMS], int size)
{}

struct sof_dai_types {};

static const struct sof_dai_types sof_dais[] =;

static enum sof_ipc_dai_type find_dai(const char *name)
{}

/*
 * Supported Frame format types and lookup, add new ones to end of list.
 */

struct sof_frame_types {};

static const struct sof_frame_types sof_frames[] =;

static enum sof_ipc_frame find_format(const char *name)
{}

int get_token_u32(void *elem, void *object, u32 offset)
{}

int get_token_u16(void *elem, void *object, u32 offset)
{}

int get_token_uuid(void *elem, void *object, u32 offset)
{}

/*
 * The string gets from topology will be stored in heap, the owner only
 * holds a char* member point to the heap.
 */
int get_token_string(void *elem, void *object, u32 offset)
{
	/* "dst" here points to the char* member of the owner */
	char **dst = (char **)((u8 *)object + offset);

	*dst = kstrdup(elem, GFP_KERNEL);
	if (!*dst)
		return -ENOMEM;
	return 0;
};

int get_token_comp_format(void *elem, void *object, u32 offset)
{}

int get_token_dai_type(void *elem, void *object, u32 offset)
{}

/* PCM */
static const struct sof_topology_token stream_tokens[] =;

/* Leds */
static const struct sof_topology_token led_tokens[] =;

static const struct sof_topology_token comp_pin_tokens[] =;

static const struct sof_topology_token comp_input_pin_binding_tokens[] =;

static const struct sof_topology_token comp_output_pin_binding_tokens[] =;

/**
 * sof_parse_uuid_tokens - Parse multiple sets of UUID tokens
 * @scomp: pointer to soc component
 * @object: target ipc struct for parsed values
 * @offset: offset within the object pointer
 * @tokens: array of struct sof_topology_token containing the tokens to be matched
 * @num_tokens: number of tokens in tokens array
 * @array: source pointer to consecutive vendor arrays in topology
 *
 * This function parses multiple sets of string type tokens in vendor arrays
 */
static int sof_parse_uuid_tokens(struct snd_soc_component *scomp,
				  void *object, size_t offset,
				  const struct sof_topology_token *tokens, int num_tokens,
				  struct snd_soc_tplg_vendor_array *array)
{}

/**
 * sof_copy_tuples - Parse tokens and copy them to the @tuples array
 * @sdev: pointer to struct snd_sof_dev
 * @array: source pointer to consecutive vendor arrays in topology
 * @array_size: size of @array
 * @token_id: Token ID associated with a token array
 * @token_instance_num: number of times the same @token_id needs to be parsed i.e. the function
 *			looks for @token_instance_num of each token in the token array associated
 *			with the @token_id
 * @tuples: tuples array to copy the matched tuples to
 * @tuples_size: size of @tuples
 * @num_copied_tuples: pointer to the number of copied tuples in the tuples array
 *
 */
static int sof_copy_tuples(struct snd_sof_dev *sdev, struct snd_soc_tplg_vendor_array *array,
			   int array_size, u32 token_id, int token_instance_num,
			   struct snd_sof_tuple *tuples, int tuples_size, int *num_copied_tuples)
{}

/**
 * sof_parse_string_tokens - Parse multiple sets of tokens
 * @scomp: pointer to soc component
 * @object: target ipc struct for parsed values
 * @offset: offset within the object pointer
 * @tokens: array of struct sof_topology_token containing the tokens to be matched
 * @num_tokens: number of tokens in tokens array
 * @array: source pointer to consecutive vendor arrays in topology
 *
 * This function parses multiple sets of string type tokens in vendor arrays
 */
static int sof_parse_string_tokens(struct snd_soc_component *scomp,
				   void *object, int offset,
				   const struct sof_topology_token *tokens, int num_tokens,
				   struct snd_soc_tplg_vendor_array *array)
{}

/**
 * sof_parse_word_tokens - Parse multiple sets of tokens
 * @scomp: pointer to soc component
 * @object: target ipc struct for parsed values
 * @offset: offset within the object pointer
 * @tokens: array of struct sof_topology_token containing the tokens to be matched
 * @num_tokens: number of tokens in tokens array
 * @array: source pointer to consecutive vendor arrays in topology
 *
 * This function parses multiple sets of word type tokens in vendor arrays
 */
static int sof_parse_word_tokens(struct snd_soc_component *scomp,
				  void *object, int offset,
				  const struct sof_topology_token *tokens, int num_tokens,
				  struct snd_soc_tplg_vendor_array *array)
{}

/**
 * sof_parse_token_sets - Parse multiple sets of tokens
 * @scomp: pointer to soc component
 * @object: target ipc struct for parsed values
 * @tokens: token definition array describing what tokens to parse
 * @count: number of tokens in definition array
 * @array: source pointer to consecutive vendor arrays in topology
 * @array_size: total size of @array
 * @token_instance_num: number of times the same tokens needs to be parsed i.e. the function
 *			looks for @token_instance_num of each token in the @tokens
 * @object_size: offset to next target ipc struct with multiple sets
 *
 * This function parses multiple sets of tokens in vendor arrays into
 * consecutive ipc structs.
 */
static int sof_parse_token_sets(struct snd_soc_component *scomp,
				void *object, const struct sof_topology_token *tokens,
				int count, struct snd_soc_tplg_vendor_array *array,
				int array_size, int token_instance_num, size_t object_size)
{}

/**
 * sof_parse_tokens - Parse one set of tokens
 * @scomp: pointer to soc component
 * @object: target ipc struct for parsed values
 * @tokens: token definition array describing what tokens to parse
 * @num_tokens: number of tokens in definition array
 * @array: source pointer to consecutive vendor arrays in topology
 * @array_size: total size of @array
 *
 * This function parses a single set of tokens in vendor arrays into
 * consecutive ipc structs.
 */
static int sof_parse_tokens(struct snd_soc_component *scomp,  void *object,
			    const struct sof_topology_token *tokens, int num_tokens,
			    struct snd_soc_tplg_vendor_array *array,
			    int array_size)

{}

/*
 * Standard Kcontrols.
 */

static int sof_control_load_volume(struct snd_soc_component *scomp,
				   struct snd_sof_control *scontrol,
				   struct snd_kcontrol_new *kc,
				   struct snd_soc_tplg_ctl_hdr *hdr)
{}

static int sof_control_load_enum(struct snd_soc_component *scomp,
				 struct snd_sof_control *scontrol,
				 struct snd_kcontrol_new *kc,
				 struct snd_soc_tplg_ctl_hdr *hdr)
{}

static int sof_control_load_bytes(struct snd_soc_component *scomp,
				  struct snd_sof_control *scontrol,
				  struct snd_kcontrol_new *kc,
				  struct snd_soc_tplg_ctl_hdr *hdr)
{}

/* external kcontrol init - used for any driver specific init */
static int sof_control_load(struct snd_soc_component *scomp, int index,
			    struct snd_kcontrol_new *kc,
			    struct snd_soc_tplg_ctl_hdr *hdr)
{}

static int sof_control_unload(struct snd_soc_component *scomp,
			      struct snd_soc_dobj *dobj)
{}

/*
 * DAI Topology
 */

static int sof_connect_dai_widget(struct snd_soc_component *scomp,
				  struct snd_soc_dapm_widget *w,
				  struct snd_soc_tplg_dapm_widget *tw,
				  struct snd_sof_dai *dai)
{}

static void sof_disconnect_dai_widget(struct snd_soc_component *scomp,
				      struct snd_soc_dapm_widget *w)
{}

/* bind PCM ID to host component ID */
static int spcm_bind(struct snd_soc_component *scomp, struct snd_sof_pcm *spcm,
		     int dir)
{}

static int sof_get_token_value(u32 token_id, struct snd_sof_tuple *tuples, int num_tuples)
{}

static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
				   struct snd_soc_tplg_dapm_widget *tw,
				   enum sof_tokens *object_token_list, int count)
{}

static void sof_free_pin_binding(struct snd_sof_widget *swidget,
				 bool pin_type)
{}

static int sof_parse_pin_binding(struct snd_sof_widget *swidget,
				 struct snd_soc_tplg_private *priv, bool pin_type)
{}

static int get_w_no_wname_in_long_name(void *elem, void *object, u32 offset)
{}

static const struct sof_topology_token dapm_widget_tokens[] =;

/* external widget init - used for any driver specific init */
static int sof_widget_ready(struct snd_soc_component *scomp, int index,
			    struct snd_soc_dapm_widget *w,
			    struct snd_soc_tplg_dapm_widget *tw)
{}

static int sof_route_unload(struct snd_soc_component *scomp,
			    struct snd_soc_dobj *dobj)
{}

static int sof_widget_unload(struct snd_soc_component *scomp,
			     struct snd_soc_dobj *dobj)
{}

/*
 * DAI HW configuration.
 */

/* FE DAI - used for any driver specific init */
static int sof_dai_load(struct snd_soc_component *scomp, int index,
			struct snd_soc_dai_driver *dai_drv,
			struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai)
{}

static int sof_dai_unload(struct snd_soc_component *scomp,
			  struct snd_soc_dobj *dobj)
{}

static const struct sof_topology_token common_dai_link_tokens[] =;

/* DAI link - used for any driver specific init */
static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_soc_dai_link *link,
			 struct snd_soc_tplg_link_config *cfg)
{}

static int sof_link_unload(struct snd_soc_component *scomp, struct snd_soc_dobj *dobj)
{}

/* DAI link - used for any driver specific init */
static int sof_route_load(struct snd_soc_component *scomp, int index,
			  struct snd_soc_dapm_route *route)
{}

/**
 * sof_set_widget_pipeline - Set pipeline for a component
 * @sdev: pointer to struct snd_sof_dev
 * @spipe: pointer to struct snd_sof_pipeline
 * @swidget: pointer to struct snd_sof_widget that has the same pipeline ID as @pipe_widget
 *
 * Return: 0 if successful, -EINVAL on error.
 * The function checks if @swidget is associated with any volatile controls. If so, setting
 * the dynamic_pipeline_widget is disallowed.
 */
static int sof_set_widget_pipeline(struct snd_sof_dev *sdev, struct snd_sof_pipeline *spipe,
				   struct snd_sof_widget *swidget)
{}

/* completion - called at completion of firmware loading */
static int sof_complete(struct snd_soc_component *scomp)
{}

/* manifest - optional to inform component of manifest */
static int sof_manifest(struct snd_soc_component *scomp, int index,
			struct snd_soc_tplg_manifest *man)
{}

/* vendor specific kcontrol handlers available for binding */
static const struct snd_soc_tplg_kcontrol_ops sof_io_ops[] =;

/* vendor specific bytes ext handlers available for binding */
static const struct snd_soc_tplg_bytes_ext_ops sof_bytes_ext_ops[] =;

static const struct snd_soc_tplg_ops sof_tplg_ops =;

static int snd_sof_dspless_kcontrol(struct snd_kcontrol *kcontrol,
				    struct snd_ctl_elem_value *ucontrol)
{}

static const struct snd_soc_tplg_kcontrol_ops sof_dspless_io_ops[] =;

static int snd_sof_dspless_bytes_ext_get(struct snd_kcontrol *kcontrol,
					 unsigned int __user *binary_data,
					 unsigned int size)
{}

static int snd_sof_dspless_bytes_ext_put(struct snd_kcontrol *kcontrol,
					 const unsigned int __user *binary_data,
					 unsigned int size)
{}

static const struct snd_soc_tplg_bytes_ext_ops sof_dspless_bytes_ext_ops[] =;

/* external widget init - used for any driver specific init */
static int sof_dspless_widget_ready(struct snd_soc_component *scomp, int index,
				    struct snd_soc_dapm_widget *w,
				    struct snd_soc_tplg_dapm_widget *tw)
{}

static int sof_dspless_widget_unload(struct snd_soc_component *scomp,
				     struct snd_soc_dobj *dobj)
{}

static int sof_dspless_link_load(struct snd_soc_component *scomp, int index,
				 struct snd_soc_dai_link *link,
				 struct snd_soc_tplg_link_config *cfg)
{}

static const struct snd_soc_tplg_ops sof_dspless_tplg_ops =;

int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
{}
EXPORT_SYMBOL();