2 * linux/sound/soc.h -- ALSA SoC Layer
4 * Author: Liam Girdwood
5 * Created: Aug 11th 2005
6 * Copyright: Wolfson Microelectronics. PLC.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #ifndef __LINUX_SND_SOC_H
14 #define __LINUX_SND_SOC_H
17 #include <linux/platform_device.h>
18 #include <linux/types.h>
19 #include <linux/notifier.h>
20 #include <linux/workqueue.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/regmap.h>
24 #include <linux/log2.h>
25 #include <linux/async.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/compress_driver.h>
29 #include <sound/control.h>
30 #include <sound/ac97_codec.h>
31 #include <sound/soc-topology.h>
34 * Convenience kcontrol builders
36 #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \
37 ((unsigned long)&(struct soc_mixer_control) \
38 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
39 .rshift = shift_right, .max = xmax, .platform_max = xmax, \
40 .invert = xinvert, .autodisable = xautodisable})
41 #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \
42 ((unsigned long)&(struct soc_mixer_control) \
43 {.reg = xreg, .rreg = xreg, .shift = shift_left, \
44 .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \
45 .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable})
46 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \
47 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable)
48 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
49 ((unsigned long)&(struct soc_mixer_control) \
50 {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
51 #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
52 ((unsigned long)&(struct soc_mixer_control) \
53 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
54 .max = xmax, .platform_max = xmax, .invert = xinvert})
55 #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
56 ((unsigned long)&(struct soc_mixer_control) \
57 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
58 .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \
60 #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
61 ((unsigned long)&(struct soc_mixer_control) \
62 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
63 .min = xmin, .max = xmax, .platform_max = xmax, .invert = xinvert})
64 #define SOC_SINGLE(xname, reg, shift, max, invert) \
65 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
66 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
67 .put = snd_soc_put_volsw, \
68 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
69 #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \
70 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
71 .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \
72 .put = snd_soc_put_volsw_range, \
73 .private_value = (unsigned long)&(struct soc_mixer_control) \
74 {.reg = xreg, .rreg = xreg, .shift = xshift, \
75 .rshift = xshift, .min = xmin, .max = xmax, \
76 .platform_max = xmax, .invert = xinvert} }
77 #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
78 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
79 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
80 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
81 .tlv.p = (tlv_array), \
82 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
83 .put = snd_soc_put_volsw, \
84 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
85 #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \
86 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
87 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
88 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
89 .tlv.p = (tlv_array),\
90 .info = snd_soc_info_volsw_sx, \
91 .get = snd_soc_get_volsw_sx,\
92 .put = snd_soc_put_volsw_sx, \
93 .private_value = (unsigned long)&(struct soc_mixer_control) \
94 {.reg = xreg, .rreg = xreg, \
95 .shift = xshift, .rshift = xshift, \
96 .max = xmax, .min = xmin} }
97 #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \
98 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
99 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
100 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
101 .tlv.p = (tlv_array), \
102 .info = snd_soc_info_volsw_range, \
103 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
104 .private_value = (unsigned long)&(struct soc_mixer_control) \
105 {.reg = xreg, .rreg = xreg, .shift = xshift, \
106 .rshift = xshift, .min = xmin, .max = xmax, \
107 .platform_max = xmax, .invert = xinvert} }
108 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
109 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
110 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
111 .put = snd_soc_put_volsw, \
112 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
114 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
115 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
116 .info = snd_soc_info_volsw, \
117 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
118 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
120 #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \
122 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
123 .info = snd_soc_info_volsw_range, \
124 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
125 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
126 xshift, xmin, xmax, xinvert) }
127 #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
128 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
129 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
130 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
131 .tlv.p = (tlv_array), \
132 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
133 .put = snd_soc_put_volsw, \
134 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
136 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
137 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
138 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
139 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
140 .tlv.p = (tlv_array), \
141 .info = snd_soc_info_volsw, \
142 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
143 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
145 #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \
146 xmax, xinvert, tlv_array) \
147 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
148 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
149 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
150 .tlv.p = (tlv_array), \
151 .info = snd_soc_info_volsw_range, \
152 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \
153 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \
154 xshift, xmin, xmax, xinvert) }
155 #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \
156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
157 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
158 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
159 .tlv.p = (tlv_array), \
160 .info = snd_soc_info_volsw_sx, \
161 .get = snd_soc_get_volsw_sx, \
162 .put = snd_soc_put_volsw_sx, \
163 .private_value = (unsigned long)&(struct soc_mixer_control) \
164 {.reg = xreg, .rreg = xrreg, \
165 .shift = xshift, .rshift = xshift, \
166 .max = xmax, .min = xmin} }
167 #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
168 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
169 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
170 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
171 .tlv.p = (tlv_array), \
172 .info = snd_soc_info_volsw, \
173 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
174 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
175 xmin, xmax, xsign_bit, xinvert) }
176 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
177 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
178 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
179 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
180 .tlv.p = (tlv_array), \
181 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
182 .put = snd_soc_put_volsw, \
183 .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) }
184 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
185 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
186 .items = xitems, .texts = xtexts, \
187 .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
188 #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
189 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
190 #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
191 { .items = xitems, .texts = xtexts }
192 #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
193 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
194 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
195 #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
196 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
197 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
198 { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
199 .mask = xmask, .items = xitems, .texts = xtexts, \
200 .values = xvalues, .autodisable = 1}
201 #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
202 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
203 #define SOC_ENUM(xname, xenum) \
204 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
205 .info = snd_soc_info_enum_double, \
206 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
207 .private_value = (unsigned long)&xenum }
208 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
209 xhandler_get, xhandler_put) \
210 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
211 .info = snd_soc_info_volsw, \
212 .get = xhandler_get, .put = xhandler_put, \
213 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
214 #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
215 xhandler_get, xhandler_put) \
216 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
217 .info = snd_soc_info_volsw, \
218 .get = xhandler_get, .put = xhandler_put, \
220 SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) }
221 #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\
222 xhandler_get, xhandler_put) \
223 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
224 .info = snd_soc_info_volsw, \
225 .get = xhandler_get, .put = xhandler_put, \
226 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
228 #define SOC_SINGLE_MULTI_EXT(xname, xreg, xshift, xmax, xinvert, xcount,\
229 xhandler_get, xhandler_put) \
230 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
231 .info = snd_soc_info_multi_ext, \
232 .get = xhandler_get, .put = xhandler_put, \
233 .private_value = (unsigned long)&(struct soc_multi_mixer_control) \
234 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
235 .count = xcount, .platform_max = xmax, .invert = xinvert} }
236 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
237 xhandler_get, xhandler_put, tlv_array) \
238 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
239 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
240 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
241 .tlv.p = (tlv_array), \
242 .info = snd_soc_info_volsw, \
243 .get = xhandler_get, .put = xhandler_put, \
244 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) }
245 #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \
246 xhandler_get, xhandler_put, tlv_array) \
247 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
248 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
249 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
250 .tlv.p = (tlv_array), \
251 .info = snd_soc_info_volsw_range, \
252 .get = xhandler_get, .put = xhandler_put, \
253 .private_value = (unsigned long)&(struct soc_mixer_control) \
254 {.reg = xreg, .rreg = xreg, .shift = xshift, \
255 .rshift = xshift, .min = xmin, .max = xmax, \
256 .platform_max = xmax, .invert = xinvert} }
257 #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
258 xhandler_get, xhandler_put, tlv_array) \
259 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
260 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
261 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
262 .tlv.p = (tlv_array), \
263 .info = snd_soc_info_volsw, \
264 .get = xhandler_get, .put = xhandler_put, \
265 .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
267 #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
268 xhandler_get, xhandler_put, tlv_array) \
269 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
270 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
271 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
272 .tlv.p = (tlv_array), \
273 .info = snd_soc_info_volsw, \
274 .get = xhandler_get, .put = xhandler_put, \
275 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
277 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
278 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
279 .info = snd_soc_info_bool_ext, \
280 .get = xhandler_get, .put = xhandler_put, \
281 .private_value = xdata }
282 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
283 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
284 .info = snd_soc_info_enum_double, \
285 .get = xhandler_get, .put = xhandler_put, \
286 .private_value = (unsigned long)&xenum }
287 #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
288 SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
290 #define SND_SOC_BYTES(xname, xbase, xregs) \
291 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
292 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
293 .put = snd_soc_bytes_put, .private_value = \
294 ((unsigned long)&(struct soc_bytes) \
295 {.base = xbase, .num_regs = xregs }) }
297 #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \
298 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
299 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
300 .put = snd_soc_bytes_put, .private_value = \
301 ((unsigned long)&(struct soc_bytes) \
302 {.base = xbase, .num_regs = xregs, \
305 #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \
306 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
307 .info = snd_soc_bytes_info_ext, \
308 .get = xhandler_get, .put = xhandler_put, \
309 .private_value = (unsigned long)&(struct soc_bytes_ext) \
311 #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \
312 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
313 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \
314 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
315 .tlv.c = (snd_soc_bytes_tlv_callback), \
316 .info = snd_soc_bytes_info_ext, \
317 .private_value = (unsigned long)&(struct soc_bytes_ext) \
318 {.max = xcount, .get = xhandler_get, .put = xhandler_put, } }
319 #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \
320 xmin, xmax, xinvert) \
321 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
322 .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \
323 .put = snd_soc_put_xr_sx, \
324 .private_value = (unsigned long)&(struct soc_mreg_control) \
325 {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \
326 .invert = xinvert, .min = xmin, .max = xmax} }
328 #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \
329 SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \
330 snd_soc_get_strobe, snd_soc_put_strobe)
333 * Simplified versions of above macros, declaring a struct and calculating
334 * ARRAY_SIZE internally
336 #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
337 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
338 ARRAY_SIZE(xtexts), xtexts)
339 #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
340 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
341 #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
342 const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
343 #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
344 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
345 ARRAY_SIZE(xtexts), xtexts, xvalues)
346 #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
347 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
349 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
350 const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
351 xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
353 #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
354 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
357 * Component probe and remove ordering levels for components with runtime
360 #define SND_SOC_COMP_ORDER_FIRST -2
361 #define SND_SOC_COMP_ORDER_EARLY -1
362 #define SND_SOC_COMP_ORDER_NORMAL 0
363 #define SND_SOC_COMP_ORDER_LATE 1
364 #define SND_SOC_COMP_ORDER_LAST 2
366 /* DAI Link Host Mode Support */
367 #define SND_SOC_DAI_LINK_NO_HOST 0x1
368 #define SND_SOC_DAI_LINK_OPT_HOST 0x2
373 * @ON: Bias is fully on for audio playback and capture operations.
374 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
375 * stream start and stop operations.
376 * @STANDBY: Low power standby state when no playback/capture operations are
377 * in progress. NOTE: The transition time between STANDBY and ON
378 * should be as fast as possible and no longer than 10ms.
379 * @OFF: Power Off. No restrictions on transition times.
381 enum snd_soc_bias_level {
382 SND_SOC_BIAS_OFF = 0,
383 SND_SOC_BIAS_STANDBY = 1,
384 SND_SOC_BIAS_PREPARE = 2,
391 struct snd_soc_pcm_stream;
393 struct snd_soc_pcm_runtime;
395 struct snd_soc_dai_driver;
396 struct snd_soc_platform;
397 struct snd_soc_dai_link;
398 struct snd_soc_platform_driver;
399 struct snd_soc_codec;
400 struct snd_soc_codec_driver;
401 struct snd_soc_component;
402 struct snd_soc_component_driver;
405 struct snd_soc_jack_zone;
406 struct snd_soc_jack_pin;
407 #include <sound/soc-dapm.h>
408 #include <sound/soc-dpcm.h>
410 struct snd_soc_jack_gpio;
412 typedef int (*hw_write_t)(void *,const char* ,int);
414 enum snd_soc_pcm_subclass {
415 SND_SOC_PCM_CLASS_PCM = 0,
416 SND_SOC_PCM_CLASS_BE = 1,
419 enum snd_soc_card_subclass {
420 SND_SOC_CARD_CLASS_INIT = 0,
421 SND_SOC_CARD_CLASS_RUNTIME = 1,
424 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
425 int source, unsigned int freq, int dir);
426 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
427 unsigned int freq_in, unsigned int freq_out);
429 int snd_soc_register_card(struct snd_soc_card *card);
430 int snd_soc_unregister_card(struct snd_soc_card *card);
431 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
432 #ifdef CONFIG_PM_SLEEP
433 int snd_soc_suspend(struct device *dev);
434 int snd_soc_resume(struct device *dev);
436 static inline int snd_soc_suspend(struct device *dev)
441 static inline int snd_soc_resume(struct device *dev)
446 int snd_soc_poweroff(struct device *dev);
447 int snd_soc_register_platform(struct device *dev,
448 const struct snd_soc_platform_driver *platform_drv);
449 int devm_snd_soc_register_platform(struct device *dev,
450 const struct snd_soc_platform_driver *platform_drv);
451 void snd_soc_unregister_platform(struct device *dev);
452 int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
453 const struct snd_soc_platform_driver *platform_drv);
454 void snd_soc_remove_platform(struct snd_soc_platform *platform);
455 struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev);
456 int snd_soc_register_codec(struct device *dev,
457 const struct snd_soc_codec_driver *codec_drv,
458 struct snd_soc_dai_driver *dai_drv, int num_dai);
459 void snd_soc_unregister_codec(struct device *dev);
460 int snd_soc_register_component(struct device *dev,
461 const struct snd_soc_component_driver *cmpnt_drv,
462 struct snd_soc_dai_driver *dai_drv, int num_dai);
463 int devm_snd_soc_register_component(struct device *dev,
464 const struct snd_soc_component_driver *cmpnt_drv,
465 struct snd_soc_dai_driver *dai_drv, int num_dai);
466 void snd_soc_unregister_component(struct device *dev);
467 int snd_soc_cache_init(struct snd_soc_codec *codec);
468 int snd_soc_cache_exit(struct snd_soc_codec *codec);
470 int snd_soc_platform_read(struct snd_soc_platform *platform,
472 int snd_soc_platform_write(struct snd_soc_platform *platform,
473 unsigned int reg, unsigned int val);
474 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
475 #ifdef CONFIG_SND_SOC_COMPRESS
476 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
479 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
480 const char *dai_link, int stream);
481 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
482 const char *dai_link);
484 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
485 void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
486 void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
488 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
489 unsigned int dai_fmt);
491 /* Utility functions to get clock rates from various things */
492 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
493 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
494 int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
495 int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
497 /* set runtime hw params */
498 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
499 const struct snd_pcm_hardware *hw);
501 int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
502 int cmd, struct snd_soc_platform *platform);
504 int soc_dai_hw_params(struct snd_pcm_substream *substream,
505 struct snd_pcm_hw_params *params,
506 struct snd_soc_dai *dai);
509 int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
510 struct snd_soc_jack *jack, struct snd_soc_jack_pin *pins,
511 unsigned int num_pins);
513 void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
514 int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
515 struct snd_soc_jack_pin *pins);
516 void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
517 struct notifier_block *nb);
518 void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
519 struct notifier_block *nb);
520 int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
521 struct snd_soc_jack_zone *zones);
522 int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
523 #ifdef CONFIG_GPIOLIB
524 int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
525 struct snd_soc_jack_gpio *gpios);
526 int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
527 struct snd_soc_jack *jack,
528 int count, struct snd_soc_jack_gpio *gpios);
529 void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
530 struct snd_soc_jack_gpio *gpios);
532 static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
533 struct snd_soc_jack_gpio *gpios)
538 static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
539 struct snd_soc_jack *jack,
541 struct snd_soc_jack_gpio *gpios)
546 static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
547 struct snd_soc_jack_gpio *gpios)
552 /* codec register bit access */
553 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned int reg,
554 unsigned int mask, unsigned int value);
555 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
556 unsigned int reg, unsigned int mask,
558 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg,
559 unsigned int mask, unsigned int value);
561 void snd_soc_card_change_online_state(struct snd_soc_card *soc_card,
563 #ifdef CONFIG_SND_SOC_AC97_BUS
564 struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec);
565 struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
566 unsigned int id, unsigned int id_mask);
567 void snd_soc_free_ac97_codec(struct snd_ac97 *ac97);
568 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
569 int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
570 struct platform_device *pdev);
572 extern struct snd_ac97_bus_ops *soc_ac97_ops;
574 static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
575 struct platform_device *pdev)
580 static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
589 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
590 void *data, const char *long_name,
592 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
594 int snd_soc_add_component_controls(struct snd_soc_component *component,
595 const struct snd_kcontrol_new *controls, unsigned int num_controls);
596 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
597 const struct snd_kcontrol_new *controls, unsigned int num_controls);
598 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
599 const struct snd_kcontrol_new *controls, unsigned int num_controls);
600 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
601 const struct snd_kcontrol_new *controls, int num_controls);
602 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
603 const struct snd_kcontrol_new *controls, int num_controls);
604 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
605 struct snd_ctl_elem_info *uinfo);
606 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol);
608 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_value *ucontrol);
610 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_info *uinfo);
612 int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_info *uinfo);
614 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
615 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_value *ucontrol);
617 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
618 struct snd_ctl_elem_value *ucontrol);
619 #define snd_soc_get_volsw_2r snd_soc_get_volsw
620 #define snd_soc_put_volsw_2r snd_soc_put_volsw
621 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol);
623 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol);
625 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_info *uinfo);
627 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
628 struct snd_ctl_elem_value *ucontrol);
629 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_value *ucontrol);
631 int snd_soc_limit_volume(struct snd_soc_card *card,
632 const char *name, int max);
633 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_info *uinfo);
635 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_value *ucontrol);
637 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol);
639 int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_info *ucontrol);
641 int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
642 unsigned int size, unsigned int __user *tlv);
643 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_info *uinfo);
645 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol);
647 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol);
649 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol);
651 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol);
653 int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_info *uinfo);
657 * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
659 * @pin: name of the pin to update
660 * @mask: bits to check for in reported jack status
661 * @invert: if non-zero then pin is enabled when status is not reported
662 * @list: internal list entry
664 struct snd_soc_jack_pin {
665 struct list_head list;
672 * struct snd_soc_jack_zone - Describes voltage zones of jack detection
674 * @min_mv: start voltage in mv
675 * @max_mv: end voltage in mv
676 * @jack_type: type of jack that is expected for this voltage
677 * @debounce_time: debounce_time for jack, codec driver should wait for this
678 * duration before reading the adc for voltages
679 * @list: internal list entry
681 struct snd_soc_jack_zone {
684 unsigned int jack_type;
685 unsigned int debounce_time;
686 struct list_head list;
690 * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
692 * @gpio: legacy gpio number
693 * @idx: gpio descriptor index within the function of the GPIO
695 * @gpiod_dev: GPIO consumer device
696 * @name: gpio name. Also as connection ID for the GPIO consumer
697 * device function name lookup
698 * @report: value to report when jack detected
699 * @invert: report presence in low state
700 * @debounce_time: debounce time in ms
701 * @wake: enable as wake source
702 * @jack_status_check: callback function which overrides the detection
703 * to provide more complex checks (eg, reading an
706 struct snd_soc_jack_gpio {
709 struct device *gpiod_dev;
717 struct snd_soc_jack *jack;
718 struct delayed_work work;
719 struct gpio_desc *desc;
723 int (*jack_status_check)(void *data);
726 struct snd_soc_jack {
728 struct snd_jack *jack;
729 struct snd_soc_card *card;
730 struct list_head pins;
732 struct blocking_notifier_head notifier;
733 struct list_head jack_zones;
736 /* SoC PCM stream information */
737 struct snd_soc_pcm_stream {
738 const char *stream_name;
739 u64 formats; /* SNDRV_PCM_FMTBIT_* */
740 unsigned int rates; /* SNDRV_PCM_RATE_* */
741 unsigned int rate_min; /* min rate */
742 unsigned int rate_max; /* max rate */
743 unsigned int channels_min; /* min channels */
744 unsigned int channels_max; /* max channels */
745 unsigned int sig_bits; /* number of bits of content */
746 const char *aif_name; /* DAPM AIF widget name */
751 int (*startup)(struct snd_pcm_substream *);
752 void (*shutdown)(struct snd_pcm_substream *);
753 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
754 int (*hw_free)(struct snd_pcm_substream *);
755 int (*prepare)(struct snd_pcm_substream *);
756 int (*trigger)(struct snd_pcm_substream *, int);
759 struct snd_soc_compr_ops {
760 int (*startup)(struct snd_compr_stream *);
761 void (*shutdown)(struct snd_compr_stream *);
762 int (*set_params)(struct snd_compr_stream *);
763 int (*trigger)(struct snd_compr_stream *);
766 /* component interface */
767 struct snd_soc_component_driver {
770 /* Default control and setup, added after probe() is run */
771 const struct snd_kcontrol_new *controls;
772 unsigned int num_controls;
773 const struct snd_soc_dapm_widget *dapm_widgets;
774 unsigned int num_dapm_widgets;
775 const struct snd_soc_dapm_route *dapm_routes;
776 unsigned int num_dapm_routes;
778 int (*probe)(struct snd_soc_component *);
779 void (*remove)(struct snd_soc_component *);
782 int (*of_xlate_dai_name)(struct snd_soc_component *component,
783 struct of_phandle_args *args,
784 const char **dai_name);
785 void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
787 int (*stream_event)(struct snd_soc_component *, int event);
789 /* probe ordering - for components with runtime dependencies */
794 struct snd_soc_component {
797 const char *name_prefix;
799 struct snd_soc_card *card;
803 unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
804 unsigned int registered_as_component:1;
806 struct list_head list;
808 struct snd_soc_dai_driver *dai_drv;
811 const struct snd_soc_component_driver *driver;
813 struct list_head dai_list;
815 int (*read)(struct snd_soc_component *, unsigned int, unsigned int *);
816 int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
818 struct regmap *regmap;
821 struct mutex io_mutex;
823 /* attached dynamic objects */
824 struct list_head dobj_list;
826 #ifdef CONFIG_DEBUG_FS
827 struct dentry *debugfs_root;
831 * DO NOT use any of the fields below in drivers, they are temporary and
832 * are going to be removed again soon. If you use them in driver code the
833 * driver will be marked as BROKEN when these fields are removed.
836 /* Don't use these, use snd_soc_component_get_dapm() */
837 struct snd_soc_dapm_context dapm;
839 const struct snd_kcontrol_new *controls;
840 unsigned int num_controls;
841 const struct snd_soc_dapm_widget *dapm_widgets;
842 unsigned int num_dapm_widgets;
843 const struct snd_soc_dapm_route *dapm_routes;
844 unsigned int num_dapm_routes;
845 struct snd_soc_codec *codec;
847 int (*probe)(struct snd_soc_component *);
848 void (*remove)(struct snd_soc_component *);
850 #ifdef CONFIG_DEBUG_FS
851 void (*init_debugfs)(struct snd_soc_component *component);
852 const char *debugfs_prefix;
856 /* SoC Audio Codec device */
857 struct snd_soc_codec {
859 const struct snd_soc_codec_driver *driver;
861 struct list_head list;
862 struct list_head card_list;
865 unsigned int cache_bypass:1; /* Suppress access to the cache */
866 unsigned int suspended:1; /* Codec is in suspend PM state */
867 unsigned int cache_init:1; /* codec cache has been initialized */
870 void *control_data; /* codec control (i2c/3wire) data */
875 struct snd_soc_component component;
877 #ifdef CONFIG_DEBUG_FS
878 struct dentry *debugfs_reg;
883 struct snd_soc_codec_driver {
886 int (*probe)(struct snd_soc_codec *);
887 int (*remove)(struct snd_soc_codec *);
888 int (*suspend)(struct snd_soc_codec *);
889 int (*resume)(struct snd_soc_codec *);
890 struct snd_soc_component_driver component_driver;
892 /* Default control and setup, added after probe() is run */
893 const struct snd_kcontrol_new *controls;
895 const struct snd_soc_dapm_widget *dapm_widgets;
896 int num_dapm_widgets;
897 const struct snd_soc_dapm_route *dapm_routes;
900 /* codec wide operations */
901 int (*set_sysclk)(struct snd_soc_codec *codec,
902 int clk_id, int source, unsigned int freq, int dir);
903 int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
904 unsigned int freq_in, unsigned int freq_out);
907 struct regmap *(*get_regmap)(struct device *);
908 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
909 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
910 unsigned int reg_cache_size;
911 short reg_cache_step;
913 const void *reg_cache_default;
915 /* codec bias level */
916 int (*set_bias_level)(struct snd_soc_codec *,
917 enum snd_soc_bias_level level);
919 bool suspend_bias_off;
921 void (*seq_notifier)(struct snd_soc_dapm_context *,
922 enum snd_soc_dapm_type, int);
924 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
927 /* SoC platform interface */
928 struct snd_soc_platform_driver {
930 int (*probe)(struct snd_soc_platform *);
931 int (*remove)(struct snd_soc_platform *);
932 struct snd_soc_component_driver component_driver;
934 /* pcm creation and destruction */
935 int (*pcm_new)(struct snd_soc_pcm_runtime *);
936 void (*pcm_free)(struct snd_pcm *);
939 * For platform caused delay reporting.
942 snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
943 struct snd_soc_dai *);
946 * For platform-caused delay reporting, where the thread blocks waiting
947 * for the delay amount to be determined. Defining this will cause the
948 * ASoC core to skip calling the delay callbacks for all components in
952 snd_pcm_sframes_t (*delay_blk)(struct snd_pcm_substream *,
953 struct snd_soc_dai *);
955 /* platform stream pcm ops */
956 const struct snd_pcm_ops *ops;
958 /* platform stream compress ops */
959 const struct snd_compr_ops *compr_ops;
961 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
964 struct snd_soc_dai_link_component {
966 struct device_node *of_node;
967 const char *dai_name;
970 struct snd_soc_platform {
972 const struct snd_soc_platform_driver *driver;
974 struct list_head list;
976 struct snd_soc_component component;
979 enum snd_soc_async_ops {
980 ASYNC_DPCM_SND_SOC_OPEN = 1 << 0,
981 ASYNC_DPCM_SND_SOC_CLOSE = 1 << 1,
982 ASYNC_DPCM_SND_SOC_PREPARE = 1 << 2,
983 ASYNC_DPCM_SND_SOC_HW_PARAMS = 1 << 3,
984 ASYNC_DPCM_SND_SOC_FREE = 1 << 4,
987 struct snd_soc_dai_link {
988 /* config - must be set by machine driver */
989 const char *name; /* Codec name */
990 const char *stream_name; /* Stream name */
992 * You MAY specify the link's CPU-side device, either by device name,
993 * or by DT/OF node, but not both. If this information is omitted,
994 * the CPU-side DAI is matched using .cpu_dai_name only, which hence
995 * must be globally unique. These fields are currently typically used
996 * only for codec to codec links, or systems using device tree.
998 const char *cpu_name;
999 struct device_node *cpu_of_node;
1001 * You MAY specify the DAI name of the CPU DAI. If this information is
1002 * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
1003 * only, which only works well when that device exposes a single DAI.
1005 const char *cpu_dai_name;
1007 * You MUST specify the link's codec, either by device name, or by
1008 * DT/OF node, but not both.
1010 const char *codec_name;
1011 struct device_node *codec_of_node;
1012 /* You MUST specify the DAI name within the codec */
1013 const char *codec_dai_name;
1015 struct snd_soc_dai_link_component *codecs;
1016 unsigned int num_codecs;
1019 * You MAY specify the link's platform/PCM/DMA driver, either by
1020 * device name, or by DT/OF node, but not both. Some forms of link
1021 * do not need a platform.
1023 const char *platform_name;
1024 struct device_node *platform_of_node;
1025 int be_id; /* optional ID for machine driver BE identification */
1027 const struct snd_soc_pcm_stream *params;
1028 unsigned int num_params;
1030 unsigned int dai_fmt; /* format to set on init */
1032 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
1034 /* codec/machine specific init - e.g. add machine controls */
1035 int (*init)(struct snd_soc_pcm_runtime *rtd);
1037 /* optional hw_params re-writing for BE and FE sync */
1038 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
1039 struct snd_pcm_hw_params *params);
1041 /* machine stream operations */
1042 const struct snd_soc_ops *ops;
1043 const struct snd_soc_compr_ops *compr_ops;
1045 /* For unidirectional dai links */
1049 /* Mark this pcm with non atomic ops */
1052 /* Keep DAI active over suspend */
1053 unsigned int ignore_suspend:1;
1055 /* Symmetry requirements */
1056 unsigned int symmetric_rates:1;
1057 unsigned int symmetric_channels:1;
1058 unsigned int symmetric_samplebits:1;
1060 /* Do not create a PCM for this DAI link (Backend link) */
1061 unsigned int no_pcm:1;
1063 /* This DAI link can route to other DAI links at runtime (Frontend)*/
1064 unsigned int dynamic:1;
1066 /* This DAI can support no host IO (no pcm data is copied to from host) */
1067 unsigned int no_host_mode:2;
1069 /* DPCM capture and Playback support */
1070 unsigned int dpcm_capture:1;
1071 unsigned int dpcm_playback:1;
1073 /* DPCM used FE & BE merged format */
1074 unsigned int dpcm_merged_format:1;
1076 /* pmdown_time is ignored at stop */
1077 unsigned int ignore_pmdown_time:1;
1079 /* this value determines what all ops can be started asynchronously */
1080 enum snd_soc_async_ops async_ops;
1083 struct snd_soc_codec_conf {
1085 * specify device either by device name, or by
1086 * DT/OF node, but not both.
1088 const char *dev_name;
1089 struct device_node *of_node;
1092 * optional map of kcontrol, widget and path name prefixes that are
1093 * associated per device
1095 const char *name_prefix;
1098 struct snd_soc_aux_dev {
1099 const char *name; /* Codec name */
1102 * specify multi-codec either by device name, or by
1103 * DT/OF node, but not both.
1105 const char *codec_name;
1106 struct device_node *codec_of_node;
1108 /* codec/machine specific init - e.g. add machine controls */
1109 int (*init)(struct snd_soc_component *component);
1113 struct snd_soc_card {
1115 const char *long_name;
1116 const char *driver_name;
1118 struct snd_card *snd_card;
1119 struct module *owner;
1122 struct mutex dapm_mutex;
1123 struct mutex dapm_power_mutex;
1127 int (*probe)(struct snd_soc_card *card);
1128 int (*late_probe)(struct snd_soc_card *card);
1129 int (*remove)(struct snd_soc_card *card);
1131 /* the pre and post PM functions are used to do any PM work before and
1132 * after the codec and DAI's do any PM work. */
1133 int (*suspend_pre)(struct snd_soc_card *card);
1134 int (*suspend_post)(struct snd_soc_card *card);
1135 int (*resume_pre)(struct snd_soc_card *card);
1136 int (*resume_post)(struct snd_soc_card *card);
1139 int (*set_bias_level)(struct snd_soc_card *,
1140 struct snd_soc_dapm_context *dapm,
1141 enum snd_soc_bias_level level);
1142 int (*set_bias_level_post)(struct snd_soc_card *,
1143 struct snd_soc_dapm_context *dapm,
1144 enum snd_soc_bias_level level);
1148 /* CPU <--> Codec DAI links */
1149 struct snd_soc_dai_link *dai_link;
1151 struct snd_soc_pcm_runtime *rtd;
1154 /* optional codec specific configuration */
1155 struct snd_soc_codec_conf *codec_conf;
1159 * optional auxiliary devices such as amplifiers or codecs with DAI
1162 struct snd_soc_aux_dev *aux_dev;
1164 struct snd_soc_pcm_runtime *rtd_aux;
1167 const struct snd_kcontrol_new *controls;
1171 * Card-specific routes and widgets.
1172 * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in.
1174 const struct snd_soc_dapm_widget *dapm_widgets;
1175 int num_dapm_widgets;
1176 const struct snd_soc_dapm_route *dapm_routes;
1177 int num_dapm_routes;
1178 const struct snd_soc_dapm_widget *of_dapm_widgets;
1179 int num_of_dapm_widgets;
1180 const struct snd_soc_dapm_route *of_dapm_routes;
1181 int num_of_dapm_routes;
1184 struct work_struct deferred_resume_work;
1186 /* lists of probed devices belonging to this card */
1187 struct list_head codec_dev_list;
1189 struct list_head widgets;
1190 struct list_head paths;
1191 struct list_head dapm_list;
1192 struct list_head dapm_dirty;
1194 /* attached dynamic objects */
1195 struct list_head dobj_list;
1197 /* Generic DAPM context for the card */
1198 struct snd_soc_dapm_context dapm;
1199 struct snd_soc_dapm_stats dapm_stats;
1200 struct snd_soc_dapm_update *update;
1202 #ifdef CONFIG_DEBUG_FS
1203 struct dentry *debugfs_card_root;
1204 struct dentry *debugfs_pop_time;
1211 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
1212 struct snd_soc_pcm_runtime {
1214 struct snd_soc_card *card;
1215 struct snd_soc_dai_link *dai_link;
1216 struct mutex pcm_mutex;
1217 enum snd_soc_pcm_subclass pcm_subclass;
1218 struct snd_pcm_ops ops;
1220 unsigned int dev_registered:1;
1222 /* Dynamic PCM BE runtime data */
1223 struct snd_soc_dpcm_runtime dpcm[2];
1227 unsigned char pop_wait:1;
1229 /* err in case of ops failed */
1231 /* runtime devices */
1232 struct snd_pcm *pcm;
1233 struct snd_compr *compr;
1234 struct snd_soc_codec *codec;
1235 struct snd_soc_platform *platform;
1236 struct snd_soc_dai *codec_dai;
1237 struct snd_soc_dai *cpu_dai;
1238 struct snd_soc_component *component; /* Only valid for AUX dev rtds */
1240 struct snd_soc_dai **codec_dais;
1241 unsigned int num_codecs;
1243 struct delayed_work delayed_work;
1244 #ifdef CONFIG_DEBUG_FS
1245 struct dentry *debugfs_dpcm_root;
1246 struct dentry *debugfs_dpcm_state;
1251 struct soc_mixer_control {
1252 int min, max, platform_max;
1254 unsigned int shift, rshift;
1255 unsigned int sign_bit;
1256 unsigned int invert:1;
1257 unsigned int autodisable:1;
1258 struct snd_soc_dobj dobj;
1267 struct soc_bytes_ext {
1269 struct snd_soc_dobj dobj;
1271 /* used for TLV byte control */
1272 int (*get)(unsigned int __user *bytes, unsigned int size);
1273 int (*put)(const unsigned int __user *bytes, unsigned int size);
1276 /* multi register control */
1277 struct soc_mreg_control {
1279 unsigned int regbase, regcount, nbits, invert;
1282 struct soc_multi_mixer_control {
1283 int min, max, platform_max, count;
1284 unsigned int reg, rreg, shift, rshift, invert;
1287 /* enumerated kcontrol */
1290 unsigned char shift_l;
1291 unsigned char shift_r;
1294 const char * const *texts;
1295 const unsigned int *values;
1296 unsigned int autodisable:1;
1297 struct snd_soc_dobj dobj;
1301 * snd_soc_component_to_codec() - Casts a component to the CODEC it is embedded in
1302 * @component: The component to cast to a CODEC
1304 * This function must only be used on components that are known to be CODECs.
1305 * Otherwise the behavior is undefined.
1307 static inline struct snd_soc_codec *snd_soc_component_to_codec(
1308 struct snd_soc_component *component)
1310 return container_of(component, struct snd_soc_codec, component);
1314 * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
1315 * @component: The component to cast to a platform
1317 * This function must only be used on components that are known to be platforms.
1318 * Otherwise the behavior is undefined.
1320 static inline struct snd_soc_platform *snd_soc_component_to_platform(
1321 struct snd_soc_component *component)
1323 return container_of(component, struct snd_soc_platform, component);
1327 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
1329 * @dapm: The DAPM context to cast to the component
1331 * This function must only be used on DAPM contexts that are known to be part of
1332 * a component (e.g. in a component driver). Otherwise the behavior is
1335 static inline struct snd_soc_component *snd_soc_dapm_to_component(
1336 struct snd_soc_dapm_context *dapm)
1338 return container_of(dapm, struct snd_soc_component, dapm);
1342 * snd_soc_dapm_to_codec() - Casts a DAPM context to the CODEC it is embedded in
1343 * @dapm: The DAPM context to cast to the CODEC
1345 * This function must only be used on DAPM contexts that are known to be part of
1346 * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
1348 static inline struct snd_soc_codec *snd_soc_dapm_to_codec(
1349 struct snd_soc_dapm_context *dapm)
1351 return snd_soc_component_to_codec(snd_soc_dapm_to_component(dapm));
1355 * snd_soc_dapm_to_platform() - Casts a DAPM context to the platform it is
1357 * @dapm: The DAPM context to cast to the platform.
1359 * This function must only be used on DAPM contexts that are known to be part of
1360 * a platform (e.g. in a platform driver). Otherwise the behavior is undefined.
1362 static inline struct snd_soc_platform *snd_soc_dapm_to_platform(
1363 struct snd_soc_dapm_context *dapm)
1365 return snd_soc_component_to_platform(snd_soc_dapm_to_component(dapm));
1369 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
1371 * @component: The component for which to get the DAPM context
1373 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
1374 struct snd_soc_component *component)
1376 return &component->dapm;
1380 * snd_soc_codec_get_dapm() - Returns the DAPM context for the CODEC
1381 * @codec: The CODEC for which to get the DAPM context
1383 * Note: Use this function instead of directly accessing the CODEC's dapm field
1385 static inline struct snd_soc_dapm_context *snd_soc_codec_get_dapm(
1386 struct snd_soc_codec *codec)
1388 return snd_soc_component_get_dapm(&codec->component);
1392 * snd_soc_dapm_init_bias_level() - Initialize CODEC DAPM bias level
1393 * @codec: The CODEC for which to initialize the DAPM bias level
1394 * @level: The DAPM level to initialize to
1396 * Initializes the CODEC DAPM bias level. See snd_soc_dapm_init_bias_level().
1398 static inline void snd_soc_codec_init_bias_level(struct snd_soc_codec *codec,
1399 enum snd_soc_bias_level level)
1401 snd_soc_dapm_init_bias_level(snd_soc_codec_get_dapm(codec), level);
1405 * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level
1406 * @codec: The CODEC for which to get the DAPM bias level
1408 * Returns: The current DAPM bias level of the CODEC.
1410 static inline enum snd_soc_bias_level snd_soc_codec_get_bias_level(
1411 struct snd_soc_codec *codec)
1413 return snd_soc_dapm_get_bias_level(snd_soc_codec_get_dapm(codec));
1417 * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level
1418 * @codec: The CODEC for which to set the level
1419 * @level: The level to set to
1421 * Forces the CODEC bias level to a specific state. See
1422 * snd_soc_dapm_force_bias_level().
1424 static inline int snd_soc_codec_force_bias_level(struct snd_soc_codec *codec,
1425 enum snd_soc_bias_level level)
1427 return snd_soc_dapm_force_bias_level(snd_soc_codec_get_dapm(codec),
1432 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
1433 * @kcontrol: The kcontrol
1435 * This function must only be used on DAPM contexts that are known to be part of
1436 * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined.
1438 static inline struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(
1439 struct snd_kcontrol *kcontrol)
1441 return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol));
1445 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
1446 int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
1450 * snd_soc_cache_sync() - Sync the register cache with the hardware
1451 * @codec: CODEC to sync
1453 * Note: This function will call regcache_sync()
1455 static inline int snd_soc_cache_sync(struct snd_soc_codec *codec)
1457 return regcache_sync(codec->component.regmap);
1461 int snd_soc_component_read(struct snd_soc_component *component,
1462 unsigned int reg, unsigned int *val);
1463 int snd_soc_component_write(struct snd_soc_component *component,
1464 unsigned int reg, unsigned int val);
1465 int snd_soc_component_update_bits(struct snd_soc_component *component,
1466 unsigned int reg, unsigned int mask, unsigned int val);
1467 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
1468 unsigned int reg, unsigned int mask, unsigned int val);
1469 void snd_soc_component_async_complete(struct snd_soc_component *component);
1470 int snd_soc_component_test_bits(struct snd_soc_component *component,
1471 unsigned int reg, unsigned int mask, unsigned int value);
1472 struct snd_soc_component *soc_find_component(
1473 const struct device_node *of_node, const char *name);
1475 #ifdef CONFIG_REGMAP
1477 void snd_soc_component_init_regmap(struct snd_soc_component *component,
1478 struct regmap *regmap);
1479 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
1482 * snd_soc_codec_init_regmap() - Initialize regmap instance for the CODEC
1483 * @codec: The CODEC for which to initialize the regmap instance
1484 * @regmap: The regmap instance that should be used by the CODEC
1486 * This function allows deferred assignment of the regmap instance that is
1487 * associated with the CODEC. Only use this if the regmap instance is not yet
1488 * ready when the CODEC is registered. The function must also be called before
1489 * the first IO attempt of the CODEC.
1491 static inline void snd_soc_codec_init_regmap(struct snd_soc_codec *codec,
1492 struct regmap *regmap)
1494 snd_soc_component_init_regmap(&codec->component, regmap);
1498 * snd_soc_codec_exit_regmap() - De-initialize regmap instance for the CODEC
1499 * @codec: The CODEC for which to de-initialize the regmap instance
1501 * Calls regmap_exit() on the regmap instance associated to the CODEC and
1502 * removes the regmap instance from the CODEC.
1504 * This function should only be used if snd_soc_codec_init_regmap() was used to
1505 * initialize the regmap instance.
1507 static inline void snd_soc_codec_exit_regmap(struct snd_soc_codec *codec)
1509 snd_soc_component_exit_regmap(&codec->component);
1514 /* device driver data */
1516 static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
1519 card->drvdata = data;
1522 static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
1524 return card->drvdata;
1527 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
1530 dev_set_drvdata(c->dev, data);
1533 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
1535 return dev_get_drvdata(c->dev);
1538 static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
1541 snd_soc_component_set_drvdata(&codec->component, data);
1544 static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
1546 return snd_soc_component_get_drvdata(&codec->component);
1549 static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
1552 snd_soc_component_set_drvdata(&platform->component, data);
1555 static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
1557 return snd_soc_component_get_drvdata(&platform->component);
1560 static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
1563 dev_set_drvdata(rtd->dev, data);
1566 static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
1568 return dev_get_drvdata(rtd->dev);
1571 static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
1573 INIT_LIST_HEAD(&card->codec_dev_list);
1574 INIT_LIST_HEAD(&card->widgets);
1575 INIT_LIST_HEAD(&card->paths);
1576 INIT_LIST_HEAD(&card->dapm_list);
1579 static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
1581 if (mc->reg == mc->rreg && mc->shift == mc->rshift)
1584 * mc->reg == mc->rreg && mc->shift != mc->rshift, or
1585 * mc->reg != mc->rreg means that the control is
1586 * stereo (bits in one register or in two registers)
1591 static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
1599 for (i = 0; i < e->items; i++)
1600 if (val == e->values[i])
1606 static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
1612 return e->values[item];
1615 static inline bool snd_soc_component_is_active(
1616 struct snd_soc_component *component)
1618 return component->active != 0;
1621 static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
1623 return snd_soc_component_is_active(&codec->component);
1627 * snd_soc_kcontrol_component() - Returns the component that registered the
1629 * @kcontrol: The control for which to get the component
1631 * Note: This function will work correctly if the control has been registered
1632 * for a component. Either with snd_soc_add_codec_controls() or
1633 * snd_soc_add_platform_controls() or via table based setup for either a
1634 * CODEC, a platform or component driver. Otherwise the behavior is undefined.
1636 static inline struct snd_soc_component *snd_soc_kcontrol_component(
1637 struct snd_kcontrol *kcontrol)
1639 return snd_kcontrol_chip(kcontrol);
1643 * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
1644 * @kcontrol: The control for which to get the CODEC
1646 * Note: This function will only work correctly if the control has been
1647 * registered with snd_soc_add_codec_controls() or via table based setup of
1648 * snd_soc_codec_driver. Otherwise the behavior is undefined.
1650 static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
1651 struct snd_kcontrol *kcontrol)
1653 return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
1657 * snd_soc_kcontrol_platform() - Returns the platform that registered the control
1658 * @kcontrol: The control for which to get the platform
1660 * Note: This function will only work correctly if the control has been
1661 * registered with snd_soc_add_platform_controls() or via table based setup of
1662 * a snd_soc_platform_driver. Otherwise the behavior is undefined.
1664 static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
1665 struct snd_kcontrol *kcontrol)
1667 return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
1670 int snd_soc_util_init(void);
1671 void snd_soc_util_exit(void);
1673 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
1674 const char *propname);
1675 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
1676 const char *propname);
1677 int snd_soc_of_parse_tdm_slot(struct device_node *np,
1678 unsigned int *tx_mask,
1679 unsigned int *rx_mask,
1680 unsigned int *slots,
1681 unsigned int *slot_width);
1682 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
1683 struct snd_soc_codec_conf *codec_conf,
1684 struct device_node *of_node,
1685 const char *propname);
1686 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
1687 const char *propname);
1688 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
1690 struct device_node **bitclkmaster,
1691 struct device_node **framemaster);
1692 int snd_soc_of_get_dai_name(struct device_node *of_node,
1693 const char **dai_name);
1694 int snd_soc_of_get_dai_link_codecs(struct device *dev,
1695 struct device_node *of_node,
1696 struct snd_soc_dai_link *dai_link);
1698 #include <sound/soc-dai.h>
1700 #ifdef CONFIG_DEBUG_FS
1701 extern struct dentry *snd_soc_debugfs_root;
1704 extern const struct dev_pm_ops snd_soc_pm_ops;
1706 /* Helper functions */
1707 static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
1709 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1712 static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
1714 mutex_unlock(&dapm->card->dapm_mutex);