blob: f552c3f56368c48a524e8889f5dabbc09f45d509 [file] [log] [blame]
Liam Girdwood8a978232015-05-29 19:06:14 +01001/*
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;
Liam Girdwood294de6e2017-06-06 15:55:04 +010031struct snd_kcontrol_new;
32struct snd_soc_dai_link;
Liam Girdwood8a978232015-05-29 19:06:14 +010033
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 {
Mengdong Lineea3dd42016-11-25 16:09:17 +080058 unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
Liam Girdwood8a978232015-05-29 19:06:14 +010059};
60
Liam Girdwood8a978232015-05-29 19:06:14 +010061/* 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;
Liam Girdwood8a978232015-05-29 19:06:14 +010070 };
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
Mengdong Lin1a3232d2015-08-18 18:12:20 +080087/* Bytes ext operations, for TLV byte controls */
88struct snd_soc_tplg_bytes_ext_ops {
89 u32 id;
Mythri P Ka1e5e7e92015-11-09 23:20:00 +053090 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);
Mengdong Lin1a3232d2015-08-18 18:12:20 +080094};
95
Liam Girdwood8a978232015-05-29 19:06:14 +010096/*
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 */
112 int (*control_load)(struct snd_soc_component *,
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
117 /* external widget init - used for any driver specific init */
118 int (*widget_load)(struct snd_soc_component *,
119 struct snd_soc_dapm_widget *,
120 struct snd_soc_tplg_dapm_widget *);
Liam Girdwoodebd259d2017-06-09 15:43:23 +0100121 int (*widget_ready)(struct snd_soc_component *,
122 struct snd_soc_dapm_widget *,
123 struct snd_soc_tplg_dapm_widget *);
Liam Girdwood8a978232015-05-29 19:06:14 +0100124 int (*widget_unload)(struct snd_soc_component *,
125 struct snd_soc_dobj *);
126
Mengdong Lin64527e82016-01-15 16:13:28 +0800127 /* FE DAI - used for any driver specific init */
128 int (*dai_load)(struct snd_soc_component *,
129 struct snd_soc_dai_driver *dai_drv);
130 int (*dai_unload)(struct snd_soc_component *,
Liam Girdwood8a978232015-05-29 19:06:14 +0100131 struct snd_soc_dobj *);
132
Mengdong Linacfc7d42016-01-15 16:13:37 +0800133 /* DAI link - used for any driver specific init */
134 int (*link_load)(struct snd_soc_component *,
135 struct snd_soc_dai_link *link);
136 int (*link_unload)(struct snd_soc_component *,
137 struct snd_soc_dobj *);
138
Liam Girdwood8a978232015-05-29 19:06:14 +0100139 /* callback to handle vendor bespoke data */
140 int (*vendor_load)(struct snd_soc_component *,
141 struct snd_soc_tplg_hdr *);
142 int (*vendor_unload)(struct snd_soc_component *,
143 struct snd_soc_tplg_hdr *);
144
145 /* completion - called at completion of firmware loading */
146 void (*complete)(struct snd_soc_component *);
147
148 /* manifest - optional to inform component of manifest */
149 int (*manifest)(struct snd_soc_component *,
150 struct snd_soc_tplg_manifest *);
151
Mengdong Lin88a17d82015-08-18 18:11:51 +0800152 /* vendor specific kcontrol handlers available for binding */
Liam Girdwood8a978232015-05-29 19:06:14 +0100153 const struct snd_soc_tplg_kcontrol_ops *io_ops;
154 int io_ops_count;
Mengdong Lin1a3232d2015-08-18 18:12:20 +0800155
156 /* vendor specific bytes ext handlers available for binding */
157 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
158 int bytes_ext_ops_count;
Liam Girdwood8a978232015-05-29 19:06:14 +0100159};
160
Mark Brown78b50f32015-08-15 08:24:20 -0700161#ifdef CONFIG_SND_SOC_TOPOLOGY
162
Liam Girdwood8a978232015-05-29 19:06:14 +0100163/* gets a pointer to data from the firmware block header */
164static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
165{
166 const void *ptr = hdr;
167
168 return ptr + sizeof(*hdr);
169}
170
171/* Dynamic Object loading and removal for component drivers */
172int snd_soc_tplg_component_load(struct snd_soc_component *comp,
173 struct snd_soc_tplg_ops *ops, const struct firmware *fw,
174 u32 index);
175int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
176
177/* Widget removal - widgets also removed wth component API */
178void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
179void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
180 u32 index);
181
182/* Binds event handlers to dynamic widgets */
183int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
184 const struct snd_soc_tplg_widget_events *events, int num_events,
185 u16 event_type);
186
Mark Brown78b50f32015-08-15 08:24:20 -0700187#else
188
189static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
190 u32 index)
191{
192 return 0;
193}
194
195#endif
196
Liam Girdwood8a978232015-05-29 19:06:14 +0100197#endif