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