xref: /linux/include/sound/soc-topology.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1f2b6a1b2SKuninori Morimoto /* SPDX-License-Identifier: GPL-2.0
2f2b6a1b2SKuninori Morimoto  *
38a978234SLiam Girdwood  * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
48a978234SLiam Girdwood  *
58a978234SLiam Girdwood  * Copyright (C) 2012 Texas Instruments Inc.
68a978234SLiam Girdwood  * Copyright (C) 2015 Intel Corporation.
78a978234SLiam Girdwood  *
88a978234SLiam Girdwood  * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
98a978234SLiam Girdwood  * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
108a978234SLiam Girdwood  */
118a978234SLiam Girdwood 
128a978234SLiam Girdwood #ifndef __LINUX_SND_SOC_TPLG_H
138a978234SLiam Girdwood #define __LINUX_SND_SOC_TPLG_H
148a978234SLiam Girdwood 
158a978234SLiam Girdwood #include <sound/asoc.h>
168a978234SLiam Girdwood #include <linux/list.h>
178a978234SLiam Girdwood 
188a978234SLiam Girdwood struct firmware;
198a978234SLiam Girdwood struct snd_kcontrol;
208a978234SLiam Girdwood struct snd_soc_tplg_pcm_be;
218a978234SLiam Girdwood struct snd_ctl_elem_value;
228a978234SLiam Girdwood struct snd_ctl_elem_info;
238a978234SLiam Girdwood struct snd_soc_dapm_widget;
248a978234SLiam Girdwood struct snd_soc_component;
258a978234SLiam Girdwood struct snd_soc_tplg_pcm_fe;
268a978234SLiam Girdwood struct snd_soc_dapm_context;
278a978234SLiam Girdwood struct snd_soc_card;
28294de6e3SLiam Girdwood struct snd_kcontrol_new;
29294de6e3SLiam Girdwood struct snd_soc_dai_link;
30c60b613aSLiam Girdwood struct snd_soc_dai_driver;
31c60b613aSLiam Girdwood struct snd_soc_dai;
32503e79b7SLiam Girdwood struct snd_soc_dapm_route;
338a978234SLiam Girdwood 
348a978234SLiam Girdwood /* dynamic object type */
358a978234SLiam Girdwood enum snd_soc_dobj_type {
368a978234SLiam Girdwood 	SND_SOC_DOBJ_NONE		= 0,	/* object is not dynamic */
378a978234SLiam Girdwood 	SND_SOC_DOBJ_MIXER,
388a978234SLiam Girdwood 	SND_SOC_DOBJ_BYTES,
395c30f43fSRanjani Sridharan 	SND_SOC_DOBJ_ENUM,
405c30f43fSRanjani Sridharan 	SND_SOC_DOBJ_GRAPH,
418a978234SLiam Girdwood 	SND_SOC_DOBJ_WIDGET,
425c30f43fSRanjani Sridharan 	SND_SOC_DOBJ_DAI_LINK,
435c30f43fSRanjani Sridharan 	SND_SOC_DOBJ_PCM,
445c30f43fSRanjani Sridharan 	SND_SOC_DOBJ_CODEC_LINK,
45adfebb51SBard liao 	SND_SOC_DOBJ_BACKEND_LINK,
468a978234SLiam Girdwood };
478a978234SLiam Girdwood 
488a978234SLiam Girdwood /* dynamic control object */
498a978234SLiam Girdwood struct snd_soc_dobj_control {
508a978234SLiam Girdwood 	struct snd_kcontrol *kcontrol;
518a978234SLiam Girdwood 	char **dtexts;
528a978234SLiam Girdwood 	unsigned long *dvalues;
538a978234SLiam Girdwood };
548a978234SLiam Girdwood 
558a978234SLiam Girdwood /* dynamic widget object */
568a978234SLiam Girdwood struct snd_soc_dobj_widget {
57d29d41e2SJaska Uimonen 	unsigned int *kcontrol_type;	/* kcontrol type: mixer, enum, bytes */
588a978234SLiam Girdwood };
598a978234SLiam Girdwood 
608a978234SLiam Girdwood /* generic dynamic object - all dynamic objects belong to this struct */
618a978234SLiam Girdwood struct snd_soc_dobj {
628a978234SLiam Girdwood 	enum snd_soc_dobj_type type;
638a978234SLiam Girdwood 	unsigned int index;	/* objects can belong in different groups */
648a978234SLiam Girdwood 	struct list_head list;
6531e92739SAmadeusz Sławiński 	int (*unload)(struct snd_soc_component *comp, struct snd_soc_dobj *dobj);
668a978234SLiam Girdwood 	union {
678a978234SLiam Girdwood 		struct snd_soc_dobj_control control;
688a978234SLiam Girdwood 		struct snd_soc_dobj_widget widget;
698a978234SLiam Girdwood 	};
708a978234SLiam Girdwood 	void *private; /* core does not touch this */
718a978234SLiam Girdwood };
728a978234SLiam Girdwood 
738a978234SLiam Girdwood /*
748a978234SLiam Girdwood  * Kcontrol operations - used to map handlers onto firmware based controls.
758a978234SLiam Girdwood  */
768a978234SLiam Girdwood struct snd_soc_tplg_kcontrol_ops {
778a978234SLiam Girdwood 	u32 id;
788a978234SLiam Girdwood 	int (*get)(struct snd_kcontrol *kcontrol,
798a978234SLiam Girdwood 			struct snd_ctl_elem_value *ucontrol);
808a978234SLiam Girdwood 	int (*put)(struct snd_kcontrol *kcontrol,
818a978234SLiam Girdwood 			struct snd_ctl_elem_value *ucontrol);
828a978234SLiam Girdwood 	int (*info)(struct snd_kcontrol *kcontrol,
838a978234SLiam Girdwood 		struct snd_ctl_elem_info *uinfo);
848a978234SLiam Girdwood };
858a978234SLiam Girdwood 
861a3232d2SMengdong Lin /* Bytes ext operations, for TLV byte controls */
871a3232d2SMengdong Lin struct snd_soc_tplg_bytes_ext_ops {
881a3232d2SMengdong Lin 	u32 id;
89a1e5e7e9SMythri P K 	int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
90a1e5e7e9SMythri P K 							unsigned int size);
91a1e5e7e9SMythri P K 	int (*put)(struct snd_kcontrol *kcontrol,
92a1e5e7e9SMythri P K 			const unsigned int __user *bytes, unsigned int size);
931a3232d2SMengdong Lin };
941a3232d2SMengdong Lin 
958a978234SLiam Girdwood /*
968a978234SLiam Girdwood  * DAPM widget event handlers - used to map handlers onto widgets.
978a978234SLiam Girdwood  */
988a978234SLiam Girdwood struct snd_soc_tplg_widget_events {
998a978234SLiam Girdwood 	u16 type;
1008a978234SLiam Girdwood 	int (*event_handler)(struct snd_soc_dapm_widget *w,
1018a978234SLiam Girdwood 			struct snd_kcontrol *k, int event);
1028a978234SLiam Girdwood };
1038a978234SLiam Girdwood 
1048a978234SLiam Girdwood /*
1058a978234SLiam Girdwood  * Public API - Used by component drivers to load and unload dynamic objects
1068a978234SLiam Girdwood  * and their resources.
1078a978234SLiam Girdwood  */
1088a978234SLiam Girdwood struct snd_soc_tplg_ops {
1098a978234SLiam Girdwood 
1108a978234SLiam Girdwood 	/* external kcontrol init - used for any driver specific init */
111c60b613aSLiam Girdwood 	int (*control_load)(struct snd_soc_component *, int index,
1128a978234SLiam Girdwood 		struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
1138a978234SLiam Girdwood 	int (*control_unload)(struct snd_soc_component *,
1148a978234SLiam Girdwood 		struct snd_soc_dobj *);
1158a978234SLiam Girdwood 
116503e79b7SLiam Girdwood 	/* DAPM graph route element loading and unloading */
117503e79b7SLiam Girdwood 	int (*dapm_route_load)(struct snd_soc_component *, int index,
118503e79b7SLiam Girdwood 		struct snd_soc_dapm_route *route);
119503e79b7SLiam Girdwood 	int (*dapm_route_unload)(struct snd_soc_component *,
120503e79b7SLiam Girdwood 		struct snd_soc_dobj *);
121503e79b7SLiam Girdwood 
1228a978234SLiam Girdwood 	/* external widget init - used for any driver specific init */
123c60b613aSLiam Girdwood 	int (*widget_load)(struct snd_soc_component *, int index,
1248a978234SLiam Girdwood 		struct snd_soc_dapm_widget *,
1258a978234SLiam Girdwood 		struct snd_soc_tplg_dapm_widget *);
126c60b613aSLiam Girdwood 	int (*widget_ready)(struct snd_soc_component *, int index,
127ebd259d3SLiam Girdwood 		struct snd_soc_dapm_widget *,
128ebd259d3SLiam Girdwood 		struct snd_soc_tplg_dapm_widget *);
1298a978234SLiam Girdwood 	int (*widget_unload)(struct snd_soc_component *,
1308a978234SLiam Girdwood 		struct snd_soc_dobj *);
1318a978234SLiam Girdwood 
13264527e8aSMengdong Lin 	/* FE DAI - used for any driver specific init */
133c60b613aSLiam Girdwood 	int (*dai_load)(struct snd_soc_component *, int index,
134c60b613aSLiam Girdwood 		struct snd_soc_dai_driver *dai_drv,
135c60b613aSLiam Girdwood 		struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
136c60b613aSLiam Girdwood 
13764527e8aSMengdong Lin 	int (*dai_unload)(struct snd_soc_component *,
1388a978234SLiam Girdwood 		struct snd_soc_dobj *);
1398a978234SLiam Girdwood 
140acfc7d46SMengdong Lin 	/* DAI link - used for any driver specific init */
141c60b613aSLiam Girdwood 	int (*link_load)(struct snd_soc_component *, int index,
142c60b613aSLiam Girdwood 		struct snd_soc_dai_link *link,
143c60b613aSLiam Girdwood 		struct snd_soc_tplg_link_config *cfg);
144acfc7d46SMengdong Lin 	int (*link_unload)(struct snd_soc_component *,
145acfc7d46SMengdong Lin 		struct snd_soc_dobj *);
146acfc7d46SMengdong Lin 
1478a978234SLiam Girdwood 	/* callback to handle vendor bespoke data */
148c60b613aSLiam Girdwood 	int (*vendor_load)(struct snd_soc_component *, int index,
1498a978234SLiam Girdwood 		struct snd_soc_tplg_hdr *);
1508a978234SLiam Girdwood 	int (*vendor_unload)(struct snd_soc_component *,
1518a978234SLiam Girdwood 		struct snd_soc_tplg_hdr *);
1528a978234SLiam Girdwood 
1538a978234SLiam Girdwood 	/* completion - called at completion of firmware loading */
154415717e1SRanjani Sridharan 	int (*complete)(struct snd_soc_component *comp);
1558a978234SLiam Girdwood 
1568a978234SLiam Girdwood 	/* manifest - optional to inform component of manifest */
157c60b613aSLiam Girdwood 	int (*manifest)(struct snd_soc_component *, int index,
1588a978234SLiam Girdwood 		struct snd_soc_tplg_manifest *);
1598a978234SLiam Girdwood 
16088a17d8fSMengdong Lin 	/* vendor specific kcontrol handlers available for binding */
1618a978234SLiam Girdwood 	const struct snd_soc_tplg_kcontrol_ops *io_ops;
1628a978234SLiam Girdwood 	int io_ops_count;
1631a3232d2SMengdong Lin 
1641a3232d2SMengdong Lin 	/* vendor specific bytes ext handlers available for binding */
1651a3232d2SMengdong Lin 	const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
1661a3232d2SMengdong Lin 	int bytes_ext_ops_count;
1678a978234SLiam Girdwood };
1688a978234SLiam Girdwood 
16978b50f39SMark Brown #ifdef CONFIG_SND_SOC_TOPOLOGY
17078b50f39SMark Brown 
1718a978234SLiam Girdwood /* gets a pointer to data from the firmware block header */
snd_soc_tplg_get_data(struct snd_soc_tplg_hdr * hdr)1728a978234SLiam Girdwood static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
1738a978234SLiam Girdwood {
1748a978234SLiam Girdwood 	const void *ptr = hdr;
1758a978234SLiam Girdwood 
1768a978234SLiam Girdwood 	return ptr + sizeof(*hdr);
1778a978234SLiam Girdwood }
1788a978234SLiam Girdwood 
1798a978234SLiam Girdwood /* Dynamic Object loading and removal for component drivers */
1808a978234SLiam Girdwood int snd_soc_tplg_component_load(struct snd_soc_component *comp,
181*73444768SChristophe JAILLET 	const struct snd_soc_tplg_ops *ops, const struct firmware *fw);
182a5b8f71cSAmadeusz Sławiński int snd_soc_tplg_component_remove(struct snd_soc_component *comp);
1838a978234SLiam Girdwood 
1848a978234SLiam Girdwood /* Binds event handlers to dynamic widgets */
1858a978234SLiam Girdwood int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
1868a978234SLiam Girdwood 	const struct snd_soc_tplg_widget_events *events, int num_events,
1878a978234SLiam Girdwood 	u16 event_type);
1888a978234SLiam Girdwood 
18978b50f39SMark Brown #else
19078b50f39SMark Brown 
snd_soc_tplg_component_remove(struct snd_soc_component * comp)1911198ff12SMark Brown static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
19278b50f39SMark Brown {
19378b50f39SMark Brown 	return 0;
19478b50f39SMark Brown }
19578b50f39SMark Brown 
19678b50f39SMark Brown #endif
19778b50f39SMark Brown 
1988a978234SLiam Girdwood #endif
199