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