]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/sound/soc-topology.h
ASoC: soc-core: clear platform pointers on error
[mirror_ubuntu-jammy-kernel.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,
8a978234 41 SND_SOC_DOBJ_BYTES,
5c30f43f
RS
42 SND_SOC_DOBJ_ENUM,
43 SND_SOC_DOBJ_GRAPH,
44 SND_SOC_DOBJ_WIDGET,
8a978234 45 SND_SOC_DOBJ_DAI_LINK,
5c30f43f 46 SND_SOC_DOBJ_PCM,
8a978234 47 SND_SOC_DOBJ_CODEC_LINK,
8a978234
LG
48};
49
50/* dynamic control object */
51struct snd_soc_dobj_control {
52 struct snd_kcontrol *kcontrol;
53 char **dtexts;
54 unsigned long *dvalues;
55};
56
57/* dynamic widget object */
58struct snd_soc_dobj_widget {
eea3dd4f 59 unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
8a978234
LG
60};
61
8a978234
LG
62/* generic dynamic object - all dynamic objects belong to this struct */
63struct snd_soc_dobj {
64 enum snd_soc_dobj_type type;
65 unsigned int index; /* objects can belong in different groups */
66 struct list_head list;
67 struct snd_soc_tplg_ops *ops;
68 union {
69 struct snd_soc_dobj_control control;
70 struct snd_soc_dobj_widget widget;
8a978234
LG
71 };
72 void *private; /* core does not touch this */
73};
74
75/*
76 * Kcontrol operations - used to map handlers onto firmware based controls.
77 */
78struct snd_soc_tplg_kcontrol_ops {
79 u32 id;
80 int (*get)(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_value *ucontrol);
82 int (*put)(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_value *ucontrol);
84 int (*info)(struct snd_kcontrol *kcontrol,
85 struct snd_ctl_elem_info *uinfo);
86};
87
1a3232d2
ML
88/* Bytes ext operations, for TLV byte controls */
89struct snd_soc_tplg_bytes_ext_ops {
90 u32 id;
a1e5e7e9
M
91 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
92 unsigned int size);
93 int (*put)(struct snd_kcontrol *kcontrol,
94 const unsigned int __user *bytes, unsigned int size);
1a3232d2
ML
95};
96
8a978234
LG
97/*
98 * DAPM widget event handlers - used to map handlers onto widgets.
99 */
100struct snd_soc_tplg_widget_events {
101 u16 type;
102 int (*event_handler)(struct snd_soc_dapm_widget *w,
103 struct snd_kcontrol *k, int event);
104};
105
106/*
107 * Public API - Used by component drivers to load and unload dynamic objects
108 * and their resources.
109 */
110struct snd_soc_tplg_ops {
111
112 /* external kcontrol init - used for any driver specific init */
c60b613a 113 int (*control_load)(struct snd_soc_component *, int index,
8a978234
LG
114 struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
115 int (*control_unload)(struct snd_soc_component *,
116 struct snd_soc_dobj *);
117
503e79b7
LG
118 /* DAPM graph route element loading and unloading */
119 int (*dapm_route_load)(struct snd_soc_component *, int index,
120 struct snd_soc_dapm_route *route);
121 int (*dapm_route_unload)(struct snd_soc_component *,
122 struct snd_soc_dobj *);
123
8a978234 124 /* external widget init - used for any driver specific init */
c60b613a 125 int (*widget_load)(struct snd_soc_component *, int index,
8a978234
LG
126 struct snd_soc_dapm_widget *,
127 struct snd_soc_tplg_dapm_widget *);
c60b613a 128 int (*widget_ready)(struct snd_soc_component *, int index,
ebd259d3
LG
129 struct snd_soc_dapm_widget *,
130 struct snd_soc_tplg_dapm_widget *);
8a978234
LG
131 int (*widget_unload)(struct snd_soc_component *,
132 struct snd_soc_dobj *);
133
64527e8a 134 /* FE DAI - used for any driver specific init */
c60b613a
LG
135 int (*dai_load)(struct snd_soc_component *, int index,
136 struct snd_soc_dai_driver *dai_drv,
137 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
138
64527e8a 139 int (*dai_unload)(struct snd_soc_component *,
8a978234
LG
140 struct snd_soc_dobj *);
141
acfc7d46 142 /* DAI link - used for any driver specific init */
c60b613a
LG
143 int (*link_load)(struct snd_soc_component *, int index,
144 struct snd_soc_dai_link *link,
145 struct snd_soc_tplg_link_config *cfg);
acfc7d46
ML
146 int (*link_unload)(struct snd_soc_component *,
147 struct snd_soc_dobj *);
148
8a978234 149 /* callback to handle vendor bespoke data */
c60b613a 150 int (*vendor_load)(struct snd_soc_component *, int index,
8a978234
LG
151 struct snd_soc_tplg_hdr *);
152 int (*vendor_unload)(struct snd_soc_component *,
153 struct snd_soc_tplg_hdr *);
154
155 /* completion - called at completion of firmware loading */
156 void (*complete)(struct snd_soc_component *);
157
158 /* manifest - optional to inform component of manifest */
c60b613a 159 int (*manifest)(struct snd_soc_component *, int index,
8a978234
LG
160 struct snd_soc_tplg_manifest *);
161
88a17d8f 162 /* vendor specific kcontrol handlers available for binding */
8a978234
LG
163 const struct snd_soc_tplg_kcontrol_ops *io_ops;
164 int io_ops_count;
1a3232d2
ML
165
166 /* vendor specific bytes ext handlers available for binding */
167 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
168 int bytes_ext_ops_count;
8a978234
LG
169};
170
78b50f39
MB
171#ifdef CONFIG_SND_SOC_TOPOLOGY
172
8a978234
LG
173/* gets a pointer to data from the firmware block header */
174static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
175{
176 const void *ptr = hdr;
177
178 return ptr + sizeof(*hdr);
179}
180
181/* Dynamic Object loading and removal for component drivers */
182int snd_soc_tplg_component_load(struct snd_soc_component *comp,
183 struct snd_soc_tplg_ops *ops, const struct firmware *fw,
184 u32 index);
185int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
186
187/* Widget removal - widgets also removed wth component API */
188void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
189void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
190 u32 index);
191
192/* Binds event handlers to dynamic widgets */
193int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
194 const struct snd_soc_tplg_widget_events *events, int num_events,
195 u16 event_type);
196
78b50f39
MB
197#else
198
199static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
200 u32 index)
201{
202 return 0;
203}
204
205#endif
206
8a978234 207#endif