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