blob: e1f265e21ee1282fe3de0d1a6731494c775a7e06 [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 Girdwoodc60b6132018-06-14 20:50:37 +010033struct snd_soc_dai_driver;
34struct snd_soc_dai;
Liam Girdwood8a978232015-05-29 19:06:14 +010035
36/* object scan be loaded and unloaded in groups with identfying indexes */
37#define SND_SOC_TPLG_INDEX_ALL 0 /* ID that matches all FW objects */
38
39/* dynamic object type */
40enum snd_soc_dobj_type {
41 SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */
42 SND_SOC_DOBJ_MIXER,
43 SND_SOC_DOBJ_ENUM,
44 SND_SOC_DOBJ_BYTES,
45 SND_SOC_DOBJ_PCM,
46 SND_SOC_DOBJ_DAI_LINK,
47 SND_SOC_DOBJ_CODEC_LINK,
48 SND_SOC_DOBJ_WIDGET,
49};
50
51/* dynamic control object */
52struct snd_soc_dobj_control {
53 struct snd_kcontrol *kcontrol;
54 char **dtexts;
55 unsigned long *dvalues;
56};
57
58/* dynamic widget object */
59struct snd_soc_dobj_widget {
Mengdong Lineea3dd42016-11-25 16:09:17 +080060 unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
Liam Girdwood8a978232015-05-29 19:06:14 +010061};
62
Liam Girdwood8a978232015-05-29 19:06:14 +010063/* generic dynamic object - all dynamic objects belong to this struct */
64struct snd_soc_dobj {
65 enum snd_soc_dobj_type type;
66 unsigned int index; /* objects can belong in different groups */
67 struct list_head list;
68 struct snd_soc_tplg_ops *ops;
69 union {
70 struct snd_soc_dobj_control control;
71 struct snd_soc_dobj_widget widget;
Liam Girdwood8a978232015-05-29 19:06:14 +010072 };
73 void *private; /* core does not touch this */
74};
75
76/*
77 * Kcontrol operations - used to map handlers onto firmware based controls.
78 */
79struct snd_soc_tplg_kcontrol_ops {
80 u32 id;
81 int (*get)(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_value *ucontrol);
83 int (*put)(struct snd_kcontrol *kcontrol,
84 struct snd_ctl_elem_value *ucontrol);
85 int (*info)(struct snd_kcontrol *kcontrol,
86 struct snd_ctl_elem_info *uinfo);
87};
88
Mengdong Lin1a3232d2015-08-18 18:12:20 +080089/* Bytes ext operations, for TLV byte controls */
90struct snd_soc_tplg_bytes_ext_ops {
91 u32 id;
Mythri P Ka1e5e7e92015-11-09 23:20:00 +053092 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
93 unsigned int size);
94 int (*put)(struct snd_kcontrol *kcontrol,
95 const unsigned int __user *bytes, unsigned int size);
Mengdong Lin1a3232d2015-08-18 18:12:20 +080096};
97
Liam Girdwood8a978232015-05-29 19:06:14 +010098/*
99 * DAPM widget event handlers - used to map handlers onto widgets.
100 */
101struct snd_soc_tplg_widget_events {
102 u16 type;
103 int (*event_handler)(struct snd_soc_dapm_widget *w,
104 struct snd_kcontrol *k, int event);
105};
106
107/*
108 * Public API - Used by component drivers to load and unload dynamic objects
109 * and their resources.
110 */
111struct snd_soc_tplg_ops {
112
113 /* external kcontrol init - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100114 int (*control_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100115 struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
116 int (*control_unload)(struct snd_soc_component *,
117 struct snd_soc_dobj *);
118
119 /* external widget init - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100120 int (*widget_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100121 struct snd_soc_dapm_widget *,
122 struct snd_soc_tplg_dapm_widget *);
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100123 int (*widget_ready)(struct snd_soc_component *, int index,
Liam Girdwoodebd259d2017-06-09 15:43:23 +0100124 struct snd_soc_dapm_widget *,
125 struct snd_soc_tplg_dapm_widget *);
Liam Girdwood8a978232015-05-29 19:06:14 +0100126 int (*widget_unload)(struct snd_soc_component *,
127 struct snd_soc_dobj *);
128
Mengdong Lin64527e82016-01-15 16:13:28 +0800129 /* FE DAI - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100130 int (*dai_load)(struct snd_soc_component *, int index,
131 struct snd_soc_dai_driver *dai_drv,
132 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
133
Mengdong Lin64527e82016-01-15 16:13:28 +0800134 int (*dai_unload)(struct snd_soc_component *,
Liam Girdwood8a978232015-05-29 19:06:14 +0100135 struct snd_soc_dobj *);
136
Mengdong Linacfc7d42016-01-15 16:13:37 +0800137 /* DAI link - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100138 int (*link_load)(struct snd_soc_component *, int index,
139 struct snd_soc_dai_link *link,
140 struct snd_soc_tplg_link_config *cfg);
Mengdong Linacfc7d42016-01-15 16:13:37 +0800141 int (*link_unload)(struct snd_soc_component *,
142 struct snd_soc_dobj *);
143
Liam Girdwood8a978232015-05-29 19:06:14 +0100144 /* callback to handle vendor bespoke data */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100145 int (*vendor_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100146 struct snd_soc_tplg_hdr *);
147 int (*vendor_unload)(struct snd_soc_component *,
148 struct snd_soc_tplg_hdr *);
149
150 /* completion - called at completion of firmware loading */
151 void (*complete)(struct snd_soc_component *);
152
153 /* manifest - optional to inform component of manifest */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100154 int (*manifest)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100155 struct snd_soc_tplg_manifest *);
156
Mengdong Lin88a17d82015-08-18 18:11:51 +0800157 /* vendor specific kcontrol handlers available for binding */
Liam Girdwood8a978232015-05-29 19:06:14 +0100158 const struct snd_soc_tplg_kcontrol_ops *io_ops;
159 int io_ops_count;
Mengdong Lin1a3232d2015-08-18 18:12:20 +0800160
161 /* vendor specific bytes ext handlers available for binding */
162 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
163 int bytes_ext_ops_count;
Liam Girdwood8a978232015-05-29 19:06:14 +0100164};
165
Mark Brown78b50f32015-08-15 08:24:20 -0700166#ifdef CONFIG_SND_SOC_TOPOLOGY
167
Liam Girdwood8a978232015-05-29 19:06:14 +0100168/* gets a pointer to data from the firmware block header */
169static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
170{
171 const void *ptr = hdr;
172
173 return ptr + sizeof(*hdr);
174}
175
176/* Dynamic Object loading and removal for component drivers */
177int snd_soc_tplg_component_load(struct snd_soc_component *comp,
178 struct snd_soc_tplg_ops *ops, const struct firmware *fw,
179 u32 index);
180int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
181
182/* Widget removal - widgets also removed wth component API */
183void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
184void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
185 u32 index);
186
187/* Binds event handlers to dynamic widgets */
188int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
189 const struct snd_soc_tplg_widget_events *events, int num_events,
190 u16 event_type);
191
Mark Brown78b50f32015-08-15 08:24:20 -0700192#else
193
194static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
195 u32 index)
196{
197 return 0;
198}
199
200#endif
201
Liam Girdwood8a978232015-05-29 19:06:14 +0100202#endif