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