blob: b4b896f83b94cfa2e96f8661a2a8e697e70a4c34 [file] [log] [blame]
Kuninori Morimotof2b6a1b2018-07-02 06:24:45 +00001/* SPDX-License-Identifier: GPL-2.0
2 *
Liam Girdwood8a978232015-05-29 19:06:14 +01003 * 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 Girdwood8a978232015-05-29 19:06:14 +01008 * 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
18struct firmware;
19struct snd_kcontrol;
20struct snd_soc_tplg_pcm_be;
21struct snd_ctl_elem_value;
22struct snd_ctl_elem_info;
23struct snd_soc_dapm_widget;
24struct snd_soc_component;
25struct snd_soc_tplg_pcm_fe;
26struct snd_soc_dapm_context;
27struct snd_soc_card;
Liam Girdwood294de6e2017-06-06 15:55:04 +010028struct snd_kcontrol_new;
29struct snd_soc_dai_link;
Liam Girdwoodc60b6132018-06-14 20:50:37 +010030struct snd_soc_dai_driver;
31struct snd_soc_dai;
Liam Girdwood503e79b2018-06-14 20:53:59 +010032struct snd_soc_dapm_route;
Liam Girdwood8a978232015-05-29 19:06:14 +010033
Liam Girdwood8a978232015-05-29 19:06:14 +010034/* dynamic object type */
35enum snd_soc_dobj_type {
36 SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */
37 SND_SOC_DOBJ_MIXER,
Liam Girdwood8a978232015-05-29 19:06:14 +010038 SND_SOC_DOBJ_BYTES,
Ranjani Sridharan5c30f432019-01-25 14:06:46 -060039 SND_SOC_DOBJ_ENUM,
40 SND_SOC_DOBJ_GRAPH,
Liam Girdwood8a978232015-05-29 19:06:14 +010041 SND_SOC_DOBJ_WIDGET,
Ranjani Sridharan5c30f432019-01-25 14:06:46 -060042 SND_SOC_DOBJ_DAI_LINK,
43 SND_SOC_DOBJ_PCM,
44 SND_SOC_DOBJ_CODEC_LINK,
Bard liaoadfebb52019-02-01 11:07:40 -060045 SND_SOC_DOBJ_BACKEND_LINK,
Liam Girdwood8a978232015-05-29 19:06:14 +010046};
47
48/* dynamic control object */
49struct snd_soc_dobj_control {
50 struct snd_kcontrol *kcontrol;
51 char **dtexts;
52 unsigned long *dvalues;
53};
54
55/* dynamic widget object */
56struct snd_soc_dobj_widget {
Jaska Uimonend29d41e22021-05-07 10:02:46 +030057 unsigned int *kcontrol_type; /* kcontrol type: mixer, enum, bytes */
Liam Girdwood8a978232015-05-29 19:06:14 +010058};
59
Liam Girdwood8a978232015-05-29 19:06:14 +010060/* generic dynamic object - all dynamic objects belong to this struct */
61struct snd_soc_dobj {
62 enum snd_soc_dobj_type type;
63 unsigned int index; /* objects can belong in different groups */
64 struct list_head list;
65 struct snd_soc_tplg_ops *ops;
66 union {
67 struct snd_soc_dobj_control control;
68 struct snd_soc_dobj_widget widget;
Liam Girdwood8a978232015-05-29 19:06:14 +010069 };
70 void *private; /* core does not touch this */
71};
72
73/*
74 * Kcontrol operations - used to map handlers onto firmware based controls.
75 */
76struct snd_soc_tplg_kcontrol_ops {
77 u32 id;
78 int (*get)(struct snd_kcontrol *kcontrol,
79 struct snd_ctl_elem_value *ucontrol);
80 int (*put)(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_value *ucontrol);
82 int (*info)(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_info *uinfo);
84};
85
Mengdong Lin1a3232d2015-08-18 18:12:20 +080086/* Bytes ext operations, for TLV byte controls */
87struct snd_soc_tplg_bytes_ext_ops {
88 u32 id;
Mythri P Ka1e5e7e92015-11-09 23:20:00 +053089 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
90 unsigned int size);
91 int (*put)(struct snd_kcontrol *kcontrol,
92 const unsigned int __user *bytes, unsigned int size);
Mengdong Lin1a3232d2015-08-18 18:12:20 +080093};
94
Liam Girdwood8a978232015-05-29 19:06:14 +010095/*
96 * DAPM widget event handlers - used to map handlers onto widgets.
97 */
98struct snd_soc_tplg_widget_events {
99 u16 type;
100 int (*event_handler)(struct snd_soc_dapm_widget *w,
101 struct snd_kcontrol *k, int event);
102};
103
104/*
105 * Public API - Used by component drivers to load and unload dynamic objects
106 * and their resources.
107 */
108struct snd_soc_tplg_ops {
109
110 /* external kcontrol init - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100111 int (*control_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100112 struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
113 int (*control_unload)(struct snd_soc_component *,
114 struct snd_soc_dobj *);
115
Liam Girdwood503e79b2018-06-14 20:53:59 +0100116 /* DAPM graph route element loading and unloading */
117 int (*dapm_route_load)(struct snd_soc_component *, int index,
118 struct snd_soc_dapm_route *route);
119 int (*dapm_route_unload)(struct snd_soc_component *,
120 struct snd_soc_dobj *);
121
Liam Girdwood8a978232015-05-29 19:06:14 +0100122 /* external widget init - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100123 int (*widget_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100124 struct snd_soc_dapm_widget *,
125 struct snd_soc_tplg_dapm_widget *);
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100126 int (*widget_ready)(struct snd_soc_component *, int index,
Liam Girdwoodebd259d2017-06-09 15:43:23 +0100127 struct snd_soc_dapm_widget *,
128 struct snd_soc_tplg_dapm_widget *);
Liam Girdwood8a978232015-05-29 19:06:14 +0100129 int (*widget_unload)(struct snd_soc_component *,
130 struct snd_soc_dobj *);
131
Mengdong Lin64527e82016-01-15 16:13:28 +0800132 /* FE DAI - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100133 int (*dai_load)(struct snd_soc_component *, int index,
134 struct snd_soc_dai_driver *dai_drv,
135 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
136
Mengdong Lin64527e82016-01-15 16:13:28 +0800137 int (*dai_unload)(struct snd_soc_component *,
Liam Girdwood8a978232015-05-29 19:06:14 +0100138 struct snd_soc_dobj *);
139
Mengdong Linacfc7d42016-01-15 16:13:37 +0800140 /* DAI link - used for any driver specific init */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100141 int (*link_load)(struct snd_soc_component *, int index,
142 struct snd_soc_dai_link *link,
143 struct snd_soc_tplg_link_config *cfg);
Mengdong Linacfc7d42016-01-15 16:13:37 +0800144 int (*link_unload)(struct snd_soc_component *,
145 struct snd_soc_dobj *);
146
Liam Girdwood8a978232015-05-29 19:06:14 +0100147 /* callback to handle vendor bespoke data */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100148 int (*vendor_load)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100149 struct snd_soc_tplg_hdr *);
150 int (*vendor_unload)(struct snd_soc_component *,
151 struct snd_soc_tplg_hdr *);
152
153 /* completion - called at completion of firmware loading */
Ranjani Sridharan415717e2021-09-27 15:05:06 +0300154 int (*complete)(struct snd_soc_component *comp);
Liam Girdwood8a978232015-05-29 19:06:14 +0100155
156 /* manifest - optional to inform component of manifest */
Liam Girdwoodc60b6132018-06-14 20:50:37 +0100157 int (*manifest)(struct snd_soc_component *, int index,
Liam Girdwood8a978232015-05-29 19:06:14 +0100158 struct snd_soc_tplg_manifest *);
159
Mengdong Lin88a17d82015-08-18 18:11:51 +0800160 /* vendor specific kcontrol handlers available for binding */
Liam Girdwood8a978232015-05-29 19:06:14 +0100161 const struct snd_soc_tplg_kcontrol_ops *io_ops;
162 int io_ops_count;
Mengdong Lin1a3232d2015-08-18 18:12:20 +0800163
164 /* vendor specific bytes ext handlers available for binding */
165 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
166 int bytes_ext_ops_count;
Liam Girdwood8a978232015-05-29 19:06:14 +0100167};
168
Mark Brown78b50f32015-08-15 08:24:20 -0700169#ifdef CONFIG_SND_SOC_TOPOLOGY
170
Liam Girdwood8a978232015-05-29 19:06:14 +0100171/* gets a pointer to data from the firmware block header */
172static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
173{
174 const void *ptr = hdr;
175
176 return ptr + sizeof(*hdr);
177}
178
179/* Dynamic Object loading and removal for component drivers */
180int snd_soc_tplg_component_load(struct snd_soc_component *comp,
Amadeusz Sławińskia5b8f712020-10-30 10:54:23 -0400181 struct snd_soc_tplg_ops *ops, const struct firmware *fw);
182int snd_soc_tplg_component_remove(struct snd_soc_component *comp);
Liam Girdwood8a978232015-05-29 19:06:14 +0100183
Liam Girdwood8a978232015-05-29 19:06:14 +0100184/* Binds event handlers to dynamic widgets */
185int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
186 const struct snd_soc_tplg_widget_events *events, int num_events,
187 u16 event_type);
188
Mark Brown78b50f32015-08-15 08:24:20 -0700189#else
190
Mark Brown1198ff12021-10-25 16:48:44 +0100191static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
Mark Brown78b50f32015-08-15 08:24:20 -0700192{
193 return 0;
194}
195
196#endif
197
Liam Girdwood8a978232015-05-29 19:06:14 +0100198#endif