2 * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
4 * Copyright (C) 2012 Texas Instruments Inc.
5 * Copyright (C) 2015 Intel Corporation.
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.
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.
15 #ifndef __LINUX_SND_SOC_TPLG_H
16 #define __LINUX_SND_SOC_TPLG_H
18 #include <sound/asoc.h>
19 #include <linux/list.h>
23 struct snd_soc_tplg_pcm_be
;
24 struct snd_ctl_elem_value
;
25 struct snd_ctl_elem_info
;
26 struct snd_soc_dapm_widget
;
27 struct snd_soc_component
;
28 struct snd_soc_tplg_pcm_fe
;
29 struct snd_soc_dapm_context
;
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 */
35 /* dynamic object type */
36 enum snd_soc_dobj_type
{
37 SND_SOC_DOBJ_NONE
= 0, /* object is not dynamic */
42 SND_SOC_DOBJ_DAI_LINK
,
43 SND_SOC_DOBJ_CODEC_LINK
,
47 /* dynamic control object */
48 struct snd_soc_dobj_control
{
49 struct snd_kcontrol
*kcontrol
;
51 unsigned long *dvalues
;
54 /* dynamic widget object */
55 struct snd_soc_dobj_widget
{
56 unsigned int kcontrol_enum
:1; /* this widget is an enum kcontrol */
59 /* dynamic PCM DAI object */
60 struct snd_soc_dobj_pcm_dai
{
61 struct snd_soc_tplg_pcm_dai
*pd
;
65 /* generic dynamic object - all dynamic objects belong to this struct */
67 enum snd_soc_dobj_type type
;
68 unsigned int index
; /* objects can belong in different groups */
69 struct list_head list
;
70 struct snd_soc_tplg_ops
*ops
;
72 struct snd_soc_dobj_control control
;
73 struct snd_soc_dobj_widget widget
;
74 struct snd_soc_dobj_pcm_dai pcm_dai
;
76 void *private; /* core does not touch this */
80 * Kcontrol operations - used to map handlers onto firmware based controls.
82 struct snd_soc_tplg_kcontrol_ops
{
84 int (*get
)(struct snd_kcontrol
*kcontrol
,
85 struct snd_ctl_elem_value
*ucontrol
);
86 int (*put
)(struct snd_kcontrol
*kcontrol
,
87 struct snd_ctl_elem_value
*ucontrol
);
88 int (*info
)(struct snd_kcontrol
*kcontrol
,
89 struct snd_ctl_elem_info
*uinfo
);
92 /* Bytes ext operations, for TLV byte controls */
93 struct snd_soc_tplg_bytes_ext_ops
{
95 int (*get
)(unsigned int __user
*bytes
, unsigned int size
);
96 int (*put
)(const unsigned int __user
*bytes
, unsigned int size
);
100 * DAPM widget event handlers - used to map handlers onto widgets.
102 struct snd_soc_tplg_widget_events
{
104 int (*event_handler
)(struct snd_soc_dapm_widget
*w
,
105 struct snd_kcontrol
*k
, int event
);
109 * Public API - Used by component drivers to load and unload dynamic objects
110 * and their resources.
112 struct snd_soc_tplg_ops
{
114 /* external kcontrol init - used for any driver specific init */
115 int (*control_load
)(struct snd_soc_component
*,
116 struct snd_kcontrol_new
*, struct snd_soc_tplg_ctl_hdr
*);
117 int (*control_unload
)(struct snd_soc_component
*,
118 struct snd_soc_dobj
*);
120 /* external widget init - used for any driver specific init */
121 int (*widget_load
)(struct snd_soc_component
*,
122 struct snd_soc_dapm_widget
*,
123 struct snd_soc_tplg_dapm_widget
*);
124 int (*widget_unload
)(struct snd_soc_component
*,
125 struct snd_soc_dobj
*);
127 /* FE - used for any driver specific init */
128 int (*pcm_dai_load
)(struct snd_soc_component
*,
129 struct snd_soc_tplg_pcm_dai
*pcm_dai
, int num_fe
);
130 int (*pcm_dai_unload
)(struct snd_soc_component
*,
131 struct snd_soc_dobj
*);
133 /* callback to handle vendor bespoke data */
134 int (*vendor_load
)(struct snd_soc_component
*,
135 struct snd_soc_tplg_hdr
*);
136 int (*vendor_unload
)(struct snd_soc_component
*,
137 struct snd_soc_tplg_hdr
*);
139 /* completion - called at completion of firmware loading */
140 void (*complete
)(struct snd_soc_component
*);
142 /* manifest - optional to inform component of manifest */
143 int (*manifest
)(struct snd_soc_component
*,
144 struct snd_soc_tplg_manifest
*);
146 /* vendor specific kcontrol handlers available for binding */
147 const struct snd_soc_tplg_kcontrol_ops
*io_ops
;
150 /* vendor specific bytes ext handlers available for binding */
151 const struct snd_soc_tplg_bytes_ext_ops
*bytes_ext_ops
;
152 int bytes_ext_ops_count
;
155 #ifdef CONFIG_SND_SOC_TOPOLOGY
157 /* gets a pointer to data from the firmware block header */
158 static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr
*hdr
)
160 const void *ptr
= hdr
;
162 return ptr
+ sizeof(*hdr
);
165 /* Dynamic Object loading and removal for component drivers */
166 int snd_soc_tplg_component_load(struct snd_soc_component
*comp
,
167 struct snd_soc_tplg_ops
*ops
, const struct firmware
*fw
,
169 int snd_soc_tplg_component_remove(struct snd_soc_component
*comp
, u32 index
);
171 /* Widget removal - widgets also removed wth component API */
172 void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget
*w
);
173 void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context
*dapm
,
176 /* Binds event handlers to dynamic widgets */
177 int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget
*w
,
178 const struct snd_soc_tplg_widget_events
*events
, int num_events
,
183 static inline int snd_soc_tplg_component_remove(struct snd_soc_component
*comp
,