18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments Inc.
68c2ecf20Sopenharmony_ci * Copyright (C) 2015 Intel Corporation.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
98c2ecf20Sopenharmony_ci * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __LINUX_SND_SOC_TPLG_H
138c2ecf20Sopenharmony_ci#define __LINUX_SND_SOC_TPLG_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <sound/asoc.h>
168c2ecf20Sopenharmony_ci#include <linux/list.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct firmware;
198c2ecf20Sopenharmony_cistruct snd_kcontrol;
208c2ecf20Sopenharmony_cistruct snd_soc_tplg_pcm_be;
218c2ecf20Sopenharmony_cistruct snd_ctl_elem_value;
228c2ecf20Sopenharmony_cistruct snd_ctl_elem_info;
238c2ecf20Sopenharmony_cistruct snd_soc_dapm_widget;
248c2ecf20Sopenharmony_cistruct snd_soc_component;
258c2ecf20Sopenharmony_cistruct snd_soc_tplg_pcm_fe;
268c2ecf20Sopenharmony_cistruct snd_soc_dapm_context;
278c2ecf20Sopenharmony_cistruct snd_soc_card;
288c2ecf20Sopenharmony_cistruct snd_kcontrol_new;
298c2ecf20Sopenharmony_cistruct snd_soc_dai_link;
308c2ecf20Sopenharmony_cistruct snd_soc_dai_driver;
318c2ecf20Sopenharmony_cistruct snd_soc_dai;
328c2ecf20Sopenharmony_cistruct snd_soc_dapm_route;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* object scan be loaded and unloaded in groups with identfying indexes */
358c2ecf20Sopenharmony_ci#define SND_SOC_TPLG_INDEX_ALL	0	/* ID that matches all FW objects */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* dynamic object type */
388c2ecf20Sopenharmony_cienum snd_soc_dobj_type {
398c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_NONE		= 0,	/* object is not dynamic */
408c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_MIXER,
418c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_BYTES,
428c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_ENUM,
438c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_GRAPH,
448c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_WIDGET,
458c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_DAI_LINK,
468c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_PCM,
478c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_CODEC_LINK,
488c2ecf20Sopenharmony_ci	SND_SOC_DOBJ_BACKEND_LINK,
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* dynamic control object */
528c2ecf20Sopenharmony_cistruct snd_soc_dobj_control {
538c2ecf20Sopenharmony_ci	struct snd_kcontrol *kcontrol;
548c2ecf20Sopenharmony_ci	char **dtexts;
558c2ecf20Sopenharmony_ci	unsigned long *dvalues;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* dynamic widget object */
598c2ecf20Sopenharmony_cistruct snd_soc_dobj_widget {
608c2ecf20Sopenharmony_ci	unsigned int kcontrol_type;	/* kcontrol type: mixer, enum, bytes */
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* generic dynamic object - all dynamic objects belong to this struct */
648c2ecf20Sopenharmony_cistruct snd_soc_dobj {
658c2ecf20Sopenharmony_ci	enum snd_soc_dobj_type type;
668c2ecf20Sopenharmony_ci	unsigned int index;	/* objects can belong in different groups */
678c2ecf20Sopenharmony_ci	struct list_head list;
688c2ecf20Sopenharmony_ci	struct snd_soc_tplg_ops *ops;
698c2ecf20Sopenharmony_ci	union {
708c2ecf20Sopenharmony_ci		struct snd_soc_dobj_control control;
718c2ecf20Sopenharmony_ci		struct snd_soc_dobj_widget widget;
728c2ecf20Sopenharmony_ci	};
738c2ecf20Sopenharmony_ci	void *private; /* core does not touch this */
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/*
778c2ecf20Sopenharmony_ci * Kcontrol operations - used to map handlers onto firmware based controls.
788c2ecf20Sopenharmony_ci */
798c2ecf20Sopenharmony_cistruct snd_soc_tplg_kcontrol_ops {
808c2ecf20Sopenharmony_ci	u32 id;
818c2ecf20Sopenharmony_ci	int (*get)(struct snd_kcontrol *kcontrol,
828c2ecf20Sopenharmony_ci			struct snd_ctl_elem_value *ucontrol);
838c2ecf20Sopenharmony_ci	int (*put)(struct snd_kcontrol *kcontrol,
848c2ecf20Sopenharmony_ci			struct snd_ctl_elem_value *ucontrol);
858c2ecf20Sopenharmony_ci	int (*info)(struct snd_kcontrol *kcontrol,
868c2ecf20Sopenharmony_ci		struct snd_ctl_elem_info *uinfo);
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* Bytes ext operations, for TLV byte controls */
908c2ecf20Sopenharmony_cistruct snd_soc_tplg_bytes_ext_ops {
918c2ecf20Sopenharmony_ci	u32 id;
928c2ecf20Sopenharmony_ci	int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
938c2ecf20Sopenharmony_ci							unsigned int size);
948c2ecf20Sopenharmony_ci	int (*put)(struct snd_kcontrol *kcontrol,
958c2ecf20Sopenharmony_ci			const unsigned int __user *bytes, unsigned int size);
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/*
998c2ecf20Sopenharmony_ci * DAPM widget event handlers - used to map handlers onto widgets.
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_cistruct snd_soc_tplg_widget_events {
1028c2ecf20Sopenharmony_ci	u16 type;
1038c2ecf20Sopenharmony_ci	int (*event_handler)(struct snd_soc_dapm_widget *w,
1048c2ecf20Sopenharmony_ci			struct snd_kcontrol *k, int event);
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/*
1088c2ecf20Sopenharmony_ci * Public API - Used by component drivers to load and unload dynamic objects
1098c2ecf20Sopenharmony_ci * and their resources.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_cistruct snd_soc_tplg_ops {
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/* external kcontrol init - used for any driver specific init */
1148c2ecf20Sopenharmony_ci	int (*control_load)(struct snd_soc_component *, int index,
1158c2ecf20Sopenharmony_ci		struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
1168c2ecf20Sopenharmony_ci	int (*control_unload)(struct snd_soc_component *,
1178c2ecf20Sopenharmony_ci		struct snd_soc_dobj *);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	/* DAPM graph route element loading and unloading */
1208c2ecf20Sopenharmony_ci	int (*dapm_route_load)(struct snd_soc_component *, int index,
1218c2ecf20Sopenharmony_ci		struct snd_soc_dapm_route *route);
1228c2ecf20Sopenharmony_ci	int (*dapm_route_unload)(struct snd_soc_component *,
1238c2ecf20Sopenharmony_ci		struct snd_soc_dobj *);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* external widget init - used for any driver specific init */
1268c2ecf20Sopenharmony_ci	int (*widget_load)(struct snd_soc_component *, int index,
1278c2ecf20Sopenharmony_ci		struct snd_soc_dapm_widget *,
1288c2ecf20Sopenharmony_ci		struct snd_soc_tplg_dapm_widget *);
1298c2ecf20Sopenharmony_ci	int (*widget_ready)(struct snd_soc_component *, int index,
1308c2ecf20Sopenharmony_ci		struct snd_soc_dapm_widget *,
1318c2ecf20Sopenharmony_ci		struct snd_soc_tplg_dapm_widget *);
1328c2ecf20Sopenharmony_ci	int (*widget_unload)(struct snd_soc_component *,
1338c2ecf20Sopenharmony_ci		struct snd_soc_dobj *);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	/* FE DAI - used for any driver specific init */
1368c2ecf20Sopenharmony_ci	int (*dai_load)(struct snd_soc_component *, int index,
1378c2ecf20Sopenharmony_ci		struct snd_soc_dai_driver *dai_drv,
1388c2ecf20Sopenharmony_ci		struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	int (*dai_unload)(struct snd_soc_component *,
1418c2ecf20Sopenharmony_ci		struct snd_soc_dobj *);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	/* DAI link - used for any driver specific init */
1448c2ecf20Sopenharmony_ci	int (*link_load)(struct snd_soc_component *, int index,
1458c2ecf20Sopenharmony_ci		struct snd_soc_dai_link *link,
1468c2ecf20Sopenharmony_ci		struct snd_soc_tplg_link_config *cfg);
1478c2ecf20Sopenharmony_ci	int (*link_unload)(struct snd_soc_component *,
1488c2ecf20Sopenharmony_ci		struct snd_soc_dobj *);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	/* callback to handle vendor bespoke data */
1518c2ecf20Sopenharmony_ci	int (*vendor_load)(struct snd_soc_component *, int index,
1528c2ecf20Sopenharmony_ci		struct snd_soc_tplg_hdr *);
1538c2ecf20Sopenharmony_ci	int (*vendor_unload)(struct snd_soc_component *,
1548c2ecf20Sopenharmony_ci		struct snd_soc_tplg_hdr *);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	/* completion - called at completion of firmware loading */
1578c2ecf20Sopenharmony_ci	void (*complete)(struct snd_soc_component *);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	/* manifest - optional to inform component of manifest */
1608c2ecf20Sopenharmony_ci	int (*manifest)(struct snd_soc_component *, int index,
1618c2ecf20Sopenharmony_ci		struct snd_soc_tplg_manifest *);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	/* vendor specific kcontrol handlers available for binding */
1648c2ecf20Sopenharmony_ci	const struct snd_soc_tplg_kcontrol_ops *io_ops;
1658c2ecf20Sopenharmony_ci	int io_ops_count;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	/* vendor specific bytes ext handlers available for binding */
1688c2ecf20Sopenharmony_ci	const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
1698c2ecf20Sopenharmony_ci	int bytes_ext_ops_count;
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_SOC_TOPOLOGY
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* gets a pointer to data from the firmware block header */
1758c2ecf20Sopenharmony_cistatic inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	const void *ptr = hdr;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	return ptr + sizeof(*hdr);
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* Dynamic Object loading and removal for component drivers */
1838c2ecf20Sopenharmony_ciint snd_soc_tplg_component_load(struct snd_soc_component *comp,
1848c2ecf20Sopenharmony_ci	struct snd_soc_tplg_ops *ops, const struct firmware *fw,
1858c2ecf20Sopenharmony_ci	u32 index);
1868c2ecf20Sopenharmony_ciint snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* Widget removal - widgets also removed wth component API */
1898c2ecf20Sopenharmony_civoid snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
1908c2ecf20Sopenharmony_civoid snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
1918c2ecf20Sopenharmony_ci	u32 index);
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* Binds event handlers to dynamic widgets */
1948c2ecf20Sopenharmony_ciint snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
1958c2ecf20Sopenharmony_ci	const struct snd_soc_tplg_widget_events *events, int num_events,
1968c2ecf20Sopenharmony_ci	u16 event_type);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci#else
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
2018c2ecf20Sopenharmony_ci						u32 index)
2028c2ecf20Sopenharmony_ci{
2038c2ecf20Sopenharmony_ci	return 0;
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#endif
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci#endif
209