Skip to content

Commit 8a97823

Browse files
lrgirdwobroonie
authored andcommitted
ASoC: topology: Add topology core
The topology core parses the FW topology file for known block types and instanciates any common ALSA/ASoC objects that it discovers. The core also passes any block that is does not understand to client component drivers for enumeration. The core exports some APIs to client drivers in order to load and unload firmware topology data as use case require. Currently the core deals with the following object types :- o kcontrols. This includes TLV, enumerated and bytes controls. o DAPM widgets. All types with any associated kcontrol. o DAPM graph. o FE PCM. FE PCM capabilities and configuration can be defined. o BE DAI Link. BE DAI link capabilities and configuration can be defined. o Codec <-> codec style links capabilities and configuration. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c147c0e commit 8a97823

6 files changed

Lines changed: 2012 additions & 0 deletions

File tree

‎include/sound/soc-dapm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <linux/types.h>
1717
#include <sound/control.h>
18+
#include <sound/soc-topology.h>
1819
#include <sound/asoc.h>
1920

2021
struct device;
@@ -572,6 +573,7 @@ struct snd_soc_dapm_widget {
572573
int num_kcontrols;
573574
const struct snd_kcontrol_new *kcontrol_news;
574575
struct snd_kcontrol **kcontrols;
576+
struct snd_soc_dobj dobj;
575577

576578
/* widget input and outputs */
577579
struct list_head sources;

‎include/sound/soc-topology.h‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
21+
struct firmware;
22+
struct snd_kcontrol;
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;
30+
struct 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 */
36+
enum 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 */
48+
struct snd_soc_dobj_control {
49+
struct snd_kcontrol *kcontrol;
50+
char **dtexts;
51+
unsigned long *dvalues;
52+
};
53+
54+
/* dynamic widget object */
55+
struct snd_soc_dobj_widget {
56+
unsigned int kcontrol_enum:1; /* this widget is an enum kcontrol */
57+
};
58+
59+
/* dynamic PCM DAI object */
60+
struct snd_soc_dobj_pcm_dai {
61+
struct snd_soc_tplg_pcm_dai *pd;
62+
unsigned int count;
63+
};
64+
65+
/* generic dynamic object - all dynamic objects belong to this struct */
66+
struct snd_soc_dobj {
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;
71+
union {
72+
struct snd_soc_dobj_control control;
73+
struct snd_soc_dobj_widget widget;
74+
struct snd_soc_dobj_pcm_dai pcm_dai;
75+
};
76+
void *private; /* core does not touch this */
77+
};
78+
79+
/*
80+
* Kcontrol operations - used to map handlers onto firmware based controls.
81+
*/
82+
struct snd_soc_tplg_kcontrol_ops {
83+
u32 id;
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);
90+
};
91+
92+
/*
93+
* DAPM widget event handlers - used to map handlers onto widgets.
94+
*/
95+
struct snd_soc_tplg_widget_events {
96+
u16 type;
97+
int (*event_handler)(struct snd_soc_dapm_widget *w,
98+
struct snd_kcontrol *k, int event);
99+
};
100+
101+
/*
102+
* Public API - Used by component drivers to load and unload dynamic objects
103+
* and their resources.
104+
*/
105+
struct snd_soc_tplg_ops {
106+
107+
/* external kcontrol init - used for any driver specific init */
108+
int (*control_load)(struct snd_soc_component *,
109+
struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
110+
int (*control_unload)(struct snd_soc_component *,
111+
struct snd_soc_dobj *);
112+
113+
/* external widget init - used for any driver specific init */
114+
int (*widget_load)(struct snd_soc_component *,
115+
struct snd_soc_dapm_widget *,
116+
struct snd_soc_tplg_dapm_widget *);
117+
int (*widget_unload)(struct snd_soc_component *,
118+
struct snd_soc_dobj *);
119+
120+
/* FE - used for any driver specific init */
121+
int (*pcm_dai_load)(struct snd_soc_component *,
122+
struct snd_soc_tplg_pcm_dai *pcm_dai, int num_fe);
123+
int (*pcm_dai_unload)(struct snd_soc_component *,
124+
struct snd_soc_dobj *);
125+
126+
/* callback to handle vendor bespoke data */
127+
int (*vendor_load)(struct snd_soc_component *,
128+
struct snd_soc_tplg_hdr *);
129+
int (*vendor_unload)(struct snd_soc_component *,
130+
struct snd_soc_tplg_hdr *);
131+
132+
/* completion - called at completion of firmware loading */
133+
void (*complete)(struct snd_soc_component *);
134+
135+
/* manifest - optional to inform component of manifest */
136+
int (*manifest)(struct snd_soc_component *,
137+
struct snd_soc_tplg_manifest *);
138+
139+
/* bespoke kcontrol handlers available for binding */
140+
const struct snd_soc_tplg_kcontrol_ops *io_ops;
141+
int io_ops_count;
142+
};
143+
144+
/* gets a pointer to data from the firmware block header */
145+
static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
146+
{
147+
const void *ptr = hdr;
148+
149+
return ptr + sizeof(*hdr);
150+
}
151+
152+
/* Dynamic Object loading and removal for component drivers */
153+
int snd_soc_tplg_component_load(struct snd_soc_component *comp,
154+
struct snd_soc_tplg_ops *ops, const struct firmware *fw,
155+
u32 index);
156+
int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
157+
158+
/* Widget removal - widgets also removed wth component API */
159+
void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
160+
void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
161+
u32 index);
162+
163+
/* Binds event handlers to dynamic widgets */
164+
int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
165+
const struct snd_soc_tplg_widget_events *events, int num_events,
166+
u16 event_type);
167+
168+
#endif

‎include/sound/soc.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sound/compress_driver.h>
2828
#include <sound/control.h>
2929
#include <sound/ac97_codec.h>
30+
#include <sound/soc-topology.h>
3031

3132
/*
3233
* Convenience kcontrol builders
@@ -764,6 +765,9 @@ struct snd_soc_component {
764765

765766
struct mutex io_mutex;
766767

768+
/* attached dynamic objects */
769+
struct list_head dobj_list;
770+
767771
#ifdef CONFIG_DEBUG_FS
768772
struct dentry *debugfs_root;
769773
#endif
@@ -1108,6 +1112,9 @@ struct snd_soc_card {
11081112
struct list_head dapm_list;
11091113
struct list_head dapm_dirty;
11101114

1115+
/* attached dynamic objects */
1116+
struct list_head dobj_list;
1117+
11111118
/* Generic DAPM context for the card */
11121119
struct snd_soc_dapm_context dapm;
11131120
struct snd_soc_dapm_stats dapm_stats;
@@ -1167,6 +1174,7 @@ struct soc_mixer_control {
11671174
unsigned int sign_bit;
11681175
unsigned int invert:1;
11691176
unsigned int autodisable:1;
1177+
struct snd_soc_dobj dobj;
11701178
};
11711179

11721180
struct soc_bytes {
@@ -1177,6 +1185,8 @@ struct soc_bytes {
11771185

11781186
struct soc_bytes_ext {
11791187
int max;
1188+
struct snd_soc_dobj dobj;
1189+
11801190
/* used for TLV byte control */
11811191
int (*get)(unsigned int __user *bytes, unsigned int size);
11821192
int (*put)(const unsigned int __user *bytes, unsigned int size);
@@ -1198,6 +1208,7 @@ struct soc_enum {
11981208
const char * const *texts;
11991209
const unsigned int *values;
12001210
unsigned int autodisable:1;
1211+
struct snd_soc_dobj dobj;
12011212
};
12021213

12031214
/**

‎sound/soc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
22
snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o
3+
snd-soc-core-objs += soc-topology.o
34

45
ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
56
snd-soc-core-objs += soc-generic-dmaengine-pcm.o

‎sound/soc/soc-core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <sound/pcm_params.h>
4141
#include <sound/soc.h>
4242
#include <sound/soc-dpcm.h>
43+
#include <sound/soc-topology.h>
4344
#include <sound/initval.h>
4445

4546
#define CREATE_TRACE_POINTS
@@ -2422,6 +2423,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
24222423
card->rtd_aux[i].card = card;
24232424

24242425
INIT_LIST_HEAD(&card->dapm_dirty);
2426+
INIT_LIST_HEAD(&card->dobj_list);
24252427
card->instantiated = 0;
24262428
mutex_init(&card->mutex);
24272429
mutex_init(&card->dapm_mutex);
@@ -2736,6 +2738,7 @@ static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
27362738
}
27372739

27382740
list_add(&component->list, &component_list);
2741+
INIT_LIST_HEAD(&component->dobj_list);
27392742
}
27402743

27412744
static void snd_soc_component_add(struct snd_soc_component *component)
@@ -2812,6 +2815,7 @@ void snd_soc_unregister_component(struct device *dev)
28122815
return;
28132816

28142817
found:
2818+
snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL);
28152819
snd_soc_component_del_unlocked(cmpnt);
28162820
mutex_unlock(&client_mutex);
28172821
snd_soc_component_cleanup(cmpnt);

0 commit comments

Comments
 (0)