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(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) |\
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 }
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.
125 enum snd_soc_bias_level
{
127 SND_SOC_BIAS_PREPARE
,
128 SND_SOC_BIAS_STANDBY
,
133 * Digital Audio Interface (DAI) types
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 */
141 * DAI hardware audio formats
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 */
150 #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
151 #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
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 */
161 * Synchronous LR (Left Right) clocks and Frame signals.
163 #define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */
164 #define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */
169 #define SND_SOC_DAIFMT_TDM (1 << 6)
172 * DAI hardware signal inversions
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 */
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.
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 */
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
197 * Master Clock Directions
199 #define SND_SOC_CLOCK_IN 0
200 #define SND_SOC_CLOCK_OUT 1
203 * AC97 codec ID's bitmask
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)
210 struct snd_soc_device
;
211 struct snd_soc_pcm_stream
;
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
;
220 struct snd_soc_ac97_ops
;
221 struct snd_soc_clock_info
;
223 typedef int (*hw_write_t
)(void *,const char* ,int);
224 typedef int (*hw_read_t
)(void *,char* ,int);
226 extern struct snd_ac97_bus_ops soc_ac97_ops
;
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
);
233 /* set runtime hw params */
234 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
235 const struct snd_pcm_hardware
*hw
);
238 #define snd_soc_read(codec, reg) codec->read(codec, reg)
239 #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
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
);
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
);
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
);
286 /* SoC PCM stream information */
287 struct snd_soc_pcm_stream
{
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 */
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);
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
);
318 /* DAI format configuration */
319 int (*set_fmt
)(struct snd_soc_codec_dai
*codec_dai
,
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
);
326 int (*digital_mute
)(struct snd_soc_codec_dai
*, int mute
);
330 struct snd_soc_codec_dai
{
335 /* DAI capabilities */
336 struct snd_soc_pcm_stream playback
;
337 struct snd_soc_pcm_stream capture
;
339 /* DAI runtime info */
340 struct snd_soc_codec
*codec
;
342 unsigned char pop_wait
:1;
345 struct snd_soc_ops ops
;
346 struct snd_soc_dai_ops dai_ops
;
348 /* DAI private data */
353 struct snd_soc_cpu_dai
{
355 /* DAI description */
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
);
371 struct snd_soc_ops ops
;
372 struct snd_soc_dai_ops dai_ops
;
374 /* DAI capabilities */
375 struct snd_soc_pcm_stream capture
;
376 struct snd_soc_pcm_stream playback
;
378 /* DAI runtime info */
379 struct snd_pcm_runtime
*runtime
;
380 unsigned char active
:1;
383 /* DAI private data */
387 /* SoC Audio Codec */
388 struct snd_soc_codec
{
390 struct module
*owner
;
394 int (*set_bias_level
)(struct snd_soc_codec
*,
395 enum snd_soc_bias_level level
);
398 struct snd_card
*card
;
399 struct snd_ac97
*ac97
; /* for ad-hoc ac97 devices */
401 unsigned int pcm_devs
;
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);
411 short reg_cache_size
;
412 short reg_cache_step
;
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
;
422 struct snd_soc_codec_dai
*dai
;
423 unsigned int num_dai
;
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
);
434 /* SoC platform interface */
435 struct snd_soc_platform
{
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
);
445 /* pcm creation and destruction */
446 int (*pcm_new
)(struct snd_card
*, struct snd_soc_codec_dai
*,
448 void (*pcm_free
)(struct snd_pcm
*);
450 /* platform stream ops */
451 struct snd_pcm_ops
*pcm_ops
;
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 */
460 struct snd_soc_codec_dai
*codec_dai
;
461 struct snd_soc_cpu_dai
*cpu_dai
;
463 /* machine stream operations */
464 struct snd_soc_ops
*ops
;
466 /* codec/machine specific init - e.g. add machine controls */
467 int (*init
)(struct snd_soc_codec
*codec
);
474 struct snd_soc_machine
{
477 int (*probe
)(struct platform_device
*pdev
);
478 int (*remove
)(struct platform_device
*pdev
);
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
);
488 int (*set_bias_level
)(struct snd_soc_machine
*,
489 enum snd_soc_bias_level level
);
491 /* CPU <--> Codec DAI links */
492 struct snd_soc_dai_link
*dai_link
;
496 /* SoC Device - the audio subsystem */
497 struct snd_soc_device
{
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
;
507 /* runtime channel data */
508 struct snd_soc_pcm_runtime
{
509 struct snd_soc_dai_link
*dai
;
510 struct snd_soc_device
*socdev
;
513 /* enumerated kcontrol */
517 unsigned char shift_l
;
518 unsigned char shift_r
;