ASoC: topology: fix memory leak in soc_tplg_dapm_widget_create
[linux-2.6-block.git] / include / sound / soc-topology.h
CommitLineData
f2b6a1b2
KM
1/* SPDX-License-Identifier: GPL-2.0
2 *
8a978234
LG
3 * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
4 *
5 * Copyright (C) 2012 Texas Instruments Inc.
6 * Copyright (C) 2015 Intel Corporation.
7 *
8a978234
LG
8 * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
9 * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
10 */
11
12#ifndef __LINUX_SND_SOC_TPLG_H
13#define __LINUX_SND_SOC_TPLG_H
14
15#include <sound/asoc.h>
16#include <linux/list.h>
17
18struct firmware;
19struct snd_kcontrol;
20struct snd_soc_tplg_pcm_be;
21struct snd_ctl_elem_value;
22struct snd_ctl_elem_info;
23struct snd_soc_dapm_widget;
24struct snd_soc_component;
25struct snd_soc_tplg_pcm_fe;
26struct snd_soc_dapm_context;
27struct snd_soc_card;
294de6e3
LG
28struct snd_kcontrol_new;
29struct snd_soc_dai_link;
c60b613a
LG
30struct snd_soc_dai_driver;
31struct snd_soc_dai;
503e79b7 32struct snd_soc_dapm_route;
8a978234
LG
33
34/* object scan be loaded and unloaded in groups with identfying indexes */
35#define SND_SOC_TPLG_INDEX_ALL 0 /* ID that matches all FW objects */
36
37/* dynamic object type */
38enum snd_soc_dobj_type {
39 SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */
40 SND_SOC_DOBJ_MIXER,
41 SND_SOC_DOBJ_ENUM,
42 SND_SOC_DOBJ_BYTES,
43 SND_SOC_DOBJ_PCM,
44 SND_SOC_DOBJ_DAI_LINK,
45 SND_SOC_DOBJ_CODEC_LINK,
46 SND_SOC_DOBJ_WIDGET,
47};
48
49/* dynamic control object */
50struct snd_soc_dobj_control {
51 struct snd_kcontrol *kcontrol;
52 char **dtexts;
53 unsigned long *dvalues;
54};
55
56/* dynamic widget object */
57struct snd_soc_dobj_widget {
eea3dd4f 58 unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
8a978234
LG
59};
60
8a978234
LG
61/* generic dynamic object - all dynamic objects belong to this struct */
62struct snd_soc_dobj {
63 enum snd_soc_dobj_type type;
64 unsigned int index; /* objects can belong in different groups */
65 struct list_head list;
66 struct snd_soc_tplg_ops *ops;
67 union {
68 struct snd_soc_dobj_control control;
69 struct snd_soc_dobj_widget widget;
8a978234
LG
70 };
71 void *private; /* core does not touch this */
72};
73
74/*
75 * Kcontrol operations - used to map handlers onto firmware based controls.
76 */
77struct snd_soc_tplg_kcontrol_ops {
78 u32 id;
79 int (*get)(struct snd_kcontrol *kcontrol,
80 struct snd_ctl_elem_value *ucontrol);
81 int (*put)(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_value *ucontrol);
83 int (*info)(struct snd_kcontrol *kcontrol,
84 struct snd_ctl_elem_info *uinfo);
85};
86
1a3232d2
ML
87/* Bytes ext operations, for TLV byte controls */
88struct snd_soc_tplg_bytes_ext_ops {
89 u32 id;
a1e5e7e9
M
90 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
91 unsigned int size);
92 int (*put)(struct snd_kcontrol *kcontrol,
93 const unsigned int __user *bytes, unsigned int size);
1a3232d2
ML
94};
95
8a978234
LG
96/*
97 * DAPM widget event handlers - used to map handlers onto widgets.
98 */
99struct snd_soc_tplg_widget_events {
100 u16 type;
101 int (*event_handler)(struct snd_soc_dapm_widget *w,
102 struct snd_kcontrol *k, int event);
103};
104
105/*
106 * Public API - Used by component drivers to load and unload dynamic objects
107 * and their resources.
108 */
109struct snd_soc_tplg_ops {
110
111 /* external kcontrol init - used for any driver specific init */
c60b613a 112 int (*control_load)(struct snd_soc_component *, int index,
8a978234
LG
113 struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
114 int (*control_unload)(struct snd_soc_component *,
115 struct snd_soc_dobj *);
116
503e79b7
LG
117 /* DAPM graph route element loading and unloading */
118 int (*dapm_route_load)(struct snd_soc_component *, int index,
119 struct snd_soc_dapm_route *route);
120 int (*dapm_route_unload)(struct snd_soc_component *,
121 struct snd_soc_dobj *);
122
8a978234 123 /* external widget init - used for any driver specific init */
c60b613a 124 int (*widget_load)(struct snd_soc_component *, int index,
8a978234
LG
125 struct snd_soc_dapm_widget *,
126 struct snd_soc_tplg_dapm_widget *);
c60b613a 127 int (*widget_ready)(struct snd_soc_component *, int index,
ebd259d3
LG
128 struct snd_soc_dapm_widget *,
129 struct snd_soc_tplg_dapm_widget *);
8a978234
LG
130 int (*widget_unload)(struct snd_soc_component *,
131 struct snd_soc_dobj *);
132
64527e8a 133 /* FE DAI - used for any driver specific init */
c60b613a
LG
134 int (*dai_load)(struct snd_soc_component *, int index,
135 struct snd_soc_dai_driver *dai_drv,
136 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
137
64527e8a 138 int (*dai_unload)(struct snd_soc_component *,
8a978234
LG
139 struct snd_soc_dobj *);
140
acfc7d46 141 /* DAI link - used for any driver specific init */
c60b613a
LG
142 int (*link_load)(struct snd_soc_component *, int index,
143 struct snd_soc_dai_link *link,
144 struct snd_soc_tplg_link_config *cfg);
acfc7d46
ML
145 int (*link_unload)(struct snd_soc_component *,
146 struct snd_soc_dobj *);
147
8a978234 148 /* callback to handle vendor bespoke data */
c60b613a 149 int (*vendor_load)(struct snd_soc_component *, int index,
8a978234
LG
150 struct snd_soc_tplg_hdr *);
151 int (*vendor_unload)(struct snd_soc_component *,
152 struct snd_soc_tplg_hdr *);
153
154 /* completion - called at completion of firmware loading */
155 void (*complete)(struct snd_soc_component *);
156
157 /* manifest - optional to inform component of manifest */
c60b613a 158 int (*manifest)(struct snd_soc_component *, int index,
8a978234
LG
159 struct snd_soc_tplg_manifest *);
160
88a17d8f 161 /* vendor specific kcontrol handlers available for binding */
8a978234
LG
162 const struct snd_soc_tplg_kcontrol_ops *io_ops;
163 int io_ops_count;
1a3232d2
ML
164
165 /* vendor specific bytes ext handlers available for binding */
166 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
167 int bytes_ext_ops_count;
8a978234
LG
168};
169
78b50f39
MB
170#ifdef CONFIG_SND_SOC_TOPOLOGY
171
8a978234
LG
172/* gets a pointer to data from the firmware block header */
173static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
174{
175 const void *ptr = hdr;
176
177 return ptr + sizeof(*hdr);
178}
179
180/* Dynamic Object loading and removal for component drivers */
181int snd_soc_tplg_component_load(struct snd_soc_component *comp,
182 struct snd_soc_tplg_ops *ops, const struct firmware *fw,
183 u32 index);
184int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
185
186/* Widget removal - widgets also removed wth component API */
187void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
188void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
189 u32 index);
190
191/* Binds event handlers to dynamic widgets */
192int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
193 const struct snd_soc_tplg_widget_events *events, int num_events,
194 u16 event_type);
195
78b50f39
MB
196#else
197
198static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
199 u32 index)
200{
201 return 0;
202}
203
204#endif
205
8a978234 206#endif