blob: 427bc41df3aef3a3f931bd94830f027bafea2661 [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;
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_enum:1; /* this widget is an enum kcontrol */
57};
58
59/* dynamic PCM DAI object */
60struct 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 */
66struct 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 */
82struct 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 */
95struct 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 */
105struct 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
Mark Brown78b50f32015-08-15 08:24:20 -0700144#ifdef CONFIG_SND_SOC_TOPOLOGY
145
Liam Girdwood8a978232015-05-29 19:06:14 +0100146/* gets a pointer to data from the firmware block header */
147static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
148{
149 const void *ptr = hdr;
150
151 return ptr + sizeof(*hdr);
152}
153
154/* Dynamic Object loading and removal for component drivers */
155int snd_soc_tplg_component_load(struct snd_soc_component *comp,
156 struct snd_soc_tplg_ops *ops, const struct firmware *fw,
157 u32 index);
158int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
159
160/* Widget removal - widgets also removed wth component API */
161void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
162void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
163 u32 index);
164
165/* Binds event handlers to dynamic widgets */
166int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
167 const struct snd_soc_tplg_widget_events *events, int num_events,
168 u16 event_type);
169
Mark Brown78b50f32015-08-15 08:24:20 -0700170#else
171
172static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
173 u32 index)
174{
175 return 0;
176}
177
178#endif
179
Liam Girdwood8a978232015-05-29 19:06:14 +0100180#endif