1 /* SPDX-License-Identifier: GPL-2.0
2 *
3 * linux/sound/soc.h -- ALSA SoC Layer
4 *
5 * Author: Liam Girdwood
6 * Created: Aug 11th 2005
7 * Copyright: Wolfson Microelectronics. PLC.
8 */
9
10 #ifndef __LINUX_SND_SOC_H
11 #define __LINUX_SND_SOC_H
12
13 #include <linux/of.h>
14 #include <linux/platform_device.h>
15 #include <linux/types.h>
16 #include <linux/notifier.h>
17 #include <linux/workqueue.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/regmap.h>
21 #include <linux/log2.h>
22 #include <linux/android_kabi.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/compress_driver.h>
26 #include <sound/control.h>
27 #include <sound/ac97_codec.h>
28
29 /*
30 * Convenience kcontrol builders
31 */
32 #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \
33 ((unsigned long)&(struct soc_mixer_control) \
34 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
35 .rshift = shift_right, .max = xmax, \
36 .invert = xinvert, .autodisable = xautodisable})
37 #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
38 ((unsigned long)&(struct soc_mixer_control) \
39 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
40 .rshift = shift_right, .min = xmin, .max = xmax, \
41 .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
42 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
43 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
44 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
45 ((unsigned long)&(struct soc_mixer_control) \
46 {.reg = xreg, .max = xmax, .invert = xinvert})
47 #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
48 ((unsigned long)&(struct soc_mixer_control) \
49 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
50 .max = xmax, .invert = xinvert})
51 #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
52 ((unsigned long)&(struct soc_mixer_control) \
53 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
54 .max = xmax, .min = xmin, .sign_bit = xsign_bit, \
55 .invert = xinvert})
56 #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
57 ((unsigned long)&(struct soc_mixer_control) \
58 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
59 .min = xmin, .max = xmax, .invert = xinvert})
60 #define SOC_SINGLE(xname, reg, shift, max, invert) \
61 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
62 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
63 .put = snd_soc_put_volsw, \
64 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
65 #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
66 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
67 .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
68 .put = snd_soc_put_volsw_range, \
69 .private_value = (unsigned long)&(struct soc_mixer_control) \
70 {.reg = xreg, .rreg = xreg, .shift = xshift, \
71 .rshift = xshift, .min = xmin, .max = xmax, \
72 .invert = xinvert} }
73 #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
74 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
75 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
76 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
77 .tlv.p = (tlv_array), \
78 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
79 .put = snd_soc_put_volsw, \
80 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
81 #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
82 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
83 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
84 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
85 .tlv.p = (tlv_array),\
86 .info = snd_soc_info_volsw_sx, \
87 .get = snd_soc_get_volsw_sx,\
88 .put = snd_soc_put_volsw_sx, \
89 .private_value = (unsigned long)&(struct soc_mixer_control) \
90 {.reg = xreg, .rreg = xreg, \
91 .shift = xshift, .rshift = xshift, \
92 .max = xmax, .min = xmin} }
93 #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
94 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
95 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
96 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
97 .tlv.p = (tlv_array), \
98 .info = snd_soc_info_volsw_range, \
99 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
100 .private_value = (unsigned long)&(struct soc_mixer_control) \
101 {.reg = xreg, .rreg = xreg, .shift = xshift, \
102 .rshift = xshift, .min = xmin, .max = xmax, \
103 .invert = xinvert} }
104 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
105 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
106 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
107 .put = snd_soc_put_volsw, \
108 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
109 max, invert, 0) }
110 #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \
111 { \
112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
113 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
114 .access = SNDRV_CTL_ELEM_ACCESS_READ | \
115 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
116 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
117 max, invert, 0) }
118 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
119 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
120 .info = snd_soc_info_volsw, \
121 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
122 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
123 xmax, xinvert) }
124 #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
125 xmax, xinvert) \
126 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
127 .info = snd_soc_info_volsw_range, \
128 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
129 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
130 xshift, xmin, xmax, xinvert) }
131 #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
132 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
133 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
134 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
135 .tlv.p = (tlv_array), \
136 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
137 .put = snd_soc_put_volsw, \
138 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
139 max, invert, 0) }
140 #define SOC_DOUBLE_SX_TLV(xname, xreg, shift_left, shift_right, xmin, xmax, tlv_array) \
141 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
142 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
143 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
144 .tlv.p = (tlv_array), \
145 .info = snd_soc_info_volsw_sx, \
146 .get = snd_soc_get_volsw_sx, \
147 .put = snd_soc_put_volsw_sx, \
148 .private_value = (unsigned long)&(struct soc_mixer_control) \
149 {.reg = xreg, .rreg = xreg, \
150 .shift = shift_left, .rshift = shift_right, \
151 .max = xmax, .min = xmin} }
152 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
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), \
157 .info = snd_soc_info_volsw, \
158 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
159 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
160 xmax, xinvert) }
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), \
167 .info = snd_soc_info_volsw_range, \
168 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
169 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
170 xshift, xmin, xmax, xinvert) }
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), \
176 .info = snd_soc_info_volsw_sx, \
177 .get = snd_soc_get_volsw_sx, \
178 .put = snd_soc_put_volsw_sx, \
179 .private_value = (unsigned long)&(struct soc_mixer_control) \
180 {.reg = xreg, .rreg = xrreg, \
181 .shift = xshift, .rshift = xshift, \
182 .max = xmax, .min = xmin} }
183 #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
184 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
185 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
186 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
187 .tlv.p = (tlv_array), \
188 .info = snd_soc_info_volsw, \
189 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
190 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
191 xmin, xmax, xsign_bit, xinvert) }
192 #define SOC_SINGLE_S_TLV(xname, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
193 SOC_DOUBLE_R_S_TLV(xname, xreg, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array)
194 #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
195 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
196 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
197 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
198 .tlv.p = (tlv_array), \
199 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
200 .put = snd_soc_put_volsw, \
201 .private_value = (unsigned long)&(struct soc_mixer_control) \
202 {.reg = xreg, .rreg = xreg, \
203 .min = xmin, .max = xmax, \
204 .sign_bit = 7,} }
205 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
206 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
207 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
208 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
209 .tlv.p = (tlv_array), \
210 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
211 .put = snd_soc_put_volsw, \
212 .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
213 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
214 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
215 .items = xitems, .texts = xtexts, \
216 .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
217 #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
218 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
219 #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
220 { .items = xitems, .texts = xtexts }
221 #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
222 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
223 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
224 #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
225 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
226 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
227 { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
228 .mask = xmask, .items = xitems, .texts = xtexts, \
229 .values = xvalues, .autodisable = 1}
230 #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
231 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
232 #define SOC_ENUM(xname, xenum) \
233 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
234 .info = snd_soc_info_enum_double, \
235 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
236 .private_value = (unsigned long)&xenum }
237 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
238 xhandler_get, xhandler_put) \
239 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
240 .info = snd_soc_info_volsw, \
241 .get = xhandler_get, .put = xhandler_put, \
242 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
243 #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
244 xhandler_get, xhandler_put) \
245 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
246 .info = snd_soc_info_volsw, \
247 .get = xhandler_get, .put = xhandler_put, \
248 .private_value = \
249 SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
250 #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
251 xhandler_get, xhandler_put) \
252 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
253 .info = snd_soc_info_volsw, \
254 .get = xhandler_get, .put = xhandler_put, \
255 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
256 xmax, xinvert) }
257 #define SOC_SINGLE_MULTI_EXT(xname, xreg, xshift, xmax, xinvert, xcount,\
258 xhandler_get, xhandler_put) \
259 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
260 .info = snd_soc_info_multi_ext, \
261 .get = xhandler_get, .put = xhandler_put, \
262 .private_value = (unsigned long)&(struct soc_multi_mixer_control) \
263 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
264 .count = xcount, .platform_max = xmax, .invert = xinvert} }
265 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
266 xhandler_get, xhandler_put, tlv_array) \
267 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
268 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
269 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
270 .tlv.p = (tlv_array), \
271 .info = snd_soc_info_volsw, \
272 .get = xhandler_get, .put = xhandler_put, \
273 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
274 #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
275 xhandler_get, xhandler_put, tlv_array) \
276 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
277 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
278 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
279 .tlv.p = (tlv_array), \
280 .info = snd_soc_info_volsw_range, \
281 .get = xhandler_get, .put = xhandler_put, \
282 .private_value = (unsigned long)&(struct soc_mixer_control) \
283 {.reg = xreg, .rreg = xreg, .shift = xshift, \
284 .rshift = xshift, .min = xmin, .max = xmax, \
285 .invert = xinvert} }
286 #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
287 xhandler_get, xhandler_put, tlv_array) \
288 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
289 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
290 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
291 .tlv.p = (tlv_array), \
292 .info = snd_soc_info_volsw, \
293 .get = xhandler_get, .put = xhandler_put, \
294 .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
295 xmax, xinvert, 0) }
296 #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
297 xhandler_get, xhandler_put, tlv_array) \
298 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
299 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
300 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
301 .tlv.p = (tlv_array), \
302 .info = snd_soc_info_volsw, \
303 .get = xhandler_get, .put = xhandler_put, \
304 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
305 xmax, xinvert) }
306 #define SOC_DOUBLE_R_S_EXT_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, \
307 xsign_bit, xinvert, xhandler_get, xhandler_put, \
308 tlv_array) \
309 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
310 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
311 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
312 .tlv.p = (tlv_array), \
313 .info = snd_soc_info_volsw, \
314 .get = xhandler_get, .put = xhandler_put, \
315 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
316 xmin, xmax, xsign_bit, xinvert) }
317 #define SOC_SINGLE_S_EXT_TLV(xname, xreg, xshift, xmin, xmax, \
318 xsign_bit, xinvert, xhandler_get, xhandler_put, \
319 tlv_array) \
320 SOC_DOUBLE_R_S_EXT_TLV(xname, xreg, xreg, xshift, xmin, xmax, \
321 xsign_bit, xinvert, xhandler_get, xhandler_put, \
322 tlv_array)
323 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
324 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
325 .info = snd_soc_info_bool_ext, \
326 .get = xhandler_get, .put = xhandler_put, \
327 .private_value = xdata }
328 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
329 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
330 .info = snd_soc_info_enum_double, \
331 .get = xhandler_get, .put = xhandler_put, \
332 .private_value = (unsigned long)&xenum }
333 #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
334 SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
335
336 #define SND_SOC_BYTES(xname, xbase, xregs) \
337 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
338 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
339 .put = snd_soc_bytes_put, .private_value = \
340 ((unsigned long)&(struct soc_bytes) \
341 {.base = xbase, .num_regs = xregs }) }
342 #define SND_SOC_BYTES_E(xname, xbase, xregs, xhandler_get, xhandler_put) \
343 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
344 .info = snd_soc_bytes_info, .get = xhandler_get, \
345 .put = xhandler_put, .private_value = \
346 ((unsigned long)&(struct soc_bytes) \
347 {.base = xbase, .num_regs = xregs }) }
348
349 #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
350 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
351 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
352 .put = snd_soc_bytes_put, .private_value = \
353 ((unsigned long)&(struct soc_bytes) \
354 {.base = xbase, .num_regs = xregs, \
355 .mask = xmask }) }
356
357 /*
358 * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead
359 */
360 #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
361 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
362 .info = snd_soc_bytes_info_ext, \
363 .get = xhandler_get, .put = xhandler_put, \
364 .private_value = (unsigned long)&(struct soc_bytes_ext) \
365 {.max = xcount} }
366 #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
367 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
368 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
369 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
370 .tlv.c = (snd_soc_bytes_tlv_callback), \
371 .info = snd_soc_bytes_info_ext, \
372 .private_value = (unsigned long)&(struct soc_bytes_ext) \
373 {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
374 #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
375 xmin, xmax, xinvert) \
376 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
377 .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
378 .put = snd_soc_put_xr_sx, \
379 .private_value = (unsigned long)&(struct soc_mreg_control) \
380 {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
381 .invert = xinvert, .min = xmin, .max = xmax} }
382
383 #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
384 SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
385 snd_soc_get_strobe, snd_soc_put_strobe)
386
387 /*
388 * Simplified versions of above macros, declaring a struct and calculating
389 * ARRAY_SIZE internally
390 */
391 #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
392 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
393 ARRAY_SIZE(xtexts), xtexts)
394 #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
395 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
396 #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
397 const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
398 #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
399 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
400 ARRAY_SIZE(xtexts), xtexts, xvalues)
401 #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
402 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
403
404 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
405 const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
406 xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
407
408 #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
409 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
410
411 struct device_node;
412 struct snd_jack;
413 struct snd_soc_card;
414 struct snd_soc_pcm_stream;
415 struct snd_soc_ops;
416 struct snd_soc_pcm_runtime;
417 struct snd_soc_dai;
418 struct snd_soc_dai_driver;
419 struct snd_soc_dai_link;
420 struct snd_soc_component;
421 struct snd_soc_component_driver;
422 struct soc_enum;
423 struct snd_soc_jack;
424 struct snd_soc_jack_zone;
425 struct snd_soc_jack_pin;
426 #include <sound/soc-dapm.h>
427 #include <sound/soc-dpcm.h>
428 #include <sound/soc-topology.h>
429
430 struct snd_soc_jack_gpio;
431
432 enum snd_soc_pcm_subclass {
433 SND_SOC_PCM_CLASS_PCM = 0,
434 SND_SOC_PCM_CLASS_BE = 1,
435 };
436
437 int snd_soc_register_card(struct snd_soc_card *card);
438 void snd_soc_unregister_card(struct snd_soc_card *card);
439 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
440 #ifdef CONFIG_PM_SLEEP
441 int snd_soc_suspend(struct device *dev);
442 int snd_soc_resume(struct device *dev);
443 #else
snd_soc_suspend(struct device * dev)444 static inline int snd_soc_suspend(struct device *dev)
445 {
446 return 0;
447 }
448
snd_soc_resume(struct device * dev)449 static inline int snd_soc_resume(struct device *dev)
450 {
451 return 0;
452 }
453 #endif
454 int snd_soc_poweroff(struct device *dev);
455 int snd_soc_component_initialize(struct snd_soc_component *component,
456 const struct snd_soc_component_driver *driver,
457 struct device *dev);
458 int snd_soc_add_component(struct snd_soc_component *component,
459 struct snd_soc_dai_driver *dai_drv,
460 int num_dai);
461 int snd_soc_register_component(struct device *dev,
462 const struct snd_soc_component_driver *component_driver,
463 struct snd_soc_dai_driver *dai_drv, int num_dai);
464 int devm_snd_soc_register_component(struct device *dev,
465 const struct snd_soc_component_driver *component_driver,
466 struct snd_soc_dai_driver *dai_drv, int num_dai);
467 void snd_soc_unregister_component(struct device *dev);
468 void snd_soc_unregister_component_by_driver(struct device *dev,
469 const struct snd_soc_component_driver *component_driver);
470 struct snd_soc_component *snd_soc_lookup_component_nolocked(struct device *dev,
471 const char *driver_name);
472 struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
473 const char *driver_name);
474
475 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
476 #ifdef CONFIG_SND_SOC_COMPRESS
477 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
478 #else
snd_soc_new_compress(struct snd_soc_pcm_runtime * rtd,int num)479 static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
480 {
481 return 0;
482 }
483 #endif
484
485 void snd_soc_disconnect_sync(struct device *dev);
486
487 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
488 struct snd_soc_dai_link *dai_link);
489
490 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
491
492 void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
493 int stream, int action);
snd_soc_runtime_activate(struct snd_soc_pcm_runtime * rtd,int stream)494 static inline void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd,
495 int stream)
496 {
497 snd_soc_runtime_action(rtd, stream, 1);
498 }
snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime * rtd,int stream)499 static inline void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd,
500 int stream)
501 {
502 snd_soc_runtime_action(rtd, stream, -1);
503 }
504
505 int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
506 struct snd_pcm_hardware *hw, int stream);
507
508 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
509 unsigned int dai_fmt);
510
511 #ifdef CONFIG_DMI
512 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour);
513 #else
snd_soc_set_dmi_name(struct snd_soc_card * card,const char * flavour)514 static inline int snd_soc_set_dmi_name(struct snd_soc_card *card,
515 const char *flavour)
516 {
517 return 0;
518 }
519 #endif
520
521 /* Utility functions to get clock rates from various things */
522 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
523 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
524 int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
525 int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
526 int snd_soc_tdm_params_to_bclk(struct snd_pcm_hw_params *params,
527 int tdm_width, int tdm_slots, int slot_multiple);
528
529 /* set runtime hw params */
530 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
531 const struct snd_pcm_hardware *hw);
532
533 struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
534 struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
535 unsigned int id, unsigned int id_mask);
536 void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
537
538 #ifdef CONFIG_SND_SOC_AC97_BUS
539 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
540 int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
541 struct platform_device *pdev);
542
543 extern struct snd_ac97_bus_ops *soc_ac97_ops;
544 #else
snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops * ops,struct platform_device * pdev)545 static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
546 struct platform_device *pdev)
547 {
548 return 0;
549 }
550
snd_soc_set_ac97_ops(struct snd_ac97_bus_ops * ops)551 static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
552 {
553 return 0;
554 }
555 #endif
556
557 /*
558 *Controls
559 */
560 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
561 void *data, const char *long_name,
562 const char *prefix);
563 int snd_soc_add_component_controls(struct snd_soc_component *component,
564 const struct snd_kcontrol_new *controls, unsigned int num_controls);
565 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
566 const struct snd_kcontrol_new *controls, int num_controls);
567 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
568 const struct snd_kcontrol_new *controls, int num_controls);
569 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
570 struct snd_ctl_elem_info *uinfo);
571 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
572 struct snd_ctl_elem_value *ucontrol);
573 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
574 struct snd_ctl_elem_value *ucontrol);
575 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_info *uinfo);
577 int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
578 struct snd_ctl_elem_info *uinfo);
579 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
580 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
581 struct snd_ctl_elem_value *ucontrol);
582 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
583 struct snd_ctl_elem_value *ucontrol);
584 #define snd_soc_get_volsw_2r snd_soc_get_volsw
585 #define snd_soc_put_volsw_2r snd_soc_put_volsw
586 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
587 struct snd_ctl_elem_value *ucontrol);
588 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
589 struct snd_ctl_elem_value *ucontrol);
590 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
591 struct snd_ctl_elem_info *uinfo);
592 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
593 struct snd_ctl_elem_value *ucontrol);
594 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_value *ucontrol);
596 int snd_soc_limit_volume(struct snd_soc_card *card,
597 const char *name, int max);
598 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_info *uinfo);
600 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol);
602 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_value *ucontrol);
604 int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
605 struct snd_ctl_elem_info *ucontrol);
606 int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
607 unsigned int size, unsigned int __user *tlv);
608 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_info *uinfo);
610 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol);
612 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol);
614 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol);
616 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol);
618 int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_info *uinfo);
620
621 /* SoC PCM stream information */
622 struct snd_soc_pcm_stream {
623 const char *stream_name;
624 u64 formats; /* SNDRV_PCM_FMTBIT_* */
625 unsigned int rates; /* SNDRV_PCM_RATE_* */
626 unsigned int rate_min; /* min rate */
627 unsigned int rate_max; /* max rate */
628 unsigned int channels_min; /* min channels */
629 unsigned int channels_max; /* max channels */
630 unsigned int sig_bits; /* number of bits of content */
631 };
632
633 /* SoC audio ops */
634 struct snd_soc_ops {
635 int (*startup)(struct snd_pcm_substream *);
636 void (*shutdown)(struct snd_pcm_substream *);
637 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
638 int (*hw_free)(struct snd_pcm_substream *);
639 int (*prepare)(struct snd_pcm_substream *);
640 int (*trigger)(struct snd_pcm_substream *, int);
641 };
642
643 struct snd_soc_compr_ops {
644 int (*startup)(struct snd_compr_stream *);
645 void (*shutdown)(struct snd_compr_stream *);
646 int (*set_params)(struct snd_compr_stream *);
647 int (*trigger)(struct snd_compr_stream *);
648 };
649
650 struct snd_soc_component*
651 snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
652 const char *driver_name);
653
654 struct snd_soc_dai_link_component {
655 const char *name;
656 struct device_node *of_node;
657 const char *dai_name;
658 };
659
660 struct snd_soc_dai_link {
661 /* config - must be set by machine driver */
662 const char *name; /* Codec name */
663 const char *stream_name; /* Stream name */
664
665 /*
666 * You MAY specify the link's CPU-side device, either by device name,
667 * or by DT/OF node, but not both. If this information is omitted,
668 * the CPU-side DAI is matched using .cpu_dai_name only, which hence
669 * must be globally unique. These fields are currently typically used
670 * only for codec to codec links, or systems using device tree.
671 */
672 /*
673 * You MAY specify the DAI name of the CPU DAI. If this information is
674 * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
675 * only, which only works well when that device exposes a single DAI.
676 */
677 struct snd_soc_dai_link_component *cpus;
678 unsigned int num_cpus;
679
680 /*
681 * You MUST specify the link's codec, either by device name, or by
682 * DT/OF node, but not both.
683 */
684 /* You MUST specify the DAI name within the codec */
685 struct snd_soc_dai_link_component *codecs;
686 unsigned int num_codecs;
687
688 /*
689 * You MAY specify the link's platform/PCM/DMA driver, either by
690 * device name, or by DT/OF node, but not both. Some forms of link
691 * do not need a platform. In such case, platforms are not mandatory.
692 */
693 struct snd_soc_dai_link_component *platforms;
694 unsigned int num_platforms;
695
696 int id; /* optional ID for machine driver link identification */
697
698 const struct snd_soc_pcm_stream *params;
699 unsigned int num_params;
700
701 unsigned int dai_fmt; /* format to set on init */
702
703 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
704
705 /* codec/machine specific init - e.g. add machine controls */
706 int (*init)(struct snd_soc_pcm_runtime *rtd);
707
708 /* codec/machine specific exit - dual of init() */
709 void (*exit)(struct snd_soc_pcm_runtime *rtd);
710
711 /* optional hw_params re-writing for BE and FE sync */
712 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
713 struct snd_pcm_hw_params *params);
714
715 /* machine stream operations */
716 const struct snd_soc_ops *ops;
717 const struct snd_soc_compr_ops *compr_ops;
718
719 /* Mark this pcm with non atomic ops */
720 unsigned int nonatomic:1;
721
722 /* For unidirectional dai links */
723 unsigned int playback_only:1;
724 unsigned int capture_only:1;
725
726 /* Keep DAI active over suspend */
727 unsigned int ignore_suspend:1;
728
729 /* Symmetry requirements */
730 unsigned int symmetric_rate:1;
731 unsigned int symmetric_channels:1;
732 unsigned int symmetric_sample_bits:1;
733
734 /* Do not create a PCM for this DAI link (Backend link) */
735 unsigned int no_pcm:1;
736
737 /* This DAI link can route to other DAI links at runtime (Frontend)*/
738 unsigned int dynamic:1;
739
740 /* DPCM capture and Playback support */
741 unsigned int dpcm_capture:1;
742 unsigned int dpcm_playback:1;
743
744 /* DPCM used FE & BE merged format */
745 unsigned int dpcm_merged_format:1;
746 /* DPCM used FE & BE merged channel */
747 unsigned int dpcm_merged_chan:1;
748 /* DPCM used FE & BE merged rate */
749 unsigned int dpcm_merged_rate:1;
750
751 /* pmdown_time is ignored at stop */
752 unsigned int ignore_pmdown_time:1;
753
754 /* Do not create a PCM for this DAI link (Backend link) */
755 unsigned int ignore:1;
756
757 /* This flag will reorder stop sequence. By enabling this flag
758 * DMA controller stop sequence will be invoked first followed by
759 * CPU DAI driver stop sequence
760 */
761 unsigned int stop_dma_first:1;
762
763 #ifdef CONFIG_SND_SOC_TOPOLOGY
764 struct snd_soc_dobj dobj; /* For topology */
765 #endif
766
767 ANDROID_KABI_RESERVE(1);
768 };
769
770 static inline struct snd_soc_dai_link_component*
asoc_link_to_cpu(struct snd_soc_dai_link * link,int n)771 asoc_link_to_cpu(struct snd_soc_dai_link *link, int n) {
772 return &(link)->cpus[n];
773 }
774
775 static inline struct snd_soc_dai_link_component*
asoc_link_to_codec(struct snd_soc_dai_link * link,int n)776 asoc_link_to_codec(struct snd_soc_dai_link *link, int n) {
777 return &(link)->codecs[n];
778 }
779
780 static inline struct snd_soc_dai_link_component*
asoc_link_to_platform(struct snd_soc_dai_link * link,int n)781 asoc_link_to_platform(struct snd_soc_dai_link *link, int n) {
782 return &(link)->platforms[n];
783 }
784
785 #define for_each_link_codecs(link, i, codec) \
786 for ((i) = 0; \
787 ((i) < link->num_codecs) && \
788 ((codec) = asoc_link_to_codec(link, i)); \
789 (i)++)
790
791 #define for_each_link_platforms(link, i, platform) \
792 for ((i) = 0; \
793 ((i) < link->num_platforms) && \
794 ((platform) = asoc_link_to_platform(link, i)); \
795 (i)++)
796
797 #define for_each_link_cpus(link, i, cpu) \
798 for ((i) = 0; \
799 ((i) < link->num_cpus) && \
800 ((cpu) = asoc_link_to_cpu(link, i)); \
801 (i)++)
802
803 /*
804 * Sample 1 : Single CPU/Codec/Platform
805 *
806 * SND_SOC_DAILINK_DEFS(test,
807 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai")),
808 * DAILINK_COMP_ARRAY(COMP_CODEC("codec", "codec_dai")),
809 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
810 *
811 * struct snd_soc_dai_link link = {
812 * ...
813 * SND_SOC_DAILINK_REG(test),
814 * };
815 *
816 * Sample 2 : Multi CPU/Codec, no Platform
817 *
818 * SND_SOC_DAILINK_DEFS(test,
819 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
820 * COMP_CPU("cpu_dai2")),
821 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
822 * COMP_CODEC("codec2", "codec_dai2")));
823 *
824 * struct snd_soc_dai_link link = {
825 * ...
826 * SND_SOC_DAILINK_REG(test),
827 * };
828 *
829 * Sample 3 : Define each CPU/Codec/Platform manually
830 *
831 * SND_SOC_DAILINK_DEF(test_cpu,
832 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"),
833 * COMP_CPU("cpu_dai2")));
834 * SND_SOC_DAILINK_DEF(test_codec,
835 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"),
836 * COMP_CODEC("codec2", "codec_dai2")));
837 * SND_SOC_DAILINK_DEF(test_platform,
838 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform")));
839 *
840 * struct snd_soc_dai_link link = {
841 * ...
842 * SND_SOC_DAILINK_REG(test_cpu,
843 * test_codec,
844 * test_platform),
845 * };
846 *
847 * Sample 4 : Sample3 without platform
848 *
849 * struct snd_soc_dai_link link = {
850 * ...
851 * SND_SOC_DAILINK_REG(test_cpu,
852 * test_codec);
853 * };
854 */
855
856 #define SND_SOC_DAILINK_REG1(name) SND_SOC_DAILINK_REG3(name##_cpus, name##_codecs, name##_platforms)
857 #define SND_SOC_DAILINK_REG2(cpu, codec) SND_SOC_DAILINK_REG3(cpu, codec, null_dailink_component)
858 #define SND_SOC_DAILINK_REG3(cpu, codec, platform) \
859 .cpus = cpu, \
860 .num_cpus = ARRAY_SIZE(cpu), \
861 .codecs = codec, \
862 .num_codecs = ARRAY_SIZE(codec), \
863 .platforms = platform, \
864 .num_platforms = ARRAY_SIZE(platform)
865
866 #define SND_SOC_DAILINK_REGx(_1, _2, _3, func, ...) func
867 #define SND_SOC_DAILINK_REG(...) \
868 SND_SOC_DAILINK_REGx(__VA_ARGS__, \
869 SND_SOC_DAILINK_REG3, \
870 SND_SOC_DAILINK_REG2, \
871 SND_SOC_DAILINK_REG1)(__VA_ARGS__)
872
873 #define SND_SOC_DAILINK_DEF(name, def...) \
874 static struct snd_soc_dai_link_component name[] = { def }
875
876 #define SND_SOC_DAILINK_DEFS(name, cpu, codec, platform...) \
877 SND_SOC_DAILINK_DEF(name##_cpus, cpu); \
878 SND_SOC_DAILINK_DEF(name##_codecs, codec); \
879 SND_SOC_DAILINK_DEF(name##_platforms, platform)
880
881 #define DAILINK_COMP_ARRAY(param...) param
882 #define COMP_EMPTY() { }
883 #define COMP_CPU(_dai) { .dai_name = _dai, }
884 #define COMP_CODEC(_name, _dai) { .name = _name, .dai_name = _dai, }
885 #define COMP_PLATFORM(_name) { .name = _name }
886 #define COMP_AUX(_name) { .name = _name }
887 #define COMP_CODEC_CONF(_name) { .name = _name }
888 #define COMP_DUMMY() { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", }
889
890 extern struct snd_soc_dai_link_component null_dailink_component[0];
891
892
893 struct snd_soc_codec_conf {
894 /*
895 * specify device either by device name, or by
896 * DT/OF node, but not both.
897 */
898 struct snd_soc_dai_link_component dlc;
899
900 /*
901 * optional map of kcontrol, widget and path name prefixes that are
902 * associated per device
903 */
904 const char *name_prefix;
905 };
906
907 struct snd_soc_aux_dev {
908 /*
909 * specify multi-codec either by device name, or by
910 * DT/OF node, but not both.
911 */
912 struct snd_soc_dai_link_component dlc;
913
914 /* codec/machine specific init - e.g. add machine controls */
915 int (*init)(struct snd_soc_component *component);
916 };
917
918 /* SoC card */
919 struct snd_soc_card {
920 const char *name;
921 const char *long_name;
922 const char *driver_name;
923 const char *components;
924 #ifdef CONFIG_DMI
925 char dmi_longname[80];
926 #endif /* CONFIG_DMI */
927 char topology_shortname[32];
928
929 struct device *dev;
930 struct snd_card *snd_card;
931 struct module *owner;
932
933 struct mutex mutex;
934 struct mutex dapm_mutex;
935
936 /* Mutex for PCM operations */
937 struct mutex pcm_mutex;
938 enum snd_soc_pcm_subclass pcm_subclass;
939
940 int (*probe)(struct snd_soc_card *card);
941 int (*late_probe)(struct snd_soc_card *card);
942 void (*fixup_controls)(struct snd_soc_card *card);
943 int (*remove)(struct snd_soc_card *card);
944
945 /* the pre and post PM functions are used to do any PM work before and
946 * after the codec and DAI's do any PM work. */
947 int (*suspend_pre)(struct snd_soc_card *card);
948 int (*suspend_post)(struct snd_soc_card *card);
949 int (*resume_pre)(struct snd_soc_card *card);
950 int (*resume_post)(struct snd_soc_card *card);
951
952 /* callbacks */
953 int (*set_bias_level)(struct snd_soc_card *,
954 struct snd_soc_dapm_context *dapm,
955 enum snd_soc_bias_level level);
956 int (*set_bias_level_post)(struct snd_soc_card *,
957 struct snd_soc_dapm_context *dapm,
958 enum snd_soc_bias_level level);
959
960 int (*add_dai_link)(struct snd_soc_card *,
961 struct snd_soc_dai_link *link);
962 void (*remove_dai_link)(struct snd_soc_card *,
963 struct snd_soc_dai_link *link);
964
965 long pmdown_time;
966
967 /* CPU <--> Codec DAI links */
968 struct snd_soc_dai_link *dai_link; /* predefined links only */
969 int num_links; /* predefined links only */
970
971 struct list_head rtd_list;
972 int num_rtd;
973
974 /* optional codec specific configuration */
975 struct snd_soc_codec_conf *codec_conf;
976 int num_configs;
977
978 /*
979 * optional auxiliary devices such as amplifiers or codecs with DAI
980 * link unused
981 */
982 struct snd_soc_aux_dev *aux_dev;
983 int num_aux_devs;
984 struct list_head aux_comp_list;
985
986 const struct snd_kcontrol_new *controls;
987 int num_controls;
988
989 /*
990 * Card-specific routes and widgets.
991 * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
992 */
993 const struct snd_soc_dapm_widget *dapm_widgets;
994 int num_dapm_widgets;
995 const struct snd_soc_dapm_route *dapm_routes;
996 int num_dapm_routes;
997 const struct snd_soc_dapm_widget *of_dapm_widgets;
998 int num_of_dapm_widgets;
999 const struct snd_soc_dapm_route *of_dapm_routes;
1000 int num_of_dapm_routes;
1001
1002 /* lists of probed devices belonging to this card */
1003 struct list_head component_dev_list;
1004 struct list_head list;
1005
1006 struct list_head widgets;
1007 struct list_head paths;
1008 struct list_head dapm_list;
1009 struct list_head dapm_dirty;
1010
1011 /* attached dynamic objects */
1012 struct list_head dobj_list;
1013
1014 /* Generic DAPM context for the card */
1015 struct snd_soc_dapm_context dapm;
1016 struct snd_soc_dapm_stats dapm_stats;
1017 struct snd_soc_dapm_update *update;
1018
1019 #ifdef CONFIG_DEBUG_FS
1020 struct dentry *debugfs_card_root;
1021 #endif
1022 #ifdef CONFIG_PM_SLEEP
1023 struct work_struct deferred_resume_work;
1024 #endif
1025 u32 pop_time;
1026
1027 /* bit field */
1028 unsigned int instantiated:1;
1029 unsigned int topology_shortname_created:1;
1030 unsigned int fully_routed:1;
1031 unsigned int disable_route_checks:1;
1032 unsigned int probed:1;
1033 unsigned int component_chaining:1;
1034
1035 void *drvdata;
1036
1037 ANDROID_KABI_RESERVE(1);
1038 ANDROID_KABI_RESERVE(2);
1039 ANDROID_KABI_RESERVE(3);
1040 ANDROID_KABI_RESERVE(4);
1041 };
1042 #define for_each_card_prelinks(card, i, link) \
1043 for ((i) = 0; \
1044 ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \
1045 (i)++)
1046 #define for_each_card_pre_auxs(card, i, aux) \
1047 for ((i) = 0; \
1048 ((i) < (card)->num_aux_devs) && ((aux) = &(card)->aux_dev[i]); \
1049 (i)++)
1050
1051 #define for_each_card_rtds(card, rtd) \
1052 list_for_each_entry(rtd, &(card)->rtd_list, list)
1053 #define for_each_card_rtds_safe(card, rtd, _rtd) \
1054 list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list)
1055
1056 #define for_each_card_auxs(card, component) \
1057 list_for_each_entry(component, &card->aux_comp_list, card_aux_list)
1058 #define for_each_card_auxs_safe(card, component, _comp) \
1059 list_for_each_entry_safe(component, _comp, \
1060 &card->aux_comp_list, card_aux_list)
1061
1062 #define for_each_card_components(card, component) \
1063 list_for_each_entry(component, &(card)->component_dev_list, card_list)
1064
1065 #define for_each_card_dapms(card, dapm) \
1066 list_for_each_entry(dapm, &card->dapm_list, list)
1067
1068 #define for_each_card_widgets(card, w)\
1069 list_for_each_entry(w, &card->widgets, list)
1070 #define for_each_card_widgets_safe(card, w, _w) \
1071 list_for_each_entry_safe(w, _w, &card->widgets, list)
1072
1073 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
1074 struct snd_soc_pcm_runtime {
1075 struct device *dev;
1076 struct snd_soc_card *card;
1077 struct snd_soc_dai_link *dai_link;
1078 struct snd_pcm_ops ops;
1079
1080 unsigned int params_select; /* currently selected param for dai link */
1081
1082 /* Dynamic PCM BE runtime data */
1083 struct snd_soc_dpcm_runtime dpcm[SNDRV_PCM_STREAM_LAST + 1];
1084 struct snd_soc_dapm_widget *c2c_widget[SNDRV_PCM_STREAM_LAST + 1];
1085
1086 long pmdown_time;
1087
1088 /* runtime devices */
1089 struct snd_pcm *pcm;
1090 struct snd_compr *compr;
1091
1092 /*
1093 * dais = cpu_dai + codec_dai
1094 * see
1095 * soc_new_pcm_runtime()
1096 * asoc_rtd_to_cpu()
1097 * asoc_rtd_to_codec()
1098 */
1099 struct snd_soc_dai **dais;
1100
1101 struct delayed_work delayed_work;
1102 void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
1103 #ifdef CONFIG_DEBUG_FS
1104 struct dentry *debugfs_dpcm_root;
1105 #endif
1106
1107 unsigned int num; /* 0-based and monotonic increasing */
1108 struct list_head list; /* rtd list of the soc card */
1109
1110 /* function mark */
1111 struct snd_pcm_substream *mark_startup;
1112 struct snd_pcm_substream *mark_hw_params;
1113 struct snd_pcm_substream *mark_trigger;
1114 struct snd_compr_stream *mark_compr_startup;
1115
1116 /* bit field */
1117 unsigned int pop_wait:1;
1118 unsigned int fe_compr:1; /* for Dynamic PCM */
1119
1120 int num_components;
1121
1122 ANDROID_KABI_RESERVE(1);
1123
1124 struct snd_soc_component *components[]; /* CPU/Codec/Platform */
1125 };
1126 /* see soc_new_pcm_runtime() */
1127 #define asoc_rtd_to_cpu(rtd, n) (rtd)->dais[n]
1128 #define asoc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
1129 #define asoc_substream_to_rtd(substream) \
1130 (struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream)
1131
1132 #define for_each_rtd_components(rtd, i, component) \
1133 for ((i) = 0, component = NULL; \
1134 ((i) < rtd->num_components) && ((component) = rtd->components[i]);\
1135 (i)++)
1136 #define for_each_rtd_cpu_dais(rtd, i, dai) \
1137 for ((i) = 0; \
1138 ((i) < rtd->dai_link->num_cpus) && ((dai) = asoc_rtd_to_cpu(rtd, i)); \
1139 (i)++)
1140 #define for_each_rtd_codec_dais(rtd, i, dai) \
1141 for ((i) = 0; \
1142 ((i) < rtd->dai_link->num_codecs) && ((dai) = asoc_rtd_to_codec(rtd, i)); \
1143 (i)++)
1144 #define for_each_rtd_dais(rtd, i, dai) \
1145 for ((i) = 0; \
1146 ((i) < (rtd)->dai_link->num_cpus + (rtd)->dai_link->num_codecs) && \
1147 ((dai) = (rtd)->dais[i]); \
1148 (i)++)
1149
1150 void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
1151
1152 /* mixer control */
1153 struct soc_mixer_control {
1154 int min, max, platform_max;
1155 int reg, rreg;
1156 unsigned int shift, rshift;
1157 unsigned int sign_bit;
1158 unsigned int invert:1;
1159 unsigned int autodisable:1;
1160 #ifdef CONFIG_SND_SOC_TOPOLOGY
1161 struct snd_soc_dobj dobj;
1162 #endif
1163
1164 ANDROID_KABI_RESERVE(1);
1165 };
1166
1167 struct soc_bytes {
1168 int base;
1169 int num_regs;
1170 u32 mask;
1171 };
1172
1173 struct soc_bytes_ext {
1174 int max;
1175 #ifdef CONFIG_SND_SOC_TOPOLOGY
1176 struct snd_soc_dobj dobj;
1177 #endif
1178 /* used for TLV byte control */
1179 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
1180 unsigned int size);
1181 int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes,
1182 unsigned int size);
1183 };
1184
1185 /* multi register control */
1186 struct soc_mreg_control {
1187 long min, max;
1188 unsigned int regbase, regcount, nbits, invert;
1189 };
1190
1191 struct soc_multi_mixer_control {
1192 int min, max, platform_max, count;
1193 unsigned int reg, rreg, shift, rshift, invert;
1194 };
1195
1196 /* enumerated kcontrol */
1197 struct soc_enum {
1198 int reg;
1199 unsigned char shift_l;
1200 unsigned char shift_r;
1201 unsigned int items;
1202 unsigned int mask;
1203 const char * const *texts;
1204 const unsigned int *values;
1205 unsigned int autodisable:1;
1206 #ifdef CONFIG_SND_SOC_TOPOLOGY
1207 struct snd_soc_dobj dobj;
1208 #endif
1209
1210 ANDROID_KABI_RESERVE(1);
1211 };
1212
snd_soc_volsw_is_stereo(struct soc_mixer_control * mc)1213 static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
1214 {
1215 if (mc->reg == mc->rreg && mc->shift == mc->rshift)
1216 return false;
1217 /*
1218 * mc->reg == mc->rreg && mc->shift != mc->rshift, or
1219 * mc->reg != mc->rreg means that the control is
1220 * stereo (bits in one register or in two registers)
1221 */
1222 return true;
1223 }
1224
snd_soc_enum_val_to_item(struct soc_enum * e,unsigned int val)1225 static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
1226 unsigned int val)
1227 {
1228 unsigned int i;
1229
1230 if (!e->values)
1231 return val;
1232
1233 for (i = 0; i < e->items; i++)
1234 if (val == e->values[i])
1235 return i;
1236
1237 return 0;
1238 }
1239
snd_soc_enum_item_to_val(struct soc_enum * e,unsigned int item)1240 static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
1241 unsigned int item)
1242 {
1243 if (!e->values)
1244 return item;
1245
1246 return e->values[item];
1247 }
1248
1249 /**
1250 * snd_soc_kcontrol_component() - Returns the component that registered the
1251 * control
1252 * @kcontrol: The control for which to get the component
1253 *
1254 * Note: This function will work correctly if the control has been registered
1255 * for a component. With snd_soc_add_codec_controls() or via table based
1256 * setup for either a CODEC or component driver. Otherwise the behavior is
1257 * undefined.
1258 */
snd_soc_kcontrol_component(struct snd_kcontrol * kcontrol)1259 static inline struct snd_soc_component *snd_soc_kcontrol_component(
1260 struct snd_kcontrol *kcontrol)
1261 {
1262 return snd_kcontrol_chip(kcontrol);
1263 }
1264
1265 int snd_soc_util_init(void);
1266 void snd_soc_util_exit(void);
1267
1268 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
1269 const char *propname);
1270 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
1271 const char *propname);
1272 int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop);
1273 int snd_soc_of_get_slot_mask(struct device_node *np,
1274 const char *prop_name,
1275 unsigned int *mask);
1276 int snd_soc_of_parse_tdm_slot(struct device_node *np,
1277 unsigned int *tx_mask,
1278 unsigned int *rx_mask,
1279 unsigned int *slots,
1280 unsigned int *slot_width);
1281 void snd_soc_of_parse_node_prefix(struct device_node *np,
1282 struct snd_soc_codec_conf *codec_conf,
1283 struct device_node *of_node,
1284 const char *propname);
1285 static inline
snd_soc_of_parse_audio_prefix(struct snd_soc_card * card,struct snd_soc_codec_conf * codec_conf,struct device_node * of_node,const char * propname)1286 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
1287 struct snd_soc_codec_conf *codec_conf,
1288 struct device_node *of_node,
1289 const char *propname)
1290 {
1291 snd_soc_of_parse_node_prefix(card->dev->of_node,
1292 codec_conf, of_node, propname);
1293 }
1294
1295 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
1296 const char *propname);
1297 int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
1298
1299 unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt);
1300 unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame);
1301
1302 unsigned int snd_soc_daifmt_parse_format(struct device_node *np, const char *prefix);
1303 unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
1304 const char *prefix,
1305 struct device_node **bitclkmaster,
1306 struct device_node **framemaster);
1307 #define snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix) \
1308 snd_soc_daifmt_parse_clock_provider_raw(np, prefix, NULL, NULL)
1309 #define snd_soc_daifmt_parse_clock_provider_as_phandle \
1310 snd_soc_daifmt_parse_clock_provider_raw
1311 #define snd_soc_daifmt_parse_clock_provider_as_flag(np, prefix) \
1312 snd_soc_daifmt_clock_provider_from_bitmap( \
1313 snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
1314
1315 int snd_soc_get_dai_id(struct device_node *ep);
1316 int snd_soc_get_dai_name(const struct of_phandle_args *args,
1317 const char **dai_name);
1318 int snd_soc_of_get_dai_name(struct device_node *of_node,
1319 const char **dai_name);
1320 int snd_soc_of_get_dai_link_codecs(struct device *dev,
1321 struct device_node *of_node,
1322 struct snd_soc_dai_link *dai_link);
1323 void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
1324 int snd_soc_of_get_dai_link_cpus(struct device *dev,
1325 struct device_node *of_node,
1326 struct snd_soc_dai_link *dai_link);
1327 void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
1328
1329 int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
1330 struct snd_soc_dai_link *dai_link);
1331 void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
1332 struct snd_soc_pcm_runtime *rtd);
1333
1334 struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
1335 struct snd_soc_dai_driver *dai_drv,
1336 bool legacy_dai_naming);
1337 struct snd_soc_dai *devm_snd_soc_register_dai(struct device *dev,
1338 struct snd_soc_component *component,
1339 struct snd_soc_dai_driver *dai_drv,
1340 bool legacy_dai_naming);
1341 void snd_soc_unregister_dai(struct snd_soc_dai *dai);
1342
1343 struct snd_soc_dai *snd_soc_find_dai(
1344 const struct snd_soc_dai_link_component *dlc);
1345 struct snd_soc_dai *snd_soc_find_dai_with_mutex(
1346 const struct snd_soc_dai_link_component *dlc);
1347
1348 #include <sound/soc-dai.h>
1349
1350 static inline
snd_soc_fixup_dai_links_platform_name(struct snd_soc_card * card,const char * platform_name)1351 int snd_soc_fixup_dai_links_platform_name(struct snd_soc_card *card,
1352 const char *platform_name)
1353 {
1354 struct snd_soc_dai_link *dai_link;
1355 const char *name;
1356 int i;
1357
1358 if (!platform_name) /* nothing to do */
1359 return 0;
1360
1361 /* set platform name for each dailink */
1362 for_each_card_prelinks(card, i, dai_link) {
1363 /* only single platform is supported for now */
1364 if (dai_link->num_platforms != 1)
1365 return -EINVAL;
1366
1367 if (!dai_link->platforms)
1368 return -EINVAL;
1369
1370 name = devm_kstrdup(card->dev, platform_name, GFP_KERNEL);
1371 if (!name)
1372 return -ENOMEM;
1373
1374 /* only single platform is supported for now */
1375 dai_link->platforms->name = name;
1376 }
1377
1378 return 0;
1379 }
1380
1381 #ifdef CONFIG_DEBUG_FS
1382 extern struct dentry *snd_soc_debugfs_root;
1383 #endif
1384
1385 extern const struct dev_pm_ops snd_soc_pm_ops;
1386
1387 /*
1388 * DAPM helper functions
1389 */
1390 enum snd_soc_dapm_subclass {
1391 SND_SOC_DAPM_CLASS_ROOT = 0,
1392 SND_SOC_DAPM_CLASS_RUNTIME = 1,
1393 };
1394
_snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card * card)1395 static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
1396 {
1397 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
1398 }
1399
_snd_soc_dapm_mutex_lock_c(struct snd_soc_card * card)1400 static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
1401 {
1402 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1403 }
1404
_snd_soc_dapm_mutex_unlock_c(struct snd_soc_card * card)1405 static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
1406 {
1407 mutex_unlock(&card->dapm_mutex);
1408 }
1409
_snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card * card)1410 static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
1411 {
1412 lockdep_assert_held(&card->dapm_mutex);
1413 }
1414
_snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context * dapm)1415 static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
1416 {
1417 _snd_soc_dapm_mutex_lock_root_c(dapm->card);
1418 }
1419
_snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context * dapm)1420 static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
1421 {
1422 _snd_soc_dapm_mutex_lock_c(dapm->card);
1423 }
1424
_snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context * dapm)1425 static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
1426 {
1427 _snd_soc_dapm_mutex_unlock_c(dapm->card);
1428 }
1429
_snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context * dapm)1430 static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
1431 {
1432 _snd_soc_dapm_mutex_assert_held_c(dapm->card);
1433 }
1434
1435 #define snd_soc_dapm_mutex_lock_root(x) _Generic((x), \
1436 struct snd_soc_card * : _snd_soc_dapm_mutex_lock_root_c, \
1437 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
1438 #define snd_soc_dapm_mutex_lock(x) _Generic((x), \
1439 struct snd_soc_card * : _snd_soc_dapm_mutex_lock_c, \
1440 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
1441 #define snd_soc_dapm_mutex_unlock(x) _Generic((x), \
1442 struct snd_soc_card * : _snd_soc_dapm_mutex_unlock_c, \
1443 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
1444 #define snd_soc_dapm_mutex_assert_held(x) _Generic((x), \
1445 struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
1446 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
1447
1448 /*
1449 * PCM helper functions
1450 */
_snd_soc_dpcm_mutex_lock_c(struct snd_soc_card * card)1451 static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
1452 {
1453 mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
1454 }
1455
_snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card * card)1456 static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
1457 {
1458 mutex_unlock(&card->pcm_mutex);
1459 }
1460
_snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card * card)1461 static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
1462 {
1463 lockdep_assert_held(&card->pcm_mutex);
1464 }
1465
_snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime * rtd)1466 static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
1467 {
1468 _snd_soc_dpcm_mutex_lock_c(rtd->card);
1469 }
1470
_snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime * rtd)1471 static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
1472 {
1473 _snd_soc_dpcm_mutex_unlock_c(rtd->card);
1474 }
1475
_snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime * rtd)1476 static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
1477 {
1478 _snd_soc_dpcm_mutex_assert_held_c(rtd->card);
1479 }
1480
1481 #define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
1482 struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
1483 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
1484
1485 #define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
1486 struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
1487 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
1488
1489 #define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
1490 struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
1491 struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
1492
1493 #include <sound/soc-component.h>
1494 #include <sound/soc-card.h>
1495 #include <sound/soc-jack.h>
1496
1497 #endif
1498