Kuninori Morimoto | f2b6a1b | 2018-07-02 06:24:45 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 3 | * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM |
| 4 | * |
| 5 | * Copyright (C) 2012 Texas Instruments Inc. |
| 6 | * Copyright (C) 2015 Intel Corporation. |
| 7 | * |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 8 | * Simple file API to load FW that includes mixers, coefficients, DAPM graphs, |
| 9 | * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc. |
| 10 | */ |
| 11 | |
| 12 | #ifndef __LINUX_SND_SOC_TPLG_H |
| 13 | #define __LINUX_SND_SOC_TPLG_H |
| 14 | |
| 15 | #include <sound/asoc.h> |
| 16 | #include <linux/list.h> |
| 17 | |
| 18 | struct firmware; |
| 19 | struct snd_kcontrol; |
| 20 | struct snd_soc_tplg_pcm_be; |
| 21 | struct snd_ctl_elem_value; |
| 22 | struct snd_ctl_elem_info; |
| 23 | struct snd_soc_dapm_widget; |
| 24 | struct snd_soc_component; |
| 25 | struct snd_soc_tplg_pcm_fe; |
| 26 | struct snd_soc_dapm_context; |
| 27 | struct snd_soc_card; |
Liam Girdwood | 294de6e | 2017-06-06 15:55:04 +0100 | [diff] [blame] | 28 | struct snd_kcontrol_new; |
| 29 | struct snd_soc_dai_link; |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 30 | struct snd_soc_dai_driver; |
| 31 | struct snd_soc_dai; |
Liam Girdwood | 503e79b | 2018-06-14 20:53:59 +0100 | [diff] [blame] | 32 | struct snd_soc_dapm_route; |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 33 | |
| 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 */ |
| 38 | enum snd_soc_dobj_type { |
| 39 | SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */ |
| 40 | SND_SOC_DOBJ_MIXER, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 41 | SND_SOC_DOBJ_BYTES, |
Ranjani Sridharan | 5c30f43 | 2019-01-25 14:06:46 -0600 | [diff] [blame] | 42 | SND_SOC_DOBJ_ENUM, |
| 43 | SND_SOC_DOBJ_GRAPH, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 44 | SND_SOC_DOBJ_WIDGET, |
Ranjani Sridharan | 5c30f43 | 2019-01-25 14:06:46 -0600 | [diff] [blame] | 45 | SND_SOC_DOBJ_DAI_LINK, |
| 46 | SND_SOC_DOBJ_PCM, |
| 47 | SND_SOC_DOBJ_CODEC_LINK, |
Bard liao | adfebb5 | 2019-02-01 11:07:40 -0600 | [diff] [blame] | 48 | SND_SOC_DOBJ_BACKEND_LINK, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /* dynamic control object */ |
| 52 | struct snd_soc_dobj_control { |
| 53 | struct snd_kcontrol *kcontrol; |
| 54 | char **dtexts; |
| 55 | unsigned long *dvalues; |
| 56 | }; |
| 57 | |
| 58 | /* dynamic widget object */ |
| 59 | struct snd_soc_dobj_widget { |
Mengdong Lin | eea3dd4 | 2016-11-25 16:09:17 +0800 | [diff] [blame] | 60 | unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */ |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 63 | /* generic dynamic object - all dynamic objects belong to this struct */ |
| 64 | struct 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 Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 72 | }; |
| 73 | void *private; /* core does not touch this */ |
| 74 | }; |
| 75 | |
| 76 | /* |
| 77 | * Kcontrol operations - used to map handlers onto firmware based controls. |
| 78 | */ |
| 79 | struct 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 Lin | 1a3232d | 2015-08-18 18:12:20 +0800 | [diff] [blame] | 89 | /* Bytes ext operations, for TLV byte controls */ |
| 90 | struct snd_soc_tplg_bytes_ext_ops { |
| 91 | u32 id; |
Mythri P K | a1e5e7e9 | 2015-11-09 23:20:00 +0530 | [diff] [blame] | 92 | 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 Lin | 1a3232d | 2015-08-18 18:12:20 +0800 | [diff] [blame] | 96 | }; |
| 97 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 98 | /* |
| 99 | * DAPM widget event handlers - used to map handlers onto widgets. |
| 100 | */ |
| 101 | struct 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 | */ |
| 111 | struct snd_soc_tplg_ops { |
| 112 | |
| 113 | /* external kcontrol init - used for any driver specific init */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 114 | int (*control_load)(struct snd_soc_component *, int index, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 115 | struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *); |
| 116 | int (*control_unload)(struct snd_soc_component *, |
| 117 | struct snd_soc_dobj *); |
| 118 | |
Liam Girdwood | 503e79b | 2018-06-14 20:53:59 +0100 | [diff] [blame] | 119 | /* DAPM graph route element loading and unloading */ |
| 120 | int (*dapm_route_load)(struct snd_soc_component *, int index, |
| 121 | struct snd_soc_dapm_route *route); |
| 122 | int (*dapm_route_unload)(struct snd_soc_component *, |
| 123 | struct snd_soc_dobj *); |
| 124 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 125 | /* external widget init - used for any driver specific init */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 126 | int (*widget_load)(struct snd_soc_component *, int index, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 127 | struct snd_soc_dapm_widget *, |
| 128 | struct snd_soc_tplg_dapm_widget *); |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 129 | int (*widget_ready)(struct snd_soc_component *, int index, |
Liam Girdwood | ebd259d | 2017-06-09 15:43:23 +0100 | [diff] [blame] | 130 | struct snd_soc_dapm_widget *, |
| 131 | struct snd_soc_tplg_dapm_widget *); |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 132 | int (*widget_unload)(struct snd_soc_component *, |
| 133 | struct snd_soc_dobj *); |
| 134 | |
Mengdong Lin | 64527e8 | 2016-01-15 16:13:28 +0800 | [diff] [blame] | 135 | /* FE DAI - used for any driver specific init */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 136 | int (*dai_load)(struct snd_soc_component *, int index, |
| 137 | struct snd_soc_dai_driver *dai_drv, |
| 138 | struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai); |
| 139 | |
Mengdong Lin | 64527e8 | 2016-01-15 16:13:28 +0800 | [diff] [blame] | 140 | int (*dai_unload)(struct snd_soc_component *, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 141 | struct snd_soc_dobj *); |
| 142 | |
Mengdong Lin | acfc7d4 | 2016-01-15 16:13:37 +0800 | [diff] [blame] | 143 | /* DAI link - used for any driver specific init */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 144 | int (*link_load)(struct snd_soc_component *, int index, |
| 145 | struct snd_soc_dai_link *link, |
| 146 | struct snd_soc_tplg_link_config *cfg); |
Mengdong Lin | acfc7d4 | 2016-01-15 16:13:37 +0800 | [diff] [blame] | 147 | int (*link_unload)(struct snd_soc_component *, |
| 148 | struct snd_soc_dobj *); |
| 149 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 150 | /* callback to handle vendor bespoke data */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 151 | int (*vendor_load)(struct snd_soc_component *, int index, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 152 | struct snd_soc_tplg_hdr *); |
| 153 | int (*vendor_unload)(struct snd_soc_component *, |
| 154 | struct snd_soc_tplg_hdr *); |
| 155 | |
| 156 | /* completion - called at completion of firmware loading */ |
| 157 | void (*complete)(struct snd_soc_component *); |
| 158 | |
| 159 | /* manifest - optional to inform component of manifest */ |
Liam Girdwood | c60b613 | 2018-06-14 20:50:37 +0100 | [diff] [blame] | 160 | int (*manifest)(struct snd_soc_component *, int index, |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 161 | struct snd_soc_tplg_manifest *); |
| 162 | |
Mengdong Lin | 88a17d8 | 2015-08-18 18:11:51 +0800 | [diff] [blame] | 163 | /* vendor specific kcontrol handlers available for binding */ |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 164 | const struct snd_soc_tplg_kcontrol_ops *io_ops; |
| 165 | int io_ops_count; |
Mengdong Lin | 1a3232d | 2015-08-18 18:12:20 +0800 | [diff] [blame] | 166 | |
| 167 | /* vendor specific bytes ext handlers available for binding */ |
| 168 | const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops; |
| 169 | int bytes_ext_ops_count; |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Mark Brown | 78b50f3 | 2015-08-15 08:24:20 -0700 | [diff] [blame] | 172 | #ifdef CONFIG_SND_SOC_TOPOLOGY |
| 173 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 174 | /* gets a pointer to data from the firmware block header */ |
| 175 | static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr) |
| 176 | { |
| 177 | const void *ptr = hdr; |
| 178 | |
| 179 | return ptr + sizeof(*hdr); |
| 180 | } |
| 181 | |
| 182 | /* Dynamic Object loading and removal for component drivers */ |
| 183 | int snd_soc_tplg_component_load(struct snd_soc_component *comp, |
| 184 | struct snd_soc_tplg_ops *ops, const struct firmware *fw, |
| 185 | u32 index); |
| 186 | int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index); |
| 187 | |
| 188 | /* Widget removal - widgets also removed wth component API */ |
| 189 | void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w); |
| 190 | void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm, |
| 191 | u32 index); |
| 192 | |
| 193 | /* Binds event handlers to dynamic widgets */ |
| 194 | int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, |
| 195 | const struct snd_soc_tplg_widget_events *events, int num_events, |
| 196 | u16 event_type); |
| 197 | |
Mark Brown | 78b50f3 | 2015-08-15 08:24:20 -0700 | [diff] [blame] | 198 | #else |
| 199 | |
| 200 | static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp, |
| 201 | u32 index) |
| 202 | { |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | #endif |
| 207 | |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 208 | #endif |