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
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>
24 #define SND_SOC_VERSION "0.13.2"
27 * Convenience kcontrol builders
29 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
30 ((unsigned long)&(struct soc_mixer_control) \
31 {.reg = xreg, .shift = xshift, .max = xmax, .invert = xinvert})
32 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
33 ((unsigned long)&(struct soc_mixer_control) \
34 {.reg = xreg, .max = xmax, .invert = xinvert})
35 #define SOC_SINGLE(xname, reg, shift, max, invert) \
36 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
37 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
38 .put = snd_soc_put_volsw, \
39 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
40 #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
41 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
42 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
43 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
44 .tlv.p = (tlv_array), \
45 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
46 .put = snd_soc_put_volsw, \
47 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
48 #define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
49 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
50 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
51 .put = snd_soc_put_volsw, \
52 .private_value = (unsigned long)&(struct soc_mixer_control) \
53 {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
54 .max = xmax, .invert = xinvert} }
55 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
56 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
57 .info = snd_soc_info_volsw_2r, \
58 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
59 .private_value = (unsigned long)&(struct soc_mixer_control) \
60 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
61 .max = xmax, .invert = xinvert} }
62 #define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
63 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
64 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
65 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
66 .tlv.p = (tlv_array), \
67 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
68 .put = snd_soc_put_volsw, \
69 .private_value = (unsigned long)&(struct soc_mixer_control) \
70 {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
71 .max = xmax, .invert = xinvert} }
72 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
73 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
74 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
75 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
76 .tlv.p = (tlv_array), \
77 .info = snd_soc_info_volsw_2r, \
78 .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
79 .private_value = (unsigned long)&(struct soc_mixer_control) \
80 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
81 .max = xmax, .invert = xinvert} }
82 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
83 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
84 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
85 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
86 .tlv.p = (tlv_array), \
87 .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
88 .put = snd_soc_put_volsw_s8, \
89 .private_value = (unsigned long)&(struct soc_mixer_control) \
90 {.reg = xreg, .min = xmin, .max = xmax} }
91 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
92 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
93 .max = xmax, .texts = xtexts }
94 #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
95 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
96 #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
97 { .max = xmax, .texts = xtexts }
98 #define SOC_ENUM(xname, xenum) \
99 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
100 .info = snd_soc_info_enum_double, \
101 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
102 .private_value = (unsigned long)&xenum }
103 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
104 xhandler_get, xhandler_put) \
105 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
106 .info = snd_soc_info_volsw, \
107 .get = xhandler_get, .put = xhandler_put, \
108 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
109 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
110 xhandler_get, xhandler_put, tlv_array) \
111 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
112 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
113 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
114 .tlv.p = (tlv_array), \
115 .info = snd_soc_info_volsw, \
116 .get = xhandler_get, .put = xhandler_put, \
117 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
118 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
119 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
120 .info = snd_soc_info_bool_ext, \
121 .get = xhandler_get, .put = xhandler_put, \
122 .private_value = xdata }
123 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
124 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
125 .info = snd_soc_info_enum_ext, \
126 .get = xhandler_get, .put = xhandler_put, \
127 .private_value = (unsigned long)&xenum }
132 * @ON: Bias is fully on for audio playback and capture operations.
133 * @PREPARE: Prepare for audio operations. Called before DAPM switching for
134 * stream start and stop operations.
135 * @STANDBY: Low power standby state when no playback/capture operations are
136 * in progress. NOTE: The transition time between STANDBY and ON
137 * should be as fast as possible and no longer than 10ms.
138 * @OFF: Power Off. No restrictions on transition times.
140 enum snd_soc_bias_level {
142 SND_SOC_BIAS_PREPARE,
143 SND_SOC_BIAS_STANDBY,
148 * Digital Audio Interface (DAI) types
150 #define SND_SOC_DAI_AC97 0x1
151 #define SND_SOC_DAI_I2S 0x2
152 #define SND_SOC_DAI_PCM 0x4
153 #define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
156 * DAI hardware audio formats
158 #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
159 #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
160 #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
161 #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
162 #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
163 #define SND_SOC_DAIFMT_AC97 5 /* AC97 */
165 #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
166 #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
171 #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
172 #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
176 * Synchronous LR (Left Right) clocks and Frame signals.
178 #define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */
179 #define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */
184 #define SND_SOC_DAIFMT_TDM (1 << 6)
187 * DAI hardware signal inversions
189 #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bclk + frm */
190 #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
191 #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
192 #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
195 * DAI hardware clock masters
196 * This is wrt the codec, the inverse is true for the interface
197 * i.e. if the codec is clk and frm master then the interface is
198 * clk and frame slave.
200 #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
201 #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
202 #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
203 #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
205 #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
206 #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
207 #define SND_SOC_DAIFMT_INV_MASK 0x0f00
208 #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
212 * Master Clock Directions
214 #define SND_SOC_CLOCK_IN 0
215 #define SND_SOC_CLOCK_OUT 1
218 * AC97 codec ID's bitmask
220 #define SND_SOC_DAI_AC97_ID0 (1 << 0)
221 #define SND_SOC_DAI_AC97_ID1 (1 << 1)
222 #define SND_SOC_DAI_AC97_ID2 (1 << 2)
223 #define SND_SOC_DAI_AC97_ID3 (1 << 3)
225 struct snd_soc_device;
226 struct snd_soc_pcm_stream;
228 struct snd_soc_dai_mode;
229 struct snd_soc_pcm_runtime;
231 struct snd_soc_codec;
232 struct snd_soc_machine_config;
234 struct snd_soc_ac97_ops;
235 struct snd_soc_clock_info;
237 typedef int (*hw_write_t)(void *,const char* ,int);
238 typedef int (*hw_read_t)(void *,char* ,int);
240 extern struct snd_ac97_bus_ops soc_ac97_ops;
242 /* pcm <-> DAI connect */
243 void snd_soc_free_pcms(struct snd_soc_device *socdev);
244 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
245 int snd_soc_register_card(struct snd_soc_device *socdev);
247 /* set runtime hw params */
248 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
249 const struct snd_pcm_hardware *hw);
252 #define snd_soc_read(codec, reg) codec->read(codec, reg)
253 #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
255 /* codec register bit access */
256 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
257 unsigned short mask, unsigned short value);
258 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
259 unsigned short mask, unsigned short value);
261 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
262 struct snd_ac97_bus_ops *ops, int num);
263 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
265 /* Digital Audio Interface clocking API.*/
266 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
267 unsigned int freq, int dir);
269 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
270 int div_id, int div);
272 int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
273 int pll_id, unsigned int freq_in, unsigned int freq_out);
275 /* Digital Audio interface formatting */
276 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
278 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
279 unsigned int mask, int slots);
281 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
283 /* Digital Audio Interface mute */
284 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
289 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
290 void *data, char *long_name);
291 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_info *uinfo);
293 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_info *uinfo);
295 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol);
297 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol);
299 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_info *uinfo);
301 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
302 struct snd_ctl_elem_info *uinfo);
303 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
304 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol);
306 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
307 struct snd_ctl_elem_value *ucontrol);
308 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_info *uinfo);
310 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
311 struct snd_ctl_elem_value *ucontrol);
312 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol);
314 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_info *uinfo);
316 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
317 struct snd_ctl_elem_value *ucontrol);
318 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_value *ucontrol);
321 /* SoC PCM stream information */
322 struct snd_soc_pcm_stream {
324 u64 formats; /* SNDRV_PCM_FMTBIT_* */
325 unsigned int rates; /* SNDRV_PCM_RATE_* */
326 unsigned int rate_min; /* min rate */
327 unsigned int rate_max; /* max rate */
328 unsigned int channels_min; /* min channels */
329 unsigned int channels_max; /* max channels */
330 unsigned int active:1; /* stream is in use */
335 int (*startup)(struct snd_pcm_substream *);
336 void (*shutdown)(struct snd_pcm_substream *);
337 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
338 int (*hw_free)(struct snd_pcm_substream *);
339 int (*prepare)(struct snd_pcm_substream *);
340 int (*trigger)(struct snd_pcm_substream *, int);
344 struct snd_soc_dai_ops {
345 /* DAI clocking configuration */
346 int (*set_sysclk)(struct snd_soc_dai *dai,
347 int clk_id, unsigned int freq, int dir);
348 int (*set_pll)(struct snd_soc_dai *dai,
349 int pll_id, unsigned int freq_in, unsigned int freq_out);
350 int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
352 /* DAI format configuration */
353 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
354 int (*set_tdm_slot)(struct snd_soc_dai *dai,
355 unsigned int mask, int slots);
356 int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
359 int (*digital_mute)(struct snd_soc_dai *dai, int mute);
362 /* SoC DAI (Digital Audio Interface) */
364 /* DAI description */
370 int (*probe)(struct platform_device *pdev,
371 struct snd_soc_dai *dai);
372 void (*remove)(struct platform_device *pdev,
373 struct snd_soc_dai *dai);
374 int (*suspend)(struct platform_device *pdev,
375 struct snd_soc_dai *dai);
376 int (*resume)(struct platform_device *pdev,
377 struct snd_soc_dai *dai);
380 struct snd_soc_ops ops;
381 struct snd_soc_dai_ops dai_ops;
383 /* DAI capabilities */
384 struct snd_soc_pcm_stream capture;
385 struct snd_soc_pcm_stream playback;
387 /* DAI runtime info */
388 struct snd_pcm_runtime *runtime;
389 struct snd_soc_codec *codec;
391 unsigned char pop_wait:1;
394 /* DAI private data */
398 /* SoC Audio Codec */
399 struct snd_soc_codec {
401 struct module *owner;
405 int (*set_bias_level)(struct snd_soc_codec *,
406 enum snd_soc_bias_level level);
409 struct snd_card *card;
410 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
412 unsigned int pcm_devs;
416 void *control_data; /* codec control (i2c/3wire) data */
417 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
418 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
419 int (*display_register)(struct snd_soc_codec *, char *,
420 size_t, unsigned int);
424 short reg_cache_size;
425 short reg_cache_step;
428 struct list_head dapm_widgets;
429 struct list_head dapm_paths;
430 enum snd_soc_bias_level bias_level;
431 enum snd_soc_bias_level suspend_bias_level;
432 struct delayed_work delayed_work;
435 struct snd_soc_dai *dai;
436 unsigned int num_dai;
440 struct snd_soc_codec_device {
441 int (*probe)(struct platform_device *pdev);
442 int (*remove)(struct platform_device *pdev);
443 int (*suspend)(struct platform_device *pdev, pm_message_t state);
444 int (*resume)(struct platform_device *pdev);
447 /* SoC platform interface */
448 struct snd_soc_platform {
451 int (*probe)(struct platform_device *pdev);
452 int (*remove)(struct platform_device *pdev);
453 int (*suspend)(struct platform_device *pdev,
454 struct snd_soc_dai *dai);
455 int (*resume)(struct platform_device *pdev,
456 struct snd_soc_dai *dai);
458 /* pcm creation and destruction */
459 int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
461 void (*pcm_free)(struct snd_pcm *);
463 /* platform stream ops */
464 struct snd_pcm_ops *pcm_ops;
467 /* SoC machine DAI configuration, glues a codec and cpu DAI together */
468 struct snd_soc_dai_link {
469 char *name; /* Codec name */
470 char *stream_name; /* Stream name */
473 struct snd_soc_dai *codec_dai;
474 struct snd_soc_dai *cpu_dai;
476 /* machine stream operations */
477 struct snd_soc_ops *ops;
479 /* codec/machine specific init - e.g. add machine controls */
480 int (*init)(struct snd_soc_codec *codec);
487 struct snd_soc_machine {
490 int (*probe)(struct platform_device *pdev);
491 int (*remove)(struct platform_device *pdev);
493 /* the pre and post PM functions are used to do any PM work before and
494 * after the codec and DAI's do any PM work. */
495 int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
496 int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
497 int (*resume_pre)(struct platform_device *pdev);
498 int (*resume_post)(struct platform_device *pdev);
501 int (*set_bias_level)(struct snd_soc_machine *,
502 enum snd_soc_bias_level level);
504 /* CPU <--> Codec DAI links */
505 struct snd_soc_dai_link *dai_link;
509 /* SoC Device - the audio subsystem */
510 struct snd_soc_device {
512 struct snd_soc_machine *machine;
513 struct snd_soc_platform *platform;
514 struct snd_soc_codec *codec;
515 struct snd_soc_codec_device *codec_dev;
516 struct delayed_work delayed_work;
517 struct work_struct deferred_resume_work;
521 /* runtime channel data */
522 struct snd_soc_pcm_runtime {
523 struct snd_soc_dai_link *dai;
524 struct snd_soc_device *socdev;
528 struct soc_mixer_control {
530 unsigned int reg, rreg, shift, rshift, invert;
533 /* enumerated kcontrol */
537 unsigned char shift_l;
538 unsigned char shift_r;