ALSA: ASoC: Pass the DAI being configured into CPU DAI probe and remove
[deliverable/linux.git] / include / sound / soc.h
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>
18 #include <linux/workqueue.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/control.h>
22 #include <sound/ac97_codec.h>
23
24 #define SND_SOC_VERSION "0.13.2"
25
26 /*
27 * Convenience kcontrol builders
28 */
29 #define SOC_SINGLE_VALUE(reg, shift, max, invert) ((reg) | ((shift) << 8) |\
30 ((shift) << 12) | ((max) << 16) | ((invert) << 24))
31 #define SOC_SINGLE_VALUE_EXT(reg, max, invert) ((reg) | ((max) << 16) |\
32 ((invert) << 31))
33 #define SOC_SINGLE(xname, reg, shift, max, invert) \
34 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
35 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
36 .put = snd_soc_put_volsw, \
37 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
38 #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
39 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
40 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
41 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
42 .tlv.p = (tlv_array), \
43 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
44 .put = snd_soc_put_volsw, \
45 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
46 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
47 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
48 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
49 .put = snd_soc_put_volsw, \
50 .private_value = (reg) | ((shift_left) << 8) | \
51 ((shift_right) << 12) | ((max) << 16) | ((invert) << 24) }
52 #define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, max, invert) \
53 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
54 .info = snd_soc_info_volsw_2r, \
55 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
56 .private_value = (reg_left) | ((shift) << 8) | \
57 ((max) << 12) | ((invert) << 20) | ((reg_right) << 24) }
58 #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
59 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
60 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
61 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
62 .tlv.p = (tlv_array), \
63 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
64 .put = snd_soc_put_volsw, \
65 .private_value = (reg) | ((shift_left) << 8) | \
66 ((shift_right) << 12) | ((max) << 16) | ((invert) << 24) }
67 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, shift, max, invert, tlv_array) \
68 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
69 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
70 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
71 .tlv.p = (tlv_array), \
72 .info = snd_soc_info_volsw_2r, \
73 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
74 .private_value = (reg_left) | ((shift) << 8) | \
75 ((max) << 12) | ((invert) << 20) | ((reg_right) << 24) }
76 #define SOC_DOUBLE_S8_TLV(xname, reg, min, max, tlv_array) \
77 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
78 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
79 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
80 .tlv.p = (tlv_array), \
81 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
82 .put = snd_soc_put_volsw_s8, \
83 .private_value = (reg) | (((signed char)max) << 16) | \
84 (((signed char)min) << 24) }
85 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
86 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
87 .mask = xmask, .texts = xtexts }
88 #define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
89 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
90 #define SOC_ENUM_SINGLE_EXT(xmask, xtexts) \
91 { .mask = xmask, .texts = xtexts }
92 #define SOC_ENUM(xname, xenum) \
93 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
94 .info = snd_soc_info_enum_double, \
95 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
96 .private_value = (unsigned long)&xenum }
97 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmask, xinvert,\
98 xhandler_get, xhandler_put) \
99 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
100 .info = snd_soc_info_volsw, \
101 .get = xhandler_get, .put = xhandler_put, \
102 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
103 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
104 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
105 .info = snd_soc_info_bool_ext, \
106 .get = xhandler_get, .put = xhandler_put, \
107 .private_value = xdata }
108 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
109 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
110 .info = snd_soc_info_enum_ext, \
111 .get = xhandler_get, .put = xhandler_put, \
112 .private_value = (unsigned long)&xenum }
113
114 /*
115 * Bias levels
116 *
117 * @ON: Bias is fully on for audio playback and capture operations.
118 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
119 * stream start and stop operations.
120 * @STANDBY: Low power standby state when no playback/capture operations are
121 * in progress. NOTE: The transition time between STANDBY and ON
122 * should be as fast as possible and no longer than 10ms.
123 * @OFF: Power Off. No restrictions on transition times.
124 */
125 enum snd_soc_bias_level {
126 SND_SOC_BIAS_ON,
127 SND_SOC_BIAS_PREPARE,
128 SND_SOC_BIAS_STANDBY,
129 SND_SOC_BIAS_OFF,
130 };
131
132 /*
133 * Digital Audio Interface (DAI) types
134 */
135 #define SND_SOC_DAI_AC97 0x1
136 #define SND_SOC_DAI_I2S 0x2
137 #define SND_SOC_DAI_PCM 0x4
138 #define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
139
140 /*
141 * DAI hardware audio formats
142 */
143 #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
144 #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
145 #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
146 #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
147 #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
148 #define SND_SOC_DAIFMT_AC97 5 /* AC97 */
149
150 #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
151 #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
152
153 /*
154 * DAI Gating
155 */
156 #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
157 #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
158
159 /*
160 * DAI Sync
161 * Synchronous LR (Left Right) clocks and Frame signals.
162 */
163 #define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */
164 #define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */
165
166 /*
167 * TDM
168 */
169 #define SND_SOC_DAIFMT_TDM (1 << 6)
170
171 /*
172 * DAI hardware signal inversions
173 */
174 #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bclk + frm */
175 #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
176 #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
177 #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
178
179 /*
180 * DAI hardware clock masters
181 * This is wrt the codec, the inverse is true for the interface
182 * i.e. if the codec is clk and frm master then the interface is
183 * clk and frame slave.
184 */
185 #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
186 #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
187 #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
188 #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
189
190 #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
191 #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
192 #define SND_SOC_DAIFMT_INV_MASK 0x0f00
193 #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
194
195
196 /*
197 * Master Clock Directions
198 */
199 #define SND_SOC_CLOCK_IN 0
200 #define SND_SOC_CLOCK_OUT 1
201
202 /*
203 * AC97 codec ID's bitmask
204 */
205 #define SND_SOC_DAI_AC97_ID0 (1 << 0)
206 #define SND_SOC_DAI_AC97_ID1 (1 << 1)
207 #define SND_SOC_DAI_AC97_ID2 (1 << 2)
208 #define SND_SOC_DAI_AC97_ID3 (1 << 3)
209
210 struct snd_soc_device;
211 struct snd_soc_pcm_stream;
212 struct snd_soc_ops;
213 struct snd_soc_dai_mode;
214 struct snd_soc_pcm_runtime;
215 struct snd_soc_codec_dai;
216 struct snd_soc_cpu_dai;
217 struct snd_soc_codec;
218 struct snd_soc_machine_config;
219 struct soc_enum;
220 struct snd_soc_ac97_ops;
221 struct snd_soc_clock_info;
222
223 typedef int (*hw_write_t)(void *,const char* ,int);
224 typedef int (*hw_read_t)(void *,char* ,int);
225
226 extern struct snd_ac97_bus_ops soc_ac97_ops;
227
228 /* pcm <-> DAI connect */
229 void snd_soc_free_pcms(struct snd_soc_device *socdev);
230 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
231 int snd_soc_register_card(struct snd_soc_device *socdev);
232
233 /* set runtime hw params */
234 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
235 const struct snd_pcm_hardware *hw);
236
237 /* codec IO */
238 #define snd_soc_read(codec, reg) codec->read(codec, reg)
239 #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
240
241 /* codec register bit access */
242 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
243 unsigned short mask, unsigned short value);
244 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
245 unsigned short mask, unsigned short value);
246
247 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
248 struct snd_ac97_bus_ops *ops, int num);
249 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
250
251 /*
252 *Controls
253 */
254 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
255 void *data, char *long_name);
256 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo);
258 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_info *uinfo);
260 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
261 struct snd_ctl_elem_value *ucontrol);
262 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol);
264 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_info *uinfo);
266 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_info *uinfo);
268 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
269 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol);
271 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol);
273 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_info *uinfo);
275 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol);
277 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_value *ucontrol);
279 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo);
281 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
282 struct snd_ctl_elem_value *ucontrol);
283 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
284 struct snd_ctl_elem_value *ucontrol);
285
286 /* SoC PCM stream information */
287 struct snd_soc_pcm_stream {
288 char *stream_name;
289 u64 formats; /* SNDRV_PCM_FMTBIT_* */
290 unsigned int rates; /* SNDRV_PCM_RATE_* */
291 unsigned int rate_min; /* min rate */
292 unsigned int rate_max; /* max rate */
293 unsigned int channels_min; /* min channels */
294 unsigned int channels_max; /* max channels */
295 unsigned int active:1; /* stream is in use */
296 };
297
298 /* SoC audio ops */
299 struct snd_soc_ops {
300 int (*startup)(struct snd_pcm_substream *);
301 void (*shutdown)(struct snd_pcm_substream *);
302 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
303 int (*hw_free)(struct snd_pcm_substream *);
304 int (*prepare)(struct snd_pcm_substream *);
305 int (*trigger)(struct snd_pcm_substream *, int);
306 };
307
308 /* ASoC DAI ops */
309 struct snd_soc_dai_ops {
310 /* DAI clocking configuration */
311 int (*set_sysclk)(struct snd_soc_codec_dai *codec_dai,
312 int clk_id, unsigned int freq, int dir);
313 int (*set_pll)(struct snd_soc_codec_dai *codec_dai,
314 int pll_id, unsigned int freq_in, unsigned int freq_out);
315 int (*set_clkdiv)(struct snd_soc_codec_dai *codec_dai,
316 int div_id, int div);
317
318 /* DAI format configuration */
319 int (*set_fmt)(struct snd_soc_codec_dai *codec_dai,
320 unsigned int fmt);
321 int (*set_tdm_slot)(struct snd_soc_codec_dai *codec_dai,
322 unsigned int mask, int slots);
323 int (*set_tristate)(struct snd_soc_codec_dai *, int tristate);
324
325 /* digital mute */
326 int (*digital_mute)(struct snd_soc_codec_dai *, int mute);
327 };
328
329 /* SoC Codec DAI */
330 struct snd_soc_codec_dai {
331 char *name;
332 int id;
333 unsigned char type;
334
335 /* DAI capabilities */
336 struct snd_soc_pcm_stream playback;
337 struct snd_soc_pcm_stream capture;
338
339 /* DAI runtime info */
340 struct snd_soc_codec *codec;
341 unsigned int active;
342 unsigned char pop_wait:1;
343
344 /* ops */
345 struct snd_soc_ops ops;
346 struct snd_soc_dai_ops dai_ops;
347
348 /* DAI private data */
349 void *private_data;
350 };
351
352 /* SoC CPU DAI */
353 struct snd_soc_cpu_dai {
354
355 /* DAI description */
356 char *name;
357 unsigned int id;
358 unsigned char type;
359
360 /* DAI callbacks */
361 int (*probe)(struct platform_device *pdev,
362 struct snd_soc_cpu_dai *dai);
363 void (*remove)(struct platform_device *pdev,
364 struct snd_soc_cpu_dai *dai);
365 int (*suspend)(struct platform_device *pdev,
366 struct snd_soc_cpu_dai *cpu_dai);
367 int (*resume)(struct platform_device *pdev,
368 struct snd_soc_cpu_dai *cpu_dai);
369
370 /* ops */
371 struct snd_soc_ops ops;
372 struct snd_soc_dai_ops dai_ops;
373
374 /* DAI capabilities */
375 struct snd_soc_pcm_stream capture;
376 struct snd_soc_pcm_stream playback;
377
378 /* DAI runtime info */
379 struct snd_pcm_runtime *runtime;
380 unsigned char active:1;
381 void *dma_data;
382
383 /* DAI private data */
384 void *private_data;
385 };
386
387 /* SoC Audio Codec */
388 struct snd_soc_codec {
389 char *name;
390 struct module *owner;
391 struct mutex mutex;
392
393 /* callbacks */
394 int (*set_bias_level)(struct snd_soc_codec *,
395 enum snd_soc_bias_level level);
396
397 /* runtime */
398 struct snd_card *card;
399 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
400 unsigned int active;
401 unsigned int pcm_devs;
402 void *private_data;
403
404 /* codec IO */
405 void *control_data; /* codec control (i2c/3wire) data */
406 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
407 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
408 hw_write_t hw_write;
409 hw_read_t hw_read;
410 void *reg_cache;
411 short reg_cache_size;
412 short reg_cache_step;
413
414 /* dapm */
415 struct list_head dapm_widgets;
416 struct list_head dapm_paths;
417 enum snd_soc_bias_level bias_level;
418 enum snd_soc_bias_level suspend_bias_level;
419 struct delayed_work delayed_work;
420
421 /* codec DAI's */
422 struct snd_soc_codec_dai *dai;
423 unsigned int num_dai;
424 };
425
426 /* codec device */
427 struct snd_soc_codec_device {
428 int (*probe)(struct platform_device *pdev);
429 int (*remove)(struct platform_device *pdev);
430 int (*suspend)(struct platform_device *pdev, pm_message_t state);
431 int (*resume)(struct platform_device *pdev);
432 };
433
434 /* SoC platform interface */
435 struct snd_soc_platform {
436 char *name;
437
438 int (*probe)(struct platform_device *pdev);
439 int (*remove)(struct platform_device *pdev);
440 int (*suspend)(struct platform_device *pdev,
441 struct snd_soc_cpu_dai *cpu_dai);
442 int (*resume)(struct platform_device *pdev,
443 struct snd_soc_cpu_dai *cpu_dai);
444
445 /* pcm creation and destruction */
446 int (*pcm_new)(struct snd_card *, struct snd_soc_codec_dai *,
447 struct snd_pcm *);
448 void (*pcm_free)(struct snd_pcm *);
449
450 /* platform stream ops */
451 struct snd_pcm_ops *pcm_ops;
452 };
453
454 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
455 struct snd_soc_dai_link {
456 char *name; /* Codec name */
457 char *stream_name; /* Stream name */
458
459 /* DAI */
460 struct snd_soc_codec_dai *codec_dai;
461 struct snd_soc_cpu_dai *cpu_dai;
462
463 /* machine stream operations */
464 struct snd_soc_ops *ops;
465
466 /* codec/machine specific init - e.g. add machine controls */
467 int (*init)(struct snd_soc_codec *codec);
468
469 /* DAI pcm */
470 struct snd_pcm *pcm;
471 };
472
473 /* SoC machine */
474 struct snd_soc_machine {
475 char *name;
476
477 int (*probe)(struct platform_device *pdev);
478 int (*remove)(struct platform_device *pdev);
479
480 /* the pre and post PM functions are used to do any PM work before and
481 * after the codec and DAI's do any PM work. */
482 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
483 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
484 int (*resume_pre)(struct platform_device *pdev);
485 int (*resume_post)(struct platform_device *pdev);
486
487 /* callbacks */
488 int (*set_bias_level)(struct snd_soc_machine *,
489 enum snd_soc_bias_level level);
490
491 /* CPU <--> Codec DAI links */
492 struct snd_soc_dai_link *dai_link;
493 int num_links;
494 };
495
496 /* SoC Device - the audio subsystem */
497 struct snd_soc_device {
498 struct device *dev;
499 struct snd_soc_machine *machine;
500 struct snd_soc_platform *platform;
501 struct snd_soc_codec *codec;
502 struct snd_soc_codec_device *codec_dev;
503 struct delayed_work delayed_work;
504 void *codec_data;
505 };
506
507 /* runtime channel data */
508 struct snd_soc_pcm_runtime {
509 struct snd_soc_dai_link *dai;
510 struct snd_soc_device *socdev;
511 };
512
513 /* enumerated kcontrol */
514 struct soc_enum {
515 unsigned short reg;
516 unsigned short reg2;
517 unsigned char shift_l;
518 unsigned char shift_r;
519 unsigned int mask;
520 const char **texts;
521 void *dapm;
522 };
523
524 #endif
This page took 0.058546 seconds and 5 git commands to generate.