Merge tag 'io_uring-6.16-20250630' of git://git.kernel.dk/linux
[linux-2.6-block.git] / include / sound / soc.h
CommitLineData
873486ed
KM
1/* SPDX-License-Identifier: GPL-2.0
2 *
808db4a4
RP
3 * linux/sound/soc.h -- ALSA SoC Layer
4 *
873486ed
KM
5 * Author: Liam Girdwood
6 * Created: Aug 11th 2005
808db4a4 7 * Copyright: Wolfson Microelectronics. PLC.
808db4a4
RP
8 */
9
10#ifndef __LINUX_SND_SOC_H
11#define __LINUX_SND_SOC_H
12
428cc410 13#include <linux/args.h>
3249c68e
AS
14#include <linux/array_size.h>
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/interrupt.h>
18#include <linux/lockdep.h>
19#include <linux/log2.h>
20#include <linux/mutex.h>
21#include <linux/notifier.h>
cb470087 22#include <linux/of.h>
808db4a4 23#include <linux/types.h>
4484bb2e 24#include <linux/workqueue.h>
3249c68e
AS
25
26#include <sound/ac97_codec.h>
49681077 27#include <sound/compress_driver.h>
808db4a4 28#include <sound/control.h>
3249c68e
AS
29#include <sound/core.h>
30#include <sound/pcm.h>
31
32struct module;
33struct platform_device;
34
35/* For the current users of sound/soc.h to avoid build issues */
36#include <linux/platform_device.h>
37#include <linux/regmap.h>
808db4a4 38
808db4a4
RP
39/*
40 * Convenience kcontrol builders
41 */
6db63090
CK
42#define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, \
43 xinvert, xautodisable) \
c1b4d1c7
LPC
44 ((unsigned long)&(struct soc_mixer_control) \
45 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
26bdcc4b 46 .rshift = shift_right, .min = xmin, .max = xmax, \
c1b4d1c7 47 .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
6db63090
CK
48#define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmin, xmax, xinvert, xautodisable) \
49 SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, 0, xinvert, \
50 xautodisable)
51#define SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, xautodisable) \
52 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmin, xmax, xinvert, xautodisable)
cd21b123
MP
53#define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
54 ((unsigned long)&(struct soc_mixer_control) \
55 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
26bdcc4b 56 .max = xmax, .min = xmin, .sign_bit = xsign_bit, \
cd21b123 57 .invert = xinvert})
1743dbb4
CK
58#define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
59 SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, 0, xinvert)
60
a7a4ac86 61#define SOC_SINGLE(xname, reg, shift, max, invert) \
808db4a4
RP
62{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
63 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
64 .put = snd_soc_put_volsw, \
6db63090 65 .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }
6c9d8cf6
AT
66#define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
67{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
fd744256 68 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
7d5df968 69 .put = snd_soc_put_volsw, \
6db63090 70 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
a7a4ac86
PZ
71#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
72{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
73 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
74 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
75 .tlv.p = (tlv_array), \
76 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
77 .put = snd_soc_put_volsw, \
6db63090 78 .private_value = SOC_SINGLE_VALUE(reg, shift, 0, max, invert, 0) }
1d99f243
BA
79#define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
80{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
81 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
82 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
83 .tlv.p = (tlv_array),\
34198710 84 .info = snd_soc_info_volsw_sx, \
1d99f243
BA
85 .get = snd_soc_get_volsw_sx,\
86 .put = snd_soc_put_volsw_sx, \
6db63090 87 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, 0, 0) }
6c9d8cf6
AT
88#define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
89{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
90 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
91 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
92 .tlv.p = (tlv_array), \
894a37c9 93 .info = snd_soc_info_volsw, \
7d5df968 94 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
6db63090 95 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
460acbec 96#define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
808db4a4
RP
97{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
98 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
99 .put = snd_soc_put_volsw, \
460acbec 100 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
6db63090 101 0, max, invert, 0) }
d13871b3
DH
102#define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
103{ \
104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
105 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
106 .access = SNDRV_CTL_ELEM_ACCESS_READ | \
107 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
108 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
6db63090 109 0, max, invert, 0) }
4eaa9819 110#define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
808db4a4 111{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
e8f5a103 112 .info = snd_soc_info_volsw, \
974815ba 113 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
cdffa775 114 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
1743dbb4 115 0, xmax, xinvert) }
229e3fdc
MB
116#define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
117 xmax, xinvert) \
118{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
894a37c9 119 .info = snd_soc_info_volsw, \
7d5df968 120 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
1743dbb4 121 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
229e3fdc 122 xshift, xmin, xmax, xinvert) }
460acbec 123#define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
a7a4ac86
PZ
124{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
125 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
126 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
127 .tlv.p = (tlv_array), \
128 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
129 .put = snd_soc_put_volsw, \
460acbec 130 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
6db63090 131 0, max, invert, 0) }
6b183919
CK
132#define SOC_DOUBLE_SX_TLV(xname, xreg, shift_left, shift_right, xmin, xmax, tlv_array) \
133{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
134 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
135 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
136 .tlv.p = (tlv_array), \
137 .info = snd_soc_info_volsw_sx, \
138 .get = snd_soc_get_volsw_sx, \
139 .put = snd_soc_put_volsw_sx, \
6db63090
CK
140 .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
141 xmin, xmax, 0, 0) }
d75a2161
LC
142#define SOC_DOUBLE_RANGE_TLV(xname, xreg, xshift_left, xshift_right, xmin, xmax, \
143 xinvert, tlv_array) \
144{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
145 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
146 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
147 .tlv.p = (tlv_array), \
148 .info = snd_soc_info_volsw, \
149 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
6db63090
CK
150 .private_value = SOC_DOUBLE_VALUE(xreg, xshift_left, xshift_right, \
151 xmin, xmax, xinvert, 0) }
4eaa9819 152#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
a7a4ac86
PZ
153{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
154 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
155 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
156 .tlv.p = (tlv_array), \
e8f5a103 157 .info = snd_soc_info_volsw, \
974815ba 158 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
cdffa775 159 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
1743dbb4 160 0, xmax, xinvert) }
229e3fdc
MB
161#define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
162 xmax, xinvert, tlv_array) \
163{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
164 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
165 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
166 .tlv.p = (tlv_array), \
894a37c9 167 .info = snd_soc_info_volsw, \
7d5df968 168 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
1743dbb4 169 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, \
229e3fdc 170 xshift, xmin, xmax, xinvert) }
1d99f243
BA
171#define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
172{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
173 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
174 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
175 .tlv.p = (tlv_array), \
34198710 176 .info = snd_soc_info_volsw_sx, \
1d99f243
BA
177 .get = snd_soc_get_volsw_sx, \
178 .put = snd_soc_put_volsw_sx, \
1743dbb4 179 .private_value = SOC_DOUBLE_R_VALUE(xreg, xrreg, xshift, xmin, xmax, 0) }
cd21b123
MP
180#define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
181{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
182 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
183 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
184 .tlv.p = (tlv_array), \
185 .info = snd_soc_info_volsw, \
186 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
187 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
188 xmin, xmax, xsign_bit, xinvert) }
bc8cb029
RF
189#define SOC_SINGLE_S_TLV(xname, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
190 SOC_DOUBLE_R_S_TLV(xname, xreg, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array)
dcc0799b
SK
191#define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
192{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
193 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
194 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
195 .tlv.p = (tlv_array), \
196 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
197 .put = snd_soc_put_volsw, \
198 .private_value = (unsigned long)&(struct soc_mixer_control) \
199 {.reg = xreg, .rreg = xreg, \
26bdcc4b 200 .min = xmin, .max = xmax, \
dcc0799b 201 .sign_bit = 7,} }
4eaa9819 202#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
e13ac2e9
MB
203{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
204 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
205 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
206 .tlv.p = (tlv_array), \
c1b4d1c7
LPC
207 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
208 .put = snd_soc_put_volsw, \
209 .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
9a8d38db 210#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
808db4a4 211{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
9a8d38db
TI
212 .items = xitems, .texts = xtexts, \
213 .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
214#define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
215 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
216#define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
217{ .items = xitems, .texts = xtexts }
218#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
2e72f8e3 219{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
9a8d38db 220 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
5967cb3d
CK
221#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
222 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
561ed680
CK
223#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
224{ .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
225 .mask = xmask, .items = xitems, .texts = xtexts, \
226 .values = xvalues, .autodisable = 1}
b948837a
LPC
227#define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
228 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
808db4a4
RP
229#define SOC_ENUM(xname, xenum) \
230{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
231 .info = snd_soc_info_enum_double, \
232 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
233 .private_value = (unsigned long)&xenum }
f8ba0b7b 234#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
808db4a4
RP
235 xhandler_get, xhandler_put) \
236{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1c433fbd 237 .info = snd_soc_info_volsw, \
808db4a4 238 .get = xhandler_get, .put = xhandler_put, \
6db63090 239 .private_value = SOC_SINGLE_VALUE(xreg, xshift, 0, xmax, xinvert, 0) }
460acbec 240#define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
7629ad24
DM
241 xhandler_get, xhandler_put) \
242{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
243 .info = snd_soc_info_volsw, \
244 .get = xhandler_get, .put = xhandler_put, \
460acbec 245 .private_value = \
6db63090 246 SOC_DOUBLE_VALUE(reg, shift_left, shift_right, 0, max, invert, 0) }
c25c79b4
AT
247#define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
248 xhandler_get, xhandler_put) \
249{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
250 .info = snd_soc_info_volsw, \
251 .get = xhandler_get, .put = xhandler_put, \
252 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
1743dbb4 253 0, xmax, xinvert) }
f8ba0b7b 254#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
10144c09
MM
255 xhandler_get, xhandler_put, tlv_array) \
256{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
257 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
258 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
259 .tlv.p = (tlv_array), \
260 .info = snd_soc_info_volsw, \
261 .get = xhandler_get, .put = xhandler_put, \
6db63090 262 .private_value = SOC_SINGLE_VALUE(xreg, xshift, 0, xmax, xinvert, 0) }
a54e22f4
CK
263#define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
264 xhandler_get, xhandler_put, tlv_array) \
265{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
266 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
267 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
268 .tlv.p = (tlv_array), \
894a37c9 269 .info = snd_soc_info_volsw, \
a54e22f4 270 .get = xhandler_get, .put = xhandler_put, \
6db63090 271 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmin, xmax, xinvert, 0) }
d0af93db
JS
272#define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
273 xhandler_get, xhandler_put, tlv_array) \
274{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
275 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
276 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
277 .tlv.p = (tlv_array), \
278 .info = snd_soc_info_volsw, \
279 .get = xhandler_get, .put = xhandler_put, \
460acbec 280 .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
6db63090 281 0, xmax, xinvert, 0) }
3ce91d5a
JS
282#define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
283 xhandler_get, xhandler_put, tlv_array) \
284{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
285 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
286 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
287 .tlv.p = (tlv_array), \
e8f5a103 288 .info = snd_soc_info_volsw, \
3ce91d5a 289 .get = xhandler_get, .put = xhandler_put, \
cdffa775 290 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
1743dbb4 291 0, xmax, xinvert) }
cf51406c
ST
292#define SOC_DOUBLE_R_S_EXT_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, \
293 xsign_bit, xinvert, xhandler_get, xhandler_put, \
294 tlv_array) \
295{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
296 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
297 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
298 .tlv.p = (tlv_array), \
299 .info = snd_soc_info_volsw, \
300 .get = xhandler_get, .put = xhandler_put, \
301 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
302 xmin, xmax, xsign_bit, xinvert) }
5349c0c9
RF
303#define SOC_SINGLE_S_EXT_TLV(xname, xreg, xshift, xmin, xmax, \
304 xsign_bit, xinvert, xhandler_get, xhandler_put, \
305 tlv_array) \
306 SOC_DOUBLE_R_S_EXT_TLV(xname, xreg, xreg, xshift, xmin, xmax, \
307 xsign_bit, xinvert, xhandler_get, xhandler_put, \
308 tlv_array)
808db4a4
RP
309#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
310{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
311 .info = snd_soc_info_bool_ext, \
312 .get = xhandler_get, .put = xhandler_put, \
313 .private_value = xdata }
314#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
315{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
9a953e6f 316 .info = snd_soc_info_enum_double, \
808db4a4
RP
317 .get = xhandler_get, .put = xhandler_put, \
318 .private_value = (unsigned long)&xenum }
1e4c0d7c
RF
319#define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
320 SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
808db4a4 321
71d08516
MB
322#define SND_SOC_BYTES(xname, xbase, xregs) \
323{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
324 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
325 .put = snd_soc_bytes_put, .private_value = \
326 ((unsigned long)&(struct soc_bytes) \
327 {.base = xbase, .num_regs = xregs }) }
fb512677
TBS
328#define SND_SOC_BYTES_E(xname, xbase, xregs, xhandler_get, xhandler_put) \
329{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
330 .info = snd_soc_bytes_info, .get = xhandler_get, \
331 .put = xhandler_put, .private_value = \
332 ((unsigned long)&(struct soc_bytes) \
333 {.base = xbase, .num_regs = xregs }) }
b6f4bb38 334
f831b055
MB
335#define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
336{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
337 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
338 .put = snd_soc_bytes_put, .private_value = \
339 ((unsigned long)&(struct soc_bytes) \
340 {.base = xbase, .num_regs = xregs, \
341 .mask = xmask }) }
342
50a4f98d
VK
343/*
344 * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
345 */
d9881208
VK
346#define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
347{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
348 .info = snd_soc_bytes_info_ext, \
349 .get = xhandler_get, .put = xhandler_put, \
350 .private_value = (unsigned long)&(struct soc_bytes_ext) \
351 {.max = xcount} }
7523a271
OMA
352#define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
353{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
354 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
355 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
356 .tlv.c = (snd_soc_bytes_tlv_callback), \
4d61b39b 357 .info = snd_soc_bytes_info_ext, \
7523a271
OMA
358 .private_value = (unsigned long)&(struct soc_bytes_ext) \
359 {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
4183eed2
KK
360#define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
361 xmin, xmax, xinvert) \
362{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
363 .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
364 .put = snd_soc_put_xr_sx, \
365 .private_value = (unsigned long)&(struct soc_mreg_control) \
366 {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
367 .invert = xinvert, .min = xmin, .max = xmax} }
368
dd7b10b3
KK
369#define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
370 SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
371 snd_soc_get_strobe, snd_soc_put_strobe)
372
6c2fb6a8
GL
373/*
374 * Simplified versions of above macros, declaring a struct and calculating
375 * ARRAY_SIZE internally
376 */
377#define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
2e7e1993 378 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
6c2fb6a8
GL
379 ARRAY_SIZE(xtexts), xtexts)
380#define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
381 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
382#define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
2e7e1993 383 const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
6c2fb6a8 384#define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
2e7e1993 385 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
6c2fb6a8
GL
386 ARRAY_SIZE(xtexts), xtexts, xvalues)
387#define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
388 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
561ed680
CK
389
390#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
391 const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
392 xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
393
b948837a
LPC
394#define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
395 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
6c2fb6a8 396
8a2cd618 397struct snd_soc_card;
808db4a4 398struct snd_soc_pcm_runtime;
3c4b266f 399struct snd_soc_dai;
f0fba2ad 400struct snd_soc_dai_driver;
d273ebe7 401struct snd_soc_dai_link;
030e79f6
KM
402struct snd_soc_component;
403struct snd_soc_component_driver;
8a2cd618
MB
404struct snd_soc_jack;
405struct snd_soc_jack_pin;
3249c68e 406
ce6120cc 407#include <sound/soc-dapm.h>
01d7584c 408#include <sound/soc-dpcm.h>
64527e8a 409#include <sound/soc-topology.h>
f0fba2ad 410
b8c0dab9
LG
411enum snd_soc_pcm_subclass {
412 SND_SOC_PCM_CLASS_PCM = 0,
413 SND_SOC_PCM_CLASS_BE = 1,
414};
415
70a7ca34 416int snd_soc_register_card(struct snd_soc_card *card);
1892a991 417void snd_soc_unregister_card(struct snd_soc_card *card);
0e4ff5c8 418int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
a3375522 419int devm_snd_soc_register_deferrable_card(struct device *dev, struct snd_soc_card *card);
aae013d6 420#ifdef CONFIG_PM_SLEEP
6f8ab4ac
MB
421int snd_soc_suspend(struct device *dev);
422int snd_soc_resume(struct device *dev);
aae013d6
JY
423#else
424static inline int snd_soc_suspend(struct device *dev)
425{
426 return 0;
427}
428
429static inline int snd_soc_resume(struct device *dev)
430{
431 return 0;
432}
433#endif
6f8ab4ac 434int snd_soc_poweroff(struct device *dev);
08ff7209
CR
435int snd_soc_component_initialize(struct snd_soc_component *component,
436 const struct snd_soc_component_driver *driver,
7274d4cd 437 struct device *dev);
ea029dd8
CR
438int snd_soc_add_component(struct snd_soc_component *component,
439 struct snd_soc_dai_driver *dai_drv,
440 int num_dai);
030e79f6 441int snd_soc_register_component(struct device *dev,
cf9e829e 442 const struct snd_soc_component_driver *component_driver,
030e79f6 443 struct snd_soc_dai_driver *dai_drv, int num_dai);
a0b03a61 444int devm_snd_soc_register_component(struct device *dev,
cf9e829e 445 const struct snd_soc_component_driver *component_driver,
a0b03a61 446 struct snd_soc_dai_driver *dai_drv, int num_dai);
144d6dfc 447#define snd_soc_unregister_component(dev) snd_soc_unregister_component_by_driver(dev, NULL)
58f30150
MR
448void snd_soc_unregister_component_by_driver(struct device *dev,
449 const struct snd_soc_component_driver *component_driver);
6fbea6b6
SW
450struct snd_soc_component *snd_soc_lookup_component_nolocked(struct device *dev,
451 const char *driver_name);
7dd5d0d9
KM
452struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
453 const char *driver_name);
427d204c 454
8b12da9a 455int soc_new_pcm(struct snd_soc_pcm_runtime *rtd);
6f0c4226 456#ifdef CONFIG_SND_SOC_COMPRESS
8b12da9a 457int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd);
0b014d72 458#else
8b12da9a 459static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd)
0b014d72
PLB
460{
461 return 0;
462}
6f0c4226 463#endif
12a48a8c 464
47c88fff 465struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
4468189f 466 struct snd_soc_dai_link *dai_link);
47c88fff 467
208a1589 468bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
d9051d86
KM
469
470void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
471 int stream, int action);
472static inline void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd,
473 int stream)
474{
475 snd_soc_runtime_action(rtd, stream, 1);
476}
477static inline void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd,
478 int stream)
479{
480 snd_soc_runtime_action(rtd, stream, -1);
481}
208a1589 482
5854a464
SH
483int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
484 struct snd_pcm_hardware *hw, int stream);
485
ce64c8b9
LPC
486int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
487 unsigned int dai_fmt);
488
7aae816d
MB
489/* Utility functions to get clock rates from various things */
490int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
f3ac3da7 491int snd_soc_params_to_frame_size(const struct snd_pcm_hw_params *params);
c0fa59df 492int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
f3ac3da7
KK
493int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *parms);
494int snd_soc_tdm_params_to_bclk(const struct snd_pcm_hw_params *params,
1ef34dd2 495 int tdm_width, int tdm_slots, int slot_multiple);
943116ba 496int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...);
7aae816d 497
808db4a4 498/* set runtime hw params */
0d3039f4
KM
499static inline int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
500 const struct snd_pcm_hardware *hw)
501{
502 substream->runtime->hw = *hw;
503
504 return 0;
505}
808db4a4 506
c95869e5
KM
507struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
508struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
7361fbea 509 unsigned int id, unsigned int id_mask);
c95869e5 510void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
808db4a4 511
576ce407 512#ifdef CONFIG_SND_SOC_AC97_BUS
b047e1cc 513int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
741a509f
MP
514int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
515 struct platform_device *pdev);
b047e1cc 516
336b8423 517extern struct snd_ac97_bus_ops *soc_ac97_ops;
336b8423 518#else
336b8423
LPC
519static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
520 struct platform_device *pdev)
521{
522 return 0;
523}
524
525static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
526{
527 return 0;
528}
529#endif
530
808db4a4
RP
531/*
532 *Controls
533 */
534struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
3056557f 535 void *data, const char *long_name,
efb7ac3f 536 const char *prefix);
0f2780ad
LPC
537int snd_soc_add_component_controls(struct snd_soc_component *component,
538 const struct snd_kcontrol_new *controls, unsigned int num_controls);
022658be
LG
539int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
540 const struct snd_kcontrol_new *controls, int num_controls);
541int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
542 const struct snd_kcontrol_new *controls, int num_controls);
808db4a4
RP
543int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_info *uinfo);
808db4a4
RP
545int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
546 struct snd_ctl_elem_value *ucontrol);
547int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
548 struct snd_ctl_elem_value *ucontrol);
549int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
808db4a4 550 struct snd_ctl_elem_info *uinfo);
34198710
CK
551int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_info *uinfo);
392abe9c 553#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
808db4a4
RP
554int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_value *ucontrol);
556int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_value *ucontrol);
a92f1394
PU
558#define snd_soc_get_volsw_2r snd_soc_get_volsw
559#define snd_soc_put_volsw_2r snd_soc_put_volsw
1d99f243
BA
560int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_value *ucontrol);
562int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol);
26d9ca34 564int snd_soc_limit_volume(struct snd_soc_card *card,
637d3847 565 const char *name, int max);
71d08516
MB
566int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_info *uinfo);
568int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol);
570int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
571 struct snd_ctl_elem_value *ucontrol);
d9881208
VK
572int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
573 struct snd_ctl_elem_info *ucontrol);
7523a271
OMA
574int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
575 unsigned int size, unsigned int __user *tlv);
4183eed2
KK
576int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_info *uinfo);
578int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
579 struct snd_ctl_elem_value *ucontrol);
580int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
581 struct snd_ctl_elem_value *ucontrol);
dd7b10b3
KK
582int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
583 struct snd_ctl_elem_value *ucontrol);
584int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
585 struct snd_ctl_elem_value *ucontrol);
808db4a4 586
356caf66
KM
587enum snd_soc_trigger_order {
588 /* start stop */
589 SND_SOC_TRIGGER_ORDER_DEFAULT = 0, /* Link->Component->DAI DAI->Component->Link */
590 SND_SOC_TRIGGER_ORDER_LDC, /* Link->DAI->Component Component->DAI->Link */
591
592 SND_SOC_TRIGGER_ORDER_MAX,
593};
594
808db4a4
RP
595/* SoC PCM stream information */
596struct snd_soc_pcm_stream {
f0fba2ad 597 const char *stream_name;
1c433fbd 598 u64 formats; /* SNDRV_PCM_FMTBIT_* */
4a6ba09e 599 u32 subformats; /* for S32_LE format, SNDRV_PCM_SUBFMTBIT_* */
1c433fbd 600 unsigned int rates; /* SNDRV_PCM_RATE_* */
808db4a4
RP
601 unsigned int rate_min; /* min rate */
602 unsigned int rate_max; /* max rate */
603 unsigned int channels_min; /* min channels */
604 unsigned int channels_max; /* max channels */
58ba9b25 605 unsigned int sig_bits; /* number of bits of content */
808db4a4
RP
606};
607
608/* SoC audio ops */
609struct snd_soc_ops {
610 int (*startup)(struct snd_pcm_substream *);
611 void (*shutdown)(struct snd_pcm_substream *);
612 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
613 int (*hw_free)(struct snd_pcm_substream *);
614 int (*prepare)(struct snd_pcm_substream *);
615 int (*trigger)(struct snd_pcm_substream *, int);
616};
617
49681077
VK
618struct snd_soc_compr_ops {
619 int (*startup)(struct snd_compr_stream *);
620 void (*shutdown)(struct snd_compr_stream *);
621 int (*set_params)(struct snd_compr_stream *);
49681077
VK
622};
623
a0ac4411
KM
624struct snd_soc_component*
625snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
626 const char *driver_name);
a0ac4411 627
88bd870f
BC
628struct snd_soc_dai_link_component {
629 const char *name;
c362effe 630 struct device_node *of_node;
88bd870f 631 const char *dai_name;
020b37d0 632 const struct of_phandle_args *dai_args;
24410f49
KM
633
634 /*
635 * Extra format = SND_SOC_DAIFMT_Bx_Fx
636 *
637 * [Note] it is Bx_Fx base, not CBx_CFx
638 *
639 * It will be used with dai_link->dai_fmt
640 * see
641 * snd_soc_runtime_set_dai_fmt()
642 */
643 unsigned int ext_fmt;
88bd870f
BC
644};
645
45cc50d1
KM
646/*
647 * [dai_link->ch_maps Image sample]
648 *
649 *-------------------------
650 * CPU0 <---> Codec0
651 *
652 * ch-map[0].cpu = 0 ch-map[0].codec = 0
653 *
654 *-------------------------
655 * CPU0 <---> Codec0
656 * CPU1 <---> Codec1
657 * CPU2 <---> Codec2
658 *
659 * ch-map[0].cpu = 0 ch-map[0].codec = 0
660 * ch-map[1].cpu = 1 ch-map[1].codec = 1
661 * ch-map[2].cpu = 2 ch-map[2].codec = 2
662 *
663 *-------------------------
664 * CPU0 <---> Codec0
665 * CPU1 <-+-> Codec1
666 * CPU2 <-/
667 *
668 * ch-map[0].cpu = 0 ch-map[0].codec = 0
669 * ch-map[1].cpu = 1 ch-map[1].codec = 1
670 * ch-map[2].cpu = 2 ch-map[2].codec = 1
671 *
672 *-------------------------
673 * CPU0 <---> Codec0
674 * CPU1 <-+-> Codec1
675 * \-> Codec2
676 *
677 * ch-map[0].cpu = 0 ch-map[0].codec = 0
678 * ch-map[1].cpu = 1 ch-map[1].codec = 1
679 * ch-map[2].cpu = 1 ch-map[2].codec = 2
680 *
681 */
682struct snd_soc_dai_link_ch_map {
683 unsigned int cpu;
684 unsigned int codec;
ac950278
BL
685 unsigned int ch_mask;
686};
687
f0fba2ad
LG
688struct snd_soc_dai_link {
689 /* config - must be set by machine driver */
690 const char *name; /* Codec name */
691 const char *stream_name; /* Stream name */
62bc79d3 692
bc92657a
SW
693 /*
694 * You MAY specify the link's CPU-side device, either by device name,
695 * or by DT/OF node, but not both. If this information is omitted,
696 * the CPU-side DAI is matched using .cpu_dai_name only, which hence
697 * must be globally unique. These fields are currently typically used
698 * only for codec to codec links, or systems using device tree.
699 */
bc92657a
SW
700 /*
701 * You MAY specify the DAI name of the CPU DAI. If this information is
702 * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
703 * only, which only works well when that device exposes a single DAI.
704 */
08a5841e
KM
705 struct snd_soc_dai_link_component *cpus;
706 unsigned int num_cpus;
707
bc92657a
SW
708 /*
709 * You MUST specify the link's codec, either by device name, or by
710 * DT/OF node, but not both.
711 */
bc92657a 712 /* You MUST specify the DAI name within the codec */
88bd870f
BC
713 struct snd_soc_dai_link_component *codecs;
714 unsigned int num_codecs;
715
45cc50d1
KM
716 /* num_ch_maps = max(num_cpu, num_codecs) */
717 struct snd_soc_dai_link_ch_map *ch_maps;
718
bc92657a
SW
719 /*
720 * You MAY specify the link's platform/PCM/DMA driver, either by
721 * device name, or by DT/OF node, but not both. Some forms of link
1d768989 722 * do not need a platform. In such case, platforms are not mandatory.
bc92657a 723 */
910fdcab
KM
724 struct snd_soc_dai_link_component *platforms;
725 unsigned int num_platforms;
daecf46e 726
2f0ad491 727 int id; /* optional ID for machine driver link identification */
4ccab3e7 728
7ddc7f91
KM
729 /*
730 * for Codec2Codec
731 */
732 const struct snd_soc_pcm_stream *c2c_params;
733 unsigned int num_c2c_params;
734
75d9ac46
MB
735 unsigned int dai_fmt; /* format to set on init */
736
01d7584c
LG
737 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
738
2dc0f16b
KM
739 /* codec/machine specific init - e.g. add machine controls */
740 int (*init)(struct snd_soc_pcm_runtime *rtd);
741
21a00fb3
PLB
742 /* codec/machine specific exit - dual of init() */
743 void (*exit)(struct snd_soc_pcm_runtime *rtd);
744
2dc0f16b
KM
745 /* optional hw_params re-writing for BE and FE sync */
746 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
747 struct snd_pcm_hw_params *params);
748
749 /* machine stream operations */
750 const struct snd_soc_ops *ops;
751 const struct snd_soc_compr_ops *compr_ops;
752
356caf66
KM
753 /*
754 * soc_pcm_trigger() start/stop sequence.
755 * see also
756 * snd_soc_component_driver
757 * soc_pcm_trigger()
758 */
759 enum snd_soc_trigger_order trigger_start;
760 enum snd_soc_trigger_order trigger_stop;
761
2dc0f16b 762 /* Mark this pcm with non atomic ops */
317ec675 763 unsigned int nonatomic:1;
2dc0f16b 764
1236fa1e
KM
765 /* For unidirectional dai links */
766 unsigned int playback_only:1;
767 unsigned int capture_only:1;
768
3efab7dc
MB
769 /* Keep DAI active over suspend */
770 unsigned int ignore_suspend:1;
771
06f409d7 772 /* Symmetry requirements */
f14654dd 773 unsigned int symmetric_rate:1;
3635bf09 774 unsigned int symmetric_channels:1;
f14654dd 775 unsigned int symmetric_sample_bits:1;
06f409d7 776
01d7584c
LG
777 /* Do not create a PCM for this DAI link (Backend link) */
778 unsigned int no_pcm:1;
779
780 /* This DAI link can route to other DAI links at runtime (Frontend)*/
781 unsigned int dynamic:1;
782
b073ed4e
KM
783 /* DPCM used FE & BE merged format */
784 unsigned int dpcm_merged_format:1;
f4c277b8
JW
785 /* DPCM used FE & BE merged channel */
786 unsigned int dpcm_merged_chan:1;
baacd8d1
JB
787 /* DPCM used FE & BE merged rate */
788 unsigned int dpcm_merged_rate:1;
b073ed4e 789
e50fad4f 790 /* pmdown_time is ignored at stop */
791 unsigned int ignore_pmdown_time:1;
f8f80361 792
a655de80
LG
793 /* Do not create a PCM for this DAI link (Backend link) */
794 unsigned int ignore:1;
795
509ba54f 796#ifdef CONFIG_SND_SOC_TOPOLOGY
f8f80361 797 struct snd_soc_dobj dobj; /* For topology */
509ba54f 798#endif
808db4a4 799};
4da40cb9 800
f3ac3da7
KK
801static inline int snd_soc_link_num_ch_map(const struct snd_soc_dai_link *link)
802{
45cc50d1
KM
803 return max(link->num_cpus, link->num_codecs);
804}
805
4da40cb9 806static inline struct snd_soc_dai_link_component*
1d5a2b5d 807snd_soc_link_to_cpu(struct snd_soc_dai_link *link, int n) {
4da40cb9
KM
808 return &(link)->cpus[n];
809}
810
811static inline struct snd_soc_dai_link_component*
1d5a2b5d 812snd_soc_link_to_codec(struct snd_soc_dai_link *link, int n) {
4da40cb9
KM
813 return &(link)->codecs[n];
814}
815
816static inline struct snd_soc_dai_link_component*
1d5a2b5d 817snd_soc_link_to_platform(struct snd_soc_dai_link *link, int n) {
4da40cb9
KM
818 return &(link)->platforms[n];
819}
820
3db769f1
KM
821#define for_each_link_codecs(link, i, codec) \
822 for ((i) = 0; \
4da40cb9 823 ((i) < link->num_codecs) && \
1d5a2b5d 824 ((codec) = snd_soc_link_to_codec(link, i)); \
3db769f1 825 (i)++)
808db4a4 826
34614739
JB
827#define for_each_link_platforms(link, i, platform) \
828 for ((i) = 0; \
829 ((i) < link->num_platforms) && \
1d5a2b5d 830 ((platform) = snd_soc_link_to_platform(link, i)); \
34614739
JB
831 (i)++)
832
76afa643
SN
833#define for_each_link_cpus(link, i, cpu) \
834 for ((i) = 0; \
4da40cb9 835 ((i) < link->num_cpus) && \
1d5a2b5d 836 ((cpu) = snd_soc_link_to_cpu(link, i)); \
76afa643
SN
837 (i)++)
838
45cc50d1
KM
839#define for_each_link_ch_maps(link, i, ch_map) \
840 for ((i) = 0; \
841 ((i) < snd_soc_link_num_ch_map(link) && \
842 ((ch_map) = link->ch_maps + i)); \
843 (i)++)
844
587c9844
KM
845/*
846 * Sample 1 : Single CPU/Codec/Platform
847 *
848 * SND_SOC_DAILINK_DEFS(test,
849 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai")),
850 * DAILINK_COMP_ARRAY(COMP_CODEC("codec", "codec_dai")),
851 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
852 *
853 * struct snd_soc_dai_link link = {
854 * ...
855 * SND_SOC_DAILINK_REG(test),
856 * };
857 *
858 * Sample 2 : Multi CPU/Codec, no Platform
859 *
860 * SND_SOC_DAILINK_DEFS(test,
861 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
862 * COMP_CPU("cpu_dai2")),
863 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
864 * COMP_CODEC("codec2", "codec_dai2")));
865 *
866 * struct snd_soc_dai_link link = {
867 * ...
868 * SND_SOC_DAILINK_REG(test),
869 * };
870 *
871 * Sample 3 : Define each CPU/Codec/Platform manually
872 *
873 * SND_SOC_DAILINK_DEF(test_cpu,
874 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
875 * COMP_CPU("cpu_dai2")));
876 * SND_SOC_DAILINK_DEF(test_codec,
877 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
878 * COMP_CODEC("codec2", "codec_dai2")));
879 * SND_SOC_DAILINK_DEF(test_platform,
880 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
881 *
882 * struct snd_soc_dai_link link = {
883 * ...
884 * SND_SOC_DAILINK_REG(test_cpu,
885 * test_codec,
886 * test_platform),
887 * };
888 *
889 * Sample 4 : Sample3 without platform
890 *
891 * struct snd_soc_dai_link link = {
892 * ...
893 * SND_SOC_DAILINK_REG(test_cpu,
894 * test_codec);
895 * };
896 */
897
898#define SND_SOC_DAILINK_REG1(name) SND_SOC_DAILINK_REG3(name##_cpus, name##_codecs, name##_platforms)
899#define SND_SOC_DAILINK_REG2(cpu, codec) SND_SOC_DAILINK_REG3(cpu, codec, null_dailink_component)
900#define SND_SOC_DAILINK_REG3(cpu, codec, platform) \
901 .cpus = cpu, \
902 .num_cpus = ARRAY_SIZE(cpu), \
903 .codecs = codec, \
904 .num_codecs = ARRAY_SIZE(codec), \
905 .platforms = platform, \
906 .num_platforms = ARRAY_SIZE(platform)
907
587c9844 908#define SND_SOC_DAILINK_REG(...) \
428cc410 909 CONCATENATE(SND_SOC_DAILINK_REG, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
587c9844
KM
910
911#define SND_SOC_DAILINK_DEF(name, def...) \
912 static struct snd_soc_dai_link_component name[] = { def }
913
914#define SND_SOC_DAILINK_DEFS(name, cpu, codec, platform...) \
915 SND_SOC_DAILINK_DEF(name##_cpus, cpu); \
916 SND_SOC_DAILINK_DEF(name##_codecs, codec); \
917 SND_SOC_DAILINK_DEF(name##_platforms, platform)
918
919#define DAILINK_COMP_ARRAY(param...) param
920#define COMP_EMPTY() { }
921#define COMP_CPU(_dai) { .dai_name = _dai, }
922#define COMP_CODEC(_name, _dai) { .name = _name, .dai_name = _dai, }
923#define COMP_PLATFORM(_name) { .name = _name }
3dc29b8b 924#define COMP_AUX(_name) { .name = _name }
c13493a2 925#define COMP_CODEC_CONF(_name) { .name = _name }
13f58267 926#define COMP_DUMMY() /* see snd_soc_fill_dummy_dai() */
587c9844
KM
927
928extern struct snd_soc_dai_link_component null_dailink_component[0];
1d5a2b5d 929extern struct snd_soc_dai_link_component snd_soc_dummy_dlc;
3e021f3b 930int snd_soc_dlc_is_dummy(struct snd_soc_dai_link_component *dlc);
587c9844 931
ff819b83 932struct snd_soc_codec_conf {
3ca041ed
SR
933 /*
934 * specify device either by device name, or by
935 * DT/OF node, but not both.
936 */
c13493a2
KM
937 struct snd_soc_dai_link_component dlc;
938
ff819b83
DP
939 /*
940 * optional map of kcontrol, widget and path name prefixes that are
941 * associated per device
942 */
ead9b919
JN
943 const char *name_prefix;
944};
945
2eea392d 946struct snd_soc_aux_dev {
3ca041ed
SR
947 /*
948 * specify multi-codec either by device name, or by
949 * DT/OF node, but not both.
950 */
3dc29b8b
KM
951 struct snd_soc_dai_link_component dlc;
952
2eea392d 953 /* codec/machine specific init - e.g. add machine controls */
57bf7726 954 int (*init)(struct snd_soc_component *component);
2eea392d
JN
955};
956
87506549
MB
957/* SoC card */
958struct snd_soc_card {
f0fba2ad 959 const char *name;
22de71ba
LG
960 const char *long_name;
961 const char *driver_name;
dc73d73a 962 const char *components;
8a6a6a38 963#ifdef CONFIG_DMI
345233d7 964 char dmi_longname[80];
8a6a6a38 965#endif /* CONFIG_DMI */
47f56e38
RF
966
967#ifdef CONFIG_PCI
968 /*
969 * PCI does not define 0 as invalid, so pci_subsystem_set indicates
970 * whether a value has been written to these fields.
971 */
972 unsigned short pci_subsystem_vendor;
973 unsigned short pci_subsystem_device;
974 bool pci_subsystem_set;
975#endif /* CONFIG_PCI */
976
a655de80 977 char topology_shortname[32];
345233d7 978
c5af3a2e 979 struct device *dev;
f0fba2ad
LG
980 struct snd_card *snd_card;
981 struct module *owner;
c5af3a2e 982
f0fba2ad 983 struct mutex mutex;
a73fb2df 984 struct mutex dapm_mutex;
c5af3a2e 985
72b745e3
PU
986 /* Mutex for PCM operations */
987 struct mutex pcm_mutex;
988 enum snd_soc_pcm_subclass pcm_subclass;
989
e7361ec4 990 int (*probe)(struct snd_soc_card *card);
28e9ad92 991 int (*late_probe)(struct snd_soc_card *card);
df4d27b1 992 void (*fixup_controls)(struct snd_soc_card *card);
e7361ec4 993 int (*remove)(struct snd_soc_card *card);
808db4a4
RP
994
995 /* the pre and post PM functions are used to do any PM work before and
996 * after the codec and DAI's do any PM work. */
70b2ac12
MB
997 int (*suspend_pre)(struct snd_soc_card *card);
998 int (*suspend_post)(struct snd_soc_card *card);
999 int (*resume_pre)(struct snd_soc_card *card);
1000 int (*resume_post)(struct snd_soc_card *card);
808db4a4 1001
0b4d221b 1002 /* callbacks */
87506549 1003 int (*set_bias_level)(struct snd_soc_card *,
d4c6005f 1004 struct snd_soc_dapm_context *dapm,
0be9898a 1005 enum snd_soc_bias_level level);
1badabd9 1006 int (*set_bias_level_post)(struct snd_soc_card *,
d4c6005f 1007 struct snd_soc_dapm_context *dapm,
1badabd9 1008 enum snd_soc_bias_level level);
0b4d221b 1009
d6f220ea
ML
1010 int (*add_dai_link)(struct snd_soc_card *,
1011 struct snd_soc_dai_link *link);
1012 void (*remove_dai_link)(struct snd_soc_card *,
1013 struct snd_soc_dai_link *link);
1014
6c5f1fed 1015 long pmdown_time;
96dd3622 1016
808db4a4 1017 /* CPU <--> Codec DAI links */
f8f80361
ML
1018 struct snd_soc_dai_link *dai_link; /* predefined links only */
1019 int num_links; /* predefined links only */
f8f80361 1020
1a497983 1021 struct list_head rtd_list;
f0fba2ad 1022 int num_rtd;
6308419a 1023
ff819b83
DP
1024 /* optional codec specific configuration */
1025 struct snd_soc_codec_conf *codec_conf;
1026 int num_configs;
ead9b919 1027
2eea392d
JN
1028 /*
1029 * optional auxiliary devices such as amplifiers or codecs with DAI
1030 * link unused
1031 */
1032 struct snd_soc_aux_dev *aux_dev;
1033 int num_aux_devs;
d2e3a135 1034 struct list_head aux_comp_list;
2eea392d 1035
b7af1daf
MB
1036 const struct snd_kcontrol_new *controls;
1037 int num_controls;
1038
b8ad29de
MB
1039 /*
1040 * Card-specific routes and widgets.
f23e860e 1041 * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
b8ad29de 1042 */
d06e48db 1043 const struct snd_soc_dapm_widget *dapm_widgets;
b8ad29de 1044 int num_dapm_widgets;
d06e48db 1045 const struct snd_soc_dapm_route *dapm_routes;
b8ad29de 1046 int num_dapm_routes;
f23e860e
NC
1047 const struct snd_soc_dapm_widget *of_dapm_widgets;
1048 int num_of_dapm_widgets;
1049 const struct snd_soc_dapm_route *of_dapm_routes;
1050 int num_of_dapm_routes;
b8ad29de 1051
f0fba2ad 1052 /* lists of probed devices belonging to this card */
d9fc4063 1053 struct list_head component_dev_list;
e894efef 1054 struct list_head list;
a6052154 1055
97c866de 1056 struct list_head widgets;
8ddab3f5 1057 struct list_head paths;
7be31be8 1058 struct list_head dapm_list;
db432b41 1059 struct list_head dapm_dirty;
8ddab3f5 1060
8a978234
LG
1061 /* attached dynamic objects */
1062 struct list_head dobj_list;
1063
e37a4970
MB
1064 /* Generic DAPM context for the card */
1065 struct snd_soc_dapm_context dapm;
de02d078 1066 struct snd_soc_dapm_stats dapm_stats;
e37a4970 1067
a6052154
JN
1068#ifdef CONFIG_DEBUG_FS
1069 struct dentry *debugfs_card_root;
b3da4251
KM
1070#endif
1071#ifdef CONFIG_PM_SLEEP
1072 struct work_struct deferred_resume_work;
a6052154 1073#endif
3a45b867 1074 u32 pop_time;
dddf3e4c 1075
317ec675
KM
1076 /* bit field */
1077 unsigned int instantiated:1;
1078 unsigned int topology_shortname_created:1;
1079 unsigned int fully_routed:1;
27f07cac 1080 unsigned int probed:1;
aa293777 1081 unsigned int component_chaining:1;
a3375522 1082 struct device *devres_dev;
317ec675 1083
dddf3e4c 1084 void *drvdata;
808db4a4 1085};
7fe072b4
KM
1086#define for_each_card_prelinks(card, i, link) \
1087 for ((i) = 0; \
1088 ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \
1089 (i)++)
c2b71c71
KM
1090#define for_each_card_pre_auxs(card, i, aux) \
1091 for ((i) = 0; \
1092 ((i) < (card)->num_aux_devs) && ((aux) = &(card)->aux_dev[i]); \
1093 (i)++)
808db4a4 1094
bcb1fd1f
KM
1095#define for_each_card_rtds(card, rtd) \
1096 list_for_each_entry(rtd, &(card)->rtd_list, list)
1097#define for_each_card_rtds_safe(card, rtd, _rtd) \
1098 list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list)
98061fdb 1099
c2b71c71
KM
1100#define for_each_card_auxs(card, component) \
1101 list_for_each_entry(component, &card->aux_comp_list, card_aux_list)
1102#define for_each_card_auxs_safe(card, component, _comp) \
1103 list_for_each_entry_safe(component, _comp, \
1104 &card->aux_comp_list, card_aux_list)
1105
f70f18f7
KM
1106#define for_each_card_components(card, component) \
1107 list_for_each_entry(component, &(card)->component_dev_list, card_list)
1108
df817f8e
KM
1109#define for_each_card_dapms(card, dapm) \
1110 list_for_each_entry(dapm, &card->dapm_list, list)
1111
14596692
KM
1112#define for_each_card_widgets(card, w)\
1113 list_for_each_entry(w, &card->widgets, list)
1114#define for_each_card_widgets_safe(card, w, _w) \
1115 list_for_each_entry_safe(w, _w, &card->widgets, list)
1116
2e5f8617
KM
1117
1118static inline int snd_soc_card_is_instantiated(struct snd_soc_card *card)
1119{
1120 return card && card->instantiated;
1121}
1122
f0fba2ad 1123/* SoC machine DAI configuration, glues a codec and cpu DAI together */
d66a327d 1124struct snd_soc_pcm_runtime {
36ae1a96 1125 struct device *dev;
87506549 1126 struct snd_soc_card *card;
f0fba2ad 1127 struct snd_soc_dai_link *dai_link;
b8c0dab9 1128 struct snd_pcm_ops ops;
f0fba2ad 1129
7ddc7f91 1130 unsigned int c2c_params_select; /* currently selected c2c_param for dai link */
243bcfaf 1131
01d7584c 1132 /* Dynamic PCM BE runtime data */
a26ec2ac 1133 struct snd_soc_dpcm_runtime dpcm[SNDRV_PCM_STREAM_LAST + 1];
3289dc02 1134 struct snd_soc_dapm_widget *c2c_widget[SNDRV_PCM_STREAM_LAST + 1];
01d7584c 1135
f0fba2ad
LG
1136 long pmdown_time;
1137
1138 /* runtime devices */
1139 struct snd_pcm *pcm;
49681077 1140 struct snd_compr *compr;
f0fba2ad 1141
1729025b
KM
1142 /*
1143 * dais = cpu_dai + codec_dai
1144 * see
1145 * soc_new_pcm_runtime()
1d5a2b5d
KM
1146 * snd_soc_rtd_to_cpu()
1147 * snd_soc_rtd_to_codec()
1729025b
KM
1148 */
1149 struct snd_soc_dai **dais;
76afa643 1150
f0fba2ad 1151 struct delayed_work delayed_work;
4bf2e385 1152 void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
f86dcef8
LG
1153#ifdef CONFIG_DEBUG_FS
1154 struct dentry *debugfs_dpcm_root;
f86dcef8 1155#endif
1a497983 1156
40e47e2d 1157 unsigned int id; /* 0-based and monotonic increasing */
1a497983 1158 struct list_head list; /* rtd list of the soc card */
a7df0d3b 1159
6064ed73
KM
1160 /* function mark */
1161 struct snd_pcm_substream *mark_startup;
918ad772 1162 struct snd_pcm_substream *mark_hw_params;
6374f493 1163 struct snd_pcm_substream *mark_trigger;
cd7c7d10 1164 struct snd_compr_stream *mark_compr_startup;
6064ed73 1165
a7df0d3b 1166 /* bit field */
a7df0d3b 1167 unsigned int pop_wait:1;
7426af50 1168 unsigned int fe_compr:1; /* for Dynamic PCM */
4849b2f7 1169 unsigned int initialized:1;
dd9f9cc1 1170
aaa5e1aa 1171 /* CPU/Codec/Platform */
613fb500 1172 int num_components;
aaa5e1aa 1173 struct snd_soc_component *components[] __counted_by(num_components);
808db4a4 1174};
1d5a2b5d 1175
2af69581 1176/* see soc_new_pcm_runtime() */
1d5a2b5d
KM
1177#define snd_soc_rtd_to_cpu(rtd, n) (rtd)->dais[n]
1178#define snd_soc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
9723cab0
KK
1179
1180static inline struct snd_soc_pcm_runtime *
1181snd_soc_substream_to_rtd(const struct snd_pcm_substream *substream)
1182{
1183 return snd_pcm_substream_chip(substream);
1184}
2af69581 1185
613fb500 1186#define for_each_rtd_components(rtd, i, component) \
be16a0f0 1187 for ((i) = 0, component = NULL; \
613fb500
KM
1188 ((i) < rtd->num_components) && ((component) = rtd->components[i]);\
1189 (i)++)
995cbc3c
KM
1190#define for_each_rtd_cpu_dais(rtd, i, dai) \
1191 for ((i) = 0; \
1d5a2b5d 1192 ((i) < rtd->dai_link->num_cpus) && ((dai) = snd_soc_rtd_to_cpu(rtd, i)); \
995cbc3c 1193 (i)++)
995cbc3c
KM
1194#define for_each_rtd_codec_dais(rtd, i, dai) \
1195 for ((i) = 0; \
1d5a2b5d 1196 ((i) < rtd->dai_link->num_codecs) && ((dai) = snd_soc_rtd_to_codec(rtd, i)); \
995cbc3c 1197 (i)++)
22a2fc81
KM
1198#define for_each_rtd_dais(rtd, i, dai) \
1199 for ((i) = 0; \
3989ade2 1200 ((i) < (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs) && \
22a2fc81
KM
1201 ((dai) = (rtd)->dais[i]); \
1202 (i)++)
31a70a71
CR
1203#define for_each_rtd_dais_reverse(rtd, i, dai) \
1204 for ((i) = (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs - 1; \
1205 (i) >= 0 && ((dai) = (rtd)->dais[i]); \
1206 (i)--)
45cc50d1 1207#define for_each_rtd_ch_maps(rtd, i, ch_maps) for_each_link_ch_maps(rtd->dai_link, i, ch_maps)
995cbc3c 1208
83f94a2e 1209void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
808db4a4 1210
4eaa9819
JS
1211/* mixer control */
1212struct soc_mixer_control {
0eba2a7e
CK
1213 /* Minimum and maximum specified as written to the hardware */
1214 int min, max;
1215 /* Limited maximum value specified as presented through the control */
1216 int platform_max;
249ce138
LPC
1217 int reg, rreg;
1218 unsigned int shift, rshift;
81eb3a2b 1219 u32 num_channels;
f227b88f 1220 unsigned int sign_bit;
57295073
LPC
1221 unsigned int invert:1;
1222 unsigned int autodisable:1;
509ba54f 1223#ifdef CONFIG_SND_SOC_TOPOLOGY
8a978234 1224 struct snd_soc_dobj dobj;
509ba54f 1225#endif
4eaa9819
JS
1226};
1227
71d08516
MB
1228struct soc_bytes {
1229 int base;
1230 int num_regs;
f831b055 1231 u32 mask;
71d08516
MB
1232};
1233
d9881208
VK
1234struct soc_bytes_ext {
1235 int max;
509ba54f 1236#ifdef CONFIG_SND_SOC_TOPOLOGY
8a978234 1237 struct snd_soc_dobj dobj;
509ba54f 1238#endif
7523a271 1239 /* used for TLV byte control */
a1e5e7e9
M
1240 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
1241 unsigned int size);
1242 int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
1243 unsigned int size);
d9881208
VK
1244};
1245
4183eed2
KK
1246/* multi register control */
1247struct soc_mreg_control {
1248 long min, max;
1249 unsigned int regbase, regcount, nbits, invert;
1250};
1251
808db4a4
RP
1252/* enumerated kcontrol */
1253struct soc_enum {
b948837a 1254 int reg;
2e72f8e3
PU
1255 unsigned char shift_l;
1256 unsigned char shift_r;
9a8d38db 1257 unsigned int items;
2e72f8e3 1258 unsigned int mask;
87023ff7 1259 const char * const *texts;
2e72f8e3 1260 const unsigned int *values;
561ed680 1261 unsigned int autodisable:1;
509ba54f 1262#ifdef CONFIG_SND_SOC_TOPOLOGY
8a978234 1263 struct snd_soc_dobj dobj;
509ba54f 1264#endif
2e72f8e3
PU
1265};
1266
f3ac3da7 1267static inline bool snd_soc_volsw_is_stereo(const struct soc_mixer_control *mc)
30d86ba4
PU
1268{
1269 if (mc->reg == mc->rreg && mc->shift == mc->rshift)
4aa86e05 1270 return false;
30d86ba4
PU
1271 /*
1272 * mc->reg == mc->rreg && mc->shift != mc->rshift, or
1273 * mc->reg != mc->rreg means that the control is
1274 * stereo (bits in one register or in two registers)
1275 */
4aa86e05 1276 return true;
30d86ba4
PU
1277}
1278
f3ac3da7 1279static inline unsigned int snd_soc_enum_val_to_item(const struct soc_enum *e,
29ae2fa5
LPC
1280 unsigned int val)
1281{
1282 unsigned int i;
1283
1284 if (!e->values)
1285 return val;
1286
1287 for (i = 0; i < e->items; i++)
1288 if (val == e->values[i])
1289 return i;
1290
1291 return 0;
1292}
1293
f3ac3da7 1294static inline unsigned int snd_soc_enum_item_to_val(const struct soc_enum *e,
29ae2fa5
LPC
1295 unsigned int item)
1296{
1297 if (!e->values)
1298 return item;
1299
1300 return e->values[item];
1301}
1302
907fe36a
LPC
1303/**
1304 * snd_soc_kcontrol_component() - Returns the component that registered the
1305 * control
1306 * @kcontrol: The control for which to get the component
1307 *
1308 * Note: This function will work correctly if the control has been registered
ef050bec
CK
1309 * for a component. With snd_soc_add_codec_controls() or via table based
1310 * setup for either a CODEC or component driver. Otherwise the behavior is
1311 * undefined.
907fe36a
LPC
1312 */
1313static inline struct snd_soc_component *snd_soc_kcontrol_component(
1314 struct snd_kcontrol *kcontrol)
1315{
1316 return snd_kcontrol_chip(kcontrol);
1317}
1318
fb257897
MB
1319int snd_soc_util_init(void);
1320void snd_soc_util_exit(void);
1321
b07609ce
KM
1322int snd_soc_of_parse_card_name(struct snd_soc_card *card,
1323 const char *propname);
21efde50
KM
1324int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
1325 const char *propname);
3d4641a4 1326int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop);
cbdfab3b
JB
1327int snd_soc_of_get_slot_mask(struct device_node *np,
1328 const char *prop_name,
1329 unsigned int *mask);
89c67857 1330int snd_soc_of_parse_tdm_slot(struct device_node *np,
6131084a
JS
1331 unsigned int *tx_mask,
1332 unsigned int *rx_mask,
89c67857
XL
1333 unsigned int *slots,
1334 unsigned int *slot_width);
3b710356 1335void snd_soc_of_parse_node_prefix(struct device_node *np,
5e3cdaa2
KM
1336 struct snd_soc_codec_conf *codec_conf,
1337 struct device_node *of_node,
1338 const char *propname);
2708bccf
KM
1339static inline
1340void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
1341 struct snd_soc_codec_conf *codec_conf,
1342 struct device_node *of_node,
1343 const char *propname)
1344{
1345 snd_soc_of_parse_node_prefix(card->dev->of_node,
1346 codec_conf, of_node, propname);
1347}
3b710356 1348
2bc644af
KM
1349int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
1350 const char *propname);
1ae0965d 1351int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
b44a67f8 1352
64c917d1 1353unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt);
91ae4477 1354unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame);
7766861d
KM
1355
1356unsigned int snd_soc_daifmt_parse_format(struct device_node *np, const char *prefix);
1357unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
1358 const char *prefix,
1359 struct device_node **bitclkmaster,
1360 struct device_node **framemaster);
1361#define snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix) \
1362 snd_soc_daifmt_parse_clock_provider_raw(np, prefix, NULL, NULL)
1363#define snd_soc_daifmt_parse_clock_provider_as_phandle \
1364 snd_soc_daifmt_parse_clock_provider_raw
1365#define snd_soc_daifmt_parse_clock_provider_as_flag(np, prefix) \
1366 snd_soc_daifmt_clock_provider_from_bitmap( \
1367 snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
1368
f3ac3da7 1369int snd_soc_get_stream_cpu(const struct snd_soc_dai_link *dai_link, int stream);
05722a0c
KM
1370int snd_soc_get_dlc(const struct of_phandle_args *args,
1371 struct snd_soc_dai_link_component *dlc);
1372int snd_soc_of_get_dlc(struct device_node *of_node,
1373 struct of_phandle_args *args,
1374 struct snd_soc_dai_link_component *dlc,
1375 int index);
a180e8b9 1376int snd_soc_get_dai_id(struct device_node *ep);
933f98be 1377int snd_soc_get_dai_name(const struct of_phandle_args *args,
1ad8ec53 1378 const char **dai_name);
cb470087 1379int snd_soc_of_get_dai_name(struct device_node *of_node,
3c8b5861 1380 const char **dai_name, int index);
93b0f3ee
JFM
1381int snd_soc_of_get_dai_link_codecs(struct device *dev,
1382 struct device_node *of_node,
1383 struct snd_soc_dai_link *dai_link);
94685763 1384void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
900dedd7
MP
1385int snd_soc_of_get_dai_link_cpus(struct device *dev,
1386 struct device_node *of_node,
1387 struct snd_soc_dai_link *dai_link);
1388void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
bec4fa05 1389
ffaf886e
KM
1390int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
1391 struct snd_soc_dai_link *dai_link,
1392 int num_dai_link);
50cd9b53
KM
1393void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
1394 struct snd_soc_pcm_runtime *rtd);
f8f80361 1395
988bad5e
KM
1396void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
1397 struct snd_soc_dai_link_component *cpus);
bbde4a30 1398struct of_phandle_args *snd_soc_copy_dai_args(struct device *dev,
cf88ab48
KK
1399 const struct of_phandle_args *args);
1400struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_args);
e443c205
KM
1401struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
1402 struct snd_soc_dai_driver *dai_drv,
1403 bool legacy_dai_naming);
e11381f3 1404void snd_soc_unregister_dai(struct snd_soc_dai *dai);
68003e6c 1405
305e9020
ML
1406struct snd_soc_dai *snd_soc_find_dai(
1407 const struct snd_soc_dai_link_component *dlc);
c1c277b2
KM
1408struct snd_soc_dai *snd_soc_find_dai_with_mutex(
1409 const struct snd_soc_dai_link_component *dlc);
305e9020 1410
a47cbe72
MB
1411#include <sound/soc-dai.h>
1412
cb50358b
PLB
1413static inline
1414int snd_soc_fixup_dai_links_platform_name(struct snd_soc_card *card,
1415 const char *platform_name)
1416{
1417 struct snd_soc_dai_link *dai_link;
1418 const char *name;
1419 int i;
1420
1421 if (!platform_name) /* nothing to do */
1422 return 0;
1423
1424 /* set platform name for each dailink */
1425 for_each_card_prelinks(card, i, dai_link) {
d908b922
KM
1426 /* only single platform is supported for now */
1427 if (dai_link->num_platforms != 1)
1428 return -EINVAL;
1429
4a50724e
KM
1430 if (!dai_link->platforms)
1431 return -EINVAL;
1432
cb50358b
PLB
1433 name = devm_kstrdup(card->dev, platform_name, GFP_KERNEL);
1434 if (!name)
1435 return -ENOMEM;
1436
adb76b5b
KM
1437 /* only single platform is supported for now */
1438 dai_link->platforms->name = name;
cb50358b
PLB
1439 }
1440
1441 return 0;
1442}
1443
faff4bb0 1444#ifdef CONFIG_DEBUG_FS
8a9dab1a 1445extern struct dentry *snd_soc_debugfs_root;
faff4bb0
SW
1446#endif
1447
6f8ab4ac
MB
1448extern const struct dev_pm_ops snd_soc_pm_ops;
1449
4a778bdc
KM
1450/*
1451 * DAPM helper functions
1452 */
1453enum snd_soc_dapm_subclass {
1454 SND_SOC_DAPM_CLASS_ROOT = 0,
1455 SND_SOC_DAPM_CLASS_RUNTIME = 1,
1456};
1457
1458static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
1459{
1460 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
1461}
1462
1463static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
1464{
1465 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1466}
1467
1468static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
f6d5e586 1469{
4a778bdc 1470 mutex_unlock(&card->dapm_mutex);
f6d5e586
CK
1471}
1472
4a778bdc 1473static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
f6d5e586 1474{
4a778bdc 1475 lockdep_assert_held(&card->dapm_mutex);
f6d5e586
CK
1476}
1477
4a778bdc
KM
1478static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
1479{
1480 _snd_soc_dapm_mutex_lock_root_c(dapm->card);
1481}
1482
1483static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
1484{
1485 _snd_soc_dapm_mutex_lock_c(dapm->card);
1486}
1487
1488static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
1489{
1490 _snd_soc_dapm_mutex_unlock_c(dapm->card);
1491}
1492
1493static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
1494{
1495 _snd_soc_dapm_mutex_assert_held_c(dapm->card);
1496}
1497
1498#define snd_soc_dapm_mutex_lock_root(x) _Generic((x), \
1499 struct snd_soc_card * : _snd_soc_dapm_mutex_lock_root_c, \
1500 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
1501#define snd_soc_dapm_mutex_lock(x) _Generic((x), \
1502 struct snd_soc_card * : _snd_soc_dapm_mutex_lock_c, \
1503 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
1504#define snd_soc_dapm_mutex_unlock(x) _Generic((x), \
1505 struct snd_soc_card * : _snd_soc_dapm_mutex_unlock_c, \
1506 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
1507#define snd_soc_dapm_mutex_assert_held(x) _Generic((x), \
1508 struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
1509 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
1510
38e42f6d
KM
1511/*
1512 * PCM helper functions
1513 */
1514static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
1515{
1516 mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
1517}
1518
1519static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
1520{
1521 mutex_unlock(&card->pcm_mutex);
1522}
1523
1524static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
1525{
1526 lockdep_assert_held(&card->pcm_mutex);
1527}
1528
1529static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
1530{
1531 _snd_soc_dpcm_mutex_lock_c(rtd->card);
1532}
1533
1534static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
1535{
1536 _snd_soc_dpcm_mutex_unlock_c(rtd->card);
1537}
1538
1539static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
1540{
1541 _snd_soc_dpcm_mutex_assert_held_c(rtd->card);
1542}
1543
1544#define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
1545 struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
1546 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
1547
1548#define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
1549 struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
1550 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
1551
1552#define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
1553 struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
1554 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
1555
4ff1fef1 1556#include <sound/soc-component.h>
1793936b 1557#include <sound/soc-card.h>
ddfbe828 1558#include <sound/soc-jack.h>
1b4d9c22 1559
808db4a4 1560#endif