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