]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/sound/soc.h
Merge branch 'linus' into release
[mirror_ubuntu-bionic-kernel.git] / include / sound / soc.h
CommitLineData
808db4a4
RP
1/*
2 * linux/sound/soc.h -- ALSA SoC Layer
3 *
4 * Author: Liam Girdwood
5 * Created: Aug 11th 2005
6 * Copyright: Wolfson Microelectronics. PLC.
7 *
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.
11 */
12
13#ifndef __LINUX_SND_SOC_H
14#define __LINUX_SND_SOC_H
15
16#include <linux/platform_device.h>
17#include <linux/types.h>
4484bb2e 18#include <linux/workqueue.h>
808db4a4
RP
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/control.h>
22#include <sound/ac97_codec.h>
23
808db4a4
RP
24/*
25 * Convenience kcontrol builders
26 */
4eaa9819
JS
27#define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
28 ((unsigned long)&(struct soc_mixer_control) \
762b8df7
MB
29 {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
30 .invert = xinvert})
4eaa9819
JS
31#define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
32 ((unsigned long)&(struct soc_mixer_control) \
33 {.reg = xreg, .max = xmax, .invert = xinvert})
a7a4ac86 34#define SOC_SINGLE(xname, reg, shift, max, invert) \
808db4a4
RP
35{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
36 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
37 .put = snd_soc_put_volsw, \
a7a4ac86
PZ
38 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
39#define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
40{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
41 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
42 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
43 .tlv.p = (tlv_array), \
44 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
45 .put = snd_soc_put_volsw, \
46 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
4eaa9819 47#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
808db4a4
RP
48{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
49 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
50 .put = snd_soc_put_volsw, \
4eaa9819
JS
51 .private_value = (unsigned long)&(struct soc_mixer_control) \
52 {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
53 .max = xmax, .invert = xinvert} }
54#define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
808db4a4
RP
55{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
56 .info = snd_soc_info_volsw_2r, \
57 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
4eaa9819
JS
58 .private_value = (unsigned long)&(struct soc_mixer_control) \
59 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
60 .max = xmax, .invert = xinvert} }
61#define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
a7a4ac86
PZ
62{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
63 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
64 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
65 .tlv.p = (tlv_array), \
66 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
67 .put = snd_soc_put_volsw, \
4eaa9819
JS
68 .private_value = (unsigned long)&(struct soc_mixer_control) \
69 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
70 .max = xmax, .invert = xinvert} }
71#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
a7a4ac86
PZ
72{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
73 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
74 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
75 .tlv.p = (tlv_array), \
76 .info = snd_soc_info_volsw_2r, \
77 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
4eaa9819
JS
78 .private_value = (unsigned long)&(struct soc_mixer_control) \
79 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
80 .max = xmax, .invert = xinvert} }
81#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
e13ac2e9
MB
82{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
83 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
84 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
85 .tlv.p = (tlv_array), \
86 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
87 .put = snd_soc_put_volsw_s8, \
4eaa9819
JS
88 .private_value = (unsigned long)&(struct soc_mixer_control) \
89 {.reg = xreg, .min = xmin, .max = xmax} }
f8ba0b7b 90#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
808db4a4 91{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
f8ba0b7b
JS
92 .max = xmax, .texts = xtexts }
93#define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
94 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
95#define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
96{ .max = xmax, .texts = xtexts }
2e72f8e3
PU
97#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
98{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
99 .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
100#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
101 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
808db4a4
RP
102#define SOC_ENUM(xname, xenum) \
103{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
104 .info = snd_soc_info_enum_double, \
105 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
106 .private_value = (unsigned long)&xenum }
2e72f8e3
PU
107#define SOC_VALUE_ENUM(xname, xenum) \
108{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
109 .info = snd_soc_info_value_enum_double, \
110 .get = snd_soc_get_value_enum_double, \
111 .put = snd_soc_put_value_enum_double, \
112 .private_value = (unsigned long)&xenum }
f8ba0b7b 113#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
808db4a4
RP
114 xhandler_get, xhandler_put) \
115{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1c433fbd 116 .info = snd_soc_info_volsw, \
808db4a4 117 .get = xhandler_get, .put = xhandler_put, \
f8ba0b7b
JS
118 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
119#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
10144c09
MM
120 xhandler_get, xhandler_put, tlv_array) \
121{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
122 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
123 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
124 .tlv.p = (tlv_array), \
125 .info = snd_soc_info_volsw, \
126 .get = xhandler_get, .put = xhandler_put, \
f8ba0b7b 127 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
808db4a4
RP
128#define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
129{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
130 .info = snd_soc_info_bool_ext, \
131 .get = xhandler_get, .put = xhandler_put, \
132 .private_value = xdata }
133#define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
134{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
135 .info = snd_soc_info_enum_ext, \
136 .get = xhandler_get, .put = xhandler_put, \
137 .private_value = (unsigned long)&xenum }
138
0be9898a
MB
139/*
140 * Bias levels
141 *
142 * @ON: Bias is fully on for audio playback and capture operations.
143 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
144 * stream start and stop operations.
145 * @STANDBY: Low power standby state when no playback/capture operations are
146 * in progress. NOTE: The transition time between STANDBY and ON
147 * should be as fast as possible and no longer than 10ms.
148 * @OFF: Power Off. No restrictions on transition times.
149 */
150enum snd_soc_bias_level {
151 SND_SOC_BIAS_ON,
152 SND_SOC_BIAS_PREPARE,
153 SND_SOC_BIAS_STANDBY,
154 SND_SOC_BIAS_OFF,
155};
156
808db4a4
RP
157struct snd_soc_device;
158struct snd_soc_pcm_stream;
159struct snd_soc_ops;
160struct snd_soc_dai_mode;
161struct snd_soc_pcm_runtime;
3c4b266f 162struct snd_soc_dai;
12a48a8c 163struct snd_soc_platform;
808db4a4 164struct snd_soc_codec;
808db4a4
RP
165struct soc_enum;
166struct snd_soc_ac97_ops;
808db4a4
RP
167
168typedef int (*hw_write_t)(void *,const char* ,int);
169typedef int (*hw_read_t)(void *,char* ,int);
170
171extern struct snd_ac97_bus_ops soc_ac97_ops;
172
12a48a8c
MB
173int snd_soc_register_platform(struct snd_soc_platform *platform);
174void snd_soc_unregister_platform(struct snd_soc_platform *platform);
0d0cf00a
MB
175int snd_soc_register_codec(struct snd_soc_codec *codec);
176void snd_soc_unregister_codec(struct snd_soc_codec *codec);
12a48a8c 177
808db4a4
RP
178/* pcm <-> DAI connect */
179void snd_soc_free_pcms(struct snd_soc_device *socdev);
180int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
968a6025 181int snd_soc_init_card(struct snd_soc_device *socdev);
808db4a4
RP
182
183/* set runtime hw params */
184int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
185 const struct snd_pcm_hardware *hw);
808db4a4
RP
186
187/* codec IO */
188#define snd_soc_read(codec, reg) codec->read(codec, reg)
189#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
190
191/* codec register bit access */
192int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
193 unsigned short mask, unsigned short value);
194int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
195 unsigned short mask, unsigned short value);
196
197int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
198 struct snd_ac97_bus_ops *ops, int num);
199void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
200
201/*
202 *Controls
203 */
204struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
205 void *data, char *long_name);
206int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_info *uinfo);
208int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
209 struct snd_ctl_elem_info *uinfo);
210int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_value *ucontrol);
212int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol);
2e72f8e3
PU
214int snd_soc_info_value_enum_double(struct snd_kcontrol *kcontrol,
215 struct snd_ctl_elem_info *uinfo);
216int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
217 struct snd_ctl_elem_value *ucontrol);
218int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_value *ucontrol);
808db4a4
RP
220int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
221 struct snd_ctl_elem_info *uinfo);
222int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
223 struct snd_ctl_elem_info *uinfo);
392abe9c 224#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
808db4a4
RP
225int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol);
227int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol);
229int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_info *uinfo);
231int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol);
233int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_value *ucontrol);
e13ac2e9
MB
235int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_info *uinfo);
237int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
238 struct snd_ctl_elem_value *ucontrol);
239int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
240 struct snd_ctl_elem_value *ucontrol);
808db4a4
RP
241
242/* SoC PCM stream information */
243struct snd_soc_pcm_stream {
244 char *stream_name;
1c433fbd
GG
245 u64 formats; /* SNDRV_PCM_FMTBIT_* */
246 unsigned int rates; /* SNDRV_PCM_RATE_* */
808db4a4
RP
247 unsigned int rate_min; /* min rate */
248 unsigned int rate_max; /* max rate */
249 unsigned int channels_min; /* min channels */
250 unsigned int channels_max; /* max channels */
251 unsigned int active:1; /* stream is in use */
252};
253
254/* SoC audio ops */
255struct snd_soc_ops {
256 int (*startup)(struct snd_pcm_substream *);
257 void (*shutdown)(struct snd_pcm_substream *);
258 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
259 int (*hw_free)(struct snd_pcm_substream *);
260 int (*prepare)(struct snd_pcm_substream *);
261 int (*trigger)(struct snd_pcm_substream *, int);
262};
263
808db4a4
RP
264/* SoC Audio Codec */
265struct snd_soc_codec {
266 char *name;
267 struct module *owner;
268 struct mutex mutex;
0d0cf00a
MB
269 struct device *dev;
270
271 struct list_head list;
808db4a4
RP
272
273 /* callbacks */
0be9898a
MB
274 int (*set_bias_level)(struct snd_soc_codec *,
275 enum snd_soc_bias_level level);
808db4a4
RP
276
277 /* runtime */
278 struct snd_card *card;
279 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
280 unsigned int active;
281 unsigned int pcm_devs;
282 void *private_data;
283
284 /* codec IO */
285 void *control_data; /* codec control (i2c/3wire) data */
286 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
287 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
58cd33c0
MB
288 int (*display_register)(struct snd_soc_codec *, char *,
289 size_t, unsigned int);
808db4a4
RP
290 hw_write_t hw_write;
291 hw_read_t hw_read;
292 void *reg_cache;
293 short reg_cache_size;
294 short reg_cache_step;
295
296 /* dapm */
12ef193d 297 u32 pop_time;
808db4a4
RP
298 struct list_head dapm_widgets;
299 struct list_head dapm_paths;
0be9898a
MB
300 enum snd_soc_bias_level bias_level;
301 enum snd_soc_bias_level suspend_bias_level;
1321b160 302 struct delayed_work delayed_work;
808db4a4
RP
303
304 /* codec DAI's */
3c4b266f 305 struct snd_soc_dai *dai;
808db4a4 306 unsigned int num_dai;
384c89e2
MB
307
308#ifdef CONFIG_DEBUG_FS
309 struct dentry *debugfs_reg;
310 struct dentry *debugfs_pop_time;
311#endif
808db4a4
RP
312};
313
314/* codec device */
315struct snd_soc_codec_device {
316 int (*probe)(struct platform_device *pdev);
317 int (*remove)(struct platform_device *pdev);
318 int (*suspend)(struct platform_device *pdev, pm_message_t state);
319 int (*resume)(struct platform_device *pdev);
320};
321
322/* SoC platform interface */
323struct snd_soc_platform {
324 char *name;
12a48a8c 325 struct list_head list;
808db4a4
RP
326
327 int (*probe)(struct platform_device *pdev);
328 int (*remove)(struct platform_device *pdev);
07c84d04
MB
329 int (*suspend)(struct snd_soc_dai *dai);
330 int (*resume)(struct snd_soc_dai *dai);
808db4a4
RP
331
332 /* pcm creation and destruction */
3c4b266f 333 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
808db4a4
RP
334 struct snd_pcm *);
335 void (*pcm_free)(struct snd_pcm *);
336
337 /* platform stream ops */
338 struct snd_pcm_ops *pcm_ops;
339};
340
341/* SoC machine DAI configuration, glues a codec and cpu DAI together */
342struct snd_soc_dai_link {
343 char *name; /* Codec name */
344 char *stream_name; /* Stream name */
345
346 /* DAI */
3c4b266f
LG
347 struct snd_soc_dai *codec_dai;
348 struct snd_soc_dai *cpu_dai;
1c433fbd
GG
349
350 /* machine stream operations */
351 struct snd_soc_ops *ops;
808db4a4
RP
352
353 /* codec/machine specific init - e.g. add machine controls */
354 int (*init)(struct snd_soc_codec *codec);
4ccab3e7
LG
355
356 /* DAI pcm */
357 struct snd_pcm *pcm;
808db4a4
RP
358};
359
87506549
MB
360/* SoC card */
361struct snd_soc_card {
808db4a4 362 char *name;
c5af3a2e
MB
363 struct device *dev;
364
365 struct list_head list;
366
367 int instantiated;
808db4a4
RP
368
369 int (*probe)(struct platform_device *pdev);
370 int (*remove)(struct platform_device *pdev);
371
372 /* the pre and post PM functions are used to do any PM work before and
373 * after the codec and DAI's do any PM work. */
374 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
375 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
376 int (*resume_pre)(struct platform_device *pdev);
377 int (*resume_post)(struct platform_device *pdev);
378
0b4d221b 379 /* callbacks */
87506549 380 int (*set_bias_level)(struct snd_soc_card *,
0be9898a 381 enum snd_soc_bias_level level);
0b4d221b 382
808db4a4
RP
383 /* CPU <--> Codec DAI links */
384 struct snd_soc_dai_link *dai_link;
385 int num_links;
6308419a
MB
386
387 struct snd_soc_device *socdev;
388
87689d56 389 struct snd_soc_platform *platform;
6308419a
MB
390 struct delayed_work delayed_work;
391 struct work_struct deferred_resume_work;
808db4a4
RP
392};
393
394/* SoC Device - the audio subsystem */
395struct snd_soc_device {
396 struct device *dev;
87506549 397 struct snd_soc_card *card;
808db4a4
RP
398 struct snd_soc_codec *codec;
399 struct snd_soc_codec_device *codec_dev;
400 void *codec_data;
401};
402
403/* runtime channel data */
404struct snd_soc_pcm_runtime {
1c433fbd 405 struct snd_soc_dai_link *dai;
808db4a4
RP
406 struct snd_soc_device *socdev;
407};
408
4eaa9819
JS
409/* mixer control */
410struct soc_mixer_control {
411 int min, max;
815ecf8d 412 unsigned int reg, rreg, shift, rshift, invert;
4eaa9819
JS
413};
414
808db4a4
RP
415/* enumerated kcontrol */
416struct soc_enum {
417 unsigned short reg;
418 unsigned short reg2;
419 unsigned char shift_l;
420 unsigned char shift_r;
f8ba0b7b 421 unsigned int max;
808db4a4
RP
422 const char **texts;
423 void *dapm;
424};
425
2e72f8e3
PU
426/* semi enumerated kcontrol */
427struct soc_value_enum {
428 unsigned short reg;
429 unsigned short reg2;
430 unsigned char shift_l;
431 unsigned char shift_r;
432 unsigned int max;
433 unsigned int mask;
434 const char **texts;
435 const unsigned int *values;
436 void *dapm;
437};
438
a47cbe72
MB
439#include <sound/soc-dai.h>
440
808db4a4 441#endif