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